~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(strategies): give the empty-synthesis placeholder its own message (#6948)
LearningCircuit735cff86ece6
diff --git a/changelog.d/6940.bugfix.md b/changelog.d/6940.bugfix.mdnew file mode 100644index 0000000000..8030def6ae--- /dev/null+++ b/changelog.d/6940.bugfix.md@@ -0,0 +1 @@+A source-based or focused-iteration run whose final synthesis returns empty or whitespace-only text now reports "Final synthesis produced no usable text." and logs a warning, instead of the "No relevant results found" message of a search that found nothing, so a degraded synthesis is distinguishable from an empty search.diff --git a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py b/src/local_deep_research/advanced_search_system/strategies/base_strategy.pyindex 2a5370ee89..43df2f00f4 100644--- a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/base_strategy.py@@ -23,6 +23,14 @@ CHECK_CONTEXT_REFINEMENT_LOOP = "refinement_loop"CHECK_CONTEXT_AGENT_STREAM = "agent_stream"CHECK_CONTEXT_FALLBACK_SYNTHESIS = "fallback_synthesis"+# Final-synthesis text for a citation result that is truthy but carries no+# usable ``content`` / ``response`` (think-only model replies stringify to+# ""). Deliberately unlike the strategies' "No relevant results found" text,+# so a degraded synthesis cannot be mistaken for a search that found nothing+# (#6940). It says nothing about sources: there may be none, and a report+# that lists only cited sources would omit them anyway.+NO_USABLE_SYNTHESIS_MESSAGE = "Final synthesis produced no usable text."+class BaseSearchStrategy(ABC):"""Abstract base class for all search strategies."""diff --git a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.pyindex f4c53e4b2f..caa0f2beca 100644--- a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py@@ -40,6 +40,7 @@ from .base_strategy import (CHECK_CONTEXT_ITERATION_START,CHECK_CONTEXT_POST_SEARCH,CHECK_CONTEXT_PRE_SYNTHESIS,+ NO_USABLE_SYNTHESIS_MESSAGE,)@@ -388,9 +389,14 @@ class FocusedIterationStrategy(BaseSearchStrategy):)if final_result:- synthesized_content = self.first_usable_text(- final_result, "No relevant results found."- )+ synthesized_content = self.first_usable_text(final_result)+ if synthesized_content is None:+ logger.warning(+ "Final synthesis returned no usable text in the "+ "focused-iteration strategy; this is a degraded "+ "synthesis, not an empty search"+ )+ synthesized_content = NO_USABLE_SYNTHESIS_MESSAGEdocuments = final_result.get("documents", [])elif citation_failed:synthesized_content = (diff --git a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.pyindex e12724979e..4ea697166d 100644--- a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py@@ -23,6 +23,7 @@ from .base_strategy import (CHECK_CONTEXT_ITERATION_START,CHECK_CONTEXT_POST_SEARCH,CHECK_CONTEXT_PRE_SYNTHESIS,+ NO_USABLE_SYNTHESIS_MESSAGE,)@@ -562,9 +563,15 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):# Null check — synthesis can fail on empty/malformed resultsif final_citation_result:synthesized_content = self.first_usable_text(- final_citation_result,- "No relevant results found in final synthesis.",+ final_citation_result)+ if synthesized_content is None:+ logger.warning(+ "Final synthesis returned no usable text in the "+ "source-based strategy; this is a degraded synthesis, "+ "not an empty search"+ )+ synthesized_content = NO_USABLE_SYNTHESIS_MESSAGEdocuments = final_citation_result.get("documents", [])elif citation_failed:# Distinct from the empty-result message below: the sources arediff --git a/tests/advanced_search_system/strategies/test_citation_handler_failure_keeps_sources.py b/tests/advanced_search_system/strategies/test_citation_handler_failure_keeps_sources.pyindex dfc1519f84..7b263fd8d3 100644--- a/tests/advanced_search_system/strategies/test_citation_handler_failure_keeps_sources.py+++ b/tests/advanced_search_system/strategies/test_citation_handler_failure_keeps_sources.py@@ -124,17 +124,21 @@ def test_content_wins_over_response_when_both_are_usable(factory):@pytest.mark.parametrize("factory,content,expected",[- (_focused, "", "No relevant results found."),- (_focused, {"unexpected": True}, "No relevant results found."),+ (_focused, "", "Final synthesis produced no usable text."),+ (+ _focused,+ {"unexpected": True},+ "Final synthesis produced no usable text.",+ ),(_source_based," \n\t",- "No relevant results found in final synthesis.",+ "Final synthesis produced no usable text.",),(_source_based,["unexpected"],- "No relevant results found in final synthesis.",+ "Final synthesis produced no usable text.",),],ids=[@@ -144,7 +148,7 @@ def test_content_wins_over_response_when_both_are_usable(factory):"source-malformed",],)-def test_unusable_citation_text_keeps_existing_fallback(+def test_unusable_citation_text_gets_the_placeholder(factory, content, expected):result = _analyze_with_citation_result(@@ -271,3 +275,121 @@ class TestSourceBased:phases = [m.get("phase") for _, _, m in events if m]assert "synthesis_error" in phases, phases+++# (strategy factory, the text of that strategy's genuine no-results branch,+# the module whose logger the degraded-synthesis warning goes through)+STRATEGIES = pytest.mark.parametrize(+ "factory,no_results,module",+ [+ (+ _focused,+ "No relevant results found.",+ "focused_iteration_strategy",+ ),+ (+ _source_based,+ "No relevant results found in final synthesis.",+ "source_based_strategy",+ ),+ ],+ ids=["focused-iteration", "source-based"],+)++PLACEHOLDER = "Final synthesis produced no usable text."+++class TestPlaceholderIsDistinguishable:+ """#6940: the empty-content placeholder must not read as a genuine+ no-results run. A degraded synthesis (think-only replies, blank+ content) and an actually empty result demand opposite+ investigations, so the two messages must differ in every strategy+ that has both."""++ @STRATEGIES+ def test_valid_content_is_used_verbatim(self, factory, no_results, module):+ """The valid-content pin the #6741 review asked for: a plain+ ``{"content": ...}`` result IS the synthesis, never the+ placeholder."""+ result = _analyze_with_citation_result(+ factory(), {"content": "Synthesized", "documents": []}+ )++ assert result["current_knowledge"] == "Synthesized"++ @STRATEGIES+ def test_neither_key_substitutes_the_placeholder_and_keeps_documents(+ self, factory, no_results, module+ ):+ """The neither-key case: no usable ``content``/``response``, but+ the citation result is truthy, so its documents survive into the+ final finding next to the placeholder."""+ documents = [{"title": "T", "link": "https://example.test/a"}]++ result = _analyze_with_citation_result(+ factory(), {"documents": documents}+ )++ assert result["findings"][-1]["documents"] == documents+ assert result["current_knowledge"] == PLACEHOLDER++ @STRATEGIES+ def test_the_placeholder_message_differs_from_the_no_results_message(+ self, factory, no_results, module+ ):+ """A falsy citation result is a genuine no-results run; a truthy+ one with no usable text is a degraded synthesis. The two+ ``current_knowledge`` values must not be confusable."""+ genuinely_empty = _analyze_with_citation_result(factory(), {})+ degraded = _analyze_with_citation_result(factory(), {"documents": []})++ assert genuinely_empty["current_knowledge"] == no_results+ assert degraded["current_knowledge"] == PLACEHOLDER+ assert degraded["current_knowledge"] != no_results++ @STRATEGIES+ def test_the_placeholder_does_not_claim_sources_that_may_not_exist(+ self, factory, no_results, module+ ):+ """No documents came back, so the text must not say sources are+ listed (and the report may hide uncited sources anyway)."""+ degraded = _analyze_with_citation_result(factory(), {"documents": []})++ text = degraded["current_knowledge"].lower()+ assert "source" not in text+ assert "listed" not in text++ @STRATEGIES+ def test_a_degraded_synthesis_logs_a_warning(+ self, factory, no_results, module+ ):+ with patch(+ "local_deep_research.advanced_search_system.strategies."+ f"{module}.logger"+ ) as mock_logger:+ _analyze_with_citation_result(factory(), {"documents": []})++ warnings = [call.args[0] for call in mock_logger.warning.call_args_list]+ assert any("no usable text" in warning for warning in warnings), (+ warnings+ )++ @STRATEGIES+ @pytest.mark.parametrize(+ "citation_result",+ [{}, {"content": "Synthesized", "documents": []}],+ ids=["genuine-empty", "valid-content"],+ )+ def test_other_outcomes_log_no_degraded_synthesis_warning(+ self, factory, no_results, module, citation_result+ ):+ with patch(+ "local_deep_research.advanced_search_system.strategies."+ f"{module}.logger"+ ) as mock_logger:+ _analyze_with_citation_result(factory(), citation_result)++ warnings = [call.args[0] for call in mock_logger.warning.call_args_list]+ assert not any("no usable text" in warning for warning in warnings), (+ warnings+ )