{"record":{"id":"90e6c4586c5167d3","repo":"headroomlabs-ai/headroom","slug":"format-retrieval-miss-detail-store-get-entry-statu","errorCode":null,"errorMessage":"format_retrieval_miss_detail(store.get_entry_status(hash_key, clean_expired=True))","messagePattern":"format_retrieval_miss_detail\\(store\\.get_entry_status\\(hash_key, clean_expired=True\\)\\)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"headroom/proxy/server.py","lineNumber":4626,"sourceCode":"        if entry_status[\"status\"] != \"available\":\n            raise HTTPException(\n                status_code=404,\n                detail=format_retrieval_miss_detail(entry_status),\n            )\n\n        # Retrieval is by hash: always return the full original content.\n        entry = store.retrieve(hash_key)\n        if entry:\n            return {\n                \"hash\": hash_key,\n                \"original_content\": entry.original_content,\n                \"original_tokens\": entry.original_tokens,\n                \"original_item_count\": entry.original_item_count,\n                \"compressed_item_count\": entry.compressed_item_count,\n                \"tool_name\": entry.tool_name,\n                \"retrieval_count\": entry.retrieval_count,\n            }\n        raise HTTPException(\n            status_code=404,\n            detail=format_retrieval_miss_detail(\n                store.get_entry_status(hash_key, clean_expired=True)\n            ),\n        )\n\n    @app.get(\"/v1/retrieve/stats\", dependencies=[Depends(_require_loopback)])\n    async def ccr_stats():\n        \"\"\"Get CCR compression store statistics.\"\"\"\n        store = get_compression_store()\n        stats = store.get_stats()\n        events = store.get_retrieval_events(limit=20)\n        return {\n            \"store\": stats,\n            \"recent_retrievals\": [\n                {\n                    \"hash\": e.hash,\n                    \"query\": e.query,","sourceCodeStart":4608,"sourceCodeEnd":4644,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/proxy/server.py#L4608-L4644","documentation":"The fallback branch of POST /v1/retrieve returns HTTP 404 with format_retrieval_miss_detail when store.retrieve() returns no entry even though the earlier status check said 'available', a rare race where the entry expires between check and read. The detail is computed from a fresh get_entry_status call.","triggerScenarios":"Entry TTL elapsing or eviction happening between get_entry_status and store.retrieve within one request; concurrent cleanup running during retrieval.","commonSituations":"Aggressive expiry timers; heavy parallel retrievals of the same marker; store compaction mid-request.","solutions":["Retry retrieval once on 404 immediately after a successful compression.","Increase retention/TTL so markers outlive their sessions.","Treat 404 as 'gone'; recompute or re-compress the context."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    resp = await client.post(\"/v1/retrieve\", json={\"hash\": h})\n    if resp.status_code != 404:\n        break\nelse:\n    regenerate_context()  # entry truly gone","preventionTips":["One bounded retry covers the check/read race.","Avoid extremely short TTLs near retrieval time."],"tags":["http","cache","race-condition"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}