From 252521682854d1d0d9a816d798e672a5587bb39f Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 27 Feb 2026 10:53:52 -0500 Subject: [PATCH] fix: deduplicate memories on save with exact-match check Prevents inserting a memory if an identical one already exists for the user. Also cleaned up 30 anonymized and 4 duplicate memories from DB. Co-Authored-By: Claude Opus 4.6 --- utils/database.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/database.py b/utils/database.py index 82f769b..dc8c312 100644 --- a/utils/database.py +++ b/utils/database.py @@ -542,6 +542,14 @@ class Database: conn = self._connect() try: cursor = conn.cursor() + # Skip if an identical memory already exists for this user + cursor.execute( + "SELECT COUNT(*) FROM UserMemory WHERE UserId = ? AND Memory = ?", + user_id, memory[:500], + ) + if cursor.fetchone()[0] > 0: + cursor.close() + return cursor.execute( """INSERT INTO UserMemory (UserId, Memory, Topics, Importance, ExpiresAt, Source) VALUES (?, ?, ?, ?, ?, ?)""",