~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(followup): carry the follow-up router's delegate strategy to the strategy (#7567)
Lukas6cddca1e37fd
diff --git a/changelog.d/7567.bugfix.md b/changelog.d/7567.bugfix.mdnew file mode 100644index 0000000000..08b5d2d92a--- /dev/null+++ b/changelog.d/7567.bugfix.md@@ -0,0 +1 @@+Follow-up research started from the follow-up dialog now uses your configured search strategy as its delegate instead of always falling back to source-based.diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.pyindex 9a1efb3ff2..6a3e13c057 100644--- a/src/local_deep_research/web/services/research_service.py+++ b/src/local_deep_research/web/services/research_service.py@@ -1889,6 +1889,15 @@ def run_research_process(research_id, query, mode, **kwargs):# For other errors, re-raise to avoid silent failuresraise+ # AdvancedSearchSystem takes a follow-up's delegate strategy from+ # research_context["delegate_strategy"]. The chat router writes it+ # there; the follow-up router hands the user's strategy over as its+ # own keyword, which nothing read, so every follow-up delegated to+ # source-based whatever strategy the user had chosen.+ delegate_strategy = kwargs.get("delegate_strategy")+ if delegate_strategy:+ shared_research_context["delegate_strategy"] = delegate_strategy+# Set the progress callback in the systemsystem = AdvancedSearchSystem(llm=use_llm, # type: ignore[arg-type]diff --git a/tests/followup/test_followup_context_contracts.py b/tests/followup/test_followup_context_contracts.pyindex 2b150a847e..7ccb06def0 100644--- a/tests/followup/test_followup_context_contracts.py+++ b/tests/followup/test_followup_context_contracts.py@@ -16,9 +16,10 @@ What is pinned here:research id inherits nothing -- with an owner-side positive control so thenegative result cannot be explained by "the feature is simply broken".2. The multi-turn context window is bounded, and where the bound comes from.-3. ``delegate_strategy`` / ``is_multi_turn`` routing matches main's, including- main's pre-existing quirk that the follow-up router's ``delegate_strategy=``- kwarg never reaches the code that reads it.+3. ``delegate_strategy`` / ``is_multi_turn`` routing. The follow-up router's+ ``delegate_strategy=`` kwarg never reached the code that reads it, on main+ as on the port; ``run_research_process`` now carries it into the research+ context (``tests/web/services/test_research_execution_boundary.py``).4. Deleted / still-running parents.5. Prompt-injection surface. Parent text (originally fetched web pages) isconcatenated into a new prompt with no delimiting and no escaping. That is@@ -915,16 +916,19 @@ class TestDelegateStrategyRouting:assert create.call_args.kwargs["strategy_name"] == "source-based"- def test_followup_router_kwarg_never_reaches_the_delegate_selector(self):- """PARITY NOTE, matches main: the router's kwarg is inert.+ def test_service_hands_the_delegate_over_outside_the_context(self):+ """The service returns the delegate as its own key, not in+ ``research_context``.``AdvancedSearchSystem`` reads the delegate from``research_context["delegate_strategy"]``. The chat router writes that- key. The follow-up router instead passes ``delegate_strategy=`` as a- keyword to ``start_research_process`` -- and the service-built- ``research_context`` has no such key, so a follow-up always delegates- to ``source-based`` regardless of the user's configured strategy.- Identical in main's ``followup_research/routes.py``.+ key. The follow-up router passes this value as the+ ``delegate_strategy=`` keyword to ``start_research_process``, and the+ service-built ``research_context`` has no such key. On main the+ keyword was inert, so a follow-up always delegated to+ ``source-based``. ``run_research_process`` now copies it into the+ context (``test_research_execution_boundary.py::+ TestTheFollowUpDelegateReachesTheStrategySystem``)."""from local_deep_research.followup_research.models import FollowUpRequestfrom local_deep_research.followup_research.service import (diff --git a/tests/web/services/test_research_execution_boundary.py b/tests/web/services/test_research_execution_boundary.pyindex a3b4ec41e8..5007803aa7 100644--- a/tests/web/services/test_research_execution_boundary.py+++ b/tests/web/services/test_research_execution_boundary.py@@ -289,6 +289,7 @@ def _run(use_real_research_state: bool = False,expect_reached_strategy: bool = True,snapshot: dict | None = None,+ run_kwargs: dict | None = None,) -> RunProbe:"""Drive the real ``run_research_process`` in quick mode.@@ -377,6 +378,7 @@ def _run("quick",username=username,settings_snapshot=snapshot or _snapshot(),+ **(run_kwargs or {}),)except BaseException as exc: # noqa: BLE001 -- recorded, not hiddenraised = exc@@ -812,3 +814,51 @@ class TestSettingsResolveFromTheOwnersSnapshot:"second-users-engine")assert probe.system_cls.call_args.kwargs["max_iterations"] == 11+++# =====================================================================+# 5. A follow-up's delegate strategy reaches the strategy system+# =====================================================================+++class TestTheFollowUpDelegateReachesTheStrategySystem:+ """``AdvancedSearchSystem`` picks a follow-up's delegate from+ ``research_context["delegate_strategy"]``. The chat router writes that+ key; the follow-up router passes the user's strategy as the+ ``delegate_strategy=`` keyword instead, and the run has to carry it+ into the context or the user's choice is lost (#7565)."""++ def test_the_delegate_keyword_lands_in_the_strategys_context(self):+ probe = _run(+ research_id=9501,+ run_kwargs={+ "delegate_strategy": "focused-iteration",+ "research_context": {"past_findings": "prior"},+ },+ )++ context = probe.system_cls.call_args.kwargs["research_context"]+ assert context["delegate_strategy"] == "focused-iteration"+ assert context["past_findings"] == "prior"++ def test_the_keyword_wins_over_a_delegate_already_in_the_context(self):+ probe = _run(+ research_id=9502,+ run_kwargs={+ "delegate_strategy": "focused-iteration",+ "research_context": {"delegate_strategy": "source-based"},+ },+ )++ context = probe.system_cls.call_args.kwargs["research_context"]+ assert context["delegate_strategy"] == "focused-iteration"++ def test_a_context_delegate_is_kept_when_no_keyword_is_passed(self):+ """The chat router's path: the delegate arrives in the context."""+ probe = _run(+ research_id=9503,+ run_kwargs={"research_context": {"delegate_strategy": "iterative"}},+ )++ context = probe.system_cls.call_args.kwargs["research_context"]+ assert context["delegate_strategy"] == "iterative"