mirror of
https://github.com/kvcache-ai/sglang.git
synced 2026-11-05 01:07:39 +00:00
[PR #89] fix: restore radix cache namespace isolation #89
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/sglang#89
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/sglang/pull/89
Author: @wildoranges
Created: 9/2/2026
Status: 🔄 Open
Base:
main← Head:kt-main-latest📝 Commits (2)
fa13d5efix: restore radix cache namespace isolationf29d63ftest: reset cache between identity collision cases📊 Changes
8 files changed (+281 additions, -18 deletions)
View changed files
➕
python/sglang/srt/cache_identity.py(+33 -0)📝
python/sglang/srt/disaggregation/encode_receiver.py(+1 -0)📝
python/sglang/srt/entrypoints/openai/serving_base.py(+7 -11)📝
python/sglang/srt/managers/schedule_batch.py(+5 -7)📝
python/sglang/srt/managers/scheduler.py(+1 -0)📝
python/sglang/srt/managers/session_controller.py(+1 -0)📝
test/manual/openai_server/features/test_cache_report.py(+76 -0)➕
test/unit/test_extra_key_cache_isolation.py(+157 -0)📄 Description
Motivation
Fixes https://github.com/kvcache-ai/ktransformers/issues/2184.
The OpenAI serving layer computes a per-request cache namespace from
cache_saltandextra_key, and the request structs carry that value to thescheduler. However, the normal scheduler path did not pass the value into
Req, so caller-provided cache namespaces were dropped before radix-cachelookup. Session requests and the asynchronous multimodal receiver had the same
problem when constructing a new
Req.As a result, affected requests with different
cache_saltorextra_keyvalues could reuse each other's KV cache entries. A pre-patch reproduction with
Qwen2.5-0.5B on an 8x RTX 3090 server showed the same full cache hit
(
#cached-token: 458) for five semantically distinct cache contexts, while thecold request prefetched 457 new tokens. The reproduction log is attached to
the linked issue.
Simply propagating the existing value would also expose two ambiguous string
concatenations:
(cache_salt, extra_key)in the OpenAI layer and(extra_key, lora_id)inReq. Different component tuples could thereforeproduce the same radix-cache key.
Modifications
component names, and null positions.
(cache_salt, extra_key)identities without delimiter orfield-position collisions.
extra_keythrough normal scheduler requests, session requests,and asynchronous multimodal receiver requests.
(extra_key, lora_id)identity inReq, preserving LoRAisolation without ambiguous concatenation.
the
OpenAIServingBase -> Req -> RadixCachepath, and scheduler/sessionpropagation.
collisions, and native session
extra_keyisolation.The encoded namespace is internal and opaque; no request or response schema is
changed. Requests that do not provide a cache namespace or LoRA adapter retain
Noneas their radix-cacheextra_key.Accuracy Tests
This change does not modify model kernels, forward computation, sampling, or
generated-token selection. It only controls which radix-cache namespace is
eligible for prefix reuse, so model accuracy evaluation is not applicable.
python -m pytest -q test/unit/test_extra_key_cache_isolation.py: 4 passed.python -m pytest -q test/registered/radix_cache/test_radix_cache_unit.py::TestRadixCache::test_extra_key_isolation: 1 passed.test/manual/openai_server/features/test_cache_report.py, but were not runlocally because this workspace does not have the GPU/model-server
environment required by that test module.
Benchmarking and Profiling
No inference benchmark was run. The change adds deterministic JSON encoding on
the CPU request-control path when a cache namespace or LoRA adapter is present;
it does not alter GPU inference kernels. No material throughput impact is
expected, but this has not been measured.
Checklist
F401,F821),py_compile, andgit diff --checkpassed for the changed files.Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.