{"record":{"id":"6e3d0b6aeef39ff4","repo":"headroomlabs-ai/headroom","slug":"memory-old-memory-id-not-found","errorCode":null,"errorMessage":"Memory {old_memory_id} not found","messagePattern":"Memory (.+?) not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/adapters/sqlite.py","lineNumber":731,"sourceCode":"        This is an explicit repair operation. It never infers identity from\n        content or embedding similarity and leaves neighboring chain edges\n        untouched.\n        \"\"\"\n        if old_memory_id == new_memory_id:\n            raise ValueError(\"A memory cannot supersede itself\")\n\n        with self._get_conn() as conn:\n            conn.execute(\"BEGIN IMMEDIATE\")\n            rows = conn.execute(\n                \"SELECT * FROM memories WHERE id IN (?, ?)\",\n                (old_memory_id, new_memory_id),\n            ).fetchall()\n            memories = {row[\"id\"]: self._row_to_memory(row) for row in rows}\n            old_memory = memories.get(old_memory_id)\n            new_memory = memories.get(new_memory_id)\n\n            if old_memory is None:\n                raise ValueError(f\"Memory {old_memory_id} not found\")\n            if new_memory is None:\n                raise ValueError(f\"Memory {new_memory_id} not found\")\n            if old_memory.superseded_by != new_memory_id or new_memory.supersedes != old_memory_id:\n                raise ValueError(\n                    f\"Memories {old_memory_id} and {new_memory_id} do not form \"\n                    \"a reciprocal supersession edge\"\n                )\n\n            conn.execute(\n                \"UPDATE memories SET valid_until = NULL, superseded_by = NULL WHERE id = ?\",\n                (old_memory_id,),\n            )\n            conn.execute(\n                \"UPDATE memories SET supersedes = NULL WHERE id = ?\",\n                (new_memory_id,),\n            )\n\n        old_memory.valid_until = None","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/adapters/sqlite.py#L713-L749","documentation":"Raised by detach_supersession when the old memory ID is not present in the memories table. The operation looks up both endpoints inside a BEGIN IMMEDIATE transaction; a missing old endpoint means there is no supersession edge to detach.","triggerScenarios":"Calling detach_supersession with an ID that was deleted (possibly by the supersession chain's own cleanup); IDs from another database or with trailing whitespace/case differences; stale references after a data migration.","commonSituations":"Repair scripts replaying old edge logs after rows were removed; cross-environment ID confusion; chain-compaction having already removed the node.","solutions":["Verify both IDs exist (SELECT) before invoking detach_supersession.","Regenerate edge pairs from the current database state (superseded_by/supersedes columns) rather than cached lists.","Catch the ValueError and treat it as 'nothing to detach', logging for audit."],"exampleFix":"// before\nawait store.detach_supersession(old_id, new_id)\n\n// after\ntry:\n    await store.detach_supersession(old_id, new_id)\nexcept ValueError as e:\n    logger.info(\"edge already gone: %s\", e)","handlingStrategy":"try-catch","validationCode":"rows = await store.get_many([old_memory_id, new_memory_id])\nif old_memory_id not in rows or new_memory_id not in rows:\n    logger.warning(\"endpoint missing; nothing to detach\")\n    return","typeGuard":null,"tryCatchPattern":"try:\n    await store.detach_supersession(old_id, new_id)\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        logger.info(\"edge endpoints missing; treating as detached\")\n    else:\n        raise","preventionTips":["Derive edge pairs from live superseded_by/supersedes columns, not cached logs.","Idempotent repair loops should tolerate already-removed rows."],"tags":["sqlite","supersession","not-found","transactions"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}