~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(queue): scope the missing-parent metadata sweep to the dispatching user (#7566)
Lukas26a937951c96
diff --git a/changelog.d/7566.bugfix.md b/changelog.d/7566.bugfix.mdnew file mode 100644index 0000000000..4096beb561--- /dev/null+++ b/changelog.d/7566.bugfix.md@@ -0,0 +1 @@+One user's queue dispatch no longer deletes another user's queued research whose parent history row is missing: the missing-parent sweep now only collects research metadata that no queue entry points at or that the dispatching user's own queue entry points at.diff --git a/src/local_deep_research/web/queue/processor_v2.py b/src/local_deep_research/web/queue/processor_v2.pyindex 736470e752..210dd6a490 100644--- a/src/local_deep_research/web/queue/processor_v2.py+++ b/src/local_deep_research/web/queue/processor_v2.py@@ -11,7 +11,7 @@ from enum import Enum, autofrom typing import Any, Dict, Optionalfrom loguru import logger-from sqlalchemy import select+from sqlalchemy import or_, selectfrom sqlalchemy.orm import Sessionfrom ...constants import ResearchStatus@@ -1291,6 +1291,11 @@ class QueueProcessorV2:.all())}+ # TaskMetadata has no owner column. A row that another user's queue+ # entry points at is theirs, and cleanup_queued_research_state+ # deletes queue rows by research_id alone, so sweeping it here+ # removed that user's queued research. The queue row stands in for+ # the owner only because queued_researches.research_id is UNIQUE.metadata_orphan_ids = {task_idfor (task_id,) in (@@ -1299,9 +1304,17 @@ class QueueProcessorV2:ResearchHistory,TaskMetadata.task_id == ResearchHistory.id,)+ .outerjoin(+ QueuedResearch,+ TaskMetadata.task_id == QueuedResearch.research_id,+ ).filter(TaskMetadata.task_type == "research",ResearchHistory.id.is_(None),+ or_(+ QueuedResearch.research_id.is_(None),+ QueuedResearch.username == username,+ ),).all())diff --git a/tests/security/test_queue_processor_writes.py b/tests/security/test_queue_processor_writes.pyindex b2860bee3c..a2a844dc14 100644--- a/tests/security/test_queue_processor_writes.py+++ b/tests/security/test_queue_processor_writes.py@@ -106,10 +106,15 @@ def test_queue_sweep_cleanup_commits_database_rows_without_filesystem_state(processor = processor_module.QueueProcessorV2(check_interval=1)session = MagicMock()- query_results = iter([[("../queued",)], [("/tmp/metadata",)]])- session.query.return_value.outerjoin.return_value.filter.return_value.all.side_effect = (- lambda: next(query_results)- )+ query = session.query.return_value+ # Queue orphans join the history table; metadata orphans also join the+ # queue table, to leave rows another user's queue entry points at.+ query.outerjoin.return_value.filter.return_value.all.return_value = [+ ("../queued",)+ ]+ query.outerjoin.return_value.outerjoin.return_value.filter.return_value.all.return_value = [+ ("/tmp/metadata",)+ ]cleaned = MagicMock(cleaned_ids=frozenset({"../queued", "/tmp/metadata"}))cleanup = MagicMock(return_value=cleaned)monkeypatch.setattr(diff --git a/tests/web/queue/test_queue_processor_contracts.py b/tests/web/queue/test_queue_processor_contracts.pyindex 1120943210..4c9d71fcf4 100644--- a/tests/web/queue/test_queue_processor_contracts.py+++ b/tests/web/queue/test_queue_processor_contracts.py@@ -29,7 +29,6 @@ import threadingfrom contextlib import contextmanagerfrom unittest.mock import ANY, Mock, patch-import pytestfrom sqlalchemy import create_engine, eventfrom sqlalchemy.orm import sessionmaker@@ -535,19 +534,6 @@ def test_dispatch_for_one_user_never_touches_another_users_queue_rows(engine.dispose()- strict=True,- reason=(- "DEFECT (unfixed): the missing-parent sweep in "- "_sweep_missing_parent_queue_rows scopes its QueuedResearch orphan "- "query by username but its TaskMetadata orphan query is NOT "- "username-scoped. cleanup_queued_research_state then deletes the "- "matching QueuedResearch rows by research_id alone, so alice's "- "dispatch tick deletes bob's queue row. Harmless while every "- "username owns its own encrypted DB, but it is the one dispatch "- "path that is not user-scoped. Flip to a plain test when fixed."- ),-)def test_missing_parent_sweep_is_username_scoped(tmp_path):"""Alice's sweep must not delete bob's orphaned queue row."""engine = _ondisk_engine(tmp_path)