Skip to content

feat: add opt-in CoDel load shedding#450

Merged
pratyush618 merged 7 commits into
masterfrom
feat/s27-codel
Jul 18, 2026
Merged

feat: add opt-in CoDel load shedding#450
pratyush618 merged 7 commits into
masterfrom
feat/s27-codel

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Opt-in CoDel (Controlled Delay, RFC 8289) load shedding per queue (S27, Tier 4). Under sustained overload — a job's wait past its eligibility staying above target for a full interval — the dispatcher sheds the stalest jobs to the DLQ instead of running them stale. A transient spike is never shed; that's the whole point of CoDel over a fixed max-age cutoff. Off by default.

Design

  • scheduler/codel.rs — the CoDel controller (should_drop, interval / sqrt(count) control law), unit-tested with explicit time (no wall clock).
  • Enforced in the poller before the claim (codel_admit): the job is still Pending, so move_to_dlq is uniform across backends and leaves no dangling execution claim. Sojourn is measured from scheduled_at, so an intentional delay is never counted as staleness.
  • Shed reason is prefixed codel:; the DLQ auto-retry sweep skips those entries so dropped jobs aren't resurrected.
  • Kept off QueueConfig (its own codel_configs map + register_queue_codel) so the common no-CoDel path pays nothing.

Cross-SDK surface

  • Pythonset_queue_codel(queue, target_ms, interval_ms).
  • NodeconfigureQueue(q, { codel: { targetMs, intervalMs } }).
  • JavaTaskito.codel(queue, targetMs, intervalMs) (adds the per-queue config path to the Java worker options).

Tests

  • Rust: 5 controller unit tests (below-target, transient spike, sustained overload, recovery, drop-rate bound) + 2 integration tests (shed→DLQ, uncapped no-op).
  • Python 3 · Node 1 · Java 2 behavioral tests. Full suites green; clippy / ruff / mypy / biome / tsc clean.

Summary by CodeRabbit

  • New Features
    • Added opt-in CoDel load shedding for individual queues (per-queue target/interval).
    • Under sustained overload, stale jobs are shed to the dead-letter queue with a codel:-prefixed reason.
    • Exposed CoDel queue configuration across Java, Node.js, and Python SDKs.
  • Bug Fixes
    • CoDel-shed dead-letter entries are no longer retried by the DLQ auto-retry sweep.
  • Documentation
    • Added/updated SDK-facing configuration fields and guidance for CoDel timing settings.
  • Tests
    • Added end-to-end and SDK-level tests covering admission, sustained overload shedding, and parameter validation.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ddcbcc02-37f8-42ee-966c-2140bc2fba57

📥 Commits

Reviewing files that changed from the base of the PR and between f5f3609 and 219e265.

📒 Files selected for processing (1)
  • sdks/node/src/queue.ts
📝 Walkthrough

Walkthrough

Adds opt-in per-queue Classic CoDel load shedding to the scheduler, routes shed jobs to the DLQ with codel: reasons, prevents their auto-retry, and exposes configuration through Java, Node, and Python SDKs.

Changes

CoDel load shedding

Layer / File(s) Summary
Controller state and drop scheduling
crates/taskito-core/src/scheduler/codel.rs
Defines CoDel configuration and state, applies sustained-sojourn drop decisions, increases drop frequency during overload, and tests recovery and timing behavior.
Scheduler admission and DLQ handling
crates/taskito-core/src/scheduler/{mod.rs,poller.rs,maintenance.rs}
Registers per-queue CoDel settings, evaluates jobs before dispatch, moves shed jobs to the DLQ with codel: metadata, and excludes them from automatic retry.

Runtime configuration wiring

Layer / File(s) Summary
Worker startup adapters
crates/taskito-java/src/{convert.rs,worker.rs}, crates/taskito-node/src/{config.rs,convert/*,worker.rs}, crates/taskito-python/src/py_queue/worker.rs
Translates runtime queue settings into validated CodelConfig values and registers them during worker startup.

Java SDK configuration

Layer / File(s) Summary
Java queue API and worker transport
sdks/java/src/main/java/org/byteveda/taskito/{Taskito.java,DefaultTaskito.java,worker/Worker.java}
Adds the queue-scoped codel API, stores settings, encodes worker queue configurations, and forwards non-empty settings to native workers.
Java end-to-end coverage
sdks/java/src/test/java/org/byteveda/taskito/core/CodelTest.java
Validates parameter rejection, overload shedding, job accounting, and late configuration application.

Node and Python SDK configuration

Layer / File(s) Summary
Node and Python queue settings
sdks/node/src/{types.ts,queue.ts,worker.ts}, sdks/python/taskito/mixins/runtime_config.py
Adds optional Node queue limits and Python runtime configuration for positive CoDel target and interval values.
Node and Python validation
sdks/node/test/core/codel.test.ts, sdks/python/tests/core/test_codel.py
Covers input validation, overload shedding, completed/dead job accounting, and protection of CoDel DLQ entries from auto-retry.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SDK
  participant Worker
  participant Scheduler
  participant CodelState
  participant DLQ
  SDK->>Worker: provide per-queue CoDel settings
  Worker->>Scheduler: register_queue_codel
  Scheduler->>CodelState: evaluate job sojourn time before dispatch
  CodelState-->>Scheduler: return drop decision
  Scheduler->>DLQ: move shed job with codel: reason
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding opt-in CoDel load shedding.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/s27-codel

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/taskito-core/src/scheduler/maintenance.rs (1)

313-335: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Prevent CoDel entries from starving ordinary DLQ retries.

The 50-row candidate limit is applied before this filter. If the selected window contains only permanent codel: entries, every sweep skips the same rows and eligible non-CoDel entries behind them are never retried. Filter CoDel rows in list_dead_for_retry, or page past skipped rows until retryable candidates are found; add a regression test with 50 CoDel entries followed by a normal retryable entry.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/taskito-core/src/scheduler/maintenance.rs` around lines 313 - 335, The
retry sweep in the maintenance flow must not let skipped CoDel entries consume
the fixed candidate window. Update list_dead_for_retry or the surrounding
pagination logic to exclude codel: entries before applying the 50-row limit, or
continue fetching pages until retryable candidates are collected; preserve
existing retry behavior and add a regression test covering 50 CoDel entries
followed by one retryable entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java`:
- Around line 1112-1113: The worker currently captures queue configurations when
the builder is created instead of when it starts. In DefaultTaskito, pass a
late-bound queue-config source; update Worker’s construction and
option-serialization flow to retain that source and resolve the latest
configurations immediately before serialization, and add the CodelTest
regression covering builder creation before Taskito.codel(...) configuration
followed by startup and shedding verification.

In `@sdks/node/src/types.ts`:
- Around line 176-182: Update Queue.configureQueue to validate codel.targetMs
and codel.intervalMs before forwarding them to native code, requiring each value
to be a positive finite integer and rejecting zero, negatives, fractions, NaN,
and infinities. Reuse the existing queue option validation pattern and add Node
tests covering invalid CoDel inputs.

---

Outside diff comments:
In `@crates/taskito-core/src/scheduler/maintenance.rs`:
- Around line 313-335: The retry sweep in the maintenance flow must not let
skipped CoDel entries consume the fixed candidate window. Update
list_dead_for_retry or the surrounding pagination logic to exclude codel:
entries before applying the 50-row limit, or continue fetching pages until
retryable candidates are collected; preserve existing retry behavior and add a
regression test covering 50 CoDel entries followed by one retryable entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d8b809ad-6c81-4113-aee2-57ea11760ca4

📥 Commits

Reviewing files that changed from the base of the PR and between 8df8819 and 1abe90d.

📒 Files selected for processing (20)
  • crates/taskito-core/src/scheduler/codel.rs
  • crates/taskito-core/src/scheduler/maintenance.rs
  • crates/taskito-core/src/scheduler/mod.rs
  • crates/taskito-core/src/scheduler/poller.rs
  • crates/taskito-java/src/convert.rs
  • crates/taskito-java/src/worker.rs
  • crates/taskito-node/src/config.rs
  • crates/taskito-node/src/convert/mod.rs
  • crates/taskito-node/src/convert/task_config.rs
  • crates/taskito-node/src/worker.rs
  • crates/taskito-python/src/py_queue/worker.rs
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/Taskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/Worker.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/CodelTest.java
  • sdks/node/src/types.ts
  • sdks/node/src/worker.ts
  • sdks/node/test/core/codel.test.ts
  • sdks/python/taskito/mixins/runtime_config.py
  • sdks/python/tests/core/test_codel.py

Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java Outdated
Comment thread sdks/node/src/types.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/node/src/queue.ts`:
- Around line 397-404: Update the limits validation and storage flow around the
codel checks to snapshot the configuration after validation. Store a
shallow-copied limits object and a separately copied codel object so later
caller mutations to targetMs or intervalMs cannot affect runWorker().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69a851df-3d17-4858-9b29-66691c9fd999

📥 Commits

Reviewing files that changed from the base of the PR and between 1abe90d and f5f3609.

📒 Files selected for processing (5)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/Worker.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/CodelTest.java
  • sdks/node/src/queue.ts
  • sdks/node/test/core/codel.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java

Comment thread sdks/node/src/queue.ts
@pratyush618
pratyush618 merged commit cb6bc0e into master Jul 18, 2026
35 checks passed
@pratyush618
pratyush618 deleted the feat/s27-codel branch July 18, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant