feat(llm): normalize prompt cache retention into KV hints#11534
Draft
ishandhanani wants to merge 8 commits into
Draft
feat(llm): normalize prompt cache retention into KV hints#11534ishandhanani wants to merge 8 commits into
ishandhanani wants to merge 8 commits into
Conversation
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
This was referenced Jul 10, 2026
|
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 draft normalizes current OpenAI and Anthropic prompt-cache controls into one provider-neutral full-prompt KV retention envelope and carries it through Dynamo to SGLang. It creates the first narrow KV-hint contract without changing sticky sessions, router placement, admission ordering, or scheduler policy.
CLOSES: DYN-3451
CLOSES: DYN-3420
CLOSES: DYN-3419
Depends on frontend-crates #107, SGLang #30796, and Mooncake #2835. Parent design: SGLang RFC #27574.
How This Was Implemented
KvHintEnvelope { retain_full_prompt: Option<KvRetentionHint> }, where the retention item carries onlyttl_seconds, plus a shared Rust/Python JSON fixture.prompt_cache_optionsimplicit 30-minute retention and Anthropic top-level automaticcache_control5-minute/1-hour retention into serialized request metadata before tokenization.prompt_cache_keyand legacy OpenAI retention remain pass-through only.DYN_REQUEST_TRACEso replay can attribute the intervention.kv_hints; unhinted traffic remains backward-compatible.Walkthrough
Mental model
Provider-native fields stop at Dynamo's HTTP boundary. Dynamo emits one small intent envelope after tokenization, and SGLang decides whether and how that intent can be applied safely to its cache.
flowchart LR A["OpenAI prompt_cache_options"] --> C["Dynamo provider normalization"] B["Anthropic top-level cache_control"] --> C C --> D["PipelineContext metadata"] D --> E["PreprocessedRequest KvHintEnvelope"] E --> F["Dynamo routing and admission unchanged"] F --> G["SGLang Engine.async_generate kv_hints"] G --> H["HiCache / Mooncake L3 retention"]State and ordering
The only v1 action is
retain_full_prompt. OpenAI implicit mode maps to 1,800 seconds; Anthropic top-levelephemeralmaps to its typed 300- or 3,600-second TTL. The envelope accepts unknown future fields so a v1 receiver can preserve its known action instead of rejecting the entire request.Retention metadata lives in serialized request-plane context rather than a process-local registry. This covers Rust-tokenized,
--use-sglang-tokenizer,ModelInput::Text, multimodal, aggregated, prefill, and decode paths without teaching the router about provider semantics.Request lifecycle
kv_hintstoEngine.async_generate.Boundaries and limitations
prompt_cache_optionswith the typed 30-minute TTL. Explicit mode is rejected.cache_control; system/tool/message block breakpoints are rejected until formatter-aware token offsets exist.prompt_cache_keyis neither retention intent nor a new affinity key. Existing Dynamo sticky sessions remain authoritative for affinity.dynamo-protocolsgit patch is draft-only and must be replaced by a released frontend-crates version.Validation
CARGO_INCREMENTAL=0 cargo test -p dynamo-llm --lib— 1,621 passed, 5 ignored..venv/bin/python -m pytest -q components/src/dynamo/sglang/tests/test_sglang_unit.py -k kv_hint— 2 passed.cargo fmt --all -- --checkandgit diff --check origin/main...HEAD— passed.DYN_REQUEST_TRACE, and Tachometer — passed functional retention attribution.Benchmark Results
The final A/B forced seed and probe requests to different workers, drove Mooncake eviction, flushed local caches, and observed zero Dynamo router overlap on every final probe.
retain_full_prompt.ttl_seconds=1800retain_full_prompt.ttl_seconds=3600This validates the contract and retention path, not a performance win. Mooncake retrieval was slower than recompute on the tested single-node topology, so policy enablement remains separate from this API PR.