~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(progress): rebalance progress bar for detailed reports (#3806)
LearningCircuitf64f78fac569
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.pyindex 06d515b3bf..0dc8eedcde 100644--- a/src/local_deep_research/web/services/research_service.py+++ b/src/local_deep_research/web/services/research_service.py@@ -44,6 +44,20 @@ _MAX_GLOBAL_CONCURRENT = get_env_setting()_global_research_semaphore = threading.Semaphore(_MAX_GLOBAL_CONCURRENT)+# Progress allocation for detailed mode — report generation is the bulk of the work+_DETAILED_SEARCH_PROGRESS_CAP = 8 # Search/output phases capped here+_DETAILED_REPORT_PROGRESS_START = 10 # Report generation starts here+_DETAILED_REPORT_PROGRESS_END = 100 # Report generation ends here+_REPORT_PHASES = frozenset(+ {+ "report_generation",+ "report_section_research",+ "report_formatting",+ "report_structure",+ "report_complete",+ }+)+# Socket.IO emission throttling: minimum interval between progress emissions per research_EMIT_THROTTLE_SECONDS = 0.2 # 200ms_EMIT_TTL_SECONDS = 3600 # 1 hour — evict stale entries from orphaned research@@ -1060,29 +1074,34 @@ def run_research_process(research_id, query, mode, **kwargs):# Adjust progress based on research modeadjusted_progress = progress_percent- if (- mode == "detailed"- and metadata.get("phase") == "output_generation"- ):- # For detailed mode, adjust the progress range for output generation- adjusted_progress = min(80, progress_percent)- elif (- mode == "detailed"- and metadata.get("phase") == "report_generation"- ):- # Scale the progress from 80% to 95% for the report generation phase- if progress_percent is not None:- normalized = progress_percent / 100- adjusted_progress = 80 + (normalized * 15)+ phase = metadata.get("phase", "")++ if mode == "detailed":+ # Report phases pass through (already mapped by wrapper).+ # All other phases — including "complete" emitted by each+ # strategy when its analyze_topic finishes (report+ # generation runs analyze_topic per subsection, so a+ # strategy "complete" fires mid-report and must NOT be+ # treated as the end of the whole run) — are capped.+ # update_progress_and_check_active enforces global+ # monotonicity, so backwards jumps from non-monotonic+ # strategy updates are absorbed there.+ # None values (error path, sub-search relays) pass through+ # unchanged.+ if phase not in _REPORT_PHASES and progress_percent is not None:+ adjusted_progress = min(+ _DETAILED_SEARCH_PROGRESS_CAP, progress_percent+ )elif (- mode == "quick" and metadata.get("phase") == "output_generation"+ mode == "quick"+ and phase == "output_generation"+ and progress_percent is not None):- # For quick mode, ensure we're at least at 85% during output generation- adjusted_progress = max(85, progress_percent)- # Map any further progress within output_generation to 85-95% range- if progress_percent is not None and progress_percent > 0:- normalized = progress_percent / 100- adjusted_progress = 85 + (normalized * 10)+ # For quick mode, scale output_generation to 85-95% range+ if progress_percent > 0:+ adjusted_progress = 85 + (progress_percent / 100) * 10+ else:+ adjusted_progress = 85# Atomically update progress and check if research is still activeif adjusted_progress is not None:@@ -2077,18 +2096,26 @@ def run_research_process(research_id, query, mode, **kwargs):# Full Reportprogress_callback("Generating detailed report...",- 85,+ _DETAILED_REPORT_PROGRESS_START,{"phase": "report_generation"},)# Extract the search system from the results if availablesearch_system = results.get("search_system", None)- # Wrapper that maps report generator's 0-100% to 85-95% range- # and relays cancellation checks through the outer progress_callback+ # Wrapper that maps report generator's 0-100% to the configured+ # detailed-mode range and relays cancellation checks through the+ # outer progress_callback+ _report_range = (+ _DETAILED_REPORT_PROGRESS_END - _DETAILED_REPORT_PROGRESS_START+ )+def report_progress_callback(message, progress_percent, metadata):if progress_percent is not None:- adjusted = 85 + (progress_percent / 100) * 10+ adjusted = (+ _DETAILED_REPORT_PROGRESS_START+ + (progress_percent / 100) * _report_range+ )else:adjusted = progress_percentprogress_callback(message, adjusted, metadata)@@ -2103,7 +2130,9 @@ def run_research_process(research_id, query, mode, **kwargs):)progress_callback(- "Report generation complete", 95, {"phase": "report_complete"}+ "Report generation complete",+ _DETAILED_REPORT_PROGRESS_END,+ {"phase": "report_complete"},)# Format citations and split off the trailing Sourcesdiff --git a/tests/report/test_report_generator_progress.py b/tests/report/test_report_generator_progress.pyindex 27474e6736..229a86765f 100644--- a/tests/report/test_report_generator_progress.py+++ b/tests/report/test_report_generator_progress.py@@ -13,6 +13,10 @@ from unittest.mock import MagicMockimport pytestfrom local_deep_research.report_generator import IntegratedReportGenerator+from local_deep_research.web.services.research_service import (+ _DETAILED_REPORT_PROGRESS_END,+ _DETAILED_REPORT_PROGRESS_START,+)# ── Fixtures ──@@ -606,30 +610,36 @@ class TestCompletedSubsectionsCounter:class TestReportProgressCallbackWrapper:"""Tests for the report_progress_callback wrapper in research_service."""- def test_maps_0_to_85(self):- """0% internal maps to 85% external."""+ def test_maps_0_to_range_start(self):+ """0% internal maps to start of report range (10%)."""outer_callback = MagicMock()+ start = _DETAILED_REPORT_PROGRESS_START+ end = _DETAILED_REPORT_PROGRESS_END+ report_range = end - start# Simulate the wrapper logic from research_service.pydef report_progress_callback(message, progress_percent, metadata):if progress_percent is not None:- adjusted = 85 + (progress_percent / 100) * 10+ adjusted = start + (progress_percent / 100) * report_rangeelse:adjusted = progress_percentouter_callback(message, adjusted, metadata)report_progress_callback("test", 0, {"phase": "report_structure"})outer_callback.assert_called_with(- "test", 85.0, {"phase": "report_structure"}+ "test", 10.0, {"phase": "report_structure"})- def test_maps_50_to_90(self):- """50% internal maps to 90% external."""+ def test_maps_50_to_range_midpoint(self):+ """50% internal maps to midpoint of report range (55%)."""outer_callback = MagicMock()+ start = _DETAILED_REPORT_PROGRESS_START+ end = _DETAILED_REPORT_PROGRESS_END+ report_range = end - startdef report_progress_callback(message, progress_percent, metadata):if progress_percent is not None:- adjusted = 85 + (progress_percent / 100) * 10+ adjusted = start + (progress_percent / 100) * report_rangeelse:adjusted = progress_percentouter_callback(message, adjusted, metadata)@@ -638,32 +648,38 @@ class TestReportProgressCallbackWrapper:"test", 50, {"phase": "report_section_research"})outer_callback.assert_called_with(- "test", 90.0, {"phase": "report_section_research"}+ "test", 55.0, {"phase": "report_section_research"})- def test_maps_100_to_95(self):- """100% internal maps to 95% external."""+ def test_maps_100_to_range_end(self):+ """100% internal maps to end of report range (100%)."""outer_callback = MagicMock()+ start = _DETAILED_REPORT_PROGRESS_START+ end = _DETAILED_REPORT_PROGRESS_END+ report_range = end - startdef report_progress_callback(message, progress_percent, metadata):if progress_percent is not None:- adjusted = 85 + (progress_percent / 100) * 10+ adjusted = start + (progress_percent / 100) * report_rangeelse:adjusted = progress_percentouter_callback(message, adjusted, metadata)report_progress_callback("test", 100, {"phase": "report_complete"})outer_callback.assert_called_with(- "test", 95.0, {"phase": "report_complete"}+ "test", 100.0, {"phase": "report_complete"})def test_none_progress_passed_through(self):"""None progress is passed through unchanged."""outer_callback = MagicMock()+ start = _DETAILED_REPORT_PROGRESS_START+ end = _DETAILED_REPORT_PROGRESS_END+ report_range = end - startdef report_progress_callback(message, progress_percent, metadata):if progress_percent is not None:- adjusted = 85 + (progress_percent / 100) * 10+ adjusted = start + (progress_percent / 100) * report_rangeelse:adjusted = progress_percentouter_callback(message, adjusted, metadata)@@ -1562,7 +1578,7 @@ class TestResearchServiceWrapperIntegration:# Verify the wrapper is defined and usedassert "report_progress_callback" in sourceassert "progress_callback=report_progress_callback" in source- assert "85 + (progress_percent / 100) * 10" in source+ assert "_DETAILED_REPORT_PROGRESS_START" in sourcedef test_wrapper_handles_none_progress(self):"""The wrapper code handles None progress_percent."""diff --git a/tests/web/services/test_research_service_execution.py b/tests/web/services/test_research_service_execution.pyindex b39ddadbf4..4cc75e535c 100644--- a/tests/web/services/test_research_service_execution.py+++ b/tests/web/services/test_research_service_execution.py@@ -12,6 +12,12 @@ Covers:import pytest+from local_deep_research.web.services.research_service import (+ _DETAILED_REPORT_PROGRESS_END,+ _DETAILED_SEARCH_PROGRESS_CAP,+ _REPORT_PHASES,+)+class TestSettingsContext:"""Tests for SettingsContext created inside run_research_process."""@@ -59,46 +65,74 @@ class TestProgressCallback:"""Tests for progress callback logic."""def test_progress_adjusted_for_detailed_output_generation(self):- """Detailed mode output_generation → capped at 80."""+ """Detailed mode output_generation → capped at search cap."""mode = "detailed"metadata = {"phase": "output_generation"}progress_percent = 90adjusted_progress = progress_percent- if mode == "detailed" and metadata.get("phase") == "output_generation":- adjusted_progress = min(80, progress_percent)+ phase = metadata.get("phase", "")+ if mode == "detailed":+ if phase not in _REPORT_PHASES and progress_percent is not None:+ adjusted_progress = min(+ _DETAILED_SEARCH_PROGRESS_CAP, progress_percent+ )- assert adjusted_progress == 80+ assert adjusted_progress == _DETAILED_SEARCH_PROGRESS_CAPdef test_progress_adjusted_for_detailed_report_generation(self):- """Detailed mode report_generation → scaled 80-95%."""+ """Detailed mode report_generation → passes through (wrapper maps range)."""mode = "detailed"metadata = {"phase": "report_generation"}progress_percent = 50adjusted_progress = progress_percent- if mode == "detailed" and metadata.get("phase") == "report_generation":- if progress_percent is not None:- normalized = progress_percent / 100- adjusted_progress = 80 + (normalized * 15)+ phase = metadata.get("phase", "")+ if mode == "detailed" and phase not in _REPORT_PHASES:+ adjusted_progress = min(+ _DETAILED_SEARCH_PROGRESS_CAP, progress_percent+ )- assert adjusted_progress == 87.5+ assert adjusted_progress == 50def test_progress_adjusted_for_quick_output_generation(self):- """Quick mode output_generation → at least 85%, scaled 85-95%."""+ """Quick mode output_generation → scaled 85-95%."""mode = "quick"metadata = {"phase": "output_generation"}progress_percent = 50adjusted_progress = progress_percent- if mode == "quick" and metadata.get("phase") == "output_generation":- adjusted_progress = max(85, progress_percent)- if progress_percent is not None and progress_percent > 0:- normalized = progress_percent / 100- adjusted_progress = 85 + (normalized * 10)+ if (+ mode == "quick"+ and metadata.get("phase") == "output_generation"+ and progress_percent is not None+ ):+ if progress_percent > 0:+ adjusted_progress = 85 + (progress_percent / 100) * 10+ else:+ adjusted_progress = 85assert adjusted_progress == 90.0+ def test_quick_output_generation_with_none_progress_passes_through(self):+ """Quick mode output_generation with None progress must not crash."""+ mode = "quick"+ metadata = {"phase": "output_generation"}+ progress_percent = None++ adjusted_progress = progress_percent+ if (+ mode == "quick"+ and metadata.get("phase") == "output_generation"+ and progress_percent is not None+ ):+ if progress_percent > 0:+ adjusted_progress = 85 + (progress_percent / 100) * 10+ else:+ adjusted_progress = 85++ assert adjusted_progress is None+def test_search_plan_extracted_from_message(self):"""SEARCH_PLAN: in message → engines extracted."""message = "Planning SEARCH_PLAN: google, bing, wikipedia"@@ -125,6 +159,106 @@ class TestProgressCallback:assert metadata["selected_engine"] == "google"+def _apply_detailed_progress(progress_percent, phase):+ """Replicate detailed-mode progress adjustment from research_service.py.++ Mirrors the production logic so tests stay self-contained, matching the+ existing pattern in this file.+ """+ adjusted_progress = progress_percent+ if phase not in _REPORT_PHASES and progress_percent is not None:+ adjusted_progress = min(_DETAILED_SEARCH_PROGRESS_CAP, progress_percent)+ return adjusted_progress+++class TestDetailedModeSearchCap:+ """Tests for the search-phase cap in detailed mode.++ Global monotonicity is enforced by update_progress_and_check_active in+ web/routes/globals.py; these tests cover only the closure's per-call+ capping. The integration tests in+ test_research_service_progress_integration.py exercise the full+ closure + global guard pipeline.+ """++ def test_high_search_values_clamp_to_cap(self):+ """Search progress above the cap clamps to the cap."""+ emitted = [+ _apply_detailed_progress(value, "search")+ for value in (90, 33, 50, 5, 100)+ ]+ assert emitted == [8, 8, 8, 5, 8]++ def test_low_search_values_pass_through_below_cap(self):+ """Search progress below the cap passes through unchanged."""+ assert _apply_detailed_progress(3, "search") == 3+ assert _apply_detailed_progress(7, "search") == 7+ assert _apply_detailed_progress(8, "search") == 8++ def test_none_progress_passes_through_for_error_phase(self):+ """None progress with phase='error' must not crash (regression #3806)."""+ assert _apply_detailed_progress(None, "error") is None++ def test_none_progress_passes_through_for_sub_search(self):+ """None progress from constrained-search sub-callback must not crash.++ The sub-callback in constrained_search_strategy.py emits None with+ phase in {'search_complete', 'final_results'}.+ """+ for phase in ("search_complete", "final_results"):+ assert _apply_detailed_progress(None, phase) is None, (+ f"None should pass through for phase={phase}"+ )++ def test_report_phase_unaffected_by_search_cap(self):+ """Report phases pass through; the wrapper already maps the range."""+ for phase in (+ "report_generation",+ "report_section_research",+ "report_formatting",+ "report_structure",+ "report_complete",+ ):+ assert _apply_detailed_progress(55, phase) == 55++ def test_strategy_complete_phase_does_not_jump_bar_to_100_mid_report(self):+ """phase='complete' from a strategy mid-report must NOT pin bar to 100.++ Regression: every search strategy emits {'phase': 'complete'} when its+ analyze_topic finishes (e.g. standard_strategy.py:334 at value 95).+ report_generator runs analyze_topic per subsection via+ self.search_system.analyze_topic, and the SearchSystem's+ progress_callback is the outer callback (set at research_service.py:711,+ NOT the wrapper). So a strategy 'complete' fires AFTER each subsection+ and would jump the bar to 100 mid-report if treated as the final marker.++ Expected behavior: 'complete' is treated as a search-phase emission —+ capped at the search cap. The legitimate 100% emit uses phase=+ 'report_complete' (in _REPORT_PHASES) and passes through.+ """+ # First subsection's strategy finishes: emits phase='complete' at 95+ adjusted = _apply_detailed_progress(95, "complete")+ assert adjusted != 100, (+ "regression: strategy 'complete' jumped bar to 100 mid-report"+ )+ assert adjusted == _DETAILED_SEARCH_PROGRESS_CAP++ def test_legitimate_final_complete_uses_report_complete_phase(self):+ """The legitimate end-of-research 100 emit uses phase='report_complete'.++ Confirms that the production code's final detailed-mode emission+ uses a phase that's in _REPORT_PHASES, so it passes through+ unchanged to 100 — independent of the strategy-level 'complete'+ phase that is intentionally capped.+ """+ assert "report_complete" in _REPORT_PHASES+ assert "complete" not in _REPORT_PHASES+ adjusted = _apply_detailed_progress(+ _DETAILED_REPORT_PROGRESS_END, "report_complete"+ )+ assert adjusted == _DETAILED_REPORT_PROGRESS_END++class TestTerminationHandling:"""Tests for termination checks in research process."""diff --git a/tests/web/services/test_research_service_progress_integration.py b/tests/web/services/test_research_service_progress_integration.pynew file mode 100644index 0000000000..c495b379ba--- /dev/null+++ b/tests/web/services/test_research_service_progress_integration.py@@ -0,0 +1,259 @@+"""Integration tests against the ACTUAL progress_callback closure inside+run_research_process — not a replicated helper.++Why this file exists+--------------------+The unit tests in ``test_research_service_execution.py`` exercise the+detailed-mode progress logic via a local ``_apply_detailed_progress``+helper that mirrors production. That pattern is enough for arithmetic+edge cases, but it cannot catch bugs in the integration boundary+between the closure, ``SearchSystem.set_progress_callback``, and+``globals.update_progress_and_check_active``.++PR #3806's original review missed exactly such an integration bug+(F1): the closure pinned the bar to 100 whenever ``phase="complete"``+arrived — including the mid-report emissions that every strategy+produces from inside ``analyze_topic``. The replica-helper tests+passed; an integration test would have caught it.++Pattern+-------+1. Mock ``AdvancedSearchSystem`` with a ``side_effect`` on+ ``set_progress_callback`` that captures the inner closure.+2. Make ``analyze_topic`` raise ``ResearchTerminatedException`` so+ ``run_research_process`` exits gracefully — but the callback has+ been captured.+3. Mock ``update_progress_and_check_active`` with a stateful+ ``side_effect`` that mimics ``globals.py``'s monotonic guard.+4. Yield the captured callback while patches are still active so+ tests can call it with bug-triggering sequences.+"""++from contextlib import contextmanager+from unittest.mock import MagicMock, Mock, patch++import pytest+from flask import Flask+from loguru import logger++# The production callback emits at the custom "MILESTONE" log level (registered+# by log_utils.init_loguru). Tests don't run init_loguru, so we register it+# here once. Idempotent if it already exists.+try:+ logger.level("MILESTONE", no=26)+except (ValueError, TypeError):+ pass++[email protected](scope="module")+def flask_app():+ """Flask app context for @log_for_research-decorated run_research_process."""+ app = Flask(__name__)+ app.config["TESTING"] = True+ return app+++@contextmanager+def _noop_db_session(*_, **__):+ session = MagicMock()+ session.__enter__ = Mock(return_value=session)+ session.__exit__ = Mock(return_value=False)+ yield session+++@contextmanager+def captured_progress_callback(mode, flask_app):+ """Yield (callback, progress_state, update_calls) with patches active.++ progress_state[0] is the value globals.update_progress_and_check_active+ would have stored. update_calls is the list of (rid, new, stored) for+ every invocation, so tests can assert on order and rejection of lower+ values.+ """+ from local_deep_research.exceptions import ResearchTerminatedException+ from local_deep_research.web.services.research_service import (+ run_research_process,+ )++ captured = {}++ def capture(cb):+ captured["callback"] = cb++ mock_system = Mock()+ mock_system.set_progress_callback = Mock(side_effect=capture)+ mock_system.analyze_topic.side_effect = ResearchTerminatedException(+ "captured for test"+ )++ progress_state = [0]+ update_calls = []++ def fake_monotonic_update(rid, new_progress):+ if new_progress is not None and new_progress > progress_state[0]:+ progress_state[0] = new_progress+ update_calls.append((rid, new_progress, progress_state[0]))+ return (progress_state[0], True)++ with flask_app.app_context():+ with (+ patch(+ "local_deep_research.web.routes.globals.is_termination_requested",+ return_value=False,+ ),+ patch(+ "local_deep_research.web.routes.globals.is_research_active",+ return_value=True,+ ),+ # run_research_process imports update_progress_and_check_active+ # from ..routes.globals at function scope (L319), so we patch the+ # source rather than the consuming module.+ patch(+ "local_deep_research.web.routes.globals.update_progress_and_check_active",+ side_effect=fake_monotonic_update,+ ),+ patch(+ "local_deep_research.web.services.research_service.cleanup_research_resources"+ ),+ patch(+ "local_deep_research.web.services.research_service.get_user_db_session",+ side_effect=_noop_db_session,+ ),+ patch(+ "local_deep_research.web.services.research_service.AdvancedSearchSystem",+ return_value=mock_system,+ ),+ patch(+ "local_deep_research.web.services.research_service.set_search_context"+ ),+ patch(+ "local_deep_research.config.thread_settings.set_settings_context"+ ),+ patch("local_deep_research.settings.logger.log_settings"),+ patch(+ "local_deep_research.web.services.research_service.SocketIOService",+ return_value=Mock(),+ ),+ patch("local_deep_research.web.queue.processor_v2.queue_processor"),+ patch(+ "local_deep_research.web.services.research_service.handle_termination"+ ),+ ):+ run_research_process(+ research_id=1,+ query="test query",+ mode=mode,+ username="testuser",+ )+ yield captured.get("callback"), progress_state, update_calls+++class TestRunResearchProcessProgressCallbackIntegration:+ """End-to-end behaviour of the closure wired through SearchSystem + globals."""++ def test_callback_is_captured_in_detailed_mode(self, flask_app):+ """Sanity: set_progress_callback receives a callable."""+ with captured_progress_callback("detailed", flask_app) as (+ cb,+ _,+ _,+ ):+ assert cb is not None, (+ "run_research_process did not call set_progress_callback "+ "before exiting"+ )+ assert callable(cb)++ def test_strategy_complete_does_not_pin_bar_to_100_mid_report(+ self, flask_app+ ):+ """Regression for F1 (PR #3806 review).++ Every strategy emits ``{"phase": "complete"}`` at the end of its+ ``analyze_topic``. ``report_generator._research_and_generate_sections``+ runs ``self.search_system.analyze_topic`` per subsection, and the+ SearchSystem's callback is the OUTER closure (set at+ research_service.py:711, not the wrapper). Pre-fix the closure had+ ``elif phase == "complete": adjusted_progress = 100``, which fired+ after every subsection and pinned the bar at 100 for the rest of+ a multi-minute report.++ Post-fix: ``phase="complete"`` is capped at the search cap (8) and+ the globals' monotonic guard preserves the existing higher value.+ """+ with captured_progress_callback("detailed", flask_app) as (+ cb,+ progress_state,+ _,+ ):+ # Baseline: bar climbs into the report range+ cb(+ "Generating detailed report...",+ 10,+ {"phase": "report_generation"},+ )+ assert progress_state[0] == 10++ # Strategy completes its analyze_topic mid-report — this fires+ # every subsection, e.g. via standard_strategy.py:334 at value 95.+ cb("Research complete", 95, {"phase": "complete"})++ assert progress_state[0] == 10, (+ f"regression: bar jumped to {progress_state[0]} after mid-"+ "report strategy 'complete' emission. Expected 10 (the bar "+ "should stay at the report-phase value; 'complete' is capped "+ "at 8 and rejected by monotonic guard)."+ )++ def test_report_phase_sequence_climbs_through_closure(self, flask_app):+ """A normal report-phase emission sequence drives the bar 10 → 100."""+ with captured_progress_callback("detailed", flask_app) as (+ cb,+ progress_state,+ _,+ ):+ cb("structure", 10, {"phase": "report_generation"})+ cb("section 1", 30, {"phase": "report_section_research"})+ cb("section 2", 60, {"phase": "report_section_research"})+ cb("formatting", 91, {"phase": "report_formatting"})+ cb("complete", 100, {"phase": "report_complete"})+ assert progress_state[0] == 100++ def test_search_phase_capped_through_closure(self, flask_app):+ """Search-phase emissions are capped at the configured search cap."""+ from local_deep_research.web.services.research_service import (+ _DETAILED_SEARCH_PROGRESS_CAP,+ )++ with captured_progress_callback("detailed", flask_app) as (+ cb,+ progress_state,+ _,+ ):+ # Large raw values from search phase get capped.+ cb("search 1", 50, {"phase": "search"})+ assert progress_state[0] == _DETAILED_SEARCH_PROGRESS_CAP++ cb("search 2", 137, {"phase": "search"})+ assert progress_state[0] == _DETAILED_SEARCH_PROGRESS_CAP++ def test_none_progress_does_not_crash_or_pin(self, flask_app):+ """None progress (e.g. error path, sub-search relays) passes through.++ Regression for the None-guard fix from commit 5f4ae17ea: the new+ ``elif progress_percent is not None`` branch in detailed mode must+ not raise ``TypeError`` on ``min(8, None)``.+ """+ with captured_progress_callback("detailed", flask_app) as (+ cb,+ progress_state,+ _,+ ):+ cb("search 1", 5, {"phase": "search"})+ baseline = progress_state[0]++ # Should not raise; should not affect stored progress.+ cb("error", None, {"phase": "error"})+ cb("sub-search complete", None, {"phase": "search_complete"})++ assert progress_state[0] == baseline