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(#6540): source_based and focused_iteration strategies still let an empty citation 'content' erase the answer (#6741)

BingEdwardde29ca2d6667
diff --git a/changelog.d/6540.bugfix.md b/changelog.d/6540.bugfix.md
new file mode 100644
index 0000000000..1c2a3254f8
--- /dev/null
+++ b/changelog.d/6540.bugfix.md
@@ -0,0 +1 @@
+Preserve valid citation responses and existing fallbacks when synthesis content is missing, blank, or malformed.
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.py
index 3557432631..742b18c1b4 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
@@ -385,8 +385,16 @@ class FocusedIterationStrategy(BaseSearchStrategy):
)
if final_result:
- synthesized_content = final_result.get(
- "content", "No relevant results found."
+ synthesized_content = next(
+ (
+ candidate
+ for candidate in (
+ final_result.get("content"),
+ final_result.get("response"),
+ )
+ if isinstance(candidate, str) and candidate.strip()
+ ),
+ "No relevant results found.",
)
documents = final_result.get("documents", [])
elif citation_failed:
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.py
index 182ed41429..f6c0dcc19b 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
@@ -555,7 +555,17 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
# Null check — synthesis can fail on empty/malformed results
if final_citation_result:
- synthesized_content = final_citation_result["content"]
+ synthesized_content = next(
+ (
+ candidate
+ for candidate in (
+ final_citation_result.get("content"),
+ final_citation_result.get("response"),
+ )
+ if isinstance(candidate, str) and candidate.strip()
+ ),
+ "No relevant results found in final synthesis.",
+ )
documents = final_citation_result.get("documents", [])
elif citation_failed:
# Distinct from the empty-result message below: the sources are
diff --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.py
index fffa51447d..3f337cd6fa 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
@@ -10,6 +10,8 @@ what the reader lost was the findings and the report.
from unittest.mock import Mock, patch
+import pytest
+
def _focused(**kwargs):
from local_deep_research.advanced_search_system.strategies.focused_iteration_strategy import (
@@ -43,6 +45,92 @@ def _source_based():
)
+def _analyze_with_citation_result(strategy, citation_result):
+ with patch.object(
+ strategy.question_generator,
+ "generate_questions",
+ return_value=["Q1"],
+ ):
+ with patch.object(
+ strategy.citation_handler,
+ "analyze_followup",
+ return_value=citation_result,
+ ):
+ return strategy.analyze_topic("test query")
+
+
+ "factory",
+ [_focused, _source_based],
+ ids=["focused-iteration", "source-based"],
+)
+def test_response_only_result_is_used(factory):
+ documents = [{"title": "T", "link": "https://example.test/a"}]
+
+ result = _analyze_with_citation_result(
+ factory(),
+ {"response": "Synthesized from response", "documents": documents},
+ )
+
+ assert result["current_knowledge"] == "Synthesized from response"
+ assert result["findings"][-1]["documents"] == documents
+
+
+ "factory",
+ [_focused, _source_based],
+ ids=["focused-iteration", "source-based"],
+)
+def test_response_is_used_when_content_is_unusable(factory):
+ documents = [{"title": "T", "link": "https://example.test/a"}]
+
+ result = _analyze_with_citation_result(
+ factory(),
+ {
+ "content": " \n\t",
+ "response": "Synthesized from response",
+ "documents": documents,
+ },
+ )
+
+ assert result["current_knowledge"] == "Synthesized from response"
+ assert result["findings"][-1]["documents"] == documents
+
+
+ "factory,content,expected",
+ [
+ (_focused, "", "No relevant results found."),
+ (_focused, {"unexpected": True}, "No relevant results found."),
+ (
+ _source_based,
+ " \n\t",
+ "No relevant results found in final synthesis.",
+ ),
+ (
+ _source_based,
+ ["unexpected"],
+ "No relevant results found in final synthesis.",
+ ),
+ ],
+ ids=[
+ "focused-empty",
+ "focused-malformed",
+ "source-blank",
+ "source-malformed",
+ ],
+)
+def test_unusable_citation_text_keeps_existing_fallback(
+ factory, content, expected
+):
+ result = _analyze_with_citation_result(
+ factory(),
+ {"content": content, "response": None, "documents": []},
+ )
+
+ assert result["current_knowledge"] == expected
+
+
class TestFocusedIteration:
def test_a_raising_citation_handler_still_returns_the_run(self):
strategy = _focused()