{"record":{"id":"eda052dfaad9c847","repo":"sgl-project/sglang","slug":"radixkey-slice-step-must-be-1","errorCode":null,"errorMessage":"RadixKey slice step must be 1","messagePattern":"RadixKey slice step must be 1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/radix_cache.py","lineNumber":128,"sourceCode":"            for i in range(n - 1 if n > 0 else 0):\n                yield (t[i], t[i + 1])\n        elif n == len(t):\n            yield from t\n        else:\n            for i in range(n):\n                yield t[i]\n\n    def __getitem__(self, idx: Union[int, slice]) -> RadixKey:\n        # Normalize int -> 1-element slice so the rest handles one shape.\n        if isinstance(idx, int):\n            if idx < 0:\n                idx += len(self)\n            if idx < 0 or idx >= len(self):\n                raise IndexError(f\"RadixKey index out of range: {idx}\")\n            idx = slice(idx, idx + 1)\n        start, stop, step = idx.indices(len(self))\n        if step != 1:\n            raise ValueError(\"RadixKey slice step must be 1\")\n\n        if self.is_bigram:\n            # bigrams [start, stop) span raw tokens [start, stop + 1);\n            # empty slice -> empty raw tokens (not a dangling boundary token).\n            raw = self.token_ids[start : stop + 1] if stop > start else array(\"q\")\n            return RadixKey(\n                raw,\n                self.extra_key,\n                is_bigram=True,\n                cache_salt=self.cache_salt,\n            )\n        return RadixKey(\n            self.token_ids[start:stop],\n            self.extra_key,\n            cache_salt=self.cache_salt,\n        )\n\n    def __repr__(self) -> str:","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/radix_cache.py#L110-L146","documentation":"RadixKey.__getitem__ only supports slices with step 1; any slice like key[::2] or key[::-1] raises ValueError. The implementation converts the slice via slice.indices(len(self)) and rejects step != 1 because strided subkeys have no meaning in the radix tree.","triggerScenarios":"Calling key[::2], key[::-1], or any key[start:stop:step] with step != 1 on a RadixKey instance.","commonSituations":"Reusing generic tensor/list slicing code (which supports strides) on RadixKey; attempting to reverse a key for suffix matching.","solutions":["Use contiguous slices key[start:stop] only","Materialize to token ids first if you truly need striding: tokens = key.token_ids[::2] (then rebuild a RadixKey if needed)"],"exampleFix":"# before\nsub = key[::2]\n# after\nsub = key[:len(key)]  # contiguous only; stride on token_ids if needed","handlingStrategy":"validation","validationCode":"assert idx.step in (None, 1), \"RadixKey slices must have step 1\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use key[start:stop]","Stride on key.token_ids (an array) if strided access is truly needed"],"tags":["radix-cache","slice","value-error","prefix-cache"],"backgroundTag":"unsupported-slice-operation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}