fix: reset() only drops history table, leaving stale messages (#5541)

This commit is contained in:
Hrushikesh Yadav
2026-06-22 11:28:17 +05:30
committed by GitHub
parent 871a1de7d2
commit 650b734b1b
4 changed files with 77 additions and 11 deletions
+4 -8
View File
@@ -1934,10 +1934,8 @@ class Memory(MemoryBase):
"""
logger.warning("Resetting all memories")
if hasattr(self.db, "connection") and self.db.connection:
self.db.connection.execute("DROP TABLE IF EXISTS history")
self.db.connection.close()
self.db.reset()
self.db.close()
self.db = SQLiteManager(self.config.history_db_path)
if hasattr(self.vector_store, "reset"):
@@ -3509,10 +3507,8 @@ class AsyncMemory(MemoryBase):
if hasattr(self.vector_store, "client") and hasattr(self.vector_store.client, "close"):
await asyncio.to_thread(self.vector_store.client.close)
if hasattr(self.db, "connection") and self.db.connection:
await asyncio.to_thread(lambda: self.db.connection.execute("DROP TABLE IF EXISTS history"))
await asyncio.to_thread(self.db.connection.close)
await asyncio.to_thread(self.db.reset)
await asyncio.to_thread(self.db.close)
self.db = SQLiteManager(self.config.history_db_path)
self.vector_store = VectorStoreFactory.create(
+3 -3
View File
@@ -324,7 +324,9 @@ class SQLiteManager:
]
def reset(self) -> None:
"""Drop and recreate the history and messages tables."""
"""Drop both tables. Caller is expected to replace this instance."""
if not self.connection:
raise RuntimeError("Cannot reset a closed SQLiteManager")
with self._lock:
try:
self.connection.execute("BEGIN")
@@ -335,8 +337,6 @@ class SQLiteManager:
self.connection.execute("ROLLBACK")
logger.error(f"Failed to reset tables: {e}")
raise
self._create_history_table()
self._create_messages_table()
def close(self) -> None:
if self.connection: