Skip to content

refactor(kv-router): one session-affinity implementation for every selection host - #52

Closed
ishandhanani wants to merge 1 commit into
idhanani/up-7-kv-index-sourcefrom
idhanani/up-8-affinity-table
Closed

ishandhanani wants to merge 1 commit into
idhanani/up-7-kv-index-sourcefrom
idhanani/up-8-affinity-table

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

PR 8 of 9 implementing ai-dynamo#14310 (one SelectionCore for the frontend, the standalone selection service, and the EPP). Base: idhanani/up-7-kv-index-source (PR 7 of this stack).

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

Summary

Moves the session-affinity table from lib/llm into the runtime-free selection package. Frontend and standalone hosts can then reuse the same binding, lease, expiry and replica-conflict semantics.

Implementation

  • Moves SessionAffinity, versioned bindings, TTL reaping and capacity limits into dynamo_kv_router::services::selection::affinity.
  • Shares initialization and lease types, target validation and hard/soft affinity modes.
  • Exposes replica publication through AffinityReplicaSink and weak table handles.
  • Makes the frontend coordinator a transport and request-lifecycle wrapper around the shared table.
Walkthrough
flowchart LR
  Request[Frontend request] --> Coordinator[AffinityCoordinator]
  Coordinator --> Table[Shared SessionAffinity implementation]
  Table --> Lease[Initialization or active lease]
  Lease --> Stream[Response-stream lifetime]
  Table --> Sink[Host replica sink]
Loading

Binding and request lifetime

An unbound session acquires an initialization slot, which commits the dispatched worker or releases the slot when dropped. A bound session acquires a lease; dropping the lease refreshes its idle expiry. Soft mode can rebind and hard mode validates the bound target. Entry limits, ID limits and replica versions preserve their existing semantics.

Waiting returns a pinned, enabled OwnedNotified registered while the entry lock is held. The host can race that wait against request cancellation without a missed notification. The table contains no runtime transport and does not hold a lock across an await.

Boundary within the stack

At this PR, the frontend still constructs its table and uses its runtime event-plane replica transport. The standalone service does not enable affinity until #53. That final PR makes affinity partition-owned for KV selection and lets the frontend borrow the partition's table, while builtin routing modes retain host-owned tables.

Weak table handles prevent replica tasks from keeping an unused table alive. Cross-crate test hooks preserve the existing table and frontend coordinator coverage.

Validation

Current stack boundary: f413da4bd432bf6c1db31f3dd4fc2a05ccfa4da2; 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.

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 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 (this PR) 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

… host

Move the session table out of lib/llm/src/session_affinity into
dynamo_kv_router::services::selection::affinity: SessionAffinity (session id
-> bound worker/rank, versioned, TTL reaper, entry and id limits), the
AffinityInitialization / AffinityLease lifecycle (commit, rebind, invalidate,
release on drop), hard and soft validation, and replica apply with the same
outcome table. Replication becomes an AffinityReplicaSink the host installs;
the table stays transport-free.

The frontend AffinityCoordinator is now a thin wrapper: it converts the
pipeline RouteTarget at the boundary, abandons an initialization wait when the
request context stops, holds a lease for the life of a response stream, and
keeps its runtime event-plane replica sync (same subject and wire format)
behind the sink. SessionAffinityMode moves with the table; lib/llm re-exports
it. All 37 session-affinity tests and the routing-host affinity tests run
unchanged against the wrapper.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani
ishandhanani force-pushed the idhanani/up-8-affinity-table branch from 64653cd to f413da4 Compare September 9, 2026 19:06

This branch had an error being deployed

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