fix(memory): sweep legacy orphaned message vectors

Repair vector rows left behind by older databases at store startup. Keep the existing single-statement delete path from main and avoid reintroducing the redundant batched helper.
This commit is contained in:
2026-08-26 03:32:34 -05:00
parent c3a7b6eefd
commit d56d579755
2 changed files with 47 additions and 1 deletions
+21
View File
@@ -136,6 +136,27 @@ def test_conversation_recall_uses_vec_and_matches_brute_force():
asyncio.run(run())
def test_startup_sweeps_pre_existing_orphan_vectors():
"""Databases written before delete_conversation cleaned up after itself are
repaired the next time the store opens them."""
import json
path = Path(tempfile.mkdtemp()) / "t.db"
s = PersistentMemoryStore(path)
s.create_conversation("c1")
mid = s.add_message("c1", "user", "lego star wars")
conn = s._connect()
conn.execute("INSERT INTO message_vectors (message_id, embedding) VALUES (?, ?)",
(mid, json.dumps([1.0, 0.0])))
conn.execute("DELETE FROM messages WHERE id = ?", (mid,)) # the old leaky delete
conn.commit()
conn.close()
reopened = PersistentMemoryStore(path)
conn = reopened._connect()
assert conn.execute("SELECT COUNT(*) FROM message_vectors").fetchone()[0] == 0
conn.close()
def test_projects_scope_documents_and_survive_delete():
s = _store()