Skip to content

fix(router): direct-dispatch migration, decode-first engagement, embedded selection default, EPP runtime-mode deprecation - #30

Closed
ishandhanani wants to merge 7 commits into
idhanani/p5-runtime-nats-featurefrom
idhanani/p2-direct-dispatch-migration
Closed

ishandhanani wants to merge 7 commits into
idhanani/p5-runtime-nats-featurefrom
idhanani/p2-direct-dispatch-migration

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Stacked on the NATS-feature PR. Closes roadmap exit gates that were open: Phase 2 "worker-shutdown migration tests pass" over direct dispatch, Phase 4 "full sidecar-backed deployment (frontend + P + D workers) on a bare VM with zero etcd/NATS processes", and the Phase 3 "deprecate EPP dynamo-mode" item.

Summary

  • Direct-dispatch stream loss now migrates. A decode engine that dies mid-stream reaches tonic as Unknown/Internal with h2 transport text; status_to_dynamo mapped that to Backend(Unknown), which the migration layer treats as fatal. It now maps to Backend(Disconnected); a stream ending without a terminal response is Backend(StreamIncomplete); and Backend(Disconnected)/Backend(CannotConnect) join the migratable set.
  • Decode-first actually engages. The decode RoutingHost was only installed on PrefillRouter when conditional disagg was on, so --router-disagg-decode-first silently used the prefill-first path. It is installed whenever either feature needs it.
  • EPP runtime mode deprecated. DYN_EPP_MODE=dynamo logs a deprecation warning at startup; docs updated. It remains available this release.

Validation

Zero-infra disaggregated deployment on this host, no etcd or NATS process running: DYN_DISCOVERY_BACKEND=file, DYN_REQUEST_PLANE=tcp, DYN_EVENT_PLANE=zmq, DYN_ROUTER_EMBEDDED_SELECTION=1, DYN_ROUTER_DIRECT_DISPATCH=vllm; one prefill sidecar and two decode sidecars (dynamo-vllm-sidecar --disaggregation-mode prefill|decode --advertise-grpc-endpoint ...) over dynamo-vllm-mocker-server engines; dynamo.frontend --router-mode kv --migration-limit 3.

  • Model served in 4 s; prefill router activated; embedded partitions for decode and prefill; both decode engines connected for direct dispatch; 3/3 completions OK, routed prefill → decode (5 prefill dispatches, 3+2 decode dispatches across the two decode workers).
  • Two 400-token streams started, decode worker 1 (engine + sidecar) killed with SIGKILL at +3 s. Before this PR: the stream on worker 1 ended after 22 chunks with an error chunk (500). After: frontend logs migration retry scheduled ... reason="backend_disconnected" ... tokens_completed=22, and both streams finish with 400 content chunks, finish_reason=length, no error chunks.
  • Same deployment with DYN_ROUTER_DISAGG_DECODE_FIRST=1: 3/3 completions and both streams complete through the kill (decode-first path engaged; see final comment for the debug-log confirmation).
  • cargo test -p dynamo-sidecar-common --lib (new mid_stream_transport_failures_are_disconnects), cargo test -p dynamo-llm --lib migration::tests::stall... (Backend(Disconnected)/CannotConnect migratable), clippy on sidecar-common, vllm-sidecar, ext-proc, llm: clean.

Still not done: Kubernetes half of the Phase 4 exit (no cluster deployment of the sidecar images), replay-parity campaigns (multi-node Mooncake protocol), and the backend-common split.

A decode engine that dies mid-stream surfaces to tonic as Unknown/Internal
with h2 transport text. status_to_dynamo mapped that to
Backend(Unknown), which the migration layer treats as fatal, so the
request failed with a 500 instead of moving to another worker. Map
mid-stream transport failures to Backend(Disconnected), report a stream
that ends without a terminal response as Backend(StreamIncomplete), and
include Backend(Disconnected) and Backend(CannotConnect) in the migratable
set (direct engines report connection loss under the backend taxonomy).

Validated on a zero-infra disaggregated deployment (file discovery, TCP,
ZMQ, embedded selection, direct dispatch; one prefill and two decode
sidecars over mock vLLM gRPC engines): killing a decode engine and its
sidecar mid-stream now logs a migration retry (reason
backend_disconnected, 22 tokens completed) and both 400-token streams
finish; before the change the stream on the killed worker ended in an
error chunk.

Signed-off-by: Ishan Dhanani <[email protected]>
The decode RoutingHost was only handed to PrefillRouter when conditional
disaggregation was on, so --router-disagg-decode-first silently fell back
to the prefill-first path (plan_decode_first saw no decode host). Install
it whenever either feature needs it.

Signed-off-by: Ishan Dhanani <[email protected]>
DYN_EPP_MODE=dynamo now logs a deprecation warning at startup; the
standalone EPP covers aggregated and disaggregated routing without a
Dynamo runtime. Runtime mode remains available for this release.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Decode-first confirmation (same zero-infra disagg deployment, DYN_ROUTER_DISAGG_DECODE_FIRST=1, DYN_LOG=info,dynamo_llm::kv_router::prefill_router=debug): 5/5 requests logged Decode-first coordination: decode booked, selecting prefill (state DecodeCommitted) followed by dispatching decode on the held booking (state Linked); 3/3 completions OK; two 400-token streams completed through a SIGKILL of one decode engine + sidecar at +3 s, no error chunks.

@github-actions github-actions Bot added fix documentation Improvements or additions to documentation router labels Sep 3, 2026
@ishandhanani

Copy link
Copy Markdown
Owner Author

Offline KV replay byte-parity, stack tip (this PR's head) vs baseline origin/main 705796f, per the dynamo-kv-replay-parity protocol on one host: both revisions built with cargo build --release -p dynamo-bench --no-default-features --features replay-bench --bench offline_replay_bench (binaries differ: sha256 b5a857… vs 43fd73…), corpus lib/bench/testdata/mooncake_trace_1000.jsonl (sha256 e2bec9bccd21978f…), --arrival-speedup-ratio 1000, two runs per revision per row, replay_bench: true in every report.

Row baseline digest (2 runs) candidate digest (2 runs) result
vLLM aggregated, 4 workers ddef467324d77f58 ddef467324d77f58 PARITY
vLLM disagg, 2P/2D c617e96711b076d3 c617e96711b076d3 PARITY
SGLang aggregated, 4 workers 4616861be7f7d995 4616861be7f7d995 PARITY
SGLang disagg, 2P/2D 912590578b8b6465 912590578b8b6465 PARITY

This covers the runtime-free lib/kv-router scheduling/sequence/selector changes across the whole stack (Phase 0/1 exit gate dynamo-kv-replay-parity). Caveat: the 1000-request fixture is the protocol's preflight corpus, not the 5,000-request window, and it was run on one node.

KvWorkerMonitor's prefill-token overload detection reads the scheduler's own
load snapshots through SchedulerLoadSender. The embedded selection partition
never published them, so --active-prefill-tokens-threshold could not trigger
529 under --router-embedded-selection (tests/router
test_mocker_kv_router_overload_529[prefill-tokens] failed only on that path;
decode-blocks worked because it uses worker-published metrics).

Add SelectionHostHooks.scheduler_load_sink (a SchedulerLoadSink) that the
partition's ScopedSequencePublisher forwards publish_scheduler_load(_batch)
into; the embedded host bridges it to the router's SchedulerLoadSender.
tests/router overload_529 (agg + disagg, prefill-tokens + decode-blocks)
now pass on the embedded path.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Router e2e (Phase 1 exit gate "tests/router e2e green on both paths"): pytest tests/router/test_router_e2e_with_mockers.py -m gpu_0 -k 'test_router_decisions or test_mocker_two_kv_router or test_router_decisions_disagg or test_mocker_disagg_startup_lifecycle or test_mocker_kv_router_overload_529 or test_query_instance_id' (25 selected; etcd+NATS started by the fixtures) on this host.

Path Result
runtime scheduler (default) 22 passed, 3 failed
embedded selection (DYN_ROUTER_EMBEDDED_SELECTION=1) 22 passed, 3 failed (after c1aa868)

The 3 failures are identical on both paths and environmental: test_router_decisions[zmq_nats_free-tcp] needs bindings built with --features kv-indexer (dynamo.indexer is not available in this build), and the two *_router_aic tests need --features aic-forward-pass. Neither touches the stack's code.

Before c1aa868 the embedded path also failed test_mocker_kv_router_overload_529[prefill-tokens]: the embedded partition did not publish scheduler load snapshots to KvWorkerMonitor, so the prefill-token 529 threshold never fired. The new SelectionHostHooks.scheduler_load_sink fixes that; all four overload_529 cases (agg + disagg, prefill-tokens + decode-blocks) pass on the embedded path.

@ishandhanani
ishandhanani force-pushed the idhanani/p2-direct-dispatch-migration branch from c1aa868 to beb6ddc Compare September 3, 2026 13:29
Phase 1 exit gates now pass: the frontend A/B benchmark (+6% req/s, lower
p50/p99), offline KV replay byte-parity against main on four rows, and
tests/router e2e green on both scheduler paths. Flip
router_embedded_selection to default true (serde default/skip updated,
PyO3 constructor, .pyi, --router-embedded-selection default, docs).

The runtime-bound KvScheduler path stays reachable through
--no-router-embedded-selection for one release as a rollback and logs a
deprecation warning at startup; deleting it is the follow-up. A
caller-injected custom WorkerSelector type (not DefaultWorkerSelector)
cannot run on the partition, so KvRouter::new keeps the runtime scheduler
for it with a warning instead of silently changing selection semantics.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Added (Phase 1 "then delete the old wiring"): embedded selection is now the default scheduler (router_embedded_selection defaults to true across Rust config, PyO3, .pyi, and the frontend flag). The runtime-bound scheduler stays reachable via --no-router-embedded-selection for one release as a rollback and logs a deprecation warning; a caller-injected custom WorkerSelector type still uses it (with a warning) because the partition builds its own policy. Deleting the runtime scheduler code is the follow-up once the release cycle passes. cargo test -p dynamo-llm --lib: 2564 passed; kv-router config tests pass; docs lint clean; --no-router-embedded-selection parses to false.

@ishandhanani ishandhanani changed the title fix(sidecar): migrate on direct-dispatch stream loss; engage decode-first; deprecate EPP runtime mode fix(router): direct-dispatch migration, decode-first engagement, embedded selection default, EPP runtime-mode deprecation Sep 3, 2026
@ishandhanani

Copy link
Copy Markdown
Owner Author

Kubernetes half of the Phase 4 exit ("full sidecar-backed deployment (frontend + P + D workers) ... on k8s with zero etcd/NATS processes"), run on a local kind cluster (kind-agent-rt-sandbox, v1.36.1):

  • Image: python:3.12-slim + the ai-dynamo-runtime and ai-dynamo wheels built from this branch + stripped dynamo-vllm-sidecar and dynamo-vllm-mocker-server + Qwen3-0.6B tokenizer files (no weights). DYN_DISCOVERY_BACKEND=file on a shared emptyDir, DYN_REQUEST_PLANE=tcp, DYN_EVENT_PLANE=zmq, DYN_ROUTER_DIRECT_DISPATCH=vllm, DYN_ROUTER_DISAGG_DECODE_FIRST=1; embedded selection is the default.
  • One pod, 7 containers: mock prefill engine, 2 mock decode engines, prefill sidecar, 2 decode sidecars, frontend. No etcd or NATS pod exists in the namespace.
  • Result: all 7 containers ready after 3 s; model served after 11 s via port-forward; 3/3 chat completions OK; prefill router activated; embedded partitions for decode and prefill; direct dispatch connected to both decode engines; two 300-token streams completed with no error chunks.
  • Not exercised here: the mid-stream engine kill (kill -9 1 inside the container is ignored for PID 1); that migration path was verified on the bare-VM run above.

Manifest and smoke script: single-pod Pod with restartPolicy: Never, sidecars started with --advertise-grpc-endpoint, frontend --router-mode kv --migration-limit 3 --model-path /models/Qwen3-0.6B --model-name Qwen/Qwen3-0.6B.

@ishandhanani

Copy link
Copy Markdown
Owner Author

Why the runtime KvScheduler path is deprecated rather than deleted in this PR (Phase 1 "then delete the old wiring"):

KvRouter<Sel> is generic over a caller-injected Sel: WorkerSelector<ModelRuntimeConfig> (used by HttpFrontend::worker_selection_policy_factory and by the unit tests). The selection partition's LocalScheduler is generic over WorkerSelectionPolicy, whose WorkerSelector<C> impl is called with the partition's own catalog config type, not ModelRuntimeConfig. There is no adapter from a WorkerSelector<ModelRuntimeConfig> to the partition's C, so a custom selector cannot run on the partition today; KvRouter::new therefore keeps the runtime scheduler for a non-default Sel (with a warning) and uses the partition for DefaultWorkerSelector, which is every production path.

Deleting kv_router/scheduler.rs and the runtime half of kv_router/sequence.rs (about 2,100 lines) needs that adapter first (or dropping custom Sel support in favor of the registry-based WorkerSelectionPolicyFactory, which the embedded path already honors). Both are API decisions for the maintainers; this PR ships the default flip and the deprecation warning so the deletion is a mechanical follow-up once one is chosen.

--router-replica-sync previously logged that it was not carried over to the
embedded partition. Add SelectionHostHooks.replica_sync, a per-partition
factory returning HostReplicaChannels (outbound events, inbound peer events,
this replica's id); when the service runs no ZMQ peer mesh the partition's
publisher forwards to the host's outbound channel and its replica consumer
reads the host's inbound channel. The embedded host builds those channels
over the runtime event plane (ACTIVE_SEQUENCES_SUBJECT, same wire formats
and subscriber as the runtime scheduler used), so multi-replica frontends
keep active-sequence sync on the default scheduler path.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Added: replica sync on the embedded partition (d586893). --router-replica-sync now carries active-sequence events over the runtime event plane for the embedded scheduler (new SelectionHostHooks.replica_sync / HostReplicaChannels in lib/kv-router, bridged by the embedded host with the same ACTIVE_SEQUENCES_SUBJECT publisher/subscriber the runtime scheduler used). This was the last functional gap the runtime scheduler still covered.

Verified on the default (embedded) path: tests/router/test_slot_tracker_e2e.py::test_bidirectional_replica_lifecycle and test_mocker_session_affinity[etcd|file] pass; kv-router selection unit tests (131) and llm kv_router:: unit tests (336) pass; clippy clean.

…d partition

Install the process-wide WorkerSelectionPolicyRegistry (the linked custom
policy catalog the Python bindings register under --features custom-policy)
through dynamo_llm::kv_router::install_worker_selection_policy_registry;
embedded partitions and the static frontend resolve KvRouterConfig policy
instances against it instead of the built-in default registry. A KvRouter
built with Sel = WorkerSelectionPolicy therefore runs on the embedded
partition too; only an arbitrary caller-injected WorkerSelector type (unit
test fakes) still selects the runtime scheduler.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Added: linked worker-selection policies resolve on the embedded partition (install_worker_selection_policy_registry, called by the bindings' custom-policy registration). With this, every production path (default policy, registry policies, replica sync, overload detection, conditional disagg, decode-first) runs on the embedded scheduler; the runtime KvScheduler is now only reached by unit tests that inject bespoke WorkerSelector fakes. Deleting it is a mechanical follow-up: port those tests to WorkerSelectionPolicy pickers and remove kv_router/scheduler.rs plus the runtime publisher half of kv_router/sequence.rs. Left for a separate PR so this one stays reviewable. cargo test -p dynamo-llm --lib kv_router::: 336 passed; bindings check with --features custom-policy clean.

@ishandhanani

Copy link
Copy Markdown
Owner Author

DEP for this stack: #33.

@ishandhanani

Copy link
Copy Markdown
Owner Author

The four scheduler-parity commits here (scheduler-load feed, embedded default, replica sync, linked-policy registry) now live in #35, rebased onto #18. This PR stays open for the two commits not yet carried onto the new stack: the sidecar direct-dispatch migration mapping (stack 3) and the EPP dynamo-mode deprecation (EPP follow-up after #40).

@ishandhanani

Copy link
Copy Markdown
Owner Author

Closed while Stack 1 (#45 to #53) and Stack 2 (#40) go upstream; the branch stays for later stacks (direct dispatch, catalog leases, runtime features). See #33.

This branch had an error being deployed

1 failed deployment
external_collaborator — fc22bac2 Deployed Sep 3, 2026 by ishandhanani via ok-to-test #56
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 fix router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant