~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
Complete error handling system with UI improvements
LearningCircuit8d7635b62e23
diff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.pyindex 7c6269ae0a..5f48b75852 100644--- a/src/local_deep_research/web/routes/history_routes.py+++ b/src/local_deep_research/web/routes/history_routes.py@@ -254,7 +254,7 @@ def get_research_details(research_id):)-@history_bp.route("/report/<int:research_id>")+@history_bp.route("/history/report/<int:research_id>")def get_report(research_id):conn = get_db_connection()conn.row_factory = lambda cursor, row: {diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.pyindex 762c82f52f..95bfa14309 100644--- a/src/local_deep_research/web/services/research_service.py+++ b/src/local_deep_research/web/services/research_service.py@@ -18,6 +18,7 @@ from ...utilities.threading_utils import thread_context, thread_with_app_contextfrom ..database.models import ResearchStrategyfrom ..models.database import calculate_duration, get_db_connectionfrom .socket_service import SocketIOService+from ...error_handling.report_generator import ErrorReportGenerator# Output directory for research results_PROJECT_ROOT = Path(__file__).parents[4]@@ -675,8 +676,31 @@ def run_research_process()try:- # Get the synthesized content from the LLM directly- clean_markdown = raw_formatted_findings+ # Check if we have an error in the findings and use enhanced error handling+ if isinstance(raw_formatted_findings, str) and raw_formatted_findings.startswith("Error:"):+ logger.info("Generating enhanced error report using ErrorReportGenerator")++ # Get LLM for error explanation if available+ try:+ llm = get_llm(research_id=research_id)+ except Exception:+ llm = None+ logger.warning("Could not get LLM for error explanation")++ # Generate comprehensive error report+ error_generator = ErrorReportGenerator(llm)+ clean_markdown = error_generator.generate_error_report(+ error_message=raw_formatted_findings,+ query=query,+ partial_results=results,+ search_iterations=results.get("iterations", 0),+ research_id=research_id+ )++ logger.info("Generated enhanced error report with %d characters", len(clean_markdown))+ else:+ # Get the synthesized content from the LLM directly+ clean_markdown = raw_formatted_findings# Extract all sources from findings to add them to the summaryall_links = []@@ -905,10 +929,61 @@ def run_research_process("solution": "Check API configuration and credentials."}+ # Generate enhanced error report for failed research+ enhanced_report_content = None+ try:+ # Get LLM for error explanation if available+ try:+ llm = get_llm(research_id=research_id)+ except Exception:+ llm = None+ logger.warning("Could not get LLM for error explanation in failure handler")++ # Get partial results if they exist+ partial_results = results if 'results' in locals() else None+ search_iterations = results.get("iterations", 0) if partial_results else 0++ # Generate comprehensive error report+ error_generator = ErrorReportGenerator(llm)+ enhanced_report_content = error_generator.generate_error_report(+ error_message=f"Research failed: {str(e)}",+ query=query,+ partial_results=partial_results,+ search_iterations=search_iterations,+ research_id=research_id+ )++ logger.info("Generated enhanced error report for failed research (length: %d)", len(enhanced_report_content))++ # Save enhanced error report as the actual report file+ try:+ reports_folder = get_reports_folder()+ report_filename = f"research_{research_id}_error_report.md"+ report_path = reports_folder / report_filename++ with open(report_path, "w", encoding="utf-8") as f:+ f.write(enhanced_report_content)++ logger.info("Saved enhanced error report to: %s", report_path)++ # Store the report path so it can be retrieved later+ report_path_to_save = str(report_path.relative_to(reports_folder.parent))++ except Exception as report_error:+ logger.exception("Failed to save enhanced error report: %s", report_error)+ report_path_to_save = None++ except Exception as error_gen_error:+ logger.exception("Failed to generate enhanced error report: %s", error_gen_error)+ enhanced_report_content = None+ report_path_to_save = None+# Update metadata with more context about the errormetadata = {"phase": "error", "error": user_friendly_error}if error_context:metadata.update(error_context)+ if enhanced_report_content:+ metadata["has_enhanced_report"] = True# If we still have an active research record, update its logif research_id in active_research:@@ -948,16 +1023,30 @@ def run_research_process(if result and result[0]:duration_seconds = calculate_duration(result[0])- cursor.execute(- "UPDATE research_history SET status = ?, completed_at = ?, duration_seconds = ?, metadata = ? WHERE id = ?",- (- status,- completed_at,- duration_seconds,- json.dumps(metadata),- research_id,- ),- )+ # Update database with error report path if available+ if 'report_path_to_save' in locals() and report_path_to_save:+ cursor.execute(+ "UPDATE research_history SET status = ?, completed_at = ?, duration_seconds = ?, metadata = ?, report_path = ? WHERE id = ?",+ (+ status,+ completed_at,+ duration_seconds,+ json.dumps(metadata),+ report_path_to_save,+ research_id,+ ),+ )+ else:+ cursor.execute(+ "UPDATE research_history SET status = ?, completed_at = ?, duration_seconds = ?, metadata = ? WHERE id = ?",+ (+ status,+ completed_at,+ duration_seconds,+ json.dumps(metadata),+ research_id,+ ),+ )conn.commit()conn.close()diff --git a/src/local_deep_research/web/static/js/components/progress.js b/src/local_deep_research/web/static/js/components/progress.jsindex 35ab760d9f..7ca9bc61db 100644--- a/src/local_deep_research/web/static/js/components/progress.js+++ b/src/local_deep_research/web/static/js/components/progress.js@@ -630,18 +630,20 @@cancelButton.style.display = 'none';}} else if (data.status === 'failed' || data.status === 'cancelled') {- // Show error message- if (window.ui) {- window.ui.showError(data.error || 'Research was unsuccessful');+ // For failed research, try to show the error report if available+ if (data.status === 'failed') {+ if (viewResultsButton) {+ viewResultsButton.textContent = 'View Error Report';+ viewResultsButton.href = `/research/results/${currentResearchId}`;+ viewResultsButton.style.display = 'inline-block';+ }} else {- console.error('Research failed:', data.error || 'Unknown error');- }-- // Update button to go back to home- if (viewResultsButton) {- viewResultsButton.textContent = 'Start New Research';- viewResultsButton.href = '/';- viewResultsButton.style.display = 'inline-block';+ // For cancelled research, go back to home+ if (viewResultsButton) {+ viewResultsButton.textContent = 'Start New Research';+ viewResultsButton.href = '/';+ viewResultsButton.style.display = 'inline-block';+ }}// Hide cancel button@@ -917,8 +919,12 @@cancelButton.style.display = 'none';}- // Show results button (might have partial results)- showResultsButton();+ // Show error report button+ if (viewResultsButton) {+ viewResultsButton.textContent = 'View Error Report';+ viewResultsButton.href = `/research/results/${currentResearchId}`;+ viewResultsButton.style.display = 'inline-block';+ }// Show notification if enabledshowNotification('Research Error', `There was an error with your research: ${data.error}`);diff --git a/src/local_deep_research/web/static/js/components/results.js b/src/local_deep_research/web/static/js/components/results.jsindex 2469e28c0f..0120f9388d 100644--- a/src/local_deep_research/web/static/js/components/results.js+++ b/src/local_deep_research/web/static/js/components/results.js@@ -98,7 +98,7 @@resultsContainer.innerHTML = '<div class="text-center my-5"><i class="fas fa-spinner fa-pulse"></i><p class="mt-3">Loading research results...</p></div>';// Fetch result from API- const response = await fetch(`/research/api/report/${researchId}`);+ const response = await fetch(`/research/api/history/report/${researchId}`);if (!response.ok) {throw new Error(`HTTP error ${response.status}`);