{"record":{"id":"2c98dba3a5ef90a9","repo":"diegosouzapw/OmniRoute","slug":"memory-not-found-memoryid","errorCode":null,"errorMessage":"memory not found: ${memoryId}","messagePattern":"memory not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/memory/vectorStore.ts","lineNumber":214,"sourceCode":"      } catch (err: unknown) {\n        const msg = sanitizeErrorMessage(err instanceof Error ? err.message : String(err));\n        return { ready: false, reason: `failed to create vec_memories: ${msg}` };\n      }\n    }\n\n    return { ready: false, reason: \"no dimensions available yet (lazy probe pending)\" };\n  }\n\n  async upsertVector(memoryId: string, vector: Float32Array): Promise<void> {\n    const db = getDbInstance();\n\n    // Map UUID memoryId → INTEGER rowid (the rowid is used as the FK into vec_memories).\n    const row = db.prepare(\"SELECT rowid FROM memories WHERE id = ?\").get(memoryId) as\n      | { rowid: number }\n      | undefined;\n\n    if (!row) {\n      throw new Error(`memory not found: ${memoryId}`);\n    }\n\n    // vec0 v0.1.9 requires BigInt for explicit rowid insertion — plain numbers are rejected.\n    // INSERT OR REPLACE is not supported by vec0 — use DELETE + INSERT for upsert semantics.\n    // int8 tables quantize the float32 blob in SQL (vec_quantize_int8); float32 bind raw.\n    const q = liveVecQuantization();\n    try {\n      db.prepare(\"DELETE FROM vec_memories WHERE rowid = ?\").run(BigInt(row.rowid));\n      db.prepare(`INSERT INTO vec_memories(rowid, embedding) VALUES (?, ${vecValueExpr(q)})`).run(\n        BigInt(row.rowid),\n        encodeVector(vector),\n      );\n    } catch (err: unknown) {\n      // Self-heal: a concurrent ensureReady()'s reset raced ahead of us and\n      // dropped the table after our own ensureReady() already ran. Recreate\n      // from the last-known-good meta and retry once before giving up.\n      if (!isMissingVecTableError(err) || !recreateFromMeta()) throw err;\n      db.prepare(\"DELETE FROM vec_memories WHERE rowid = ?\").run(BigInt(row.rowid));","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/memory/vectorStore.ts#L196-L232","documentation":"upsertVector's lookup of the memory by UUID id in the memories table returned no row, so there is no rowid to insert into vec_memories. The memory was deleted (or never committed) before its vector arrived.","triggerScenarios":"Thrown at src/lib/memory/vectorStore.ts:214 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Skip the upsert — the parent memory no longer exists","Ensure memory creation commits before enqueueing vector generation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}