Skip to content

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

Closed
ishandhanani wants to merge 1 commit into
idhanani/s1c-kv-index-unifyfrom
idhanani/s1d-affinity
Closed

ishandhanani wants to merge 1 commit into
idhanani/s1c-kv-index-unifyfrom
idhanani/s1d-affinity

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Stack 1, group D (session affinity and replication). Stacked on #41. DEP #33, "Stack 1 DEP r2" comment.

Summary

One logical commit: the session-affinity table moves out of lib/llm/src/session_affinity into dynamo_kv_router::services::selection::affinity, so every selection host shares one implementation.

  • SessionAffinity: session id to bound worker/rank, versioned (AffinityVersion: sequence plus writer id), TTL reaper, entry and id limits, try_acquire / acquire / query_target, replica apply with the same ReplicaApplyOutcome table.
  • AffinityInitialization (commit with the dispatched worker; dropping uncommitted frees the slot and wakes waiters) and AffinityLease (publish, soft-mode rebind, invalidate, release on drop refreshes the idle deadline).
  • validate_bound_target / validate_dispatch_target for the hard/soft contract; SessionAffinityMode moves with the table.
  • Replication is an AffinityReplicaSink the host installs with its writer id; the table stays transport-free. A wait on another request's initialization is returned as an already-registered OwnedNotified so the host can race it against its own cancellation without a missed wakeup.

The frontend AffinityCoordinator is now a wrapper over the table: it converts the pipeline RouteTarget at the boundary, abandons a wait when the request context stops or is killed, holds a lease for the life of a response stream (AffinityTrackedStream), and keeps its runtime event-plane replica sync behind the sink with the same subject and wire format. RoutingHost, PrefillRouter, and the entrypoints are untouched.

Behavior

Unchanged for the frontend: same table semantics (the code moved), same replication messages, same error types (InvalidArgument, ResourceExhausted, Cancelled). All 37 session-affinity tests and the routing-host affinity tests run unchanged against the wrapper.

Scope note

The DEP's "one replication hook carrying active-sequence and affinity-binding events over either transport" is satisfied at the API level (AffinityReplicaSink for bindings, HostReplication for active sequences; the frontend implements both over the runtime event plane). Carrying bindings over the standalone ZMQ peer mesh, and a core-owned table for request-shaped hosts, add capability the EPP does not consume yet (it passes no session context), so they are not in this PR. The frontend's builtin routing modes (no partition) also need a host-owned table, which is why the host, not the core, owns the instance.

Validation

  • cargo test -p dynamo-llm --lib: full suite passes (session affinity and routing-host affinity tests included).
  • cargo clippy -p dynamo-kv-router --features standalone-selection -p dynamo-llm --tests: clean. Bindings cargo check: clean.

Review notes (graham-code-review pass)

  • AcquireStep::Wait hands out a pinned, enabled OwnedNotified created while the entry lock is held, preserving the original's missed-wakeup guard; the table does not await anything itself.
  • Test hooks (wait_for_reaper, wait_for_initializing_waiter, expire_for_test) are real methods because the frontend's tests live in another crate; they cost two Notifys per table.
  • WeakSessionAffinity replaces the Weak<Inner> the replica applier held, so a sink task never keeps the table alive.

… 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

Copy link
Copy Markdown
Owner Author

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

This branch had an error being deployed

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