Skip to content

~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.

refactor(db): centralize pool_pre_ping and pool_recycle into pool_config.py (#3209)

LearningCircuitedbe5933c798
diff --git a/src/local_deep_research/database/auth_db.py b/src/local_deep_research/database/auth_db.py
index 0a2764a131..be91853244 100644
--- a/src/local_deep_research/database/auth_db.py
+++ b/src/local_deep_research/database/auth_db.py
@@ -17,6 +17,7 @@ from sqlalchemy.schema import CreateIndex, CreateTable
from ..config.paths import get_data_directory
from .models.auth import User
+from .pool_config import POOL_PRE_PING, POOL_RECYCLE_SECONDS
# Global cached engine for auth database to prevent file descriptor leaks
@@ -77,8 +78,8 @@ def _get_auth_engine() -> Engine:
poolclass=QueuePool,
pool_size=5,
max_overflow=10,
- pool_pre_ping=True, # Verify connections before use
- pool_recycle=14400, # Recycle connections after 4 h to bound SQLCipher memory/state accumulation
+ pool_pre_ping=POOL_PRE_PING,
+ pool_recycle=POOL_RECYCLE_SECONDS,
echo=False,
)
_auth_engine_path = auth_db_path
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 48f5b34c1c..1e54fa1f9e 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -18,6 +18,7 @@ from sqlalchemy.pool import QueuePool, NullPool, StaticPool
from ..config.paths import get_data_directory, get_user_database_filename
from ..settings.env_registry import get_env_setting
from .sqlcipher_compat import get_sqlcipher_module
+from .pool_config import POOL_PRE_PING, POOL_RECYCLE_SECONDS
from .sqlcipher_utils import (
set_sqlcipher_key,
set_sqlcipher_rekey,
@@ -66,8 +67,8 @@ class DatabaseManager:
return {
"pool_size": 10,
"max_overflow": 30, # Increase overflow so we don't run out of connections
- "pool_pre_ping": True, # Validate connections before use (prevents stale connections)
- "pool_recycle": 14400, # Recycle connections after 4 h to bound SQLCipher memory/state accumulation
+ "pool_pre_ping": POOL_PRE_PING,
+ "pool_recycle": POOL_RECYCLE_SECONDS,
}
def _is_valid_encryption_key(self, password: str) -> bool:
diff --git a/src/local_deep_research/database/pool_config.py b/src/local_deep_research/database/pool_config.py
new file mode 100644
index 0000000000..242fde0b44
--- /dev/null
+++ b/src/local_deep_research/database/pool_config.py
@@ -0,0 +1,12 @@
+"""Shared SQLAlchemy connection pool configuration constants.
+
+Pool sizing (pool_size, max_overflow) remains per-engine since
+different databases have different concurrency profiles.
+"""
+
+# Validate connections before checkout (detects stale/broken connections)
+POOL_PRE_PING = True
+
+# Recycle connections after 4 hours to release file handles
+# in long-running processes
+POOL_RECYCLE_SECONDS = 14400
diff --git a/tests/database/test_pool_config.py b/tests/database/test_pool_config.py
new file mode 100644
index 0000000000..ab30185872
--- /dev/null
+++ b/tests/database/test_pool_config.py
@@ -0,0 +1,30 @@
+"""
+Test that pool configuration constants have expected values.
+
+These tests ensure consistency across database engines.
+If values need to change, update pool_config.py and these tests together.
+"""
+
+
+class TestPoolConfigConstants:
+ """Verify shared pool configuration constants."""
+
+ def test_pool_pre_ping_is_true(self):
+ from local_deep_research.database.pool_config import POOL_PRE_PING
+
+ assert POOL_PRE_PING is True
+
+ def test_pool_recycle_seconds_value(self):
+ from local_deep_research.database.pool_config import (
+ POOL_RECYCLE_SECONDS,
+ )
+
+ assert POOL_RECYCLE_SECONDS == 14400
+
+ def test_pool_recycle_is_positive_integer(self):
+ from local_deep_research.database.pool_config import (
+ POOL_RECYCLE_SECONDS,
+ )
+
+ assert isinstance(POOL_RECYCLE_SECONDS, int)
+ assert POOL_RECYCLE_SECONDS > 0