Skip to content

~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.

chore(research): stop creating empty research_outputs/research_<id> dirs (#5152)

LearningCircuitef7dd733ca2b
diff --git a/changelog.d/+no-empty-research-output-dirs.misc.md b/changelog.d/+no-empty-research-output-dirs.misc.md
new file mode 100644
index 0000000000..06277d88c8
--- /dev/null
+++ b/changelog.d/+no-empty-research-output-dirs.misc.md
@@ -0,0 +1 @@
+Running a research no longer creates an empty `research_outputs/research_<id>` directory on disk. That directory was vestigial leftover from an older on-disk report flow; reports are stored in the encrypted per-user database via `storage.save_report`, and the file path was never written to, so the directory just accumulated one empty folder per research run.
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index cfce0314e9..51e40363d6 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -925,10 +925,6 @@ def run_research_process(research_id, query, mode, **kwargs):
f"custom_endpoint={custom_endpoint}, strategy={strategy}"
)
- # Set up the AI Context Manager
- output_dir = OUTPUT_DIR / f"research_{research_id}"
- output_dir.mkdir(parents=True, exist_ok=True)
-
# Create a settings context that uses snapshot - no database access in threads
settings_context = SnapshotSettingsContext(
settings_snapshot, username=username
diff --git a/tests/web/services/test_research_service_coverage.py b/tests/web/services/test_research_service_coverage.py
index c62d5bdf35..c794ffd219 100644
--- a/tests/web/services/test_research_service_coverage.py
+++ b/tests/web/services/test_research_service_coverage.py
@@ -974,6 +974,100 @@ class TestRunResearchProcessQuickMode:
assert research.status == "completed"
+class TestRunResearchProcessNoOutputDir:
+ """Regression: run_research_process must not create an empty
+ research_outputs/research_<id> directory on disk.
+
+ Reports are persisted via storage.save_report into the encrypted
+ per-user database; the on-disk output directory is not used by the
+ encrypted-database version, so run_research_process must not create it.
+ """
+
+ def test_no_research_output_dir_created(self, tmp_path):
+ mock_session = MagicMock()
+ research = _make_research_mock()
+ mock_session.query.return_value.filter_by.return_value.first.return_value = research
+
+ mock_system = MagicMock()
+ mock_system.analyze_topic.return_value = {
+ "findings": [],
+ "formatted_findings": "# Summary",
+ "iterations": 1,
+ }
+
+ mock_formatter = MagicMock()
+ mock_formatter.format_document.return_value = "formatted content"
+
+ mock_storage = MagicMock()
+ mock_storage.save_report.return_value = True
+
+ mock_sources_service = MagicMock()
+ mock_sources_service.save_research_sources.return_value = 0
+
+ with (
+ # Point the module's output directory at an empty tmp_path so we
+ # can assert nothing gets written under it.
+ patch(f"{RS}.OUTPUT_DIR", tmp_path),
+ patch(
+ "local_deep_research.web.routes.globals.is_termination_requested",
+ return_value=False,
+ ),
+ patch(
+ "local_deep_research.web.routes.globals.is_research_active",
+ return_value=True,
+ ),
+ patch(
+ "local_deep_research.web.routes.globals.update_progress_and_check_active",
+ return_value=(50, True),
+ ),
+ patch(f"{RS}.get_llm", return_value=MagicMock()),
+ patch(f"{RS}.get_search", return_value=MagicMock()),
+ patch(f"{RS}.AdvancedSearchSystem", return_value=mock_system),
+ patch(f"{RS}.get_citation_formatter", return_value=mock_formatter),
+ patch(
+ f"{RS}.get_user_db_session",
+ side_effect=_fake_session_ctx(mock_session),
+ ),
+ patch(f"{RS}.cleanup_research_resources"),
+ patch(f"{RS}.SocketIOService"),
+ patch(f"{RS}.set_search_context"),
+ patch(f"{RS}.calculate_duration", return_value=10.0),
+ patch(
+ "local_deep_research.storage.get_report_storage",
+ return_value=mock_storage,
+ ),
+ patch(
+ f"{RS}.extract_links_from_search_results",
+ return_value=[],
+ ),
+ patch(
+ "local_deep_research.web.services.research_sources_service.ResearchSourcesService",
+ return_value=mock_sources_service,
+ ),
+ patch(
+ "local_deep_research.web.queue.processor_v2.queue_processor",
+ MagicMock(),
+ ),
+ patch("local_deep_research.settings.logger.log_settings"),
+ patch(
+ "local_deep_research.config.thread_settings.set_settings_context"
+ ),
+ ):
+ raw_fn = _get_raw_run_research_process()
+ raw_fn(
+ "r_no_dir",
+ "test query",
+ "quick",
+ username="alice",
+ settings_snapshot={"search.tool": "searxng"},
+ )
+
+ assert research.status == "completed"
+ # The per-research output directory must never be created.
+ assert not (tmp_path / "research_r_no_dir").exists()
+ assert list(tmp_path.iterdir()) == []
+
+
class TestRunResearchProcessDetailedMode:
"""Detailed/full report mode."""