Skip to content

refactor(kv-router): one Indexer type, partition-owned index, KvEventIngress - #41

Closed
ishandhanani wants to merge 3 commits into
idhanani/s1c-kv-index-sourcefrom
idhanani/s1c-kv-index-unify
Closed

ishandhanani wants to merge 3 commits into
idhanani/s1c-kv-index-sourcefrom
idhanani/s1c-kv-index-unify

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Stack 1, group C (KV index and ingress), second slice. Stacked on #39. DEP #33, "Stack 1 DEP r2" comment.

Summary

Three logical commits:

  1. refactor(kv-router): one Indexer type for the frontend and the selection service — lib/llm and lib/kv-router each had an Indexer enum with the same Single/Concurrent/Remote shape and diverging method sets. The frontend's richer implementation moves into dynamo_kv_router::services::indexer (lookup.rs: borrowed/owned lookup pipeline; recording.rs: routing-decision recording targets and ApproximateRequestLease; backend.rs: merged enum with None, residency setters, try_apply_event, reset_worker_dp_rank_and_wait, approximate-LRU API). Remote primaries sit behind RemotePrimary, implemented by the HTTP standalone client in kv-router and by the request-plane RemoteIndexer in lib/llm. The frontend keeps construction (indexer::build, component metrics, request-plane remote), the served-indexer service, and recovery. Its 16 indexer tests move with the code. Net for lib/llm: -1,200 lines.
  2. refactor(kv-router): the frontend's index is the partition's index — KvIndexSource::External { refresh } becomes Provided(Arc<Indexer>): the host builds and feeds the index, the core holds it as every partition's index, reads it for selection and dequeue-time refresh, and never writes to it. The frontend's embedded partition now shares the KvRouter's Indexer object. RefreshProvider loses its External variant.
  3. feat(kv-router): KvEventIngress feeds core-owned indexes — KvIndexSource::Owned(Arc<dyn KvEventIngress>). The trait decides what metadata a worker needs, attaches its ranks when it becomes schedulable, detaches on delete. ZmqDirectIngress is the previous in-core listener code moved out of SelectionCore, which no longer knows about ZMQ endpoints.

lib/kv-router still never imports dynamo-runtime.

No behavior change

  • Frontend: same index construction, same event admission path (try_apply_event via RecoveryTarget), same lookups (find_matches_by_tier*), same metrics type (KvIndexerMetrics::from_component was already the kv-router type). apply_event on the shared enum is the standalone device-only apply; the frontend's test-only apply_event shim is gone and its tests call try_apply_event.
  • Standalone/EPP: same listener lifecycle, same schedulability reasons (kv_events endpoint is required for dp_rank N), same apply_event_routed and remove_worker paths. TieredMatchProvider for Indexer keeps the capability-gated retention variant, which is what both hosts relied on.

What remains in group C

RuntimeIngress: the frontend still feeds its index from KvRouter::new (subscriber, worker-query recovery, state agent, source health, served indexer, approximate-LRU reconciler). Making that an Owned(RuntimeIngress) requires the core to build the frontend's index shape (component metrics, request-plane remote, LRU retention with lease fencing) or the ingress to build it, and moving the recovery state machine into the core means abstracting the event subscriber and worker-query transport (WorkerQueryTransport exists; EventSubscriber does not). ~11k transport-bound lines; the deletion gate from the DEP (replay parity, e2e) applies. Provided is the boundary until then, and peer /dump recovery stays for the standalone service because its cold start has no engine-authoritative full dump yet.

Validation

  • cargo test -p dynamo-kv-router --features standalone-selection --lib: 1088 passed (16 moved indexer tests included).
  • cargo test -p dynamo-llm --lib: 2537 passed after commit 1; kv_router:: 309 passed at the tip.
  • cargo test -p dynamo-ext-proc: 141 passed.
  • cargo clippy for dynamo-kv-router (feature standalone-selection), dynamo-llm, dynamo-ext-proc (tests): clean. Bindings cargo check: clean.
  • Router e2e with mockers: running on this head; result posted as a comment.

Review notes (graham-code-review pass)

  • Provided(Arc<Indexer>) rather than Provided(Indexer): clippy flagged the variant size, and RefreshProvider already holds an Arc<Indexer>.
  • The core never mutates a Provided index (cleanup_indexer_registration returns early): the frontend's recovery machinery owns rank resets, and letting the core call remove_worker on catalog delete would have been a behavior change.
  • KvEventIngress::attach/detach take the WorkerRegistry because the registry holds the per-rank listener lifecycle alongside the indexes today; splitting the registry is not this PR's job.
  • SideIndexer::new gained the cancellation token the frontend always passed; the registry passes a fresh token as before.

…ion service

lib/llm and lib/kv-router each carried an Indexer enum with the same
Single/Concurrent/Remote shape (primary, lower tiers, predict-on-route side
overlay, primary_records_routing_decisions) and diverging method sets. Fold
the frontend's richer implementation into dynamo_kv_router::services::indexer:

- lookup.rs: the borrowed/owned HashInput lookup pipeline (primary, lower tiers
  seeded from confirmed primary matches, side overlay merged by per-worker
  max), find_matches_by_tier[_ref][_with_options], find_primary_*.
- recording.rs: routing-decision recording targets (side overlay, approximate
  primary, remote primary) and the per-request ApproximateRequestLease.
- backend.rs: the merged enum gains None, residency projection setters,
  try_apply_event (the backpressure-aware admit with a completion barrier on
  Cleared that recovery relies on), reset_worker_dp_rank_and_wait, and the
  approximate-LRU capacity and stats API. apply_event_routed and
  remove_worker[_dp_rank] stay as the standalone listener's path. Remote
  primaries go behind RemotePrimary so the HTTP standalone client here and the
  request-plane RemoteIndexer in lib/llm plug into the same enum. dump_events
  returns KvRouterError like the rest of the surface.
- The frontend keeps only construction (indexer::build from KvRouterConfig
  with component metrics and the request-plane remote), the served-indexer
  service, and recovery. Its 16 indexer tests move with the code.

No behavior change: both hosts run the exact code they ran before for their
own paths; TieredMatchProvider keeps the capability-gated variant.

Signed-off-by: Ishan Dhanani <[email protected]>
KvIndexSource::External { refresh } gave the core only a refresh handle onto
an index the host kept elsewhere. Replace it with Provided(Arc<Indexer>): the
host builds and feeds the index, and the core holds it as every partition's
index, reading it for selection and dequeue-time refresh (when the index
supports refresh) and never writing to it. The frontend's embedded partition
now shares the KvRouter's Indexer object instead of a TieredMatchProvider
view of it. RefreshProvider loses its External variant.

Signed-off-by: Ishan Dhanani <[email protected]>
KvIndexSource::Owned carries the ingress that feeds the core-built index.
The trait decides what metadata a worker needs to be schedulable, attaches
its ranks when the worker becomes schedulable, and detaches them when it
leaves. ZmqDirectIngress is the existing standalone behavior moved out of
SelectionCore: endpoint validation, one ZMQ listener per rank on the
registry, replay endpoint, deregistration on delete. The core keeps the
lifecycle decisions (when to attach, how to mark Incomplete) and no longer
knows about ZMQ endpoints.

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

Copy link
Copy Markdown
Owner Author

Group C exit gate: router e2e with mockers (this head, 6e9a08c68b)

pytest tests/router/test_router_e2e_with_mockers.py -m gpu_0, bindings rebuilt with maturin develop --uv (default features): 45 passed, 6 skipped, 5 failed. The five failures are the same environment-only set as on #37 (dynamo.indexer needs --features kv-indexer: test_indexers_sync[nats-etcd], test_indexers_sync[nats-file], test_router_decisions[zmq_nats_free-tcp]; AIC needs --features aic-forward-pass: test_router_decisions_router_aic[tcp], test_router_decisions_disagg_router_aic). Every KV-routing, replica-sync, overload, session-affinity, and disaggregated test that ran passed with the shared Indexer as the partition's index.

@ishandhanani

Copy link
Copy Markdown
Owner Author

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

This branch had an error being deployed

1 failed deployment
external_collaborator — 6e9a08c6 Deployed Sep 4, 2026 by ishandhanani via ok-to-test #66
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