~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(error): bound error-report classification input (#7256)
LearningCircuitfef0669a7ece
diff --git a/changelog.d/7240.bugfix.md b/changelog.d/7240.bugfix.mdnew file mode 100644index 0000000000..2ed7c32de7--- /dev/null+++ b/changelog.d/7240.bugfix.md@@ -0,0 +1 @@+Limit error classification to the first 1,024 characters so large provider errors cannot stall error-report generation with repeated partial pattern matches. Messages without a recognized cue in that prefix receive generic guidance.diff --git a/src/local_deep_research/error_handling/error_messages.py b/src/local_deep_research/error_handling/error_messages.pyindex 89178a6603..e797e19fac 100644--- a/src/local_deep_research/error_handling/error_messages.py+++ b/src/local_deep_research/error_handling/error_messages.py@@ -1,5 +1,10 @@"""Authored research failure messages shared by reports and API responses."""+# Regex classification is advisory: inspect a short prefix of provider error+# text, which can otherwise contain entire response bodies. Even a 4 KiB+# prefix takes seconds on repeated partial matches of the multi-span patterns.+MAX_ERROR_CLASSIFICATION_CHARS = 1024+TYPED_RESEARCH_ERROR_MESSAGES = {"ollama_unavailable": "Ollama AI service is unavailable.","model_not_found": "The configured LLM model was not found.",diff --git a/src/local_deep_research/error_handling/error_reporter.py b/src/local_deep_research/error_handling/error_reporter.pyindex be3c4b4001..9a6373d322 100644--- a/src/local_deep_research/error_handling/error_reporter.py+++ b/src/local_deep_research/error_handling/error_reporter.py@@ -8,6 +8,8 @@ from typing import Any, Dict, Optionalfrom loguru import logger+from .error_messages import MAX_ERROR_CLASSIFICATION_CHARS+class ErrorCategory(Enum):"""Categories of errors that can occur during research"""@@ -119,7 +121,11 @@ class ErrorReporter:Returns:ErrorCategory: The categorized error type"""- error_message = str(error_message).lower()+ # Keep the regex work bounded even when a provider includes a large+ # response body in its exception. Slice after lowercasing too, since+ # Unicode case conversion can expand a character into several.+ error_message = str(error_message)[:MAX_ERROR_CLASSIFICATION_CHARS]+ error_message = error_message.lower()[:MAX_ERROR_CLASSIFICATION_CHARS]for category, patterns in self.error_patterns.items():for pattern in patterns:diff --git a/src/local_deep_research/error_handling/report_generator.py b/src/local_deep_research/error_handling/report_generator.pyindex a3f4f2d44b..218ed018a9 100644--- a/src/local_deep_research/error_handling/report_generator.py+++ b/src/local_deep_research/error_handling/report_generator.py@@ -8,6 +8,7 @@ from typing import Any, Dict, Optionalfrom loguru import loggerfrom .error_messages import (+ MAX_ERROR_CLASSIFICATION_CHARS,TYPED_RESEARCH_ERROR_MESSAGES,get_known_research_error_message,)@@ -321,6 +322,11 @@ We're here to help you get this working:if worker_message is not None:return worker_message+ # Bound both typed-token and fallback regex scans. Preserve the exact+ # worker-message check above: truncation must not turn an untrusted+ # message with appended details into an authored exact match.+ error_message = error_message[:MAX_ERROR_CLASSIFICATION_CHARS]+# A typed upstream message can still contain a provider URL or a raw# "| Details:" suffix. Select only authored text for its code. Unknown# types fall through to the pattern table for a second classification.diff --git a/tests/error_handling/test_classification_budget.py b/tests/error_handling/test_classification_budget.pynew file mode 100644index 0000000000..4befdd181c--- /dev/null+++ b/tests/error_handling/test_classification_budget.py@@ -0,0 +1,107 @@+"""Error classification must bound regex work on provider-controlled text."""++import re++import pytest++from local_deep_research.error_handling.error_messages import (+ MAX_ERROR_CLASSIFICATION_CHARS,+ TYPED_RESEARCH_ERROR_MESSAGES,+)+from local_deep_research.error_handling.error_reporter import (+ ErrorCategory,+ ErrorReporter,+)+from local_deep_research.error_handling.report_generator import (+ ErrorReportGenerator,+)+++ "prefix", ["Model ", "localhost localhost ", "LM Studio Docker ", "İ"]+)[email protected]("stage", ["category", "guidance", "report"])+def test_large_provider_errors_bound_every_regex_input(+ monkeypatch, prefix, stage+):+ """Exercise the real patterns, without timing-dependent assertions.++ The observer fails before running an unbounded search on the old code;+ the corrected code still executes each real regex and builds the report.+ This covers the category scan that precedes the friendly-message scan.+ """+ raw_error = prefix * 50_000 + "/srv/private/provider-response.txt"+ searched_lengths = []+ native_search = re.search++ def bounded_search(pattern, string, *args, **kwargs):+ searched_lengths.append(len(string))+ assert len(string) <= MAX_ERROR_CLASSIFICATION_CHARS+ return native_search(pattern, string, *args, **kwargs)++ monkeypatch.setattr(re, "search", bounded_search)+ if stage == "category":+ result = ErrorReporter().categorize_error(raw_error)+ assert result == ErrorCategory.UNKNOWN_ERROR+ elif stage == "guidance":+ result = ErrorReportGenerator()._make_error_user_friendly(raw_error)+ assert "unexpected error" in result+ else:+ result = ErrorReportGenerator().generate_error_report(+ raw_error, query="Error classification budget"+ )+ assert "**Error Type:** Unexpected Error" in result+ assert "showing basic error information" not in result++ assert searched_lengths+ assert max(searched_lengths) <= MAX_ERROR_CLASSIFICATION_CHARS+ assert "/srv/private/provider-response.txt" not in str(result)++[email protected]("over_boundary", [False, True])+def test_guidance_and_category_agree_at_the_input_boundary(over_boundary):+ cue = "database is locked"+ padding = MAX_ERROR_CLASSIFICATION_CHARS - len(cue) + over_boundary+ raw_error = "x" * padding + cue++ category = ErrorReporter().categorize_error(raw_error)+ guidance = ErrorReportGenerator()._make_error_user_friendly(raw_error)++ if over_boundary:+ assert category == ErrorCategory.UNKNOWN_ERROR+ assert "unexpected error" in guidance+ else:+ assert category == ErrorCategory.FILE_ERROR+ assert "local database is temporarily locked" in guidance+++def test_early_guidance_survives_a_large_private_suffix():+ raw_error = (+ "Connection refused: " + "/srv/private/provider-response.txt" * 5000+ )+ generator = ErrorReportGenerator()++ assert generator._make_error_user_friendly(raw_error) == (+ generator._make_error_user_friendly("Connection refused")+ )+ assert (+ ErrorReporter().categorize_error(raw_error)+ == ErrorCategory.CONNECTION_ERROR+ )++[email protected]("after_limit", [False, True])+def test_typed_guidance_obeys_the_same_prefix_limit(after_limit):+ token = "(Error type: openai_auth)"+ raw_error = (+ "x" * MAX_ERROR_CLASSIFICATION_CHARS + token+ if after_limit+ else token + "x" * (MAX_ERROR_CLASSIFICATION_CHARS * 2)+ )++ result = ErrorReportGenerator()._make_error_user_friendly(raw_error)++ if after_limit:+ assert "unexpected error" in result+ else:+ assert result == TYPED_RESEARCH_ERROR_MESSAGES["openai_auth"]diff --git a/tests/error_handling/test_error_categorization.py b/tests/error_handling/test_error_categorization.pyindex 7da8cb2f4e..a19c78560b 100644--- a/tests/error_handling/test_error_categorization.py+++ b/tests/error_handling/test_error_categorization.py@@ -192,14 +192,20 @@ class TestErrorCategorization:category = reporter.categorize_error(" ")assert category == ErrorCategory.UNKNOWN_ERROR- def test_very_long_error_performance(self, reporter):- """10KB error message doesn't hang."""+ @pytest.mark.parametrize("cue_in_prefix", [True, False])+ def test_very_long_error_performance(self, reporter, cue_in_prefix):+ """Large errors return promptly, classifying only the bounded prefix."""from local_deep_research.error_handling.error_reporter import (ErrorCategory,)- # Create a very long error message (10KB)- long_error = "x" * 10000 + " Connection refused " + "y" * 10000+ # A cue early in a large response still gets useful guidance. A cue+ # buried outside the classification budget gets the generic category.+ long_error = (+ "Connection refused " + "x" * 20000+ if cue_in_prefix+ else "x" * 10000 + " Connection refused " + "y" * 10000+ )import time@@ -209,7 +215,11 @@ class TestErrorCategorization:# Should complete within reasonable time (< 1 second)assert elapsed < 1.0- assert category == ErrorCategory.CONNECTION_ERROR+ assert category == (+ ErrorCategory.CONNECTION_ERROR+ if cue_in_prefix+ else ErrorCategory.UNKNOWN_ERROR+ )class TestUserFriendlyTitles: