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": def zero_match_result(tree_cache, match_result: "MatchResult") -> "MatchResult":
root = getattr(tree_cache, "root_node", None) if tree_cache.is_chunk_cache():
if root is None: # Chunk caches' match_prefix already returns a miss; no root_node to walk back to.
raise RuntimeError( return match_result
f"SGLANG_RADIX_FORCE_MISS is not supported by {type(tree_cache).__name__} " root = tree_cache.root_node
"(no `root_node` attribute). Disable the flag or use a cache backend "
"that exposes a tree root."
)
return match_result._replace( return match_result._replace(
# [:0] keeps dtype and device of the original tensor (e.g. CUDA int64) # [:0] keeps dtype and device of the original tensor (e.g. CUDA int64)
# without allocating a fresh empty tensor. # 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.dtype, match.device_indices.dtype)
self.assertEqual(zeroed.device_indices.device, match.device_indices.device) self.assertEqual(zeroed.device_indices.device, match.device_indices.device)
def test_no_root_node_raises(self): def test_chunk_cache_is_passthrough(self):
# tree_cache without a root_node: must raise loudly rather than silently class _StubChunkCache:
# leak cache hits past the gate. def is_chunk_cache(self) -> bool:
class _NoRoot: return True
pass
original = MatchResult( original = MatchResult(
device_indices=torch.tensor([7, 8, 9], dtype=torch.int64), device_indices=torch.empty((0,), dtype=torch.int64),
last_device_node="sentinel-device", last_device_node=None,
last_host_node="sentinel-host", last_host_node=None,
host_hit_length=4, host_hit_length=0,
) )
with self.assertRaisesRegex(RuntimeError, "SGLANG_RADIX_FORCE_MISS"): self.assertIs(zero_match_result(_StubChunkCache(), original), original)
zero_match_result(_NoRoot(), original)
class TestMatchPrefixForReqForceMiss(unittest.TestCase): class TestMatchPrefixForReqForceMiss(unittest.TestCase):