~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(metrics): reset the call outcome when an LLM call starts (#7563)
Lukas626ab8a6e80d
diff --git a/changelog.d/7563.bugfix.md b/changelog.d/7563.bugfix.mdnew file mode 100644index 0000000000..d06df59201--- /dev/null+++ b/changelog.d/7563.bugfix.md@@ -0,0 +1 @@+Token metrics no longer record every LLM call after the first failed one as an error: the success status and error type are reset when each call starts, so the success rate on the metrics pages stays accurate for the rest of the research.diff --git a/src/local_deep_research/metrics/token_counter.py b/src/local_deep_research/metrics/token_counter.pyindex 02bd058a5f..dc5596ea9a 100644--- a/src/local_deep_research/metrics/token_counter.py+++ b/src/local_deep_research/metrics/token_counter.py@@ -120,6 +120,11 @@ class TokenCountingCallback(BaseCallbackHandler):self.context_truncated = Falseself.tokens_truncated = 0self.truncation_ratio = 0.0+ # The same goes for the outcome: on_llm_error sets it, and without+ # this reset every call after the session's first failure was saved+ # with success_status "error" and that failure's error_type.+ self.success_status = "success"+ self.error_type = None# Estimate original prompt size (rough estimate: ~4 chars per token)if prompts:diff --git a/tests/metrics/test_token_counting_attribution.py b/tests/metrics/test_token_counting_attribution.pyindex 326520a988..b1ac553f5c 100644--- a/tests/metrics/test_token_counting_attribution.py+++ b/tests/metrics/test_token_counting_attribution.py@@ -742,19 +742,6 @@ def test_empty_metrics_fallback_matches_an_empty_user_database(# ==========================================================================- strict=True,- reason=(- "SUCCESSES RECORDED AS FAILURES. TokenCountingCallback.success_status "- "/ .error_type are instance attributes set by on_llm_error and never "- "reset by on_llm_start (which resets only the truncation triple). The "- "callback is shared across every LLM call in a research session (see "- "llm_config.wrap_llm), so after the first failure EVERY subsequent "- "successful call is persisted with success_status='error' and the "- "stale error_type -- inverting the success rate for the rest of the "- "session."- ),-)def test_success_status_does_not_stick_after_an_earlier_failure(user_dbs):callback = make_callback("research-alice", "alice")