Skip to content

feat(kv-router): session affinity for request-shaped hosts (EPP parity) - #44

Closed
ishandhanani wants to merge 2 commits into
idhanani/s1c-runtime-ingressfrom
idhanani/s1d-epp-affinity
Closed

ishandhanani wants to merge 2 commits into
idhanani/s1c-runtime-ingressfrom
idhanani/s1d-epp-affinity

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Stack 1, group D, second slice: EPP session-affinity parity. Stacked on #43. DEP #33.

Summary

Two logical commits:

  1. feat(kv-router): session affinity for request-shaped selection hosts — SelectionServiceBuilder::session_affinity(ttl) gives the core its own SessionAffinity table (the one refactor(kv-router): one session-affinity implementation for every selection host #42 moved into kv-router). A booked selection whose request carries a session id and no explicit pin or affinity target acquires the session first: a bound session steers selection to its worker, a new session is bound to the worker the scheduler chose, the lease is held with the booking and released by free_reservation, and a bound worker that was not selected (it left) is invalidated and the session rebound. Advisory selects read the binding. Bindings replicate over the existing ZMQ peer mesh on their own topic (dynamo.session-affinity.v1); the active-sequence topic and wire format are untouched, and peers that do not subscribe never see the new topic. Also fixes a setup_scoped_replica_sync call in the slot tracker that the standalone-slot-tracker feature had left uncompiled since feat(router): embedded selection partition parity with the runtime scheduler #35.
  2. feat(epp): session affinity in the standalone EPP — DYN_EPP_SESSION_AFFINITY_TTL_SECS turns the table on; the EPP passes x-dynamo-session-id (the header the frontend reads) as the request's session id. Hard mode only, because the EPP routes by headers and never observes where a request ran. The standalone binary and the Python SelectionService gain the same TTL setting.

Behavior

No change unless a TTL is configured. With it, the EPP gets what the frontend has had: repeat requests of a session land on the worker that served it, and peer replicas learn the binding.

Validation

  • cargo test -p dynamo-kv-router --features standalone-selection,standalone-slot-tracker --lib: 1107 passed, including two new core tests (a session stays on its first worker across bookings and reads; a replicated binding steers a new session and its lease frees with the booking).
  • cargo test -p dynamo-ext-proc: 141 passed.
  • cargo clippy for kv-router (both features), ext-proc (tests): clean. Bindings cargo check: clean.
  • Router e2e with mockers at the tip of feat(router): RuntimeIngress feeds the partition's index for the frontend #43 and this PR: running; result posted here.

Review notes (graham-code-review pass)

  • The core holds leases in a parking_lot::Mutex<HashMap<selection_id, AffinityLease>> keyed like the reservation index, so forget_reservation releases both in one place. No lock is held across an await.
  • ReplicaSyncConfig gained an optional affinity channel rather than a new event enum, so the slot tracker (which shares the type) is unaffected and the mesh wire stays compatible.
  • The two mesh topics share one PUB socket; the publisher task selects over both channels. Bounded channels, drop on full, as for active sequences.
  • AffinityError::ResourceExhausted (entry limit) maps to SelectionError::NotReady so the HTTP surface reports it as back-pressure, not a bad request.

SelectionServiceBuilder::session_affinity(ttl) gives the core its own
SessionAffinity table. A booked selection whose request carries a session id
(session_id or session_context) and no explicit pin or affinity target
acquires the session first: a bound session steers selection to its worker
(exclusive for the default selector) and a new one is bound to the worker the
scheduler chose. The lease is held with the booking and released by
free_reservation; a bound worker that was not selected (it left) is
invalidated and the session rebound. Advisory selects read the binding.

Bindings replicate over the existing ZMQ peer mesh on their own topic
(dynamo.session-affinity.v1) so peers that do not subscribe never see them;
the active-sequence topic and wire format are untouched. The publisher
multiplexes both channels onto one socket; PeerManager subscribes to the
second topic only when a handler is given. SelectionServiceConfig carries
the TTL for the standalone binary.

Also fixes the slot tracker's setup_scoped_replica_sync call, which the
standalone-slot-tracker feature had left uncompiled since the host replica
channels landed.

Signed-off-by: Ishan Dhanani <[email protected]>
DYN_EPP_SESSION_AFFINITY_TTL_SECS turns on the selector's session table. The
EPP passes x-dynamo-session-id, the same header the frontend reads, as the
request's session id, so repeat requests of a session land on the worker that
served it and peer EPPs learn the binding over the replica mesh. Hard mode
only: the EPP routes by headers and never observes where a request ran.

The standalone selection binary and the Python SelectionService gain the same
TTL setting (--session-affinity-ttl-secs, session_affinity_ttl_secs).

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

Copy link
Copy Markdown
Owner Author

Gates at tip 64fef40

  • cargo test -p dynamo-kv-router --features standalone-selection --lib, cargo test -p dynamo-llm --lib, cargo test -p dynamo-ext-proc, clippy, bindings check: pass (see PR body).
  • maturin develop --uv then pytest tests/router/test_router_e2e_with_mockers.py -m gpu_0: 45 passed, 6 skipped, 5 failed. The 5 failures are the same environment-only set as every previous tip: test_indexers_sync[nats-etcd], test_indexers_sync[nats-file], test_router_decisions[zmq_nats_free-tcp] (kv-indexer feature not built locally), test_router_decisions_router_aic[tcp], test_router_decisions_disagg_router_aic (aic-forward-pass not built).
  • Offline KV replay byte parity vs main at 705796f, two repetitions per side:
Row Baseline Candidate Cross
vLLM agg stable stable PARITY
vLLM disagg stable stable PARITY
SGLang agg stable stable PARITY
SGLang disagg stable stable PARITY

@ishandhanani

Copy link
Copy Markdown
Owner Author

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

This branch had an error being deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant