fix: reset() only drops history table, leaving stale messages (#5541)
This commit is contained in:
+4
-8
@@ -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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user