Repository navigation
feat(agent sessions): attribute stored KV cache blocks to sessions - #37482
Conversation
Signed-off-by: Ishan Dhanani <[email protected]>
|
/tag-and-rerun-ci |
Signed-off-by: Ishan Dhanani <[email protected]>
|
/rerun-failed-ci |
…on-kv-events-sidecar Signed-off-by: Ishan Dhanani <[email protected]>
Signed-off-by: Ishan Dhanani <[email protected]>
Signed-off-by: Ishan Dhanani <[email protected]>
|
/rerun-test test/registered/e2e/models/test_inkling_unified.py |
|
Results for 🚀 |
|
/rerun-test test/registered/e2e/models/test_glm53_flash_b200.py |
|
Results for 🚀 |
|
/rerun-test test/registered/unit/disaggregation/test_kv_events.py test/registered/unit/mem_cache/test_radix_cache_unit.py test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py test/registered/unit/mem_cache/test_rust_unified_radix_cache_unittest.py test/registered/rust/test_run_sglang_radix_tree_rust_tests.py |
|
Results for 🚀 🚀 |
|
/rerun-test test/registered/unit/disaggregation/test_kv_events.py test/registered/unit/mem_cache/test_radix_cache_unit.py test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py test/registered/unit/mem_cache/test_rust_unified_radix_cache_unittest.py test/registered/rust/test_run_sglang_radix_tree_rust_tests.py |
|
Results for 🚀 🚀 |
|
all relevant CI passed. only 1 flaky base c failed. |
Brings in the segment lock protocol with receipts (#36848), SWA branching-point caching (#37584), the external cache linker (#37306), session-attributed KV events (#37482), aux LRU preservation on split (#38482), and the buffer-mode prefetch rework (#39283). Every conflicting signature keeps main's shape with V in place of Tensor; main's new Tensor-only code paths (external-linker offload transfers, the multi-node SWA backup commit) use the RadixValue operations; the duplicated read-only FULL-device walk behind full_kv_prefix_len and match_full_device_prefix is shared through one private helper.
…maps Cherry-picked from #37482. Engines now emit each KVCacheEvent as a msgspec tagged map ({"type": ..., <field>: ...}) rather than a positional array; the decoder accepts both, so the ZMQ component tests now exercise the shape live engines send. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JqRozm7pWUVqLM9Uppzypk
This PR adds optional request
session_idmetadata to SGLangBlockStoredKV events while preserving the existing seven-element base wire payload when no metadata is present. It gives external KV routers enough engine-side evidence to associate stored block lineage with the triggering session without treating shared radix-cache blocks as session-owned.How This Was Implemented
BlockStoredMetadatawith an optionalsession_idand include metadata in the wire payload only when at least one field is populated.Req.session_idthrough finished and unfinished unified-cache inserts and request-driven unevict events.session_idcompatible withcache_salt; event metadata does not participate in block hashing or cache identity.Walkthrough
Mental model
The event identifies the request that caused a physical store transition. It is not an owner list for a content-addressed block that several sessions may share.
flowchart LR A["Req.session_id"] --> B["InsertParams"] B --> C["UnifiedTreeCore insert or unevict"] C --> D["KVCacheEventRecorder"] D --> E["BlockStored metadata"] E --> F["External KV event consumer"]Request lifecycle
The request's session identifier follows the same insertion context as the token IDs and optional cache salt. New pages and request-driven unevicts attach that identifier to
BlockStored; a resident shared-prefix hit emits no duplicate store event, while a divergent tail links back to the shared parent hash and carries the session that created the tail.Boundaries and limitations
Background HiCache transitions without request context remain unattributed,
BlockRemovedremains unchanged, and events with different metadata do not coalesce. This change does not add vLLM-style opt-in full cache-hit reporting or change session-radix-cache ownership and lifecycle tracking.Validation
.venv/bin/python -m pytest -q test/registered/unit/disaggregation/test_kv_events.py::TestBlockStoredWireFormat test/registered/unit/mem_cache/test_radix_cache_unit.py::TestKVCacheEventQueue test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py -k 'TestBlockStoredWireFormat or TestKVCacheEventQueue or session_id_is_attributed or session_id_and_cache_salt or shared_prefix_hit_is_quiet_and_divergent_tails_are_attributed'— 11 passed, 2436 deselected.uvx --from 'black==26.1.0' black test/registered/unit/mem_cache/test_unified_radix_cache_unittest.pyanduvx --from 'ruff==0.15.1' ruff check --select=F401,F821,UP037 test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py— passed.SessionPrefixIndexerregression combines two route-time shared-prefix matches with two session-attributed divergent tails — all 18 session-prefix-index tests passed.Qwen/Qwen3-0.6B: raw ZMQ emitted four stored block hashes withsession_id: session-e2e-001; replay reported#cached-token: 64and Dynamo reportedoverlap_blocks=4; the request completed with HTTP 200.Related Dynamo work: ai-dynamo/dynamo#13806 and ai-dynamo/dynamo#13807
CI States
Latest PR Test (Base): 🚫 Run #34811471297
Latest PR Test (Extra): ❌ Run #34811471181
Latest PR Test (AMD ROCm 10): ❌ Run #34811471338
Wire encoding change (added after review)
KV events are now tagged msgpack maps, not positional arrays.
KVCacheEventdropsarray_like=Trueand keepstag=True, omit_defaults=True, so each event is{"type": "<ClassName>", "<field>": ...}and optional fields left atNoneare omitted.cache_saltandsession_idare plain optional fields onBlockStored.BlockStoredMetadataandBlockStoredWithMetadataare removed.EventBatchstays a positional array[ts, events, attn_dp_rank].Why: positional arrays cannot grow. msgspec does not trim a trailing
Noneinarray_likestructs (tested on 0.21.1), so salt metadata had to ride as an extra trailing element (#30827). That element landed in thelora_nameslot of consumers that share a decoder with vLLM, and Dynamo dropped every salted batch (ai-dynamo/dynamo#14530 has the reproduction). Exported typed consumers could not read the salt either (#38561). vLLM moved its KV events to this exact map encoding in v0.24, so consumers now decode both engines with one code path.This is a wire-format change for positional consumers. It will be called out in the release notes of the next SGLang release. The in-repo consumers (
experimental/sgl-routerandsgl-kv-indexer) decode the map shape only; the old array shape is rejected.Size: a 16-token, 8-block
BlockStoredgrows from about 666 to 755 bytes (keys); block hashes and token ids still dominate.Validation of the encoding change
test/registered/unit/disaggregation/test_kv_events.py: events encode as tagged maps, unset optionals are omitted, oneKVEventBatchdecoder reads a mixed stream (unsalted, salted, session-attributed, removed, cleared), batch stays an array.test_radix_cache_unit.py,test_unified_radix_cache_unittest.py,test_rust_tree_core_integration.pyupdated to the plain fields and run on GPU.sgl-routerwire decoder: 27 tests including msgspec golden bytes of a mixed map batch;sgl-kv-indexerbridge: 42 tests including map-form report/revoke/clear, ignored attribution keys, component-aware maps, and skipped undecodable maps.cache_salt;session_idread once feat(router): retrieve optional session_id field from vLLM engine KV events ai-dynamo/dynamo#13806 lands).