Repository navigation
refactor(kv-router): one session-affinity implementation for every selection host - #42
Closed
ishandhanani wants to merge 1 commit into
Closed
ishandhanani wants to merge 1 commit into
ishandhanani wants to merge 1 commit into
Conversation
… 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
had a problem deploying
to
external_collaborator
September 4, 2026 00:32 — with
GitHub Actions
Failure
This was referenced Sep 4, 2026
Closed
Owner
Author
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_affinityintodynamo_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 sameReplicaApplyOutcometable.AffinityInitialization(commit with the dispatched worker; dropping uncommitted frees the slot and wakes waiters) andAffinityLease(publish, soft-moderebind,invalidate, release on drop refreshes the idle deadline).validate_bound_target/validate_dispatch_targetfor the hard/soft contract;SessionAffinityModemoves with the table.AffinityReplicaSinkthe host installs with its writer id; the table stays transport-free. A wait on another request's initialization is returned as an already-registeredOwnedNotifiedso the host can race it against its own cancellation without a missed wakeup.The frontend
AffinityCoordinatoris now a wrapper over the table: it converts the pipelineRouteTargetat 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 (
AffinityReplicaSinkfor bindings,HostReplicationfor 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. Bindingscargo check: clean.Review notes (graham-code-review pass)
AcquireStep::Waithands out a pinned, enabledOwnedNotifiedcreated while the entry lock is held, preserving the original's missed-wakeup guard; the table does not await anything itself.wait_for_reaper,wait_for_initializing_waiter,expire_for_test) are real methods because the frontend's tests live in another crate; they cost twoNotifys per table.WeakSessionAffinityreplaces theWeak<Inner>the replica applier held, so a sink task never keeps the table alive.