Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

gracefully degrade when mem0 db is corrupt

Nick Sweeting64e2476f22bc
diff --git a/browser_use/agent/memory/service.py b/browser_use/agent/memory/service.py
index f129115df..7a128bc10 100644
--- a/browser_use/agent/memory/service.py
+++ b/browser_use/agent/memory/service.py
@@ -82,7 +82,29 @@ class Memory:
# Initialize Mem0 with the configuration
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
- self.mem0 = Mem0Memory.from_config(config_dict=self.config.full_config_dict)
+ try:
+ self.mem0 = Mem0Memory.from_config(config_dict=self.config.full_config_dict)
+ except Exception as e:
+ if 'history_old' in str(e) and 'sqlite3.OperationalError' in str(type(e)):
+ # Handle the migration error by using a unique history database path
+ import tempfile
+ import uuid
+
+ logger.warning('⚠️ Mem0 SQLite migration error detected. Using a temporary database to avoid conflicts.')
+ # Create a unique temporary database path
+ temp_dir = tempfile.gettempdir()
+ unique_id = str(uuid.uuid4())[:8]
+ history_db_path = os.path.join(temp_dir, f'browser_use_mem0_history_{unique_id}.db')
+
+ # Add the history_db_path to the config
+ config_with_history_path = self.config.full_config_dict.copy()
+ config_with_history_path['history_db_path'] = history_db_path
+
+ # Try again with the new config
+ self.mem0 = Mem0Memory.from_config(config_dict=config_with_history_path)
+ else:
+ # Re-raise if it's a different error
+ raise
@time_execution_sync('--create_procedural_memory')
def create_procedural_memory(self, current_step: int) -> None: