Skip to content

refactor(router): selection policy source, SelectionHost, and dead-flag removal - #37

Closed
ishandhanani wants to merge 4 commits into
idhanani/s1a-delete-kvschedulerfrom
idhanani/s1a-api-cleanup
Closed

ishandhanani wants to merge 4 commits into
idhanani/s1a-delete-kvschedulerfrom
idhanani/s1a-api-cleanup

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Stack 1, group A, step 3 (last) of the unification DEP (#33, "Stack 1 DEP r2" comment). Stacked on #36.

Summary

API cleanup after the runtime scheduler deletion. Four logical commits:

  1. refactor(router): remove the ignored router_embedded_selection flag — the flag was a no-op after refactor(router): delete the runtime-bound KV router scheduler #36 and never shipped, so it goes from KvRouterConfig (Rust and serde), the DYN_ROUTER_EMBEDDED_SELECTION override, the Python arg group, the bindings signature, and the frontend configuration reference. No wire shim: no released worker emits it.
  2. refactor(router): drop the selector type parameter from the frontend router — KvRouter, RoutingHost, RoutePlan, RequestGuard, PrefillRouter, ManagedKvRouter, ModelWatcher, and PreprocessedRouting lose <Sel>. Callers pass a SelectionPolicySource (Registry: the linked policy the config names, else Dynamo's default; Factory: an explicit WorkerSelectionPolicyFactory). The router resolves it once and instantiates one policy to learn its worker inputs, so shared-cache and indexer gating are unchanged. ModelManager constructors are renamed kv_chooser_for_with_policy[_and_client] / managed_kv_router_for_with_policy; the bindings' custom-policy feature no longer needs separate router types. The delegating-selector adapter in the embedded backend goes with its only caller.
  3. refactor(kv-router): remove the delegated worker-selector adapter — DelegatedWorkerSelector, ErasedWorkerConfig, and the Delegated policy state are deleted from the public selector module.
  4. refactor(kv-router): group host-supplied selection inputs into SelectionHost — SelectionHostHooks becomes SelectionHost { load, cache, eligibility, telemetry, replication }, each group defaulting to standalone behavior; builder method SelectionServiceBuilder::host. Group C replaces cache with the KV index source; group D extends replication.

Net: 614 insertions, 1131 deletions across 30 files.

Validation

  • cargo test -p dynamo-kv-router --features standalone-selection --lib: 1069 passed (selection core tests included).
  • cargo test -p dynamo-llm --lib -- kv_router:: discovery:: entrypoint::: 535 passed.
  • cargo clippy -p dynamo-llm -p dynamo-kv-router --tests: clean. Bindings cargo check with and without custom-policy: clean.
  • Group A exit gates (router e2e with mockers, replay parity, frontend A/B) run on this head; results posted as a comment.

Review notes (graham-code-review pass)

  • Unit tests that injected fake WorkerSelector types now inject picker/filter policies through the public worker-selection API. The old "all workers overloaded" test could not be expressed that way (a policy cannot report overload), so it became "all workers filtered maps to Unavailable"; the overload mapping keeps its direct map_scheduler_error unit test and the e2e 529 tests.
  • Cost of policy_worker_inputs: one extra policy instantiation at router construction (and one more in ModelManager for shared-cache gating). Factories are cheap builders; not worth a second constructor to avoid.
  • The bindings' custom-policy path wraps the caller's factory in a closure that pins the card's typed role and display name, preserving the previous behavior where those could differ from the router's metric role and model name.
  • HostTelemetry and HostReplication are single-field groups today. Kept as structs so the five groups in the DEP map one-to-one onto the type and groups C/D extend them without another rename.

The embedded selection partition is the only scheduler, so the flag has
been a no-op since the runtime scheduler was deleted. It never shipped in a
release, so no wire compatibility shim is needed: drop it from
KvRouterConfig (Rust and serde), the DYN_ROUTER_EMBEDDED_SELECTION
environment override, the Python argument group, the bindings signature,
and the frontend configuration reference.

Signed-off-by: Ishan Dhanani <[email protected]>
…router

KvRouter, RoutingHost, RoutePlan, RequestGuard, PrefillRouter, ManagedKvRouter,
ModelWatcher, and PreprocessedRouting were generic over a caller-injected
WorkerSelector type that only ever named the policy the embedded partition
would run. Replace the parameter with SelectionPolicySource: Registry (the
linked policy the router config names, else Dynamo's default) or Factory (an
explicit WorkerSelectionPolicyFactory). The router resolves it once at
construction and instantiates one policy to learn the worker inputs it needs,
so shared-cache and indexer gating are unchanged.

ModelManager constructors take the policy source in place of a selector
(kv_chooser_for_with_policy[_and_client], managed_kv_router_for_with_policy);
HttpFrontend, ModelWatcher, and PrefillRouter carry it instead of a
per-model selector factory. The bindings' custom-policy feature no longer
needs a separate router type. The delegating-selector adapter in the
embedded backend is removed with its only caller. Unit tests that injected
fake selectors now inject picker or filter policies through the public
worker-selection API; the overload test becomes a filtered-workers test
because a policy cannot report overload directly.

Signed-off-by: Ishan Dhanani <[email protected]>
DelegatedWorkerSelector, ErasedWorkerConfig, and the Delegated policy state
existed only so the frontend could run an arbitrary caller-injected
WorkerSelector type on a partition. That path is gone with the selector type
parameter; custom policies use WorkerSelectionPolicy's filter, scorer, and
picker API like every other host.

Signed-off-by: Ishan Dhanani <[email protected]>
…ionHost

SelectionHostHooks was a flat bag of eight optional fields. Regroup it by
purpose as SelectionHost { load, cache, eligibility, telemetry, replication },
each group defaulting to the standalone service's behavior so a host sets only
the groups it owns. The builder method becomes SelectionServiceBuilder::host.
No behavior change; the frontend's embedded partition sets the same values.

Signed-off-by: Ishan Dhanani <[email protected]>
@github-actions github-actions Bot added refactor documentation Improvements or additions to documentation router labels Sep 3, 2026
@ishandhanani

Copy link
Copy Markdown
Owner Author

Group A exit gate: router e2e with mockers (this head, d445ce763b)

pytest tests/router/test_router_e2e_with_mockers.py -m gpu_0 with bindings built by maturin develop --uv (default features):

Result Count
passed 45
skipped 6
failed, environment only 5

The five failures are build-feature gaps in this environment, not router behavior: test_indexers_sync[nats-etcd], test_indexers_sync[nats-file], and test_router_decisions[zmq_nats_free-tcp] need dynamo.indexer (--features kv-indexer); test_router_decisions_router_aic[tcp] and test_router_decisions_disagg_router_aic need --features aic-forward-pass. Every KV routing, replica-sync, overload (529), session-affinity, and disaggregated test that ran passed on the embedded partition with SelectionPolicySource::Registry.

@ishandhanani

Copy link
Copy Markdown
Owner Author

Superseded by the upstream-shaped staging stack: continued as #49 (rebased onto ai-dynamo/main, see #33).

This branch had an error being deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant