~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: Add error handling and fallback mechanisms in IterDRAG strategy synthesis
hashedvikingcc82bac71f10
diff --git a/src/local_deep_research/advanced_search_system/strategies/iterdrag_strategy.py b/src/local_deep_research/advanced_search_system/strategies/iterdrag_strategy.pyindex de2e6157e3..501b7a89be 100644--- a/src/local_deep_research/advanced_search_system/strategies/iterdrag_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/iterdrag_strategy.py@@ -256,6 +256,64 @@ Initial Search Results:accumulated_knowledge=current_knowledge,)+ # Check if the synthesis failed with an error+ if isinstance(final_answer, str) and final_answer.startswith("Error:"):+ logger.error(f"Synthesis returned an error: {final_answer}")++ # Extract error type for better handling+ error_type = "unknown"+ error_message = final_answer.lower()++ if "timeout" in error_message:+ error_type = "timeout"+ elif "token limit" in error_message:+ error_type = "token_limit"+ elif "rate limit" in error_message:+ error_type = "rate_limit"+ elif "connection" in error_message:+ error_type = "connection"++ # Log with specific error type+ logger.error(f"Synthesis failed with error type: {error_type}")++ # Add error information to progress update+ self._update_progress(+ f"Synthesis failed: {error_type}. Attempting fallback...",+ 85,+ {"phase": "synthesis_error", "error_type": error_type},+ )++ # Try fallback: use the best individual finding as the final answer+ longest_finding = ""+ for f in findings:+ if isinstance(f, dict) and "content" in f:+ if len(f["content"]) > len(longest_finding):+ longest_finding = f["content"]++ if longest_finding:+ logger.info("Using longest finding as fallback synthesis")+ final_answer = f"""+# Research Results (Fallback Mode)++{longest_finding}++## Note+The final synthesis could not be completed due to an error: {final_answer}+This is a fallback response using the most detailed individual finding.+ """+ else:+ # If we don't have any findings with content, use current_knowledge+ logger.info("Using current knowledge as fallback synthesis")+ final_answer = f"""+# Research Results (Fallback Mode)++{current_knowledge}++## Note+The final synthesis could not be completed due to an error: {final_answer}+This is a fallback response using the accumulated knowledge.+ """+# Create a synthesis findingfinding = {"phase": "Final synthesis",@@ -275,9 +333,66 @@ Initial Search Results:logger.error(f"Error synthesizing final answer: {str(e)}")import traceback- print(traceback.format_exc())- # If synthesis fails, keep existing knowledge- final_answer = current_knowledge # Fallback to pre-synthesis knowledge+ logger.error(traceback.format_exc())++ # Create an error finding+ error_finding = {+ "phase": "Final synthesis error",+ "content": f"Error during synthesis: {str(e)}",+ "question": query,+ "search_results": [],+ "documents": [],+ }+ findings.append(error_finding)++ # If synthesis completely fails, construct a fallback answer from the most relevant findings+ self._update_progress(+ "Synthesis failed. Creating fallback summary...",+ 85,+ {"phase": "synthesis_fallback"},+ )++ try:+ # Extract best content from findings+ key_findings = []+ for i, f in enumerate(findings):+ if isinstance(f, dict) and "content" in f and f.get("content"):+ # Only take the first 500 chars of each finding for the fallback+ content_preview = f.get("content", "")[:500]+ if content_preview:+ key_findings.append(+ f"### Finding {i + 1}\n\n{content_preview}..."+ )++ # Create fallback content+ fallback_content = f"""+# Research Results (Error Recovery Mode)++## Original Query+{query}++## Key Findings+{chr(10).join(key_findings[:5]) if key_findings else "No valid findings were generated."}++## Error Information+The system encountered an error during final synthesis: {str(e)}+This is an automatically generated fallback response.+ """++ final_answer = fallback_content+ except Exception as fallback_error:+ # Last resort fallback+ logger.error(f"Even fallback creation failed: {fallback_error}")+ final_answer = f"""+# Research Error++The system encountered multiple errors while processing your query: "{query}"++Primary error: {str(e)}+Fallback error: {str(fallback_error)}++Please try again with a different query or contact support.+ """# Compress knowledge if neededif settings.general.knowledge_accumulation == "ITERATION":