~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
refactor(api): use SettingsManager.get_settings_snapshot() instead of manual loop (#4703)
LearningCircuit99ab080b24e1
diff --git a/src/local_deep_research/web/api.py b/src/local_deep_research/web/api.pyindex fe6252afe3..45491f9fa6 100644--- a/src/local_deep_research/web/api.py+++ b/src/local_deep_research/web/api.py@@ -12,7 +12,6 @@ from flask import Blueprint, jsonify, request, Responsefrom loguru import loggerfrom ..api.research_functions import analyze_documents-from ..utilities.type_utils import unwrap_settingfrom ..database.session_context import get_user_db_sessionfrom ..security.decorators import require_json_bodyfrom ..utilities.db_utils import get_settings_manager@@ -88,10 +87,7 @@ def _load_user_context_into_params(params["settings_snapshot"] = {}return Nonesettings_manager = get_settings_manager(db_session, username)- all_settings = settings_manager.get_all_settings()- snapshot: Dict[str, Any] = {}- for key, setting in all_settings.items():- snapshot[key] = unwrap_setting(setting)+ snapshot = settings_manager.get_settings_snapshot()params["settings_snapshot"] = snapshotlogger.debug(f"Loaded settings snapshot for user '{username}' "diff --git a/tests/web/test_api_coverage.py b/tests/web/test_api_coverage.pyindex 99a8162b12..77c173e054 100644--- a/tests/web/test_api_coverage.py+++ b/tests/web/test_api_coverage.py@@ -57,8 +57,8 @@ def _mock_access_control(*, api_enabled=True, rate_limit=60):# snapshot reaches the underlying research function.# `_ldr_test_tracer` is reserved for tests; no production# code reads this key.- mock_manager.get_all_settings.return_value = {- "_ldr_test_tracer": {"value": "tracer-value"}+ mock_manager.get_settings_snapshot.return_value = {+ "_ldr_test_tracer": "tracer-value"}mock_sm.return_value = mock_manager@@ -474,12 +474,12 @@ class TestQuickSummary:def test_settings_snapshot_loaded(self, authed_client):"""When the user has a valid db session, settings_snapshot is populated."""- mock_all_settings = {- "some.key": {"value": 42},+ mock_snapshot = {+ "some.key": 42,"another.key": "raw_value",}mock_sm_instance = MagicMock()- mock_sm_instance.get_all_settings.return_value = mock_all_settings+ mock_sm_instance.get_settings_snapshot.return_value = mock_snapshot# Also handle the api_access_control decorator callsmock_sm_instance.get_setting.side_effect = lambda key, default: {"app.enable_api": True,@@ -539,7 +539,7 @@ class TestQuickSummary:Continuing with ``{}`` would resolve to the permissive BOTH scope,downgrading a configured PRIVATE_ONLY / require-local user — so theendpoint fails closed and the research function is never called.- We fail the endpoint's full-snapshot load (``get_all_settings``) on the+ We fail the endpoint's full-snapshot load (``get_settings_snapshot``) on theshared settings-manager mock, so the auth decorator's ``get_setting``calls keep working — only the snapshot build inside``_load_user_context_into_params`` is broken. (Both@@ -547,8 +547,8 @@ class TestQuickSummary:level, so they share one patch surface.)"""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.api.research_functions.quick_summary",@@ -573,8 +573,8 @@ class TestQuickSummary:request proceeds (200) instead of failing closed, and quick_summary iscalled with an empty settings_snapshot."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.api.research_functions.quick_summary",@@ -594,8 +594,8 @@ class TestQuickSummary:"""Security-boundary flag: a truthy STRING like "false" must NOT opt in— only a real JSON ``true`` does. Otherwise it still fails closed."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.api.research_functions.quick_summary",@@ -613,8 +613,8 @@ class TestQuickSummary:"""The opt-in (run-without-settings) path must log a loud policy_auditwarning — the security claim is that it is never silent."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with (patch(@@ -812,12 +812,12 @@ class TestGenerateReport:endpoint silently dropped user context, so users' encrypted-DBAPI keys / model preferences / search tool config never reachedthe research function."""- mock_all_settings = {- "llm.provider": {"value": "openai"},+ mock_snapshot = {+ "llm.provider": "openai","search.tool": "tavily",}mock_sm_instance = MagicMock()- mock_sm_instance.get_all_settings.return_value = mock_all_settings+ mock_sm_instance.get_settings_snapshot.return_value = mock_snapshotmock_sm_instance.get_setting.side_effect = lambda key, default: {"app.enable_api": True,}.get(key, default)@@ -862,8 +862,8 @@ class TestGenerateReport:settings snapshot can't be loaded, instead of silently runningwith defaults — same egress-policy boundary, same helper."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.api.research_functions.generate_report",@@ -884,8 +884,8 @@ class TestGenerateReport:snapshot when settings can't load; the flag itself must not beforwarded to generate_report."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.api.research_functions.generate_report",@@ -1049,11 +1049,11 @@ class TestAnalyzeDocuments:endpoint silently dropped user context, so users' encrypted-DBembedding model / collection settings never reached the researchfunction."""- mock_all_settings = {- "rag.embedding_model": {"value": "BAAI/bge-base"},+ mock_snapshot = {+ "rag.embedding_model": "BAAI/bge-base",}mock_sm_instance = MagicMock()- mock_sm_instance.get_all_settings.return_value = mock_all_settings+ mock_sm_instance.get_settings_snapshot.return_value = mock_snapshotmock_sm_instance.get_setting.side_effect = lambda key, default: {"app.enable_api": True,}.get(key, default)@@ -1100,8 +1100,8 @@ class TestAnalyzeDocuments:settings snapshot can't be loaded, instead of silently runningwith defaults — same egress-policy boundary, same helper."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.web.api.analyze_documents",@@ -1122,8 +1122,8 @@ class TestAnalyzeDocuments:snapshot when settings can't load; the flag itself must not beforwarded to analyze_documents."""with _mock_access_control() as (_ctx, mock_sm):- mock_sm.return_value.get_all_settings.side_effect = RuntimeError(- "settings fail"+ mock_sm.return_value.get_settings_snapshot.side_effect = (+ RuntimeError("settings fail"))with patch("local_deep_research.web.api.analyze_documents",