{"record":{"id":"fa9babde9d3a0356","repo":"sgl-project/sglang","slug":"walk-radix-cache-for-canary-does-not-support-cach","errorCode":null,"errorMessage":"walk_radix_cache_for_canary does not support {cache_type.__name__}","messagePattern":"walk_radix_cache_for_canary does not support (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/kv_canary/radix_cache_walker.py","lineNumber":38,"sourceCode":"    *,\n    radix_cache: BasePrefixCache,\n    unlocked_only: bool = False,\n    swa_resident_only: bool = False,\n) -> RadixCacheWalkResult:\n    \"\"\"Walk the radix tree and emit flat (slot_indices, positions, prev_slot_indices) tensors.\n\n    With both flags False (default), emits every slot held by the radix cache (including slots\n    also referenced by a currently-running req — that overlap is harmless redundancy with the\n    per-forward HEAD/TAIL path). ``unlocked_only=True`` skips nodes still locked by a running\n    req. ``swa_resident_only=True`` skips SWA-tombstoned nodes (slots evicted from the SWA\n    window).\"\"\"\n    cache_type = type(radix_cache)\n    if cache_type is UnifiedRadixCache:\n        return radix_cache.tree_core.walk_for_kv_canary(\n            unlocked_only=unlocked_only, swa_resident_only=swa_resident_only\n        )\n    if cache_type is not RadixCache and cache_type is not SWARadixCache:\n        raise NotImplementedError(\n            f\"walk_radix_cache_for_canary does not support {cache_type.__name__}\"\n        )\n\n    slot_buf: list[int] = []\n    position_buf: list[int] = []\n    prev_slot_buf: list[int] = []\n\n    _walk_radix_subtree(\n        node=radix_cache.root_node,\n        radix_cache=radix_cache,\n        depth=0,\n        parent_last_slot=-1,\n        slot_buf=slot_buf,\n        position_buf=position_buf,\n        prev_slot_buf=prev_slot_buf,\n        is_root=True,\n        unlocked_only=unlocked_only,\n        swa_resident_only=swa_resident_only,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/kv_canary/radix_cache_walker.py#L20-L56","documentation":"walk_radix_cache_for_canary dispatches on the exact runtime type of the radix cache: UnifiedRadixCache uses tree_core.walk_for_kv_canary, RadixCache/SWARadixCache use the manual walker. Any other cache class raises NotImplementedError because the walker does not know its node/lock layout.","triggerScenarios":"Calling walk_radix_cache_for_canary with a custom RadixCache subclass, a mocked cache, or a new cache type (e.g. HiRadixCache, ChunkCache-style variant) that is not exactly RadixCache, SWARadixCache, or UnifiedRadixCache.","commonSituations":"New radix cache subclass added to SGLang without a kv-canary walker; tests passing unittest.mock.MagicMock instead of a real cache instance; type(req_to_token_pool)-style subclasses breaking exact `is` checks.","solutions":["Pass a plain RadixCache, SWARadixCache, or UnifiedRadixCache instance","If you have a new cache type, extend walk_radix_cache_for_canary with a branch (or implement walk_for_kv_canary on its tree core) and upstream it","In tests, use a real RadixCache with dummy nodes rather than a mock"],"exampleFix":"// before\nplan = walk_radix_cache_for_canary(custom_cache)\n// after\nplan = walk_radix_cache_for_canary(RadixCache(...))  # supported concrete type","handlingStrategy":"type-guard","validationCode":"from sglang.srt.mem_cache.radix_cache import RadixCache, SWARadixCache\nfrom sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache\nassert type(radix_cache) in (RadixCache, SWARadixCache, UnifiedRadixCache)","typeGuard":"from typing import Any\n\ndef is_walkable_cache(c: Any) -> bool:\n    return type(c) in (RadixCache, SWARadixCache, UnifiedRadixCache)","tryCatchPattern":"try:\n    walk_radix_cache_for_canary(cache)\nexcept NotImplementedError:\n    logger.warning('unsupported cache type; skipping canary sweep')","preventionTips":["Use concrete supported cache classes, not subclasses or mocks","When adding a new cache type, add its walker branch in the same PR"],"tags":["kv-canary","radix-cache","notimplementederror","type-dispatch"],"backgroundTag":"unsupported-type-dispatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}