Skip to content

feat(kv-router): session affinity for the standalone service and EPP - #53

Closed
ishandhanani wants to merge 5 commits into
idhanani/up-8-affinity-tablefrom
idhanani/up-9-epp-affinity
Closed

ishandhanani wants to merge 5 commits into
idhanani/up-8-affinity-tablefrom
idhanani/up-9-epp-affinity

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

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

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

Summary

Adds session affinity to the standalone selection service and EPP, with one affinity table per selection partition and leases owned by reservation records. The final stack also fixes lifecycle bugs found during review so expiry, worker metadata updates and scale-to-zero/rejoin preserve the correct state.

Implementation

  • Enables affinity through the service builder, standalone CLI, Python constructor and DYN_EPP_SESSION_AFFINITY_TTL_SECS; EPP forwards x-dynamo-session-id and uses hard mode.
  • Scopes bindings and replica payloads to the selection partition, preventing equal session IDs in different models or routing groups from colliding.
  • Stores the affinity lease in the reservation record, so freeing or sweeping that record releases it without a separate lease map.
  • Lets the frontend borrow the partition table and share one coordinator; replica initialization is idempotent and follows the coordinator lifetime.
  • Prepares and serializes worker catalog updates, retains empty partition indexes, and preserves live bookings and unchanged subscriptions during metadata updates.
  • Preserves main's deferred replica observer and frontend expiry ownership; removes redundant wrappers/arguments/LoRA filtering and rejects invalid Python/CLI TTLs before Duration conversion.
Walkthrough
flowchart LR
  Frontend[Frontend coordinator] --> Table[Partition affinity table]
  EPP[EPP or standalone request] --> Core[SelectionCore]
  Core --> Table
  Core --> Scheduler[Partition scheduler and index]
  Core --> Reservation[Reservation record]
  Reservation --> Lease[Owned affinity lease]
  Table --> Replica[Partition-scoped replica event]
Loading

Selection and lease ownership

When affinity is enabled, a booked request with a session ID and no explicit pin or affinity target acquires the partition's session binding before selection. A new binding commits the selected worker; a valid existing binding steers later requests to that worker. If the bound worker has left and another worker is selected, the stale binding is invalidated and rebound. Waiting for another initializer honors cancellation.

The reservation index stores { partition, affinity lease } in one record. The record is inserted after fallible endpoint resolution; explicit free, missing-booking cleanup and the stale-reservation sweep all drop the same lease. Advisory selection only reads an existing binding: it does not wait, book or initialize affinity. EPP cannot observe the actual dispatch outcome, so its supported mode is hard affinity.

Catalog and replica lifecycle

Upserts prepare their records before taking the catalog mutation lock, allowing independent partition policy construction. Reconciliation publishes committed metadata and changes only removed or modified ranks/endpoints. A valid metadata update preserves surviving bookings and unchanged KV listeners; invalid records become incomplete after cleanup. An empty partition keeps its index so a rejoined worker feeds the index the scheduler still holds.

Standalone bookings retain periodic expiry. The frontend retains RequestLeaseManager expiry ownership, avoiding a second independent expiry task for those requests, and the deferred replica observer preserves startup Add/Free replay. The frontend wraps its partition table once and shares replica initialization and shutdown across coordinator clones. Builtin routing modes that have no selection partition retain their host-owned table.

Review decisions

Tom's DEP feedback informed partition ownership. Availability/overload callbacks remain because transport inhibition, immediate overload feedback, backend KV occupancy and the two-signal latch are not represented by catalog/slot state alone. Controller-aware LoRA filtering retains replica_set and is_active semantics; loaded-adapter metadata alone is insufficient. ModelManager keeps shared-cache endpoint subscriptions to preserve configuration gates, overrides and reconnect behavior without duplicate listeners.

The lease leak, cross-partition binding collision, sole-worker rejoin bug, metadata-update state loss and Python TTL panic were reproduced before their fixes. TTL validation rejects invalid, non-finite and out-of-range values before conversion; Python declarations match the runtime constructor.

Validation

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

Final-stack validation

  • Rust suites: 1,115 KV-router tests, 2,420 LLM tests with no default features, and 154 EPP tests passed (3,689 total; three ignored). Strict core Clippy passed.
  • Python: 23 targeted routing, affinity, custom-policy and stream-error checks passed. All 16 focused SelectionService bindings tests passed, including 13 TTL cases; the isolated Rust shutdown test passed with explicit libpython linking.
  • Regular/sidecar and custom-policy binding checks passed. Bindings all-target Clippy passed with kv-indexer,slot-tracker,select-service. All nine stack boundaries passed the Rust compile check above; bindings with select-service also passed at feat(kv-router): approximate, remote, and hint-aware indexing in SelectionService #46–feat(kv-router): session affinity for the standalone service and EPP #53.

Aggregated end-to-end validation

Two B200 GPUs ran two TP1 aggregated SGLang 0.5.19 workers serving Qwen3-0.6B, with a KV-aware Dynamo frontend, hard session affinity and worker ZMQ KV events enabled. Baseline was ab58558c2dff28f4ff1ea4e219030eac5da3f48f. The GPU candidate was built at 63e998744f53194c7a1a6a99adbc6e5c5c6bb317, whose Git tree exactly equals this published head b91015f183bc159e1fbf6968f2cc967cbbc0b23f; the later change only moved a bindings compatibility fix to its earliest stack boundary. Both arms used identical installed package versions, model revision and deployment settings.

  • 49 frontend completions: 16 sessions exercised unary/streaming/unary requests across two workers, followed by stream cancellation and a successful same-session follow-up.
  • 34 standalone-selector completions: SelectionService booked workers, requests were forwarded through the frontend with explicit worker pins, and every response's actual worker matched the selection. The probe exercised repeated sessions, metadata refresh, catalog withdrawal/failover, catalog scale-to-zero/rejoin and reservation release, finishing with zero active bookings.
  • 11,264 AIPerf profiling requests plus 704 warmups: all completed with zero benchmark errors, cancellations or context skips. Every profiling record was joined to a successful frontend completion; all server outputs were exactly 128 tokens and requests were balanced across both workers.

The standalone probe used approximate indexing and pinned frontend forwarding. EPP was covered by its Rust suite, not a live Envoy/Kubernetes deployment. This validation was aggregated only; no disaggregated serving test or separate DisaggCoordinator work is claimed. All benchmark jobs completed and compute was released.

Benchmark results

AIPerf 0.12.0 used streaming chat, concurrency 16, synthetic ISL 512, forced OSL 128 (ignore_eos=true, min_tokens=128) and seed 42. Three alternating main/final pairs measured 512 requests after 32 warmups per deployment. A longer reversed-order final/main pair measured 4,096 requests after 256 warmups per deployment, with approximately 73-second observation windows.

Measurement Main Final Final throughput delta
Short pair 1, requests/s 57.99 55.45 -4.38%
Short pair 2, requests/s 56.27 56.11 -0.28%
Short pair 3, requests/s 55.66 54.15 -2.71%
Median of short runs, requests/s 56.27 55.45 -1.44%
Longer pair, requests/s 56.48 56.16 -0.58%
Longer pair TTFT p50 / p99, ms 42.97 / 65.65 42.99 / 46.35 —
Longer pair latency p50 / p99, ms 283.35 / 308.50 287.01 / 313.37 —

Prompt artifacts were byte-identical between matched arms. Short-run prompts were 512 client tokens / 520 server tokens after chat framing; two prompts per longer arm retokenized to 513/521, with matching histograms on both arms. Client output retokenization varies slightly around the verified 128 server tokens, so request throughput is the primary comparison.

The small measured throughput reduction consistently favors main. These runs do not establish zero overhead, statistical equivalence or production-scale capacity.

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 idhanani/up-8-affinity-table refactor(kv-router): one session-affinity implementation for every selection host #42
9 (this PR) idhanani/up-9-epp-affinity feat(kv-router): session affinity for the standalone service and EPP #44

@github-actions github-actions Bot added documentation Improvements or additions to documentation feat labels Sep 4, 2026
@ishandhanani
ishandhanani force-pushed the idhanani/up-9-epp-affinity branch from 868bc87 to 6004852 Compare September 4, 2026 04:00
@ishandhanani
ishandhanani added this pull request to stack #54 September 9, 2026 06:20
@ishandhanani
ishandhanani force-pushed the idhanani/up-9-epp-affinity branch from 6004852 to 6e37f0d Compare September 9, 2026 18:30
@github-actions github-actions Bot added the router label Sep 9, 2026
@ishandhanani
ishandhanani force-pushed the idhanani/up-9-epp-affinity branch from 5a6bcf4 to 63e9987 Compare September 9, 2026 18:50
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.

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]>

This branch had an error being deployed

1 failed deployment
external_collaborator — b91015f1 Deployed Sep 10, 2026 by ishandhanani via ok-to-test #140
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 router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant