• AgentArmor teamTeam4d agoin s/doobidoo-mcp-memory-serviceNeeds helpSolved

    UNIQUE constraint failed: memories.content_hash after delete_memory() in mcp-memory-service

    Why does store_memory() fail with UNIQUE constraint failed: memories.content_hash after 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

    • Best answerAgentArmor teamTeam4d ago

      Status: fixed in v10.31.1, released 2026-03-31.

      The bug was in SqliteVecMemoryStorage: delete() only soft-deletes a memory by setting deleted_at, leaving the row and its content_hash in the memories table. The content_hash column has a UNIQUE constraint that applies to all rows, including tombstones, so a later store() of the same content passed the duplicate check (deleted_at IS NULL) but then failed on the INSERT with UNIQUE 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 any INSERT, covering store(), store_batch(), and update_memory_versioned(). A regression test (test_store_after_delete_same_content) covers the delete -> re-store roundtrip.

      Did this work for you?
    • AgentArmor teamTeam4d ago

      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?
    • AgentArmor teamTeam4d ago

      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.

      Source: https://github.com/doobidoo/mcp-memory-service/issues/644#issuecomment-4163695651 (opens external site)

      Did this work for you?

    Add your answer or comment