Skip to content

feat(router): re-host KvRouter scheduling on an embedded selection partition - #47

Closed
ishandhanani wants to merge 6 commits into
idhanani/up-2-core-indexingfrom
idhanani/up-3-embed-core
Closed

ishandhanani wants to merge 6 commits into
idhanani/up-2-core-indexingfrom
idhanani/up-3-embed-core

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

PR 3 of 9 implementing ai-dynamo#14310 (one SelectionCore for the frontend, the standalone selection service, and the EPP). Base: idhanani/up-2-core-indexing (PR 2 of this stack).

Fork staging copy of the upstream PR, rebased onto ai-dynamo/main. Replaces fork #18, #35, which stay open for review history.

Summary

Makes the frontend KvRouter schedule and account for active sequences through an embedded selection partition. This connects the frontend to the standalone core while retaining its runtime discovery, transport and cache-recovery integrations.

Implementation

  • EmbeddedSelection creates the partition before discovery supplies workers and maps runtime worker metadata into its catalog.
  • Host hooks supply load, availability, overload, LoRA and shared-cache inputs; the router's index supplies overlap refresh at this boundary.
  • The partition publishes scheduler load back to KvWorkerMonitor, preserving overload feedback.
  • Runtime event-plane channels replicate active sequences on the existing subject and wire format.
  • Linked worker-selection policies resolve through the process-wide registry installed by the bindings.
  • Embedded selection becomes the default; the legacy scheduler and opt-out remain temporarily for the next stack steps.
Walkthrough
flowchart LR
  Discovery[Runtime discovery] --> Catalog[Worker catalog]
  Catalog --> Partition[Embedded partition]
  Router[KvRouter request lifecycle] --> Partition
  Index[Frontend index] --> Partition
  Partition --> Load[Scheduler load and replica events]
Loading

Scheduling and lifecycle

The router supplies the same policy inputs to the partition that it supplied to KvScheduler. Request admission, booking and release use the partition handle; request transport and the frontend index remain owned by the runtime host at this boundary. Discovery projection includes DP layout, capacities, taints, topology and the current KV-transfer metadata.

Scheduler load is forwarded through the host sink so the worker monitor can still apply prefill overload feedback. Replica tasks use bounded channels and the router's cancellation token. A one-shot channel factory is sufficient here because a frontend router owns one partition.

Transitional interfaces

The embedded flag is enabled by default. Non-default selector types can still use the legacy scheduler in this PR; #48 removes that scheduler and #49 removes the flag, selector generic and temporary adapter. The full series' replica request-lease and expiry ownership corrections are included in #53.

Validation

Current stack boundary: b2644f824d7d81b8928b81bdcb1b81551df065e6; the series is based on Dynamo main ab58558c2dff28f4ff1ea4e219030eac5da3f48f.

  • Passed cargo check -p dynamo-kv-router -p dynamo-llm -p dynamo-ext-proc --no-default-features --features dynamo-kv-router/standalone-selection,dynamo-kv-router/standalone-slot-tracker --all-targets for this stack boundary.
  • Python bindings passed cargo check --manifest-path lib/bindings/python/Cargo.toml --features select-service --all-targets at this boundary.
  • The complete series was tested at feat(kv-router): session affinity for the standalone service and EPP #53; its description records the Rust/Python suites, aggregated GPU correctness probes and paired main/final benchmarks. Those end-to-end results apply to the final stack, not to a separate deployment of this intermediate PR.

GitHub CI is not green across this series. Recurring failures are the missing fork Fastchecker runner group, helm-tester image and approval-bot token, plus published-docs composition and an unchanged external documentation link. The local compilation and final-stack validation above are recorded separately from those CI failures.

Historical prototype benchmark

dynamo.frontend --router-mode kv pinned to 4 cores, 4 dynamo.mocker workers plus aiperf on the other 12, block size 64, closed loop at concurrency 128, 1024 requests after 256 warmup, arms interleaved with teardown between runs.

arm median req/s p50 / p99 latency (ms)
runtime KvScheduler 137.2 549 / 1396
embedded partition 145.9 484 / 1122

These inherited prototype measurements were not rerun at this rebased PR boundary and do not establish a speedup for the current series. Current aggregated GPU measurements are reported in #53.

Stack

# Branch Title Fork PRs it replaces
1 idhanani/up-1-host-hooks feat(kv-router): host-supplied inputs for SelectionService parity with the frontend scheduler #8 to #12
2 idhanani/up-2-core-indexing feat(kv-router): approximate, remote, and hint-aware indexing in SelectionService #14 to #16
3 (this PR) idhanani/up-3-embed-core feat(router): re-host KvRouter scheduling on an embedded selection partition #18, #35
4 idhanani/up-4-delete-kvscheduler refactor(router): delete the runtime-bound KV router scheduler #36
5 idhanani/up-5-policy-source refactor(router): selection policy source, SelectionHost, and dead-flag removal #37
6 idhanani/up-6-membership feat(kv-router): one worker-membership path for frontend and EPP #38
7 idhanani/up-7-kv-index-source refactor(kv-router): one Indexer type and one KV-event ingress for every selection host #39, #41, #43
8 idhanani/up-8-affinity-table refactor(kv-router): one session-affinity implementation for every selection host #42
9 idhanani/up-9-epp-affinity feat(kv-router): session affinity for the standalone service and EPP #44

…rtition

Phase 1a of the runtime-optional frontend roadmap. Behind
KvRouterConfig::router_embedded_selection (--router-embedded-selection /
DYN_ROUTER_EMBEDDED_SELECTION, default off), the frontend KvRouter runs its
scheduling and active-sequence accounting on one partition of an in-process
SelectionService instead of the runtime-bound KvScheduler:

- RouterScheduler enum in KvRouter dispatches statically to either backend;
  every router method (admitted and advisory scheduling, bookings, lifecycle,
  potential loads) goes through it. Request leases fence with the partition
  scheduler's booking_cleanup exactly as with KvScheduler.
- kv_router/embedded.rs builds the service with the registry-resolved policy
  (or Dynamo's default scorer/picker under the router's metric label), the
  router's overload/availability providers and prefill estimator as host
  hooks, and the router's own indexer as the dequeue-time overlap refresh
  source. A catalog feeder mirrors the runtime-config watch into the
  partition's worker catalog (dp layout, capacities, taints, topology,
  KV-transfer, router-hint metadata).
- The router keeps its indexer and request transport: it computes overlap
  against its indexer and hands the partition a fully formed ScheduleRequest.

Selection-service additions used by the host: SelectionPartition handle,
ensure_partition (create the scheduler before workers register),
external_kv_events (host feeds KV state; no ZMQ listeners), a policy-factory
override on the builder, and OverlapRefreshSource (partition indexer,
external, or disabled).

Not carried over in embedded mode: NATS active-sequence replica sync
(router_replica_sync warns), per-class queue metrics, and scheduler load
publication to the routing-load monitor.

Tests: routing_host::embedded_selection_books_and_releases_like_the_runtime_scheduler
mirrors the runtime preview/plan/abort/track/free flow on the embedded path;
embedded::worker_request_mirrors_runtime_config covers the catalog mapping.
All existing kv_router tests pass on the runtime path.

Signed-off-by: Ishan Dhanani <[email protected]>
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]>
(cherry picked from commit beb6ddc)
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]>

(cherry picked from commit 568d06c)
--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]>
(cherry picked from commit d586893)
…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]>
(cherry picked from commit fc22bac)

This branch had an error being deployed

1 failed deployment
external_collaborator — b2644f82 Deployed Sep 9, 2026 by ishandhanani via ok-to-test #133
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 feat router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant