Repository navigation
feat(sglang): support session-attributed KV events - #14144
Closed
ishandhanani wants to merge 12 commits into
Closed
ishandhanani wants to merge 12 commits into
ishandhanani wants to merge 12 commits into
Conversation
Signed-off-by: Karen Chung <[email protected]>
Add a logical, per-session prefix index that records the block-hash lineage each session has matched. The physical indexers drop blocks when the engine evicts them, so session prefix history disappears with the cache; this arena keeps the logical chain independently of the physical cache state. The index is off by default behind --enable-session-prefix-index. When enabled, the router derives it inside the existing constructor from the KvRouterConfig it already receives and feeds it once per lookup with the deepest block that lookup matched. update_session_from_stored_blocks is implemented and unit-tested but not yet wired: the KV event schema carries no session id, so there is no honest producer for it today. Signed-off-by: [email protected] <[email protected]>
Review of the session prefix indexer surfaced two defects and three smaller gaps. This addresses all five. Unbounded retention. `remove_session` had no production caller, so the index grew for the life of the process. Both halves of the fix are needed because both signals are optional: the router now releases a session when a request carries `session_final` or the `evict_session` KV hint, and the indexer caps how many sessions it tracks (`DEFAULT_MAX_SESSIONS`, overridable via `with_max_sessions`), evicting the least recently used one by exactly the path `remove_session` takes. Cyclic parent grafts. `validate_chain` only compared a block against its recorded parent, so a chain grafting an ancestor under its own descendant was accepted and closed a parent cycle -- every later walk of the forest then looped forever holding the write lock. Validation now carries the dominator set of the graft point, which also catches a chain that revisits a node it created earlier in the same update. Rejection still happens before the arena is touched, so no chain half-applies. The two parent walks are additionally bounded by the arena size so a bookkeeping bug degrades rather than hangs. Also: correct the `deepest_matched_hash` doc comment, which claimed the match spanned every cache tier when only device details are ever passed; move the binding import in the router-args test to module scope behind the documented `pytest.importorskip` guard; and state the index's actual scope in the `enable_session_prefix_index` docstring -- lineage is fed from routing-lookup matches only, since stored-block KV events carry no session ID. Validation: cargo test -p dynamo-kv-router --lib session_prefix_index (17 pass, 6 new); cargo check --workspace --all-targets; cargo check in lib/bindings/python (out of workspace); cargo clippy on both changed crates; cargo fmt --all; gen_python_api.py regenerated and --check clean; pre-commit on the changed files. Signed-off-by: [email protected] <[email protected]>
Signed-off-by: Matej Kosec <[email protected]>
…session_id Signed-off-by: Karen Chung <[email protected]>
Signed-off-by: Karen Chung <[email protected]>
Co-authored-by: GLAMR <[email protected]> Signed-off-by: Karen Chung <[email protected]>
Signed-off-by: Karen Chung <[email protected]>
Signed-off-by: Karen Chung <[email protected]>
Signed-off-by: Ishan Dhanani <[email protected]>
Signed-off-by: Ishan Dhanani <[email protected]>
Signed-off-by: Ishan Dhanani <[email protected]>
karen-sy
force-pushed
the
karenc/session-prefix-indexer-rebase
branch
from
September 11, 2026 18:56
98ae8d9 to
35e4da4
Compare
ishandhanani
force-pushed
the
karenc/session-prefix-indexer-rebase
branch
from
September 14, 2026 06:00
30e3ae8 to
74a6e8e
Compare
Base automatically changed from
karenc/session-prefix-indexer-rebase
to
main
September 17, 2026 01:46
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.
This PR completes SGLang support for session-attributed KV events in Dynamo by forwarding canonical agent session IDs through the native sidecar and decoding SGLang's typed
BlockStoredmetadata. This lets the session prefix indexer join route-time shared-prefix matches with newly stored SGLang tails while preserving legacy vLLM positional events.Stacked on #13807, which is stacked on #13806. The engine-side event metadata is provided by sgl-project/sglang#37482; retarget this PR to
mainafter the stack lands.How This Was Implemented
PreprocessedRequest.agent_context.session_idinto SGLang's top-levelsession_idfor native gRPC and native HTTP requests.lora_name, then mapcache_saltandsession_idinto canonical Dynamo event fields.Walkthrough
Mental model
The request path supplies the triggering session to SGLang, and the event path returns that session with newly stored blocks. Dynamo keeps physical residency in its existing KV indexers and uses the optional logical session index only to associate the shared route-time prefix with the attributed tail.
flowchart LR A["agent_context.session_id"] --> B["SGLang sidecar request"] B --> C["SGLang BlockStored metadata"] C --> D["RawKvEvent"] D --> E["RouterEvent.session_id"] E --> F["SessionPrefixIndexer"]State and precedence
For native HTTP, a canonical
agent_context.session_idoverwrites an opaqueextra_args.sglang_tito.session_id; when canonical context is absent, the opaque native field remains untouched. Native gRPC writes the canonical value directly intoGenerateRequest.session_id.SGLang extends its positional
BlockStoredtuple at position seven with a typed metadata map. The deserializer uses an untagged enum to distinguish that map from the legacy positional vLLM string, preserving the existing vLLM trailing-field parser while mapping SGLangcache_salttocache_namespaceand retainingsession_idthrough the canonical event conversion.Request lifecycle
A route-time match records the deepest shared G1/G2 block for the session in the base PR. A resident SGLang cache hit emits no duplicate store event; when that request creates a tail, SGLang emits the shared parent hash plus new blocks with the triggering session, and Dynamo advances only that session's logical frontier.
Boundaries and limitations
This PR does not change block hashing, physical residency,
BlockRemoved, remote-indexer behavior, or SGLang session ownership. It does not bump Dynamo's SGLang pin; that follows an upstream SGLang release containing sgl-project/sglang#37482.Validation
cargo test -p dynamo-kv-router sglang_ --lib— 5 passed.cargo test -p dynamo-sglang-sidecar session_id— 2 passed.cargo test -p dynamo-llm stored_events_update_session_lineage --lib— 1 passed.cargo test -p dynamo-kv-router session_prefix_index --lib— 18 passed.cargo check -p dynamo-kv-router --all-targets --features standalone-indexerandcargo check -p kvbm-consolidator --all-targets— passed with pre-existing dead-code warnings only.Qwen/Qwen3-0.6B: raw SGLang ZMQ emitted four block hashes withsession_id=session-e2e-001; replay produced#cached-token: 64, Dynamo reportedoverlap_blocks=4, and both requests returned HTTP 200.