{"record":{"id":"82ff8d4693ef05f8","repo":"headroomlabs-ai/headroom","slug":"memory-new-memory-id-not-found","errorCode":null,"errorMessage":"Memory {new_memory_id} not found","messagePattern":"Memory (.+?) not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/adapters/sqlite.py","lineNumber":733,"sourceCode":"        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\n        old_memory.superseded_by = None\n        new_memory.supersedes = None","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/adapters/sqlite.py#L715-L751","documentation":"Raised by detach_supersession when the new memory ID is not found in the memories table. Both edge endpoints must exist for the reciprocal edge check and the subsequent UPDATEs; a missing new endpoint aborts the transaction before any writes.","triggerScenarios":"The new memory was hard-deleted but the old one still points at it (dangling superseded_by); passing the new memory before it was saved; ID typos in manual repair invocations.","commonSituations":"Partial deletes that broke chain integrity; repair tooling operating on half-migrated data; concurrent writes deleting one endpoint.","solutions":["Confirm both memories exist before detaching; query by both IDs in one call.","If the new memory is intentionally gone, clear the dangling superseded_by/supersedes columns directly as a data repair.","Restore the missing row from backup if chain integrity matters."],"exampleFix":"// before\nawait store.detach_supersession(old_id, new_id)\n\n// after\nrows = await store.get_many([old_id, new_id])\nif rows.get(old_id) and rows.get(new_id):\n    await store.detach_supersession(old_id, new_id)\nelse:\n    logger.warning(\"endpoint missing; skipping detach\")","handlingStrategy":"try-catch","validationCode":"if await store.get(new_memory_id) is None:\n    logger.warning(\"new endpoint missing; clearing dangling edge manually\")\n    return","typeGuard":null,"tryCatchPattern":"try:\n    old_m, new_m = await store.detach_supersession(old_id, new_id)\nexcept ValueError as e:\n    logger.warning(\"detach failed, likely dangling edge: %s\", e)","preventionTips":["Never hard-delete one endpoint of a supersession pair; detach first, then delete.","Run integrity checks for dangling superseded_by/supersedes pointers after migrations."],"tags":["sqlite","supersession","not-found","data-integrity"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}