~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(config): give get_setting_from_snapshot a real default sentinel (#5996)
LearningCircuit772875d8320b
diff --git a/changelog.d/5984.bugfix.md b/changelog.d/5984.bugfix.mdnew file mode 100644index 0000000000..ac1d17d705--- /dev/null+++ b/changelog.d/5984.bugfix.md@@ -0,0 +1,7 @@+`get_setting_from_snapshot()` no longer treats `default=None` as "no+default": passing `None` explicitly now returns `None` for a missing+key (the natural spelling of "this setting is optional"), while+omitting `default` keeps the fail-loud `NoSettingsContextError`+whenever neither the snapshot nor a thread settings context can+supply the key. Root cause behind the #5331 Milvus-token breakage of+33 library/collection tests and the false crash report #5766.diff --git a/src/local_deep_research/config/thread_settings.py b/src/local_deep_research/config/thread_settings.pyindex b5c223fdeb..a0d442a471 100644--- a/src/local_deep_research/config/thread_settings.py+++ b/src/local_deep_research/config/thread_settings.py@@ -27,6 +27,14 @@ _thread_local = threading.local()# that have no thread-local context. See #4208._NOT_FOUND = object()+# Sentinel distinguishing "caller supplied no default" from "caller+# explicitly wants None when the key is absent". Before #5984, None did+# double duty for both, so the natural spelling of "this setting is+# optional" — default=None — raised NoSettingsContextError instead of+# returning None (the trap behind #5331 and #5766). Mirrors _NOT_FOUND+# above for the lookup half of the same function.+_UNSET = object()+def set_settings_context(settings_context):"""Set a settings context for the current thread."""@@ -70,7 +78,7 @@ def settings_context(ctx):def get_setting_from_snapshot(key,- default=None,+ default=_UNSET,username=None,settings_snapshot=None,):@@ -78,7 +86,12 @@ def get_setting_from_snapshot(Args:key: Setting key to retrieve- default: Default value if setting not found+ default: Default value if setting not found. Pass ``None``+ explicitly to make the setting optional — ``None`` is+ returned when the key is absent. Omit ``default`` to+ require a value: a missing key then raises, unless a thread+ settings context is bound (its lookup result — ``None``+ for a key it is missing — is returned instead).username: Username (unused, kept for backward compatibility)settings_snapshot: Optional settings snapshot dict@@ -86,7 +99,9 @@ def get_setting_from_snapshot(Setting value or defaultRaises:- RuntimeError: If no settings context is available+ NoSettingsContextError: If the key is not found in the snapshot,+ no thread settings context is available, and no default was+ provided"""# First check if we have settings_snapshot passed directly.# _NOT_FOUND (not None) is the absence sentinel so a key whose stored@@ -164,14 +179,18 @@ def get_setting_from_snapshot("default rather than serving another user's value.")else:- value = ctx.get_setting(key, default)+ # Never forward _UNSET: the context's get_setting would return+ # the sentinel itself for a missing key, leaking it to callers.+ value = ctx.get_setting(key, None if default is _UNSET else default)# Extract value from dict structure if needed (same as above)if isinstance(value, dict) and "value" in value:return value["value"]return value- # If a default was provided, return it instead of raising an exception- if default is not None:+ # If a default was provided, return it — including an explicit None,+ # which reads as "optional" (#5984). _UNSET, not None, means "no+ # default was supplied" and falls through to the raise below.+ if default is not _UNSET:from loguru import loggerlogger.debug(diff --git a/src/local_deep_research/llm/providers/_helpers.py b/src/local_deep_research/llm/providers/_helpers.pyindex 2fd29841c5..ab2532cb27 100644--- a/src/local_deep_research/llm/providers/_helpers.py+++ b/src/local_deep_research/llm/providers/_helpers.py@@ -69,12 +69,11 @@ def compute_max_tokens(populated from ``default_settings.json`` (currently 30000), so theunset branch only fires for partial-snapshot programmatic callers.- Raises:- NoSettingsContextError: when ``llm.max_tokens`` is absent from the- provided snapshot (or no snapshot is given) and no thread- settings context is available. A snapshot being present does- NOT prevent the raise — callers must wrap construction in- ``except NoSettingsContextError`` and omit the kwarg.+ ``llm.max_tokens`` is read with an explicit ``None`` default (#5984),+ so an absent key resolves to ``None`` (kwarg omitted) instead of+ raising ``NoSettingsContextError``. Provider-level ``except+ NoSettingsContextError`` wrappers around this helper are defensive+ only."""from ...config.thread_settings import get_setting_from_snapshot@@ -86,7 +85,7 @@ def compute_max_tokens(return Noneraw = get_setting_from_snapshot("llm.max_tokens",- None,+ default=None,settings_snapshot=settings_snapshot,)if raw is None:diff --git a/tests/config/test_thread_settings_child_keys.py b/tests/config/test_thread_settings_child_keys.pyindex f975a9a185..7459fb85cf 100644--- a/tests/config/test_thread_settings_child_keys.py+++ b/tests/config/test_thread_settings_child_keys.py@@ -158,17 +158,16 @@ class TestGetSettingFromSnapshotDefaults:"missing_key", settings_snapshot={"other": "val"})- def test_none_default_still_raises(self):- """default=None (the default) still raises NoSettingsContextError."""+ def test_none_default_returns_none(self):+ """Explicit default=None returns None instead of raising (#5984)."""from local_deep_research.config.thread_settings import (get_setting_from_snapshot,- NoSettingsContextError,)- with pytest.raises(NoSettingsContextError):- get_setting_from_snapshot(- "missing_key", default=None, settings_snapshot={"other": "val"}- )+ result = get_setting_from_snapshot(+ "missing_key", default=None, settings_snapshot={"other": "val"}+ )+ assert result is Nonedef test_empty_snapshot_with_default(self):"""Empty snapshot with default returns the default."""diff --git a/tests/config/test_thread_settings_extended.py b/tests/config/test_thread_settings_extended.pyindex 17da96090e..cd88df4881 100644--- a/tests/config/test_thread_settings_extended.py+++ b/tests/config/test_thread_settings_extended.py@@ -293,11 +293,48 @@ class TestGetSettingFromSnapshotDefaults:)assert result == "safe"- def test_none_default_still_raises(self, clean_thread_local):- """Explicitly passing default=None still raises (it is the sentinel- checked via `if default is not None`)."""- with pytest.raises(NoSettingsContextError):- get_setting_from_snapshot("missing", default=None)+ def test_none_default_returns_none(self, clean_thread_local):+ """Explicitly passing default=None means "optional": returns None+ instead of raising. #5984 — _UNSET, not None, is the absence+ sentinel now, mirroring _NOT_FOUND for the lookup half."""+ result = get_setting_from_snapshot("missing", default=None)+ assert result is None++ def test_none_default_returns_none_with_snapshot(self, clean_thread_local):+ """default=None with an unrelated snapshot also returns None."""+ result = get_setting_from_snapshot(+ "missing", default=None, settings_snapshot={"other": "val"}+ )+ assert result is None++ def test_falsy_defaults_are_returned(self, clean_thread_local):+ """Falsy defaults are real defaults: False/0/"" are returned,+ not treated as "no default" by the _UNSET sentinel."""+ assert get_setting_from_snapshot("missing", default=False) is False+ assert get_setting_from_snapshot("missing", default=0) == 0+ assert get_setting_from_snapshot("missing", default="") == ""++ def test_unset_sentinel_not_leaked_through_context(+ self, clean_thread_local+ ):+ """With a thread context that misses the key, the None handed to+ the context in place of _UNSET is returned — never the sentinel+ object itself."""+ ctx = MagicMock()+ ctx.get_setting.return_value = None+ set_settings_context(ctx)+ result = get_setting_from_snapshot("missing")+ assert result is None+ ctx.get_setting.assert_called_once_with("missing", None)++ def test_context_receives_explicit_default(self, clean_thread_local):+ """An explicit default is still forwarded to the context lookup."""+ ctx = MagicMock()+ ctx.get_setting.side_effect = lambda key, default: default+ set_settings_context(ctx)+ result = get_setting_from_snapshot("missing", default="fallback")+ assert result == "fallback"+ ctx.get_setting.assert_called_once_with("missing", "fallback")# ---------------------------------------------------------------------------