~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(benchmark): register workers before starting them (#6910)
LearningCircuit0fa61fc22e0d
diff --git a/changelog.d/+benchmark-worker-registration.bugfix.md b/changelog.d/+benchmark-worker-registration.bugfix.mdnew file mode 100644index 0000000000..ed18b840ca--- /dev/null+++ b/changelog.d/+benchmark-worker-registration.bugfix.md@@ -0,0 +1 @@+Keep quickly completed benchmarks marked as completed when their worker finishes before the start request returns.diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_service.py b/src/local_deep_research/benchmarks/web_api/benchmark_service.pyindex dd6d179935..c7f8eb6db6 100644--- a/src/local_deep_research/benchmarks/web_api/benchmark_service.py+++ b/src/local_deep_research/benchmarks/web_api/benchmark_service.py@@ -430,9 +430,10 @@ class BenchmarkService:args=(username, benchmark_run_id),daemon=True,)- thread.start()-+ # Publish the handle before the worker can finish and remove its+ # active_runs entry during result synchronization.self.active_runs[run_key]["thread"] = thread+ thread.start()logger.info(f"Started benchmark run {benchmark_run_id}")return Truediff --git a/tests/benchmarks/test_benchmark_service_contracts.py b/tests/benchmarks/test_benchmark_service_contracts.pyindex c5afade4b3..fbeb5d5814 100644--- a/tests/benchmarks/test_benchmark_service_contracts.py+++ b/tests/benchmarks/test_benchmark_service_contracts.py@@ -869,16 +869,6 @@ class _JoiningThread(threading.Thread):super().join()- strict=True,- reason=(- "DEFECT: start_benchmark writes self.active_runs[run_key]['thread'] "- "AFTER thread.start(). A worker that finishes first has already done "- "`del self.active_runs[run_key]` in _sync_results_to_database, so the "- "assignment raises KeyError; the handler then overwrites the "- "COMPLETED run with FAILED and returns False."- ),-)def test_fast_finishing_run_is_not_overwritten_with_failed(service, dbs):create_run(service, ALICE, "alice-only", count=1)@@ -896,24 +886,36 @@ def test_fast_finishing_run_is_not_overwritten_with_failed(service, dbs):assert started is True-def test_fast_finishing_run_is_reported_as_failed_today(service, dbs):- """Executable evidence for the defect above, pinned as-is.-- The run really did complete — its result row is committed and the worker- wrote COMPLETED — and then start_benchmark's own error handler rewrote the- row to FAILED and returned False.+def test_worker_handle_is_registered_before_start_and_released_if_start_fails(+ service, dbs+):+ """The worker may retire its ``active_runs`` entry the moment it starts,+ so the handle must already be registered when ``start()`` is called. If+ the start itself fails, the run must end FAILED and retryable with+ nothing left in ``active_runs``.++ The registry is read from inside ``start()``: that is the only point that+ tells register-then-start from start-then-register, because both orders+ end in the same FAILED row and an empty registry."""create_run(service, ALICE, "alice-only", count=1)+ handle_registered_at_start = []++ def unstartable_start(thread):+ entry = service.active_runs.get((ALICE, 1), {})+ handle_registered_at_start.append(entry.get("thread") is thread)+ raise RuntimeError("cannot start worker")with (- stub_execution(examples=[_EXAMPLES[0]]),_settings_stubbed(),- patch(f"{SVC}.threading.Thread", _JoiningThread),+ patch(f"{SVC}.threading.Thread.start", unstartable_start),):started = service.start_benchmark(1, username=ALICE)- assert len(result_rows(dbs, ALICE)) == 1 # the work genuinely happened+ assert handle_registered_at_start == [True]row = run_row(dbs, ALICE)assert started is Falseassert row["status"] is BenchmarkStatus.FAILED- assert row["error_message"] == str(KeyError((ALICE, 1)))+ assert row["error_message"] == "cannot start worker"+ assert result_rows(dbs, ALICE) == []+ assert (ALICE, 1) not in service.active_runs