Skip to content

fix(router): make the per-class decode wait limit correct for disaggregated serving - #18056

Draft
ishandhanani wants to merge 21 commits into
ai-dynamo:mainfrom
ishandhanani:idhanani/dyn-16543-disagg-decode-gate
Draft

ishandhanani wants to merge 21 commits into
ai-dynamo:mainfrom
ishandhanani:idhanani/dyn-16543-disagg-decode-gate

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#16618 added a per-class decode limit, policy_classes[].decode_busy_threshold_frac, to the policy-class queue. It works in aggregated serving. In disaggregated serving it is wrong:

  • The prefill router and the decode router both run a policy-class queue with the same policy file.
  • The prefill router does not track held KV blocks, so the decode limit does nothing there.
  • The decode router can hold a decode request after its prefill has started. This keeps prefill KV in place and breaks SGLang bootstrap, where prefill and decode must run at the same time.

This PR makes the prefill queue the only admission gate in disaggregated KV routing. The decode queue holds nothing.

  • Prefill queue: checks the class prefill limit on the prefill workers and the class decode limit on the decode workers. It reads the decode router's booked load directly, without a message to the decode actor. When decode KV is freed, a RoomChanged signal wakes the prefill queue.
  • Decode queue: books every RequestPhase::Decode request at once, with no class wait and no deadline. Router-wide reject thresholds, such as --active-decode-blocks-threshold, still apply at worker selection.
  • Aggregated serving: no change.

The BusyThresholds::has_room decode check from #16618 and the reject path do not change.

Code changes:

  • lib/kv-router: adds a PairedPoolRoom hook that a host installs with set_paired_pool. Only classes that set decode_busy_threshold_frac use it. LocalScheduler::any_rank_has_room reads booked load. An in-process admitted_upstream flag tells the queue to book a request directly. Wire types do not change.
  • lib/llm: the frontend installs the decode RoutingHost on the PrefillRouter for all KV routing, not only for conditional disagg. Each prefill KV router gets a DecodePoolRoom that points to the decode router. RoutingHost books every decode-phase request as AdmittedUpstream. Only the prefill router sets the decode phase, so aggregated requests keep the full class gate.

Known limits:

  • The decode check at the prefill hop is coarse. It uses decode worker reachability and the request's LoRA. It does not use a decode worker pin, allowed workers, routing constraints, or the KV-transfer domain. Decode worker selection still applies all of these.
  • A burst of prefill admissions can go past the decode limit, because each admission sees decode room before the earlier decode requests book.
  • If either hop does not use KV routing, no queue checks the decode limit.
  • A conditional-disagg bypass does not go through the prefill queue, so no class limit applies to it. Its only decode check is decode_busy_threshold in --router-conditional-disagg-config.
  • Request classifiers run only on the decode router, so the prefill hop does not know classes that a classifier sets.

Part of #16543

Validation

Run on main 73014901d4:

  • cargo fmt --all --check: pass.
  • cargo clippy -p dynamo-kv-router -p dynamo-llm --all-targets -- -D warnings: pass.
  • cargo test -p dynamo-kv-router --lib --features standalone-selection: 1433 passed, 0 failed, 3 ignored.
  • cargo test -p dynamo-llm --lib kv_router::: 492 passed, 0 failed.
  • cd lib/bindings/python && cargo check: pass.
  • pre-commit run --files <changed files>: pass.
  • python3 docs/fern/scripts/docs_lint.py <changed page>: 0 errors.

New tests:

  • disagg_decode_wait_limit_gates_the_prefill_hop_and_never_the_decode_hop: uses two real KV hosts with one policy file. Decode requests book past the decode limit with no wait. A new request waits at the prefill hop while decode is full, and freed decode KV releases it.
  • paired_pool_holds_until_its_room_signal_releases_the_request, paired_pool_rejects_a_never_queue_class_like_its_own_workers, paired_pool_is_ignored_by_classes_without_a_decode_limit: queue behavior with the hook.
  • admitted_upstream_skips_class_limits_but_not_reject_thresholds: a direct booking skips class limits and deadlines, but reject thresholds still apply.
  • pool_room_reads_booked_decode_blocks_and_signals_releases: the load read and the room signal.
  • kv_decode_host_resolves_the_decode_pool_without_conditional_disagg.

Performance: before the rebase, the aggregated queue-gate benchmark (selection_core no_hints_queue_gate) showed no regression at 64, 512, and 4096 workers. I did not run it again after the rebase.


Waiting on the author

The PR factory stopped at f87118f: the author's agent stopped before it finished.

  • NIT: PR description no longer describes the code at this head: Unchanged. The description is stale, but fixing it means editing the PR body, which is not among my allowed actions. Decide whether I rewrite it or you do. It needs the Decode queue and lib/llm bullets, the bypass known limit, the crate names, the validation commands and base co…
  • CI: still failing, and the factory cannot fix it

Kept up to date by the PR factory. An item goes when it is answered; this section goes when nothing is waiting.

Add a PairedPoolRoom hook a host installs on a scheduler (set_paired_pool).
A policy class with a decode_busy_threshold_frac then also waits until the
paired pool, the decode pool behind a prefill router, has a rank within that
fraction. The queue checks the hook with its own prefill check in the drain
path and in the never-queue direct path, and caches one answer per class per
gate pass for requests without a LoRA. Classes without a decode fraction
never consult it, and a scheduler with no hook is unchanged.

LocalScheduler::any_rank_has_room reads booked load from the slot registry
without a turn of the actor. subscribe_room_changed exposes a broadcast hint
(RoomChanged) fired on releases, cleanup drains, peer-router state and worker
config changes. It is separate from the actor's notify_one CapacityUpdates so
a paired queue never steals the actor's permits.

ScheduleRequest and SelectionOperation carry an in-process admitted_upstream
flag: the queue books such a request directly, with no class wait and no
deadline expiry, while selection still applies reject thresholds.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
…egated serving

In disaggregated KV routing the prefill and decode routers both run a
policy-class queue with the same profile. The class decode wait limit did
nothing on the prefill router, which tracks no held blocks, and on the
decode router it could hold a decode leg after its prefill was dispatched,
stranding prefill KV and breaking SGLang bootstrap.

Make the prefill hop the only gate. The frontend now installs the decode
RoutingHost on the PrefillRouter whenever routing is KV, and every prefill
binding's KV router judges class decode limits on a lazily resolved
DecodePoolRoom over the decode router: its booked load, reachable workers and
the request's LoRA through the decode router's own availability filter. Until
the decode host exists the pool reports room. RoutingHost books every decode-phase
request as AdmittedUpstream, so the decode queue never holds or expires one:
a decode leg whose prefill is running and a conditional-disagg bypass alike.
Only the prefill router sets the decode phase, so aggregated requests keep
the full class gate.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
State where decode_busy_threshold_frac is judged: on the same workers in
aggregated serving, and at the prefill hop against the decode pool in
disaggregated KV routing, where the decode hop books legs without waiting.
List what the pool-level decode check applies and what decode selection
still enforces.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 4, 2026 09:41 — with GitHub Actions Inactive
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 4, 2026 09:41 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added fix external-contribution Pull request is from an external contributor labels Nov 4, 2026
@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 2be8ec8

@github-actions github-actions Bot added documentation Improvements or additions to documentation router Relates to routing, KV-aware routing, etc. labels Nov 4, 2026

@ishandhanani ishandhanani left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Round 1 AI review

Automated review (round 1 of up to 2 before a human review). Findings may be wrong; reply on a thread to dispute one.

This PR makes the prefill hop's policy-class queue the only admission gate in KV-routed disaggregated serving. The prefill queue now checks each class's decode_busy_threshold_frac against the decode router's booked load through a PairedPoolRoom hook and wakes on a RoomChanged signal. The decode hop books decode-phase requests directly. I read the wiring, the wake path (every decode free path calls capacity_changed or direct_release, and the prefill actor subscribes before its first answer), and the new tests, and found them sound. One problem remains: decode-phase requests are mapped to AdmittedUpstream by phase alone, so conditional-disagg bypass requests lose all class gating even though nothing upstream admitted them and they hold no prefill KV.

New findings: 1 BUG

The next AI round runs after new commits are pushed.

@devin-ai-integration

devin-ai-integration Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Dynamo PR CI passed — run 45079071102 (attempt 1) on f87118f5d4

Gate checks: ✅ backend-status-check · ✅ deploy-status-check · ✅ dynamo-status-check

Posted automatically by Devin for run 45079071102. Updated on every full-CI run of this PR.

The decode hop booked every decode-phase request as AdmittedUpstream,
including a conditional-disagg bypass. A bypass never passes the prefill
queue and holds no staged KV, so it lost every class limit, queue limit
and deadline. Book directly only decode legs with staged KV; the bypass
keeps the decode queue's full class gate, as before this change.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 4, 2026 12:46 — with GitHub Actions Inactive
@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test d5dd600

@ishandhanani ishandhanani left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Round 2 AI review

Automated review (round 2 of up to 2 before a human review). Findings may be wrong; reply on a thread to dispute one.

The new commit fixes the round-1 finding. The decode hop now books directly only decode legs that are in the decode phase and have staged KV. A conditional-disagg bypass keeps the full class gate at the decode router, which is the pre-PR behavior and correct, because that request never passed the prefill queue and holds no prefill KV. The docs, the code comments, and the end-to-end test are updated to match: the test now shows the bypass waiting while decode is full and being released when decode KV is freed. I found no new issues in the changed code.

New findings: none
Earlier findings: 1 fixed, 0 no longer apply, 0 still open

The author's agent picks up this feedback next.

…ng request

make_scheduling_request no longer returns it as a third tuple element that the advisory path discards.
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 4, 2026 12:54 — with GitHub Actions Inactive
@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 2356540

@ishandhanani ishandhanani left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deslop · 1 cleanup · d5dd600 → 2356540

Automated deslop of this PR's own diff: duplicate or redundant new structures, one-use abstractions, dead paths, and comments a person would not write, with behavior unchanged.

Read through the whole PR diff (7301490..d5dd600) and made one cleanup. It is pushed as a fast-forward with no rewrite, and the worktree was already clean, so nothing was stashed. The cleanup: make_scheduling_request had grown a third return value, admitted_upstream. Its one user, the admitted path, now reads request.admitted_upstream before the call, and the function signature and the advisory call site are back to how they were on main. Behavior is unchanged: the advisory path ignored the flag before and still does. Checks: cargo check -p dynamo-kv-router builds clean, cargo test -p dynamo-kv-router --lib scheduling:: passes (316 passed, 1 ignored), cargo fmt --check is clean, and the commit is signed. Things I looked at and left alone: (1) KvRouter::set_paired_pool has two callers (activation and a routing_host test). (2) KvRouter::subscribe_room_changed and ActiveSequencesMultiWorker::any_rank_has_room are one-line forwarders, but they sit at layer boundaries and the fields behind them are private. (3) RoomChanged exists so a second watcher cannot steal the actor's notify_one permits. (4) PairedPoolGate::changed and close_room_changed are needed for the select! borrow and to stop watching once the signal is closed. (5) pub(crate) mod decode_room is used by routing_host/tests.rs. (6) The admitted_upstream doc comments on ScheduleRequest, SelectionOperation and FindBestMatchAdmission each sit on a public or boundary type. (7) The comment in DecodePoolRoom::has_room states a rule that is easy to miss: a request this gate lets through is routed at decode exactly as it would be with no decode wait limit.

  • 235654044a make_scheduling_request returned a 3-tuple only to pass admitted_upstream through, and the advisory caller threw it away. The admitted path now reads the field before converting the request, and the destructure binds it as _, so the signature and both call sites match main again.

…sagg-decode-gate

# Conflicts:
#	lib/kv-router/src/scheduling/queue.rs
#	lib/kv-router/src/scheduling/types.rs
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 5, 2026 02:46 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · merged main into the branch (5b1fa3c), resolving 2 conflicts

Details

Why: the branch conflicts with main. Merged origin/main into the PR branch and pushed the merge as 5b1fa3c. It is a plain merge on top of the old head, so nothing was rewritten or force-pushed, and the worktree was clean so nothing was stashed. Two files conflicted: lib/kv-router/src/scheduling/queue.rs and types.rs. They clashed with main's admission queue rework (#17723 flat policy-class config, #17724 EDF ordering, #17725 controlled delay, #18008 Fx availability set). The rest merged automatically. Main's #17723 also removed the old policy-class YAML keys, so five tests the PR added (four in queue.rs, one in lib/llm/src/kv_router/routing_host/tests.rs) failed to parse their config; I moved them to the new flat format and they pass. Checks on the merge: cargo clippy --locked --no-deps -p dynamo-kv-router -p dynamo-llm -p dynamo-mocker --all-targets -- -D warnings is clean, cargo test -p dynamo-kv-router --lib scheduling:: passes (373 passed, 1 ignored), cargo test -p dynamo-llm --lib -- kv_router::routing_host kv_router::prefill_router passes (183), cargo fmt --check is clean, and the merge commit is signed.

  • lib/kv-router/src/scheduling/queue.rs: Main's restructure is kept: self.commands, begin_turn/class_timers, apply_command/drain_after_command, AdmissionContext, Admission, enforced_due_at, extract_next/settle, and AvailableWorkerIds. The PR's behavior is threaded through it. (1) The actor loop still wakes on the paired pool's room signal, now calling handle_update(None). (2) apply_command passes admitted_upstream through to handle_enqueue. (3) In handle_enqueue, the admitted-upstream early return now builds an AdmissionContext with due_at: None, so the leg is never held or expired, and returns admit_one(..) == Admission::Booked like main's direct paths. (4) The paired-pool check stays at all three gate sites (the never-queue check, has_dispatchable_ready_head, and the extract_next closure), now beside main's available_ids lookup. (5) Main's new tests now pass admitted_upstream: false / false, and the PR's paired-pool and admitted-upstream test configs use the flat YAML format.
  • lib/kv-router/src/scheduling/types.rs: Both sides added independent items at the same spot, so both are kept: main's WorkerIdSet and AvailableWorkerIds (perf(router): probe worker availability with an Fx set #18008), followed by the PR's PairedPoolRoom trait. The auto-merged lib/llm routing_host test also needed its DECODE_WAIT_LIMIT_POLICY config moved to the flat format; that edit is in the merge commit too.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 5b1fa3c

ishandhanani added a commit to ishandhanani/bb-plugins that referenced this pull request Nov 5, 2026
…your PRs get resolved; each action is logged and noted on the PR

On your own PR in Babysit, a failing CI pass now decides between re-running
failed jobs (flakes, infra, cancelled runs) and merging the base branch
(merge_base: only when the base has what fixes the failure); the author's
agent does the merge. A merge conflict goes straight to the author's agent
(a sync run, once per head): fetch the base, merge it in (no rebase, nothing
rewritten), resolve keeping both intents, run the narrowest checks, push.
A conflict that needs your call aborts the merge and asks you. Every re-run
and merge posts a short folded PR comment (CI babysit · ...) under the
factory marker, and each pass and sync is a telemetry job with outcomes
(babysit_outcome, conflicts_resolved, pushed). Other people's PRs keep
re-run or ask; we do not push to their branches.

Live on ai-dynamo/dynamo#18056: two conflicts with main's admission queue
rework resolved, five PR tests moved to main's new config format, merge
5b1fa3c455 pushed, PR mergeable again, comment posted.
…sagg-decode-gate

# Conflicts:
#	lib/llm/src/kv_router.rs
#	lib/router/scheduler/src/local.rs
#	lib/router/scheduler/src/queue.rs
#	lib/router/scheduler/src/types.rs
#	lib/router/slot-tracker/src/multi_worker.rs
#	lib/router/slot-tracker/src/prompt_registry.rs
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 11, 2026 03:06 — with GitHub Actions Inactive
@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 3935cf9

…sagg-decode-gate

# Conflicts:
#	lib/router/scheduler/src/local.rs
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 19, 2026 14:01 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · merged main into the branch (8858607), resolving 1 conflict

Details

Why: the branch conflicts with main. Merged origin/main into the PR branch and pushed the merge as 8858607. It is a plain merge on top of the old head, so nothing was rewritten or force-pushed, and the worktree was clean so nothing was stashed. One file conflicted, lib/router/scheduler/src/local.rs, because main's #18799 deleted the legacy schedule / schedule_with_block_hashes / schedule_with_policy_class_and_block_hashes methods and trimmed the imports. The PR's only edit inside those methods was passing admitted_upstream: false, so they stay deleted and nothing the PR needs is lost. Main's other change to this file in this range, #18940 (reply-length prediction), merged without conflict. Checks: cargo clippy --locked --no-deps -D warnings is clean on dynamo-scheduler, dynamo-slot-tracker, dynamo-kv-router and dynamo-mocker (all targets) and on dynamo-llm (--lib). Tests pass: dynamo-scheduler --lib (377, including the PR's five paired-pool and admitted-upstream tests), dynamo-kv-router --lib scheduling:: (124), and dynamo-llm --lib routing_host + prefill_router (211). cargo fmt is clean and the merge commit is signed.

  • lib/router/scheduler/src/local.rs: Took main's import list, which drops ScheduleMode and TierOverlapBlocks, and added back the PR's PairedPoolRoom for set_paired_pool. The legacy schedule* methods stay deleted as chore(scheduler): delete policy.rs, the legacy schedule chain, and dead kernel surface #18799 intended. That deletion also removed this file's HashSet import, which the PR's any_rank_has_room still uses, so the import is now std::collections::{HashMap, HashSet}. The PR's set_paired_pool, any_rank_has_room, subscribe_room_changed and admitted_upstream handling are unchanged.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 8858607

…sagg-decode-gate

# Conflicts:
#	docs/fern/pages/developer-guide/knowledge-base/modular-components/router/configuration-and-tuning.md
#	lib/router/scheduler/src/queue.rs
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 19, 2026 15:00 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · merged main into the branch (2bb6d80), resolving 2 conflicts

Details

Why: the branch conflicts with main. Merged origin/main into the PR branch and pushed the merge as 2bb6d80. It is a plain merge on top of the old head, so nothing was rewritten or force-pushed, and the worktree was clean so nothing was stashed. Both conflicts come from main's #18443 (dispatch gate and session lanes), which reworked the same scheduler queue code this PR changes. Main now gives each lane-check answer a reason (LaneCheck / BlockReason), caches one room answer per class, and always listens for wake-ups. The PR's decode-room check now runs inside main's new structure. While resolving, I found that git had silently mis-merged one spot: it placed the PR's decode-room check after main's new per-class room cache and kept the old bool return. I moved the check and converted it, as described in the queue.rs item. One choice for the author to confirm: a decode-room wake-up now rechecks only lanes blocked on capacity, not lanes held by the dispatch gate (details in the queue.rs item). Checks: cargo clippy --locked --no-deps -D warnings is clean on dynamo-scheduler, dynamo-admission, dynamo-slot-tracker, dynamo-kv-router and dynamo-mocker (all targets) and on dynamo-llm (--lib). Tests pass: dynamo-scheduler --lib (386, including the PR's five paired-pool and admitted-upstream tests), dynamo-admission --lib (25), dynamo-kv-router --lib scheduling:: (129), and dynamo-llm --lib routing_host + prefill_router (211). cargo fmt is clean and the merge commit is signed.

  • lib/router/scheduler/src/queue.rs: Main's restructure is kept throughout and the PR's decode-room gate is threaded through it. (1) Fields and construction: the actor keeps both the PR's paired_pool and room_changed and main's dispatch_gate and gate_recheck_at. new() keeps main's always-on wake channel and adds the PR's room signal; a booking released directly still records the capacity change through main's capacity_wake and also signals room to the PR's paired queue. (2) Actor loop: main's always-select loop gains the PR's decode-room branch. When that branch fires it rechecks only lanes blocked on capacity (RecheckScope::Capacity), because a request held for decode room is filed as a capacity block; lanes held by the dispatch gate wait for the gate's own wake-up or timer. Before this merge, a decode-room wake-up rechecked every blocked lane. If decode room should also re-ask gate-held lanes, change it to RecheckScope::All. (3) Lane checks: the decode-room check runs after main's dispatch-gate and queueing checks and before main's per-class room cache, which only describes this pool's own workers. In has_dispatchable_ready_head a held head returns Blocked(Capacity). In the main dispatch pass it returns Blocked(SharedCapacity) for heads with no pin, allow-list or LoRA, which all get the same decode answer in a pass, and Blocked(Capacity) otherwise, matching how main reports its own capacity refusals. (4) Tests: helpers and main's new tests pass admitted_upstream: false / false to the PR's new parameter, and use main's new handle_update(None, Some(RecheckScope::All)) signature.
  • docs/fern/pages/developer-guide/knowledge-base/modular-components/router/configuration-and-tuning.md: Kept the PR's rewrite of the decode wait-limit section (aggregated vs disaggregated, the pool-level gate, where held blocks come from) and added main's feat(router): dispatch gate and session lanes; ThunderAgent on the gate #18443 clause to its sentence on when a class queues: '...every eligible worker is busy for that class, or when an installed dispatch gate holds the request, but a new arrival cannot bypass an existing backlog in the same class.' Main's new lane paragraph above it and its session-affinity table change merged without conflict.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 2bb6d80

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · the author's agent is fixing a CI failure the PR causes

Details

rust-clippy (.) and rust-tests (.) fail to compile lib/router-plugins/builtin/tests/thunderagent_gate.rs:126 with E0063 missing field admitted_upstream. The PR added pub admitted_upstream: bool to ScheduleRequest at lib/router/scheduler/src/types.rs:389 but did not update this test's initializer, which came in from main, so the fix is to add admitted_upstream: false there. The two lib/bindings/python jobs were only cancelled after the (.) jobs failed and will pass once the fix is pushed.

…quest

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 19, 2026 15:25 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · the author's agent fixed a CI failure the PR caused (5a45746)

Details

The babysitter's diagnosis was right. Both rust-clippy (.) and rust-tests (.) fail with E0063 missing field admitted_upstream at lib/router-plugins/builtin/tests/thunderagent_gate.rs:126, a ScheduleRequest initializer that main added in #18443 and that I missed when merging it in. I reproduced the failure with cargo test -p dynamo-router-policies --test thunderagent_gate, added admitted_upstream: false in one commit (5a45746), and pushed. That test now passes (3 tests), and a workspace-wide cargo clippy --locked --no-deps --workspace --all-targets -D warnings finds no other initializer missing the field. The two lib/bindings/python jobs did not fail on their own: GitHub shows them as cancelled after the (.) jobs failed, so they have nothing to fix and should run normally on the new head.

  • FIX: rust-tests (.) failed with E0063 at lib/router-plugins/builtin/tests/thunderagent_gate.rs:126: the turn() helper in a test main added (feat(router): dispatch gate and session lanes; ThunderAgent on the gate #18443) builds a ScheduleRequest without the PR's new admitted_upstream field. Added admitted_upstream: false; cargo test -p dynamo-router-policies --test thunderagent_gate now passes (3 tests).
  • FIX: rust-clippy (.) failed on the same E0063 at thunderagent_gate.rs:126. Fixed by the same commit; a local cargo clippy --locked --no-deps --workspace --all-targets -- -D warnings is clean.
  • SKIP: rust-tests (lib/bindings/python) has conclusion cancelled and its log ends in 'The operation was canceled.' with no compile or test error. It stopped when the (.) jobs failed, so there is nothing for the PR to fix; it should run normally on the new head.
  • SKIP: rust-clippy (lib/bindings/python) has conclusion cancelled with no error in its log. It stopped when the (.) jobs failed, so there is nothing for the PR to fix; it should run normally on the new head.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test 5a45746

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · treating 1 check as expected, not failing

Details

Opt-in gates or summary jobs; they need a label or another check, not a code change.

  • pre-merge-status-check

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · re-ran 1 failed job

Details

rust-tests (.) has no failing test or compile error: its log stops partway through the passing dynamo-llm lib tests at 16:01:09 with no test result line, which looks like the runner died rather than anything the PR changed. I re-ran the failed jobs; pre-merge-status-check only failed because rust-tests did.

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · re-ran 1 failed job

Details

On the re-run, rust-tests (.) failed on logging::tests::test_tokio_console_respects_console_format in dynamo-runtime: that test runs its own nested cargo build, and the linker crashed during it ("linking with cc failed", with an LLVM "please submit a bug report" note). The PR does not change dynamo-runtime logging, and the previous attempt died for a different reason (truncated log), so this looks like runner instability and I re-ran the failed jobs.

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · re-ran 1 failed job

Details

rust-tests (.) failed for the second time in a row on dynamo-runtime logging::tests::test_tokio_console_respects_console_format, with the same linker crash inside the nested cargo build that test runs. The PR changes nothing under lib/runtime or any Cargo or .cargo config, and main's recent runs of this workflow are green, so I re-ran the failed jobs. If it fails a third time, the human should look at that test's nested build on this runner image, or merge main to pick up a fresh build cache.

@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 22, 2026 22:14 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · merged main into the branch (b7b3473)

Details

Why: Nothing has changed since pass 4: the head is still 5a45746, and rust-tests (.) attempt 4 is the same failure, where the nested cargo build in logging::tests::test_tokio_console_respects_console_format dies with ld terminated with signal 7 [Bus error] because the runner disk fills up. The fix, #19155 (b57aee4, CARGO_INCREMENTAL=0 for rust-tests), is on main but not yet in this branch, and the PR is mergeable without conflicts, so main still needs to be merged in; another re-run would fail the same way. Merged origin/main (c0fc9cc, 76 commits) into the PR branch as merge commit b7b3473 and pushed it with a plain push; nothing was rebased or rewritten. The merge was clean: no conflicts, so no items. The CI fix #19155 (b57aee4, CARGO_INCREMENTAL=0 for rust-tests) is now in the branch, and the PR head is b7b3473. The worktree was already clean and level with the fork, so nothing was stashed. Seven files were changed on both sides and auto-merged (configuration-and-tuning.md, entrypoint/input/common.rs, kv_router.rs, prefill_router/activation.rs, scheduler queue.rs, selection/core/run.rs, selection/core/tests.rs). On the merged tree, on Modal, all passed: cargo fmt --check; cargo check --locked --all-targets and cargo clippy --locked --no-deps --all-targets -D warnings for dynamo-llm, dynamo-mocker, dynamo-router-policies, dynamo-kv-router, dynamo-scheduler and dynamo-slot-tracker; and the tests dynamo-scheduler --lib (387), dynamo-slot-tracker --lib (139), dynamo-kv-router --lib scheduling:: (129), dynamo-router-policies --test thunderagent_gate (3), dynamo-mocker --lib replay:: (201), dynamo-llm --lib kv_router:: entrypoint:: (545), with 0 failures. The PR's own gate tests are in those runs. Not run: the full rust-tests (.) job, including logging::tests::test_tokio_console_respects_console_format, which is the one that failed in CI on disk space; CI on the new head will show whether #19155 clears it.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test b7b3473

@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · an agent is fixing a CI failure the PR causes

Details

rust-clippy (.) and rust-feature-builds fail to compile dynamo-bench with E0063 missing field admitted_upstream in initializer of SelectionOperation at lib/bench/kv_router/selection_replay/engine.rs:1009. The PR adds pub admitted_upstream: bool to SelectionOperation (lib/router/scheduler/src/selection/core/operation.rs:59), and the main merge brought in the selection replay benchmark (#17959), which builds that struct without it; the fix is to add admitted_upstream: false to that initializer, as the PR already does in selection/core/run.rs:106 and :153.

The selection replay benchmark (ai-dynamo#17959) builds SelectionOperation without
the admitted_upstream field this branch adds, so dynamo-bench failed to
compile with the selection-replay feature. Replayed requests have no
upstream hop, so the field is false.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani
ishandhanani temporarily deployed to external_collaborator November 22, 2026 22:40 — with GitHub Actions Inactive
@ishandhanani

Copy link
Copy Markdown
Contributor Author

CI babysit · an agent fixed a CI failure the PR caused (f87118f)

Details

Pushed f87118f to the PR branch with a plain push; the PR head is now f87118f and it is still a draft. The commit adds admitted_upstream: false to the SelectionOperation initializer in lib/bench/kv_router/selection_replay/engine.rs, the compile error behind both failing checks. Both items were CI checks, not review threads, and the PR has no unresolved review threads, so I posted no replies and resolved nothing. CI on the new head has not finished, so the two checks are not yet confirmed green there.

  • FIX: Fixed in f87118f: the selection replay benchmark's SelectionOperation initializer now sets admitted_upstream: false, so dynamo-bench compiles with the selection-replay feature. This is a CI check with no review thread, so there was nothing to reply to.
  • FIX: Fixed in f87118f: same cause and same one-line change; the selection_replay_bench and selection_replay targets now pass clippy with -D warnings. This is a CI check with no review thread, so there was nothing to reply to.

@dynamo-ops

Copy link
Copy Markdown
Contributor

/ok to test f87118f

@ishandhanani ishandhanani left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Round 3 AI review · 1 TEST, 1 DESIGN, 1 NIT

Automated review, round 3. Every finding is posted, NITs included; findings may be wrong, so reply on a thread to dispute one.

The PR makes the prefill hop's policy-class queue the only gate for class decode wait limits in KV-routed disaggregated serving, and the decode hop books decode legs with staged KV directly. Since round 2 it took one cleanup commit, two one-line compile fixes and 14 merges from main. I read the hand-resolved merge of the paired-pool gate into main's lane checks, recheck scopes and wake loop and found it correct; RecheckScope::Capacity is the right scope for a decode-room wake, because a gate-held head is refused before the pool is asked. Three things remain: the direct-booking path now skips the dispatch gate that main added, with no doc or test saying so; the release of a lane-blocked head on the room signal has no test; and the PR description is stale.

Read: rust-code-review, deep-code-review, deep-code-review/references/quality.md, general-review, general-review/references/risk-buckets.md, graham-code-review, pr-checklist, lib/mocker/src/replay/online/AGENTS.md, lib/router-plugins/builtin/AGENTS.md, lib/router/slot-tracker/AGENTS.md, lib/llm/src/kv_router/AGENTS.md, lib/router/kv-router/AGENTS.md, lib/router/scheduler/AGENTS.md, docs/fern/pages/AGENTS.md, docs/fern/AGENTS.md, lib/bench/AGENTS.md, lib/llm/AGENTS.md, AGENTS.md

The author's agent picks up this feedback next.

Comment on lines +2136 to +2145
// The paired pool may have room for a request held only on it. Those lanes are
// blocked on capacity, so recheck every capacity-blocked lane.
open = PairedPoolGate::changed(&mut self.paired_pool.room_changed),
if paired_room_changed => {
if !open {
self.paired_pool.close_room_changed();
}
self.handle_update(None, Some(RecheckScope::Capacity)).await;
continue;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[TEST] No test for a lane-blocked head released by the room signal (AI review, round 3)

The merge turned the room wake into handle_update(None, Some(RecheckScope::Capacity)). That scope is now what releases a head held on decode room in a worker lane. A request pinned to a prefill worker (hard session affinity or an explicit pin) is filed in blocked_lanes as Blocked(Capacity) and is asked again only when a recheck covers it.

All four paired-pool tests enqueue unpinned, session-less requests. Those sit in the shared heap, which is re-asked on every drain, so the tests would also pass with None here. With None, a pinned request would wait for an unrelated full recheck: its own worker freeing, a cleanup drain, or the periodic queue update.

Fix: add a case to paired_pool_holds_until_its_room_signal_releases_the_request with pinned_worker: Some(..).

The SharedCapacity arm at line 2850 is also untested, and no in-tree host reaches it: the prefill hop runs no classifier, so an unconstrained head has no lane key and is always in the shared heap.

Comment on lines +2298 to +2306
if admitted_upstream {
let context = AdmissionContext {
class_index,
due_at: None,
attempt_tx,
lifecycle_transfer,
};
return self.admit_one(context, request, decay_now, prepared) == Admission::Booked;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[DESIGN] Admitted-upstream decode legs skip the dispatch gate main added (AI review, round 3)

Main's #18443, merged into this branch since round 2, asks an installed DispatchGate about every queued head in drain_ready. This early return books a decode leg with staged KV before it is queued, so the decode router's gate gets neither check nor dispatched for it. Its holds and its Go target are skipped.

When: every remote-prefill request in KV-routed disaggregated serving, when the decode set's classifier returns a gate. On the base branch the gate held these legs.

Cost: a gate policy silently stops holding in disaggregated serving. Nothing leaks: the classifier still sees the request at Sent, and ThunderAgent commits it there as it does for a never-queue class.

Not holding fits this PR, since a hold would strand the prefill's KV. But nothing says so:

  • The doc on install_dispatch_gate names the zero-queue-limit class as the only request admitted without asking the gate.
  • custom-admission-control.md:299 says Dynamo asks the gate about each queue head before it dispatches.
  • The disaggregated bullet at configuration-and-tuning.md:349 lists only class limits and deadlines.

Fix: state the exception in those three places and in the admitted_upstream doc comments. Add a queue test with a gate installed, where an admitted-upstream request books while the gate answers Hold. If a gate must be able to hold disaggregated requests, it has to be asked at the prefill hop, which runs no classifier today; say which you intend.

Comment on lines +30 to +37
let admission = match admission {
FindBestMatchAdmission::WithAdmission
if phase == RequestPhase::Decode && staged_kv == StagedKv::Present =>
{
FindBestMatchAdmission::AdmittedUpstream
}
admission => admission,
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[NIT] PR description no longer describes the code at this head (AI review, round 3)

The description is stale in two ways.

Behavior. It says the decode queue "books every RequestPhase::Decode request at once", that RoutingHost books every decode-phase request as AdmittedUpstream, and that no class limit applies to a conditional-disagg bypass. Since the round-1 fix, only a decode leg with staged KV books directly (this match), and a bypass keeps the full class gate at the decode router. The docs page and the end-to-end test already say that.

Paths and validation. It names lib/kv-router and reports cargo test -p dynamo-kv-router --lib --features standalone-selection on main 73014901d4. After the crate split the code is in lib/router/scheduler and lib/router/slot-tracker, and the queue tests run under dynamo-scheduler.

Fix: update the Decode queue bullet, the lib/llm bullet, the bypass known limit, the crate names and the validation commands. Add the dispatch-gate behavior to the known limits.

@ishandhanani ishandhanani left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Round 3 AI perf review · 3 PERF

Automated performance review, round 3. Every finding is posted, NITs included; findings may be wrong, so reply on a thread to dispute one.

This turn looked only at cost. For aggregated serving the change adds two branches per head check and a small fill per pass, which the code settles as negligible, and I found no removable clones. The disaggregated path has three costs on the prefill admission actor: once subscribed it wakes and re-asks every capacity-blocked lane on every decode release, it re-walks every decode rank per arrival while held, and that walk probes a SipHash set per rank. Nothing was measured: no existing bench installs a paired pool and the PR's own queue-gate numbers predate the merges, so each finding names the case that would settle it.

Read: dynamo-perf-best-practices, dynamo-clone-hotpath-audit, dynamo-frontend-benchmark, lib/router-plugins/builtin/AGENTS.md, lib/router/slot-tracker/AGENTS.md, lib/llm/src/kv_router/AGENTS.md, lib/router/kv-router/AGENTS.md, lib/router/scheduler/AGENTS.md

The author's agent picks up this feedback next.

Comment on lines +2136 to +2145
// The paired pool may have room for a request held only on it. Those lanes are
// blocked on capacity, so recheck every capacity-blocked lane.
open = PairedPoolGate::changed(&mut self.paired_pool.room_changed),
if paired_room_changed => {
if !open {
self.paired_pool.close_room_changed();
}
self.handle_update(None, Some(RecheckScope::Capacity)).await;
continue;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[PERF] Prefill actor wakes and sweeps blocked lanes on every decode release (AI perf review, round 3)

Once any request of a class with decode_busy_threshold_frac has consulted the pool, has_room keeps the watch::Receiver for the life of the actor (line 1062). This branch then fires on every decode-side change, whether or not a head is held on decode room.

What fires it: every decode release (capacity_changed, direct_release, drain_cleanup), every prefill completion that released prompt load, every remote-state change from a peer router (bookings included), and every config tick.

Cost per event against base:

  • Sender, on the request task: send_replace takes the watch's write lock and calls notify_waiters on its 8 Notifys. Base paid nothing for a paired queue.
  • Prefill admission actor: one extra turn (expire_due_classes, drain_into, drain_ready, the select futures rebuilt). With nothing queued, that is a no-op turn per decode release.
  • With a backlog, RecheckScope::Capacity sets recheck.capacity on every class, so the next dispatch re-asks every capacity-blocked lane. That includes lanes blocked on their own prefill worker and classes with no decode limit. On base a worker free re-asks only the lanes waiting on that worker (feat(router): dispatch gate and session lanes; ThunderAgent on the gate #18443). With hard session affinity that is up to one lane per prefill rank per decode release: at about 1,000 blocked lanes and 1,000 releases a second, about a million lane checks a second on the one actor.

Fix: keep the subscription only while a head is held on the pool. Record in PairedPoolGate that has_room returned false. When a wake or a pass finds nothing held, set room_changed = None, so receiver_count() is 0 and this branch is off. has_room already re-subscribes before its next read, so no wake is missed.

Not measured: the benches run caller and actor on one thread and install no paired pool. A multi-thread run that frees decode bookings while the prefill queue holds about 1,000 pinned lanes on their own limit would settle the size; report admission latency and actor CPU.

Comment on lines +1049 to +1051
fn begin_pass(&mut self) {
self.pass_room.fill(None);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[PERF] Held pool verdict re-walks every decode rank on each arrival (AI perf review, round 3)

begin_pass clears the pool's answer at the start of every pass, and every Enqueue runs a pass (handle_enqueued → drain_ready). While the decode pool is past a class limit, each arriving request walks every decode rank again under the decode load table's read guard and still gets false.

A false answer cannot change without a RoomChanged signal: releases, peer state and config changes all fire it, and new bookings only add load. So in the held state the walk is repeated work.

Cost: O(decode ranks) per arrival on the prefill admission actor, in exactly the overload state. On base the prefill hop's pass stops at its first rank with room. At 4,096 decode ranks that is 4,096 snapshot copies and set probes per arriving request.

Fix: keep a Some(false) across passes. Clear it in the room-changed branch and on a full drain (Drain::Full), which also covers an availability change that fires no signal. Keep re-reading a true answer: bookings fire no signal, and that read stops at the first rank with room.

Not measured. A selection_core queue-gate case with a paired pool of 4,096 ranks at the limit would show the per-admission cost.

Comment thread lib/llm/src/kv_router.rs
Comment on lines +992 to +1001
let lora_candidates_are_ours = request.lora_name.is_none()
|| (request.pinned_worker.is_none() && request.allowed_worker_ids.is_none());
let available = if lora_candidates_are_ours {
(self.available_workers)(request)
} else {
self.client.available_instance_ids()
};
self.selection
.scheduler()
.any_rank_has_room(limits, available.as_deref())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[PERF] Decode-pool read probes a SipHash set once per rank (AI perf review, round 3)

has_room_for_prefill_request hands any_rank_has_room the provider's HashSet<WorkerId>, which hashes with SipHash, and the closure probes it once per decode rank (lib/router/scheduler/src/local.rs:577). lib/router/scheduler/AGENTS.md rules that out for a loop over ranks. #18008 added AvailableWorkerIds so the queue probes an Fx set converted once per source Arc; this path bypasses it.

Two more costs in the same walk:

  • PromptRegistry::any_rank_has_room goes through iter_indexed, which copies each rank's snapshot before eligible is asked. A request whose eligible set is a few workers still copies and probes every rank ahead of them.
  • For a LoRA request the provider runs refresh_admission, which builds a Vec and a HashSet over the decode workers. PairedPoolGate::has_room does not cache LoRA answers, so that runs per LoRA head per check, on the prefill actor.

When: every pool read that does not stop at the first rank, which means a pool at or near the class limit, or a narrow eligible set. There is one read per class per pass, and one per LoRA head.

Cost: roughly 20 ns of hashing per rank by my estimate, so about 80 µs per walk at 4,096 ranks, plus an O(decode workers) allocation per LoRA head.

Fix: resolve the set through the decode scheduler's own AvailableWorkerIds, for example by taking the request in LocalScheduler::any_rank_has_room. Test eligible on the rank id before reading its load. For LoRA, cache the answer per class and adapter within a pass.

Not measured; the same selection_core paired-pool case at 4,096 ranks would settle it.

This branch was previously deployed

1 inactive deployment
external_collaborator — f87118f5 Deployed Nov 22, 2026 by ishandhanani via ok-to-test #55790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation external-contribution Pull request is from an external contributor fix router Relates to routing, KV-aware routing, etc. size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants