~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: wire RetryManager into download_as_text with exponential backoff (#3285)
LearningCircuit503ecbba47b7
diff --git a/src/local_deep_research/library/download_management/status_tracker.py b/src/local_deep_research/library/download_management/status_tracker.pyindex 201ad2d100..a22f7525e8 100644--- a/src/local_deep_research/library/download_management/status_tracker.py+++ b/src/local_deep_research/library/download_management/status_tracker.py@@ -14,6 +14,28 @@ from sqlalchemy.orm import sessionmaker, Sessionfrom .models import ResourceDownloadStatus, Basefrom .failure_classifier import BaseFailure+MAX_TOTAL_RETRIES = 5+++def compute_retry_cooldown(+ attempt: int, default_cooldown: timedelta+) -> Optional[timedelta]:+ """Return cooldown for this attempt number, or None for permanent failure.++ Schedule:+ attempt 1: default_cooldown (from failure type)+ attempt 2: 1 day+ attempt 3-4: 30 days+ attempt >= 5: None (permanent failure)+ """+ if attempt >= MAX_TOTAL_RETRIES:+ return None+ if attempt >= 3:+ return timedelta(days=30)+ if attempt == 2:+ return timedelta(days=1)+ return default_cooldown+class ResourceStatusTracker:"""Track download attempts, failures, and cooldowns in database"""@@ -94,28 +116,40 @@ class ResourceStatusTracker:f"[STATUS_TRACKER] Marked resource {resource_id} as permanently failed: {failure.error_type}")else:- status.status = "temporarily_failed"- status.retry_after_timestamp = (- failure.created_at + failure.retry_after- )status.failure_type = failure.error_typestatus.failure_message = failure.message- logger.info(- f"[STATUS_TRACKER] Marked resource {resource_id} as temporarily failed: {failure.error_type}, retry after: {failure.retry_after}"- )++ attempt = (status.total_retry_count or 0) + 1+ cooldown = compute_retry_cooldown(attempt, failure.retry_after)++ if cooldown is None:+ status.status = "permanently_failed"+ status.permanent_failure_at = datetime.now(UTC)+ status.retry_after_timestamp = None+ logger.info(+ f"[STATUS_TRACKER] Auto-promoted resource {resource_id} to "+ f"permanently failed after {attempt} attempts"+ )+ else:+ status.status = "temporarily_failed"+ status.retry_after_timestamp = datetime.now(UTC) + cooldown+ logger.info(+ f"[STATUS_TRACKER] Marked resource {resource_id} as temporarily failed: "+ f"{failure.error_type}, attempt {attempt}, retry after: {cooldown}"+ )# Update retry statistics# Ensure total_retry_count is initialized (handle None from legacy data)if status.total_retry_count is None:status.total_retry_count = 0status.total_retry_count += 1- status.last_attempt_at = datetime.now(UTC)- # Check if retry is today+ # Check if last attempt was today (before overwriting last_attempt_at)today = datetime.now(UTC).date()last_attempt = (status.last_attempt_at.date() if status.last_attempt_at else None)+ status.last_attempt_at = datetime.now(UTC)if last_attempt == today:# Ensure today_retry_count is initialized (handle None from legacy data)if status.today_retry_count is None:@@ -210,10 +244,28 @@ class ResourceStatusTracker:)# Check daily retry limit (max 3 retries per day)- if status.today_retry_count >= 3:+ # today_retry_count is only reset inside _apply_failure, so check+ # whether the stored count is actually from today before using it.+ today = datetime.now(UTC).date()+ last_attempt_date = (+ status.last_attempt_at.date()+ if status.last_attempt_at+ else None+ )+ today_count = (+ status.today_retry_count if last_attempt_date == today else 0+ )+ if today_count >= 3:+ return (+ False,+ f"Daily retry limit exceeded ({today_count}/3). Retry available tomorrow.",+ )++ # Check total retry limit (safety net for records not yet auto-promoted)+ if (status.total_retry_count or 0) >= MAX_TOTAL_RETRIES:return (False,- f"Daily retry limit exceeded ({status.today_retry_count}/3). Retry available tomorrow.",+ f"Permanently failed after {status.total_retry_count} attempts. Will not retry.",)# Can retrydiff --git a/src/local_deep_research/research_library/services/download_service.py b/src/local_deep_research/research_library/services/download_service.pyindex 8d40229fd5..11a6c1f3ce 100644--- a/src/local_deep_research/research_library/services/download_service.py+++ b/src/local_deep_research/research_library/services/download_service.py@@ -837,6 +837,7 @@ class DownloadService:return False, "Resource not found"# Handle library resources — content already in the database+ # (local-only, no network — skip retry checks)if resource.source_type == "library" or (resource.url and resource.url.startswith("/library/document/")):@@ -859,13 +860,44 @@ class DownloadService:if result is not None:return result+ # Check retry eligibility before network-dependent extraction+ if self.retry_manager:+ decision = self.retry_manager.should_retry_resource(resource_id)+ if not decision.can_retry:+ logger.info(+ f"Skipping resource {resource_id}: {decision.reason}"+ )+ return False, decision.reason+# Try API text extractionresult = self._try_api_text_extraction(session, resource)if result is not None:+ self._record_retry_attempt(resource, result, session)return result# Fallback: Download PDF and extract- return self._fallback_pdf_extraction(session, resource)+ result = self._fallback_pdf_extraction(session, resource)+ self._record_retry_attempt(resource, result, session)+ return result++ def _record_retry_attempt(+ self, resource, result: Tuple[bool, Optional[str]], session=None+ ) -> None:+ """Record a download attempt with the retry manager."""+ if not self.retry_manager:+ return+ self.retry_manager.record_attempt(+ resource_id=resource.id,+ result=result,+ url=resource.url or "",+ details=result[1]+ or (+ "Successfully extracted text"+ if result[0]+ else "Text extraction failed"+ ),+ session=session,+ )def _try_library_text_extraction(self, session, resource