~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): surface result persistence failures (#5256)
March-777ac42f43b1b2
diff --git a/changelog.d/5256.bugfix.md b/changelog.d/5256.bugfix.mdnew file mode 100644index 0000000000..4a91b350c9--- /dev/null+++ b/changelog.d/5256.bugfix.md@@ -0,0 +1 @@+Surface benchmark result persistence failures instead of presenting them as an empty successful run.diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_routes.py b/src/local_deep_research/benchmarks/web_api/benchmark_routes.pyindex 31a0611cec..980d26f284 100644--- a/src/local_deep_research/benchmarks/web_api/benchmark_routes.py+++ b/src/local_deep_research/benchmarks/web_api/benchmark_routes.py@@ -497,6 +497,9 @@ def get_benchmark_results(benchmark_run_id: int):# First sync any pending results from active runsbenchmark_service.sync_pending_results(benchmark_run_id, username)+ persistence_error = benchmark_service.get_result_persistence_error(+ benchmark_run_id+ )with get_user_db_session(username) as session:# Get recent results (limit to last 10)limit = int(request.args.get("limit", 10))@@ -598,7 +601,10 @@ def get_benchmark_results(benchmark_run_id: int):})- return jsonify({"success": True, "results": formatted_results})+ payload = {"success": True, "results": formatted_results}+ if persistence_error:+ payload["persistence_error"] = persistence_error+ return jsonify(payload)except Exception:logger.exception("Error getting benchmark results")diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_service.py b/src/local_deep_research/benchmarks/web_api/benchmark_service.pyindex 80b47fbd4c..7cc02dd8fb 100644--- a/src/local_deep_research/benchmarks/web_api/benchmark_service.py+++ b/src/local_deep_research/benchmarks/web_api/benchmark_service.py@@ -38,6 +38,13 @@ _GENERIC_BENCHMARK_ERROR = ("Benchmark run failed due to an internal error. ""Check the server logs for details.")+_RESULT_PERSISTENCE_ERROR = {+ "code": "database_write_failed",+ "message": (+ "Benchmark results could not be saved. Check server logs and "+ "database storage, then retry."+ ),+}class BenchmarkTaskStatus(Enum):@@ -1035,6 +1042,10 @@ class BenchmarkService:f"Saved {saved_count} new results for benchmark "f"{benchmark_run_id}")+ # Reaching the end of the transaction proves persistence+ # is healthy again. Clear a prior transient failure even+ # when another thread already saved the pending rows.+ run_data.pop("result_persistence_failed", None)except Exception:logger.exception(f"Error syncing pending results for benchmark {benchmark_run_id}"@@ -1043,9 +1054,20 @@ class BenchmarkService:# rolled back explicitly or the next use raises PendingRollbackError.if session is not None:safe_rollback(session, "sync_pending_results")+ run_data["result_persistence_failed"] = Truereturn saved_count+ def get_result_persistence_error(+ self, benchmark_run_id: int+ ) -> Optional[Dict[str, str]]:+ """Return a safe client-facing result persistence error, if active."""+ run_data = self.active_runs.get(benchmark_run_id)+ if not run_data or not run_data.get("result_persistence_failed"):+ return None+ # Return a copy so callers cannot mutate the shared constant.+ return dict(_RESULT_PERSISTENCE_ERROR)+def _sync_results_to_database(self, benchmark_run_id: int):"""Sync benchmark results from memory to database after thread completes."""if benchmark_run_id not in self.active_runs:@@ -1133,6 +1155,7 @@ class BenchmarkService:run_data.setdefault("saved_indices", set()).update(staged)+ run_data.pop("result_persistence_failed", None)logger.info(f"Successfully synced results for benchmark {benchmark_run_id}")@@ -1146,6 +1169,7 @@ class BenchmarkService:# so the next use doesn't raise PendingRollbackError.if session is not None:safe_rollback(session, "_sync_results_to_database")+ run_data["result_persistence_failed"] = Truedef _send_progress_update(self, benchmark_run_id: int, completed: int, total: intdiff --git a/src/local_deep_research/web/templates/pages/benchmark.html b/src/local_deep_research/web/templates/pages/benchmark.htmlindex 46a9b533c2..23b2311637 100644--- a/src/local_deep_research/web/templates/pages/benchmark.html+++ b/src/local_deep_research/web/templates/pages/benchmark.html@@ -1188,6 +1188,17 @@ function updateRecentResults() {fetch(`/benchmark/api/results/${currentBenchmarkId}?limit=50`) // Reduced from 100 for performance.then(response => response.json()).then(data => {+ if (data.persistence_error) {+ const container = document.getElementById('recent-results-container');+ container.replaceChildren();+ const error = document.createElement('div');+ error.className = 'ldr-no-results ldr-text-error';+ error.textContent = data.persistence_error.message+ || 'Benchmark results could not be saved.';+ container.appendChild(error);+ lastResultsData = null;+ return;+ }if (data.success && data.results) {// Only update if data has changedconst newResultsStr = JSON.stringify(data.results);diff --git a/src/local_deep_research/web/templates/pages/benchmark_results.html b/src/local_deep_research/web/templates/pages/benchmark_results.htmlindex 7e116e83e8..26adb7e004 100644--- a/src/local_deep_research/web/templates/pages/benchmark_results.html+++ b/src/local_deep_research/web/templates/pages/benchmark_results.html@@ -362,6 +362,16 @@ async function loadExamples(runId) {const examplesContainer = document.getElementById(`examples-${runId}`);+ if (data.persistence_error) {+ examplesContainer.replaceChildren();+ const error = document.createElement('div');+ error.className = 'ldr-no-results ldr-text-error';+ error.textContent = data.persistence_error.message+ || 'Benchmark results could not be saved.';+ examplesContainer.appendChild(error);+ return;+ }+if (data.success && data.results.length > 0) {// Calculate search result statisticsconst searchResultCounts = data.results.map(r => r.search_result_count || 0);diff --git a/tests/benchmarks/web_api/test_benchmark_routes_coverage.py b/tests/benchmarks/web_api/test_benchmark_routes_coverage.pyindex 56e4bd9e31..ab0e90429b 100644--- a/tests/benchmarks/web_api/test_benchmark_routes_coverage.py+++ b/tests/benchmarks/web_api/test_benchmark_routes_coverage.py@@ -120,6 +120,7 @@ def _patch_auth_and_db(settings_overrides=None):mock_get_session.side_effect = _session_ctxmock_get_session2.side_effect = _session_ctx+ mock_svc.get_result_persistence_error.return_value = Noneyield mock_svc, mgr, mock_db_session@@ -895,6 +896,28 @@ class TestGetBenchmarkResults:resp = client.get("/benchmark/api/results/1")assert resp.status_code == 200+ def test_results_surface_persistence_error(self):+ app = _make_app()+ safe_error = {+ "code": "database_write_failed",+ "message": "Benchmark results could not be saved.",+ }++ with _patch_auth_and_db() as (mock_svc, mgr, mock_db):+ mock_svc.get_result_persistence_error.return_value = safe_error+ mock_db.query.side_effect = _make_routed_query(results=[])++ with app.test_client() as client:+ with client.session_transaction() as sess:+ sess["username"] = "testuser"+ resp = client.get("/benchmark/api/results/1")++ assert resp.status_code == 200+ data = resp.get_json()+ assert data["success"] is True+ assert data["results"] == []+ assert data["persistence_error"] == safe_error+def test_results_exception(self):app = _make_app()with _patch_auth_and_db() as (mock_svc, mgr, mock_db):diff --git a/tests/benchmarks/web_api/test_benchmark_service_coverage.py b/tests/benchmarks/web_api/test_benchmark_service_coverage.pyindex 7d8d73cd42..c484fe2976 100644--- a/tests/benchmarks/web_api/test_benchmark_service_coverage.py+++ b/tests/benchmarks/web_api/test_benchmark_service_coverage.py@@ -732,6 +732,7 @@ class TestSyncPendingResults:"task_index": 0,},],+ "result_persistence_failed": True,}mock_session = MagicMock()@@ -751,6 +752,7 @@ class TestSyncPendingResults:assert count == 1mock_session.add.assert_called_once()mock_session.commit.assert_called_once()+ assert svc.get_result_persistence_error(1) is Nonedef test_skips_already_saved_indices(self):svc = _make_service()@@ -850,6 +852,10 @@ class TestSyncPendingResults:count = svc.sync_pending_results(1)assert count == 0+ error = svc.get_result_persistence_error(1)+ assert error is not None+ assert error["code"] == "database_write_failed"+ assert "db error" not in error["message"]def test_uses_username_from_run_data(self):svc = _make_service()@@ -1079,6 +1085,10 @@ class TestSyncResultsToDatabase:# Should not raisesvc._sync_results_to_database(1)+ error = svc.get_result_persistence_error(1)+ assert error is not None+ assert error["code"] == "database_write_failed"+def test_no_accuracy_for_non_completed_status(self):from local_deep_research.benchmarks.web_api.benchmark_service import (BenchmarkStatus,