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(cache): keep listing titles out of fetched page metadata (#8245)

LearningCircuitcf826e8db98e
diff --git a/changelog.d/8245.bugfix.md b/changelog.d/8245.bugfix.md
new file mode 100644
index 0000000000..941ed087db
--- /dev/null
+++ b/changelog.d/8245.bugfix.md
@@ -0,0 +1 @@
+Keep web search listing titles from being recorded as fetched page titles when research content is served from cache.
diff --git a/src/local_deep_research/web_search_engines/search_engine_base.py b/src/local_deep_research/web_search_engines/search_engine_base.py
index 1067a6c29b..c0fb91caa8 100644
--- a/src/local_deep_research/web_search_engines/search_engine_base.py
+++ b/src/local_deep_research/web_search_engines/search_engine_base.py
@@ -30,6 +30,7 @@ from tenacity.wait import wait_base
from ..advanced_search_system.filters.base_filter import BaseFilter
from ..utilities.type_utils import _is_strict_scope, unwrap_setting
+from ..utilities.url_utils import library_display_url
from ..config.constants import DEFAULT_MAX_FILTERED_RESULTS
from ..config.thread_settings import get_setting_from_snapshot
from ..security.log_sanitizer import sanitize_error_message, scrub_error
@@ -1069,6 +1070,14 @@ class BaseSearchEngine(ABC):
continue
provenance = _LIBRARY_PROVENANCE if is_library_key else None
try:
+ # Web result titles describe search listings, not fetched
+ # page metadata. Leave that cache field empty until a page
+ # reader supplies it; library titles come from local data.
+ cache_title = (
+ item.get("title")
+ if library_display_url(link) is not None
+ else ""
+ )
if self._is_library_chunk_link(link):
scope = self._collection_scope_for_item(item)
if scope is None:
@@ -1076,7 +1085,7 @@ class BaseSearchEngine(ABC):
cache.put(
link,
content,
- title=item.get("title"),
+ title=cache_title,
url_out=link,
collection_id=scope,
provenance=provenance,
@@ -1085,7 +1094,7 @@ class BaseSearchEngine(ABC):
cache.put(
link,
content,
- title=item.get("title"),
+ title=cache_title,
url_out=link,
provenance=provenance,
)
diff --git a/tests/advanced_search_system/tools/test_fetch_cache_titles.py b/tests/advanced_search_system/tools/test_fetch_cache_titles.py
new file mode 100644
index 0000000000..65008664cf
--- /dev/null
+++ b/tests/advanced_search_system/tools/test_fetch_cache_titles.py
@@ -0,0 +1,147 @@
+"""A search listing title must not stand in for a fetched page's title."""
+
+from unittest.mock import Mock
+
+import pytest
+
+from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ SearchResultsCollector,
+)
+from local_deep_research.advanced_search_system.tools.fetch import (
+ build_fetch_tool,
+)
+from local_deep_research.content_fetcher import ContentFetcher
+from local_deep_research.research_library.downloaders.base import DownloadResult
+from local_deep_research.utilities.research_content_cache import (
+ ResearchContentCache,
+)
+from local_deep_research.utilities.url_utils import FETCHED_TITLE_KEY
+from local_deep_research.web_search_engines.engines.search_engine_library import (
+ LibraryRAGSearchEngine,
+)
+from local_deep_research.web_search_engines.search_engine_base import (
+ BaseSearchEngine,
+)
+
+
+URL = "https://93.184.216.34/fixture-title"
+BODY = "Fully synthetic source content. " * 20
+LISTING_TITLE = "Fixture search listing"
+PAGE_TITLE = "Fixture page title"
+
+
+class _WebEngine(BaseSearchEngine):
+ def _get_previews(self, query):
+ return []
+
+ def _get_full_content(self, items):
+ return items
+
+
+def downloader(monkeypatch):
+ transport = Mock()
+ transport.download_with_result.return_value = DownloadResult(
+ content=BODY.encode("utf-8"), is_success=True, status_code=200
+ )
+ transport.get_metadata.return_value = {"title": PAGE_TITLE}
+ monkeypatch.setattr(
+ ContentFetcher, "_get_downloader", lambda self, url_type: transport
+ )
+ return transport
+
+
+def _tool_and_collector(cache):
+ collector = SearchResultsCollector([])
+ collector.add_results(
+ [{"link": URL, "title": LISTING_TITLE, "snippet": "Fixture excerpt"}],
+ engine_name="fixture",
+ )
+ tool = build_fetch_tool(
+ "full",
+ collector,
+ settings_snapshot={},
+ content_cache=cache,
+ max_fetches=0,
+ )
+ return tool, collector
+
+
+def _warm_from_search(cache):
+ engine = _WebEngine(content_cache=cache)
+ engine._store_full_content_in_cache(
+ [
+ {
+ "link": URL,
+ "title": LISTING_TITLE,
+ "full_content": BODY,
+ "full_content_is_complete": True,
+ }
+ ]
+ )
+ assert cache.get(URL)["content"] == BODY
+
+
+def test_search_cache_hit_does_not_record_a_listing_as_a_page_title(downloader):
+ cache = ResearchContentCache()
+ _warm_from_search(cache)
+ tool, collector = _tool_and_collector(cache)
+
+ output = tool.invoke({"url": URL})
+
+ assert BODY in output
+ assert "Title: None" not in output
+ downloader.download_with_result.assert_not_called()
+ assert collector.find_by_index(1)["title"] == LISTING_TITLE
+ assert not collector._doc_fetched_title
+
+
+def test_page_title_can_be_recorded_after_a_search_cache_hit(downloader):
+ cache = ResearchContentCache()
+ _warm_from_search(cache)
+ tool, collector = _tool_and_collector(cache)
+ assert BODY in tool.invoke({"url": URL})
+ downloader.download_with_result.assert_not_called()
+
+ # Content keys retain the fragment; citation grouping shares the document.
+ output = tool.invoke({"url": URL + "#fixture-section"})
+
+ assert BODY in output and PAGE_TITLE in output
+ downloader.download_with_result.assert_called_once()
+ assert collector.find_by_index(1)[FETCHED_TITLE_KEY] == PAGE_TITLE
+
+
+def test_real_page_metadata_survives_a_content_fetcher_cache_hit(downloader):
+ cache = ResearchContentCache()
+ tool, collector = _tool_and_collector(cache)
+
+ first = tool.invoke({"url": URL})
+ second = tool.invoke({"url": URL})
+
+ assert BODY in first and BODY in second
+ assert PAGE_TITLE in first and PAGE_TITLE in second
+ downloader.download_with_result.assert_called_once()
+ assert cache.get(URL)["title"] == PAGE_TITLE
+ assert collector.find_by_index(1)[FETCHED_TITLE_KEY] == PAGE_TITLE
+
+
+def test_library_cache_entries_keep_the_database_title():
+ cache = ResearchContentCache()
+ engine = LibraryRAGSearchEngine(
+ settings_snapshot={"_username": "fixture"},
+ content_cache=cache,
+ )
+ url = "/library/document/123e4567-e89b-12d3-a456-426614174000"
+ engine._store_full_content_in_cache(
+ [
+ {
+ "link": url,
+ "title": "Fixture document title",
+ "full_content": BODY,
+ "full_content_is_complete": True,
+ }
+ ]
+ )
+
+ assert cache.get(url)["content"] == BODY
+ assert cache.get(url)["title"] == "Fixture document title"