{"record":{"id":"61be62af96cbb0cc","repo":"headroomlabs-ai/headroom","slug":"memory-not-found-memory-id","errorCode":null,"errorMessage":"Memory not found: {memory_id}","messagePattern":"Memory not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/cli/memory.py","lineNumber":222,"sourceCode":"            conn.execute(\"DELETE FROM vec_metadata\")\n            conn.commit()\n    except Exception as exc:\n        print_warning(f\"Vector index cleanup incomplete: {exc}\")\n        ok = False\n\n    return ok\n\n\ndef _resolve_memory(store: SQLiteMemoryStore, memory_id: str) -> Memory:\n    \"\"\"Resolve an exact or unambiguous partial memory ID.\"\"\"\n    memory = asyncio.run(store.get(memory_id))\n    if memory is not None:\n        return memory\n\n    memories = asyncio.run(store.query(MemoryFilter(limit=10000, include_superseded=True)))\n    matches = [candidate for candidate in memories if candidate.id.startswith(memory_id)]\n    if not matches:\n        raise ValueError(f\"Memory not found: {memory_id}\")\n    if len(matches) > 1:\n        raise ValueError(\n            f\"Ambiguous ID '{memory_id}'. Matches: {[memory.id[:8] for memory in matches]}\"\n        )\n    return matches[0]\n\n\nasync def _apply_supersession_repair(\n    db_path: str,\n    old_memory_id: str,\n    new_memory_id: str,\n    vector_dimension: int,\n) -> tuple[Memory, Memory]:\n    \"\"\"Apply a repair through LocalBackend so indexes and cache are refreshed.\"\"\"\n    from ..memory.backends.local import LocalBackend, LocalBackendConfig\n\n    backend = LocalBackend(\n        LocalBackendConfig(","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/cli/memory.py#L204-L240","documentation":"CLI memory commands resolve user-supplied IDs through _resolve_memory: an exact store.get() first, then a prefix search over all (including superseded) memories. 'Memory not found' means neither the exact ID nor any stored memory ID starts with the prefix you passed. It is a ValueError raised before any mutation, so nothing was modified.","triggerScenarios":"Calling `headroom memory <cmd> <id>` where <id> is a typo, a stale ID from an older database (wrong --db-path), or an ID shorter than any stored ID's prefix space; also running against an empty/fresh store.","commonSituations":"Copying an ID from old output after the memory DB was recreated; pointing --db-path at the wrong file; trailing characters/whitespace pasted with the ID; prefix shorter than intended colliding with nothing.","solutions":["List IDs first: `headroom memory list` (or query the store) and copy the exact ID","Confirm --db-path points at the database that actually holds the memory","Re-copy the ID without surrounding whitespace/quotes","Use a prefix of at least 8 hex chars — full IDs are long UUID-like strings, short prefixes risk both misses and ambiguity"],"exampleFix":"# before\n$ headroom memory show abc123xyz\n# ValueError: Memory not found: abc123xyz\n\n# after\n$ headroom memory list | head\n$ headroom memory show 3f9c1d2e4a5b6c7d","handlingStrategy":"try-catch","validationCode":"from headroom.memory import MemoryFilter\nimport asyncio\n\ndef memory_exists(store, mid: str) -> bool:\n    if asyncio.run(store.get(mid)) is not None:\n        return True\n    hits = [m for m in asyncio.run(store.query(MemoryFilter(limit=10000, include_superseded=True)))\n            if m.id.startswith(mid)]\n    return len(hits) > 0","typeGuard":null,"tryCatchPattern":"try:\n    mem = _resolve_memory(store, memory_id)\nexcept ValueError as e:\n    if str(e).startswith(\"Memory not found\"):\n        print(\"no such memory — run `headroom memory list` and retry\")\n        sys.exit(2)\n    raise","preventionTips":["Always source IDs from list output rather than typing them","Verify --db-path matches the store you queried for the ID","In scripts, check existence before running mutating memory commands"],"tags":["cli","memory","id-resolution","valueerror"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}