{"record":{"id":"cb641f442e0f7c0f","repo":"langchain-ai/langgraph","slug":"key-redis-key-does-not-start-with-prefix-prefix","errorCode":null,"errorMessage":"Key {redis_key} does not start with prefix {prefix}","messagePattern":"Key (.+?) does not start with prefix (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/checkpoint/langgraph/cache/redis/__init__.py","lineNumber":39,"sourceCode":"\n        Args:\n            redis: Redis client instance (sync or async)\n            serde: Serializer to use for values\n            prefix: Key prefix for all cached values\n        \"\"\"\n        super().__init__(serde=serde)\n        self.redis = redis\n        self.prefix = prefix\n\n    def _make_key(self, ns: Namespace, key: str) -> str:\n        \"\"\"Create a Redis key from namespace and key.\"\"\"\n        ns_str = \":\".join(ns) if ns else \"\"\n        return f\"{self.prefix}{ns_str}:{key}\" if ns_str else f\"{self.prefix}{key}\"\n\n    def _parse_key(self, redis_key: str) -> tuple[Namespace, str]:\n        \"\"\"Parse a Redis key back to namespace and key.\"\"\"\n        if not redis_key.startswith(self.prefix):\n            raise ValueError(\n                f\"Key {redis_key} does not start with prefix {self.prefix}\"\n            )\n\n        remaining = redis_key[len(self.prefix) :]\n        if \":\" in remaining:\n            parts = remaining.split(\":\")\n            key = parts[-1]\n            ns_parts = parts[:-1]\n            return (tuple(ns_parts), key)\n        else:\n            return (tuple(), remaining)\n\n    def get(self, keys: Sequence[FullKey]) -> dict[FullKey, ValueT]:\n        \"\"\"Get the cached values for the given keys.\"\"\"\n        if not keys:\n            return {}\n\n        # Build Redis keys","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/checkpoint/langgraph/cache/redis/__init__.py#L21-L57","documentation":"Internal consistency check in RedisCache._parse_key: when decoding a key read back from Redis, the stored key does not begin with the cache's configured prefix. Because _make_key always builds keys as prefix + namespace + ':' + key, this indicates the cache entry was written by a different prefix configuration (or a foreign key collided in the same Redis database) and the namespace/key tuple cannot be recovered safely.","triggerScenarios":"Thrown at libs/checkpoint/langgraph/cache/redis/__init__.py:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the same prefix for writes and reads of a given cache; initialize RedisCache with a stable, unique prefix per deployment","Flush stale keys (SCAN + DEL by old prefix) after changing the prefix so old entries are not parsed","Give each environment/application its own Redis logical database or prefix to avoid cross-contamination"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"38031739e551638e373fb553453256c23feeb41f","analyzedAt":"2026-08-26T18:02:49.312Z","contentChangedAt":"2026-08-26T18:02:49.312Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}