~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(benchmarks): reject num_runs < 1 in measure_execution_time (#7364)
Ziyang Guod9debe5b3b6a
diff --git a/changelog.d/6664.bugfix.md b/changelog.d/6664.bugfix.mdnew file mode 100644index 0000000000..5b5af90424--- /dev/null+++ b/changelog.d/6664.bugfix.md@@ -0,0 +1 @@+`measure_execution_time` now rejects `num_runs < 1` with `ValueError` instead of running the loop zero times and returning the resulting `ZeroDivisionError` as a swallowed `{"error": "..."}` result. Callers asking for an average over N runs get a clear exception up front, matching the issue's expected behavior.diff --git a/src/local_deep_research/benchmarks/metrics/calculation.py b/src/local_deep_research/benchmarks/metrics/calculation.pyindex 2612b6d699..83c1aeb18c 100644--- a/src/local_deep_research/benchmarks/metrics/calculation.py+++ b/src/local_deep_research/benchmarks/metrics/calculation.py@@ -210,7 +210,21 @@ def measure_execution_time(Returns:Dictionary with speed metrics++ Raises:+ ValueError: If num_runs is less than 1."""+ if num_runs < 1:+ # Reject the call BEFORE the try/except below, which would otherwise+ # swallow the exception and return a dict carrying the same message+ # as 'error' (a confusing shape — the caller asked for an+ # average over N runs, and N=0 is not a configuration, it's a bug+ # in the caller). The downstream `total_time / num_runs` would+ # raise ZeroDivisionError, which the broad except turns into+ # `{'error': '... division by zero'}`; the explicit guard makes+ # the failure mode actionable (#6664).+ raise ValueError(f"num_runs must be >= 1, got: {num_runs!r}")+from local_deep_research.search_system import AdvancedSearchSystemfrom local_deep_research.config.llm_config import get_llmfrom local_deep_research.config.search_config import get_searchdiff --git a/tests/benchmarks/test_calculation_coverage.py b/tests/benchmarks/test_calculation_coverage.pyindex 5cf219cad5..dcfbfcfdcf 100644--- a/tests/benchmarks/test_calculation_coverage.py+++ b/tests/benchmarks/test_calculation_coverage.py@@ -527,6 +527,43 @@ class TestMeasureExecutionTime:expected_score = 1.0 / (1.0 + avg / 30.0)assert result["speed_score"] == pytest.approx(expected_score, abs=0.01)+ def test_num_runs_zero_raises_value_error(self):+ """num_runs=0 must raise ValueError before reaching the loop+ and the ZeroDivisionError site, instead of being swallowed by+ the broad except and returned as `{'error': '... division by zero'}` (#6664)."""+ from local_deep_research.benchmarks.metrics.calculation import (+ measure_execution_time,+ )++ patcher, _mock_cls, mock_system = self._patch_search_system()+ with patcher:+ with pytest.raises(ValueError, match="num_runs must be >= 1"):+ measure_execution_time(+ system_config={},+ num_runs=0,+ )++ # Search system must not be touched when the call is rejected up front.+ mock_system.search.assert_not_called()++ def test_num_runs_negative_raises_value_error(self):+ """Negative num_runs is the same shape of caller bug as num_runs=0+ — the loop never runs and the average is undefined. The guard rejects+ both up front with the same message (#6664)."""+ from local_deep_research.benchmarks.metrics.calculation import (+ measure_execution_time,+ )++ patcher, _mock_cls, mock_system = self._patch_search_system()+ with patcher:+ with pytest.raises(ValueError, match="num_runs must be >= 1"):+ measure_execution_time(+ system_config={},+ num_runs=-1,+ )++ mock_system.search.assert_not_called()+# ===========================================================================# calculate_quality_metrics – delegates to evaluate_benchmark_quality