fix: SGLANG_RADIX_FORCE_MISS chunk-cache passthrough (#24950)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cheng Wan
2026-05-11 00:07:46 -07:00
committed by GitHub
co-authored by Claude Opus 4.7
parent d102b0cbc3
commit 044bb88a97
2 changed files with 13 additions and 18 deletions
@@ -152,13 +152,10 @@ class MatchResult(NamedTuple):
def zero_match_result(tree_cache, match_result: "MatchResult") -> "MatchResult":
root = getattr(tree_cache, "root_node", None)
if root is None:
raise RuntimeError(
f"SGLANG_RADIX_FORCE_MISS is not supported by {type(tree_cache).__name__} "
"(no `root_node` attribute). Disable the flag or use a cache backend "
"that exposes a tree root."
)
if tree_cache.is_chunk_cache():
# Chunk caches' match_prefix already returns a miss; no root_node to walk back to.
return match_result
root = tree_cache.root_node
return match_result._replace(
# [:0] keeps dtype and device of the original tensor (e.g. CUDA int64)
# without allocating a fresh empty tensor.
@@ -55,20 +55,18 @@ class TestZeroMatchResult(unittest.TestCase):
self.assertEqual(zeroed.device_indices.dtype, match.device_indices.dtype)
self.assertEqual(zeroed.device_indices.device, match.device_indices.device)
def test_no_root_node_raises(self):
# tree_cache without a root_node: must raise loudly rather than silently
# leak cache hits past the gate.
class _NoRoot:
pass
def test_chunk_cache_is_passthrough(self):
class _StubChunkCache:
def is_chunk_cache(self) -> bool:
return True
original = MatchResult(
device_indices=torch.tensor([7, 8, 9], dtype=torch.int64),
last_device_node="sentinel-device",
last_host_node="sentinel-host",
host_hit_length=4,
device_indices=torch.empty((0,), dtype=torch.int64),
last_device_node=None,
last_host_node=None,
host_hit_length=0,
)
with self.assertRaisesRegex(RuntimeError, "SGLANG_RADIX_FORCE_MISS"):
zero_match_result(_NoRoot(), original)
self.assertIs(zero_match_result(_StubChunkCache(), original), original)
class TestMatchPrefixForReqForceMiss(unittest.TestCase):