~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): log the duplicate-skip and drop the obsolete dedup framing (#5136)
Ehsan248e1f1e9813
diff --git a/changelog.d/+benchmark-duplicate-skip-logging.misc.md b/changelog.d/+benchmark-duplicate-skip-logging.misc.mdnew file mode 100644index 0000000000..3cce32790c--- /dev/null+++ b/changelog.d/+benchmark-duplicate-skip-logging.misc.md@@ -0,0 +1 @@+Benchmark result persistence now logs a warning when it skips a result whose `query_hash` is already persisted or staged for the run, naming the run, the result index and the `example_id`. This covers the "make the gap visible" half of #4860: the skip branch in `_persist_unsaved_results` was silent, so a dropped entry showed up only as a shorter staged-index list. The docstring there and the comments in `tests/benchmarks/web_api/test_benchmark_result_dedup.py` no longer describe the pre-#5080 "a dataset can legitimately repeat a question" case, which that fix made unreachable by widening the hash to cover `example_id`. Follow-up to #5080.diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_service.py b/src/local_deep_research/benchmarks/web_api/benchmark_service.pyindex eff9aedf06..045125cd6f 100644--- a/src/local_deep_research/benchmarks/web_api/benchmark_service.py+++ b/src/local_deep_research/benchmarks/web_api/benchmark_service.py@@ -916,7 +916,11 @@ class BenchmarkService:Idempotent and rollback-safe. A result is skipped when its index isalready known-saved (``saved_indices``), its ``query_hash`` is alreadycommitted for this run, or it repeats a ``query_hash`` staged earlier- in this same batch — a dataset can legitimately repeat a question.+ in this same batch. Since ``query_hash`` covers ``example_id`` as well+ as the question text (#5080), a repeat no longer means "a dataset+ legitimately repeats a question": it is the same result entry reaching+ this method twice, so the skip is logged at WARNING rather than passed+ over in silence (#4860).Dedup correctness rests on the DB-backed ``seen_hashes``, whichsurvives a rollback (the next sync re-reads it), NOT on any in-memoryflag.@@ -951,6 +955,11 @@ class BenchmarkService:continuequery_hash = result["query_hash"]if query_hash in seen_hashes:+ logger.warning(+ f"Benchmark run {benchmark_run_id}: skipping result index "+ f"{idx} (example_id={result['example_id']!r}), its "+ f"query_hash is already persisted or staged for this run"+ )continuesession.add(BenchmarkResult(diff --git a/tests/benchmarks/web_api/test_benchmark_result_dedup.py b/tests/benchmarks/web_api/test_benchmark_result_dedup.pyindex 7ce70e807d..1c8a9523b7 100644--- a/tests/benchmarks/web_api/test_benchmark_result_dedup.py+++ b/tests/benchmarks/web_api/test_benchmark_result_dedup.py@@ -7,8 +7,9 @@ Background``run_data["results"]`` list: ``sync_pending_results`` (request thread, via the``/api/results`` route) and ``_sync_results_to_database`` (worker thread, oncompletion). The old check-then-insert was neither atomic across threads nor-deduped within a batch, so a duplicate ``(benchmark_run_id, query_hash)`` —-from a concurrent sync OR a dataset that repeats a question — raised::+deduped within a batch, so a duplicate ``(benchmark_run_id, query_hash)``,+at the time from a concurrent sync or a dataset that repeats a question,+raised::sqlcipher3.dbapi2.IntegrityError: UNIQUE constraint failed:benchmark_results.benchmark_run_id, benchmark_results.query_hash@@ -16,6 +17,12 @@ from a concurrent sync OR a dataset that repeats a question — raised::and because it failed at ``commit()`` the whole pending batch rolled back, sono results were stored and the UI showed "Found 0 results".+``query_hash`` has since been widened to cover ``example_id`` (#5080), so a+dataset repeating a question yields distinct hashes and is no longer a source+of duplicates. A duplicate hash now means the same result entry reached+``_persist_unsaved_results`` twice; the tests below construct that state+directly rather than via repeated question text.+These tests exercise ``_persist_unsaved_results`` against a real SQLite DB sothe unique constraint is actually enforced."""@@ -24,6 +31,7 @@ import threadingfrom unittest.mock import MagicMock, Mock, patchimport pytest+from loguru import loggerfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker@@ -86,9 +94,38 @@ def _count(session):return session.query(BenchmarkResult).filter_by(benchmark_run_id=1).count()+def duplicate_warnings():+ """Capture WARNING records emitted by the package under test.++ diagnose=False keeps the captured sink consistent with the production+ policy (#4185 / #4384); exceptions logged through this fixture would+ otherwise carry frame-local repr() into the captured records and into+ pytest output.++ Captures the Loguru record (not its formatted string) so a test can+ assert the level is WARNING specifically rather than WARNING-or-higher.+ The package namespace is disabled by default; teardown restores that in a+ finally so an enabled namespace does not leak into later tests in the+ same worker.+ """+ records = []+ sink_id = logger.add(+ lambda msg: records.append(msg.record), level="WARNING", diagnose=False+ )+ logger.enable("local_deep_research")+ try:+ yield records+ finally:+ logger.remove(sink_id)+ logger.disable("local_deep_research")++def test_duplicate_query_hash_within_batch_inserts_once():- """A dataset that repeats a question (same query_hash) must not trip the- unique constraint — the duplicate is collapsed to a single row."""+ """A repeated ``query_hash`` within one batch must not trip the unique+ constraint: the duplicate is collapsed to a single row. Since #5080 the+ hash covers ``example_id``, so this state means the same result entry was+ staged twice; the hashes here are set directly to construct it."""svc = BenchmarkService(socket_service=MagicMock())session = _make_session()run_data = {@@ -127,6 +164,48 @@ def test_repeated_sync_does_not_double_insert():assert _count(session) == 1+def test_duplicate_within_batch_is_logged(duplicate_warnings):+ """The within-batch skip names the run and the dropped example (#4860).++ Before this, the batch simply shrank: the caller sees a shorter+ ``staged_indices`` and nothing says which entry went missing or why.+ """+ svc = BenchmarkService(socket_service=MagicMock())+ session = _make_session()+ run_data = {"results": [_result("ex1", "dup"), _result("ex2", "dup")]}++ assert svc._persist_unsaved_results(session, 1, run_data) == [0]+ session.commit()++ assert len(duplicate_warnings) == 1+ assert duplicate_warnings[0]["level"].name == "WARNING"+ message = duplicate_warnings[0]["message"]+ assert "Benchmark run 1" in message+ assert "index 1" in message+ assert "ex2" in message+++def test_duplicate_against_committed_rows_is_logged(duplicate_warnings):+ """The other path into the skip: the hash is already committed for this+ run rather than staged earlier in the same batch."""+ svc = BenchmarkService(socket_service=MagicMock())+ session = _make_session()+ run_data = {"results": [_result("ex1", "h1")]}++ assert svc._persist_unsaved_results(session, 1, run_data) == [0]+ session.commit()+ assert duplicate_warnings == [] # the first, staging pass is silent++ # Re-sync with saved_indices lost, so the DB-backed seen_hashes is what+ # catches it (as in test_repeated_sync_does_not_double_insert).+ run_data["saved_indices"] = set()+ assert svc._persist_unsaved_results(session, 1, run_data) == []++ assert len(duplicate_warnings) == 1+ assert duplicate_warnings[0]["level"].name == "WARNING"+ assert "ex1" in duplicate_warnings[0]["message"]++def test_staged_not_marked_saved_until_commit():"""Regression for the silent-drop bug: a commit failure must NOT leaveresults flagged saved. The helper must not mark ``saved_indices`` itself,