UNIQUE constraint failed: memories.content_hash after delete_memory() in mcp-memory-service
Why does store_memory() fail with
UNIQUE constraint failed: memories.content_hashafter delete_memory() of the same content in mcp-memory-service 10.31.0 on Linux with the sqlite-vec backend, and how can I fix it? Re-storing content that was previously deleted throws an IntegrityError because the soft-delete tombstone row still occupies the unique content_hash value.Originally asked on GitHub: https://github.com/doobidoo/mcp-memory-service/issues/644
3 answers
Status: fixed in v10.31.1, released 2026-03-31.
The bug was in
SqliteVecMemoryStorage:delete()only soft-deletes a memory by settingdeleted_at, leaving the row and itscontent_hashin thememoriestable. Thecontent_hashcolumn has aUNIQUEconstraint that applies to all rows, including tombstones, so a laterstore()of the same content passed the duplicate check (deleted_at IS NULL) but then failed on theINSERTwithUNIQUE constraint failed: memories.content_hash.purge_deleted()only removes tombstones older than 30 days and is not called from the store path, so recent tombstones blocked re-insertion.Fix: upgrade to v10.31.1 (PR #645). The release adds a
_purge_tombstone(content_hash)helper that removes the soft-delete tombstone row before anyINSERT, coveringstore(),store_batch(), andupdate_memory_versioned(). A regression test (test_store_after_delete_same_content) covers the delete -> re-store roundtrip.Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Reproduced with the Python API on v10.31.0: store_memory() succeeded, delete_memory() soft-deleted the row, then store_memory() with the same content raised sqlite3.IntegrityError: UNIQUE constraint failed: memories.content_hash.
Source: https://github.com/doobidoo/mcp-memory-service/issues/644 (opens external site)
Did this work for you?What @doobidoo tried on GitHub (Worked)
Maintainer fixed it in v10.31.1 by adding _purge_tombstone(content_hash) to remove the tombstone before INSERT, released via PR #645 with a regression test.
Did this work for you?
Related questions
- mcp-memory-service Docker boot loop: container restarts after exit code 0
- mcp-memory-service v8.19.0: retrieve_memory and search_by_tag broken with 'tags' and 'float' errors
- mcp-memory-service: exact text only scores 60-70%? Use hybrid BM25 + vector search (v10.8.0)
- How do I use project management or custom memory types in mcp-memory-service?
- Claude Code ignores readOnlyHint for mcp-memory-service: workarounds?