~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: make auth engine cache aware of data directory changes
LearningCircuit601a838f1c94
diff --git a/src/local_deep_research/database/auth_db.py b/src/local_deep_research/database/auth_db.pyindex 0657fc68ce..8b39667107 100644--- a/src/local_deep_research/database/auth_db.py+++ b/src/local_deep_research/database/auth_db.py@@ -21,6 +21,9 @@ from .models.base import Base# Global cached engine for auth database to prevent file descriptor leaks_auth_engine: Optional[Engine] = None+_auth_engine_path: Optional[Path] = (+ None # Track the path the engine was created for+)_auth_engine_lock = threading.Lock()@@ -35,18 +38,34 @@ def _get_auth_engine() -> Engine:This prevents file descriptor leaks by reusing a single engineinstead of creating a new one for every session.++ The engine is invalidated if the data directory path changes+ (e.g., during testing when LDR_DATA_DIR is set to a temp directory)."""- global _auth_engine+ global _auth_engine, _auth_engine_path++ auth_db_path = get_auth_db_path()- if _auth_engine is not None:+ # Check if we have a cached engine for the current path+ if _auth_engine is not None and _auth_engine_path == auth_db_path:return _auth_enginewith _auth_engine_lock:# Double-check after acquiring lock- if _auth_engine is not None:+ if _auth_engine is not None and _auth_engine_path == auth_db_path:return _auth_engine- auth_db_path = get_auth_db_path()+ # If path changed, dispose old engine first+ if _auth_engine is not None and _auth_engine_path != auth_db_path:+ try:+ _auth_engine.dispose()+ logger.debug(+ "Disposed auth engine due to data directory change"+ )+ except Exception as e:+ logger.warning(f"Error disposing old auth engine: {e}")+ _auth_engine = None+ _auth_engine_path = None# Ensure database existsif not auth_db_path.exists():@@ -61,6 +80,7 @@ def _get_auth_engine() -> Engine:pool_pre_ping=True, # Verify connections before useecho=False,)+ _auth_engine_path = auth_db_pathlogger.debug("Created cached auth database engine")return _auth_engine@@ -127,12 +147,13 @@ def dispose_auth_engine():"""Dispose the auth engine (for shutdown/cleanup)."""- global _auth_engine+ global _auth_engine, _auth_engine_pathwith _auth_engine_lock:if _auth_engine is not None:_auth_engine.dispose()_auth_engine = None+ _auth_engine_path = Nonelogger.debug("Disposed auth database engine")diff --git a/tests/conftest.py b/tests/conftest.pyindex d3bc24fa7e..1982682ea7 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -16,6 +16,7 @@ from sqlalchemy.orm import sessionmaker, Sessionimport local_deep_research.utilities.db_utils as db_utils_modulefrom local_deep_research.database.models import Basefrom local_deep_research.database.auth_db import (+ dispose_auth_engine,init_auth_database,)from local_deep_research.web.app_factory import create_app@@ -185,6 +186,9 @@ def cleanup_database_connections():db_manager.connections.clear()session_manager.sessions.clear()+ # Dispose auth engine so it will be recreated with correct path+ dispose_auth_engine()+yield# Close any open connections with logging@@ -198,6 +202,9 @@ def cleanup_database_connections():db_manager.connections.clear()session_manager.sessions.clear()+ # Dispose auth engine after test+ dispose_auth_engine()+@pytest.fixturedef app(temp_data_dir, monkeypatch):