diff --git a/python/sglang/srt/mem_cache/base_prefix_cache.py b/python/sglang/srt/mem_cache/base_prefix_cache.py index 28670c5a4..8ec5b15b7 100644 --- a/python/sglang/srt/mem_cache/base_prefix_cache.py +++ b/python/sglang/srt/mem_cache/base_prefix_cache.py @@ -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. diff --git a/test/registered/unit/mem_cache/test_radix_force_miss.py b/test/registered/unit/mem_cache/test_radix_force_miss.py index d9a72c89d..df8046cdd 100644 --- a/test/registered/unit/mem_cache/test_radix_force_miss.py +++ b/test/registered/unit/mem_cache/test_radix_force_miss.py @@ -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):