~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
docs: document ResearchStatus lifecycle and fix terminal-state bug (#2200)
LearningCircuit6901cdb04ba3
diff --git a/docs/architecture/DATABASE_SCHEMA.md b/docs/architecture/DATABASE_SCHEMA.mdindex 596fe7c969..f2878bef30 100644--- a/docs/architecture/DATABASE_SCHEMA.md+++ b/docs/architecture/DATABASE_SCHEMA.md@@ -157,7 +157,7 @@ Simplified research record (alternative to ResearchTask).**Enums:**- `ResearchMode`: quick, detailed, report-- `ResearchStatus`: pending, running, completed, failed, cancelled+- `ResearchStatus`: pending, queued, in_progress, completed, suspended, failed, error, cancelled- `ResearchStrategy`: source-based, focused-iteration, etc.#### ResearchHistorydiff --git a/docs/architecture/OVERVIEW.md b/docs/architecture/OVERVIEW.mdindex b44d015872..c73e0a33dd 100644--- a/docs/architecture/OVERVIEW.md+++ b/docs/architecture/OVERVIEW.md@@ -7,6 +7,7 @@ This document provides a comprehensive overview of Local Deep Research's system- [System Components](#system-components)- [Entry Points](#entry-points)- [Research Execution Flow](#research-execution-flow)+ - [Research Status Lifecycle](#research-status-lifecycle)- [Module Responsibilities](#module-responsibilities)- [Threading Model](#threading-model)- [Configuration System](#configuration-system)@@ -152,6 +153,39 @@ sequenceDiagramWeb-->>User: Results via SocketIO```+### Research Status Lifecycle++```mermaid+stateDiagram-v2+ [*] --> QUEUED : Concurrency limit reached+ [*] --> IN_PROGRESS : Slots available++ QUEUED --> IN_PROGRESS : Worker picks up task+ QUEUED --> SUSPENDED : User terminates++ IN_PROGRESS --> COMPLETED : Research succeeds+ IN_PROGRESS --> FAILED : Unrecoverable error+ IN_PROGRESS --> SUSPENDED : User terminates++ COMPLETED --> [*]+ FAILED --> [*]+ SUSPENDED --> [*]++ note right of FAILED+ Set by processor_v2 and+ research_service on errors+ end note++ note left of SUSPENDED+ Set when user clicks+ terminate/stop+ end note+```++> **Unused statuses:** `PENDING` (declared as a model default but never set by any creation+> path), `ERROR` (never set; predates `FAILED`), and `CANCELLED` (unused by research; used+> by benchmarks) exist in `ResearchStatus` for backward compatibility.+---## Module Responsibilitiesdiff --git a/src/local_deep_research/constants.py b/src/local_deep_research/constants.pyindex 4819c5cef4..73a289874c 100644--- a/src/local_deep_research/constants.py+++ b/src/local_deep_research/constants.py@@ -26,16 +26,39 @@ class ResearchStatus(StrEnum):Uses StrEnum so values compare equal to plain strings,e.g. ``ResearchStatus.COMPLETED == "completed"`` is True.++ Lifecycle::++ [*] ─┬─► QUEUED ─┬─► IN_PROGRESS ─┬─► COMPLETED+ │ │ ├─► FAILED+ │ └─► SUSPENDED └─► SUSPENDED+ │ (concurrency limit) (terminated while queued)+ │+ └─► IN_PROGRESS (slots available, skips queue)++ Notes:+ - PENDING is declared as a model default but no creation path+ actually sets it. All routes use QUEUED or IN_PROGRESS.+ - ERROR is checked as a terminal state but never set by current+ code. It predates FAILED and exists for backward compatibility+ with older database records.+ - CANCELLED is not used by the research workflow. It is used by+ the benchmark subsystem (BenchmarkStatus, BenchmarkTaskStatus)."""- COMPLETED = "completed"- SUSPENDED = "suspended"- FAILED = "failed"- IN_PROGRESS = "in_progress"- PENDING = "pending"- ERROR = "error"- QUEUED = "queued"- CANCELLED = "cancelled"+ # --- Active lifecycle states ---+ PENDING = "pending" # Model default; never set by any creation path+ QUEUED = "queued" # Waiting for a worker slot+ IN_PROGRESS = "in_progress" # Worker actively executing++ # --- Terminal states ---+ COMPLETED = "completed" # Finished successfully+ SUSPENDED = "suspended" # User terminated the research+ FAILED = "failed" # Unrecoverable error during execution++ # --- Legacy / compatibility ---+ ERROR = "error" # Never set; predates FAILED+ CANCELLED = "cancelled" # Unused by research; for benchmarks# --- Rate limiting defaults ---diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.pyindex 33e289ec68..73ae51682c 100644--- a/src/local_deep_research/web/routes/research_routes.py+++ b/src/local_deep_research/web/routes/research_routes.py@@ -741,10 +741,11 @@ def terminate_research(research_id):status = research.status- # If it's already completed or suspended, return success+ # If it's already in a terminal state, return successif status in (ResearchStatus.COMPLETED,ResearchStatus.SUSPENDED,+ ResearchStatus.FAILED,ResearchStatus.ERROR,):return jsonify(diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.pyindex d6243552bc..b218a02190 100644--- a/src/local_deep_research/web/services/research_service.py+++ b/src/local_deep_research/web/services/research_service.py@@ -1776,10 +1776,11 @@ def cancel_research(research_id, username=None):)return False- # Check if already completed or suspended+ # Check if already in a terminal stateif research.status in (ResearchStatus.COMPLETED,ResearchStatus.SUSPENDED,+ ResearchStatus.FAILED,ResearchStatus.ERROR,):logger.info(diff --git a/src/local_deep_research/web/static/js/components/detail.js b/src/local_deep_research/web/static/js/components/detail.jsindex 4df780d04c..74cbb749e8 100644--- a/src/local_deep_research/web/static/js/components/detail.js+++ b/src/local_deep_research/web/static/js/components/detail.js@@ -134,8 +134,8 @@// Update UI with research detailsupdateResearchInfo(data);- // Check if research is completed- isCompleted = data.status === 'Completed' || data.status === 'Failed';+ // Check if research is in a terminal state+ isCompleted = data.status === 'completed' || data.status === 'failed' || data.status === 'suspended';} catch (error) {SafeLogger.error('Error loading basic research details:', error);@@ -166,8 +166,8 @@// Update UI with research detailsupdateResearchInfo(data);- // Check if research is completed- isCompleted = data.status === 'Completed' || data.status === 'Failed';+ // Check if research is in a terminal state+ isCompleted = data.status === 'completed' || data.status === 'failed' || data.status === 'suspended';if (isCompleted && pollInterval) {clearInterval(pollInterval);pollInterval = null;diff --git a/src/local_deep_research/web/static/js/pages/news.js b/src/local_deep_research/web/static/js/pages/news.jsindex 7131804117..7a5633eb19 100644--- a/src/local_deep_research/web/static/js/pages/news.js+++ b/src/local_deep_research/web/static/js/pages/news.js@@ -2273,7 +2273,7 @@ async function pollForNewsResearchResults(researchId, originalQuery, isResume =setTimeout(() => {loadNewsFeed();}, 1000);- } else if (status.status === 'error' || status.status === 'suspended') {+ } else if (status.status === 'error' || status.status === 'failed' || status.status === 'suspended') {clearInterval(pollInterval);localStorage.removeItem('active_news_research');showAlert(`Research ${status.status}: ${status.metadata?.error || 'Unknown error'}`, 'error');diff --git a/tests/puppeteer/test_deep_functionality.js b/tests/puppeteer/test_deep_functionality.jsindex 3f654f12e8..331210cfce 100644--- a/tests/puppeteer/test_deep_functionality.js+++ b/tests/puppeteer/test_deep_functionality.js@@ -725,8 +725,8 @@ describe('Deep Functionality Tests', function() {}, BASE_URL, researchId);console.log(` Research status: ${statusResult.research_status}`);- // Accept any valid status - research may still be running or may have errored- const validStatuses = ['queued', 'in_progress', 'completed', 'error', 'pending', 'suspended'];+ // Accept any valid ResearchStatus — mirrors the 8-member enum in constants.py+ const validStatuses = ['queued', 'in_progress', 'completed', 'error', 'pending', 'suspended', 'failed', 'cancelled'];expect(validStatuses).to.include(statusResult.research_status);// Terminate research to avoid side effects on subsequent testsdiff --git a/tests/puppeteer/test_ssrf_protection.js b/tests/puppeteer/test_ssrf_protection.jsindex 217971c8cb..fb0951827a 100644--- a/tests/puppeteer/test_ssrf_protection.js+++ b/tests/puppeteer/test_ssrf_protection.js@@ -355,7 +355,7 @@ describe('SSRF Protection - Functionality Tests', function() {await page.goto(`${BASE_URL}/library`, { waitUntil: 'domcontentloaded' });const csrfToken = await page.$eval('meta[name="csrf-token"]', el => el.content).catch(() => null);- console.log(`CSRF token available: ${csrfToken !== null}`);+ expect(csrfToken).to.not.be.null;const response = await page.evaluate(async (baseUrl, csrf) => {try {