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.

fix(chat): preserve safe title timeout diagnostics (#7761)

Chanhyo Jungaf6f34ad4959
diff --git a/changelog.d/7575.bugfix.md b/changelog.d/7575.bugfix.md
new file mode 100644
index 0000000000..bc21405cbf
--- /dev/null
+++ b/changelog.d/7575.bugfix.md
@@ -0,0 +1 @@
+Preserve safe setting diagnostics when an invalid chat-title LLM timeout falls back to query truncation.
diff --git a/src/local_deep_research/chat/service.py b/src/local_deep_research/chat/service.py
index cdd1e250de..843ba0c3ed 100644
--- a/src/local_deep_research/chat/service.py
+++ b/src/local_deep_research/chat/service.py
@@ -29,6 +29,7 @@ from ..database.models import (
UserActiveResearch,
)
from ..database.session_context import get_user_db_session
+from ..settings.exceptions import SettingsValueError
from ..security.log_sanitizer import redact_and_bound_for_log
from ..web.research_state import user_research_start_gate
from ..web.routes.globals import (
@@ -1559,11 +1560,20 @@ class ChatService:
settings_snapshot=settings_snapshot,
)
)
+ except SettingsValueError as error:
+ # The typed diagnostic contains only key/source/reason.
+ safe_diagnostic = error.diagnostic
+ logger.warning(
+ "{}; falling back to truncation", safe_diagnostic
+ )
+ return self._fallback_title(query)
except (TypeError, ValueError, OverflowError):
timeout = 0
if not isfinite(timeout) or timeout <= 0:
logger.warning(
- "Invalid title-generation timeout; falling back to truncation"
+ "Invalid setting chat.title_llm_timeout_seconds: "
+ "expected a finite positive number; "
+ "falling back to truncation"
)
return self._fallback_title(query)
# Run the blocking invoke in a worker thread so the request
diff --git a/tests/chat/test_chat_service_contracts.py b/tests/chat/test_chat_service_contracts.py
index 3902188b48..56057a5afe 100644
--- a/tests/chat/test_chat_service_contracts.py
+++ b/tests/chat/test_chat_service_contracts.py
@@ -1919,6 +1919,130 @@ class TestTitleGeneration:
)
factory.assert_not_called()
+ @pytest.mark.parametrize("source", ["value", "environment"])
+ def test_typed_timeout_preserves_safe_diagnostic(self, monkeypatch, source):
+ canary = "synthetic-timeout-secret"
+ monkeypatch.delenv("LDR_CHAT_TITLE_LLM_TIMEOUT_SECONDS", raising=False)
+ value = canary
+ if source == "environment":
+ monkeypatch.setenv("LDR_CHAT_TITLE_LLM_TIMEOUT_SECONDS", canary)
+ value = 5
+ self._assert_timeout_diagnostic(
+ {"value": value, "ui_element": "number"},
+ f"from {source}: expected a valid number value",
+ canary,
+ )
+
+ @pytest.mark.parametrize(
+ "timeout",
+ [
+ "synthetic-timeout-secret",
+ None,
+ {},
+ 10**1000,
+ "nan",
+ "inf",
+ float("-inf"),
+ 0,
+ -1,
+ ],
+ ids=[
+ "value-error",
+ "none",
+ "type-error",
+ "overflow",
+ "nan",
+ "inf",
+ "negative-inf",
+ "zero",
+ "negative",
+ ],
+ )
+ def test_raw_timeout_has_safe_diagnostic(self, timeout):
+ self._assert_timeout_diagnostic(
+ timeout,
+ "expected a finite positive number",
+ "synthetic-timeout-secret",
+ )
+
+ @staticmethod
+ def _assert_timeout_diagnostic(timeout, reason, canary):
+ from loguru import logger
+
+ records = []
+ logger.enable("local_deep_research")
+ sink = logger.add(lambda message: records.append(message.record))
+ query = "long research query " * 20
+ try:
+ with (
+ patch(
+ "local_deep_research.config.llm_config.get_llm"
+ ) as provider,
+ patch(
+ "local_deep_research.chat.service.ThreadPoolExecutor"
+ ) as worker,
+ ):
+ result = ChatService(OWNER)._generate_title(
+ query,
+ {
+ **_TITLE_SNAPSHOT,
+ "chat.title_llm_timeout_seconds": timeout,
+ },
+ )
+ provider.assert_not_called()
+ worker.assert_not_called()
+ finally:
+ logger.remove(sink)
+ logger.disable("local_deep_research")
+ assert result == query[:97] + "..."
+ warnings = [r for r in records if r["level"].name == "WARNING"]
+ assert len(warnings) == 1
+ record = warnings[0]
+ assert "chat.title_llm_timeout_seconds" in record["message"]
+ assert reason in record["message"]
+ assert "falling back to truncation" in record["message"]
+ assert canary not in str(records)
+ assert record["exception"] is None
+ assert record["extra"] == {}
+ assert "could not convert" not in record["message"]
+
+ @pytest.mark.parametrize("timeout", [5, "2.5", "missing"])
+ def test_timeout_controls_use_controlled_provider(self, timeout):
+ snapshot = dict(_TITLE_SNAPSHOT)
+ if timeout == "missing":
+ del snapshot["chat.title_llm_timeout_seconds"]
+ else:
+ snapshot["chat.title_llm_timeout_seconds"] = timeout
+ with _llm_returning("Controlled title") as llm:
+ assert (
+ ChatService(OWNER)._generate_title("query", snapshot)
+ == "Controlled title"
+ )
+ llm.invoke.assert_called_once()
+
+ def test_disabled_title_ignores_invalid_timeout(self):
+ with (
+ patch("local_deep_research.config.llm_config.get_llm") as provider,
+ patch(
+ "local_deep_research.chat.service.ThreadPoolExecutor"
+ ) as worker,
+ ):
+ assert (
+ ChatService(OWNER)._generate_title(
+ "query",
+ {
+ "chat.llm_title_generation": False,
+ "chat.title_llm_timeout_seconds": {
+ "value": "synthetic-timeout-secret",
+ "ui_element": "number",
+ },
+ },
+ )
+ == "query"
+ )
+ provider.assert_not_called()
+ worker.assert_not_called()
+
def test_numeric_string_timeout_and_visible_unicode_are_preserved(
self, titled
):