~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(vector_stores): report failed cache-root hardening from migrate_legacy_docstores (#6481)
Vladimir Babine5a4f0e260fa
diff --git a/changelog.d/6396.bugfix.md b/changelog.d/6396.bugfix.mdnew file mode 100644index 0000000000..faf6c61225--- /dev/null+++ b/changelog.d/6396.bugfix.md@@ -0,0 +1 @@+`migrate_legacy_docstores` now reports a failed `chmod(0o700)` of the RAG cache root as `hardening_errors` in its returned stats and in the "did NOT complete cleanly" error log, instead of downgrading it to a warning and reporting the run exactly like a fully clean one.diff --git a/src/local_deep_research/vector_stores/legacy_cleanup.py b/src/local_deep_research/vector_stores/legacy_cleanup.pyindex 74cd21b78b..a9adbdd0e6 100644--- a/src/local_deep_research/vector_stores/legacy_cleanup.py+++ b/src/local_deep_research/vector_stores/legacy_cleanup.py@@ -340,9 +340,12 @@ def migrate_legacy_docstores() -> Dict[str, int]:the ``.pkl``, removing all plaintext docstores from disk.Returns ``{"found", "extracted", "deleted", "reindex_fallback",- "remaining"}``. Re-scans afterward and logs a prominent error recommending- manual deletion if any docstore remains — plaintext must never pass- silently. Idempotent (a clean tree is a no-op).+ "remaining", "scan_errors", "hardening_errors"}``. Re-scans afterward and+ logs a prominent error recommending manual deletion if any docstore+ remains — plaintext must never pass silently. ``hardening_errors`` is a+ 0/1 flag (not a count): 1 when the cache root could not be restricted to+ ``0o700``, reported on its own ERROR line independent of the plaintext+ outcome. Idempotent (a clean tree is a no-op)."""root = _rag_cache_root()# SECURITY: refuse to operate on a SYMLINKED cache root. os.walk (and@@ -368,17 +371,30 @@ def migrate_legacy_docstores() -> Dict[str, int]:"reindex_fallback": 0,"remaining": 0,"scan_errors": 1,+ "hardening_errors": 0,}# Harden the RAG cache ROOT at the earliest point it is touched so another# local OS account can't traverse into any user's vector caches. Both the# leaf-only chmod in _write_sidecar_atomic and _get_index_path otherwise# leave the root at the process umask (typically world-traversable) between# startup and the first index op.+ hardening_errors = 0if root.exists():try:root.chmod(0o700)except OSError:- logger.warning(f"Could not chmod RAG cache root {root} to 0o700")+ hardening_errors = 1+ # Logged here, at the point of failure and at ERROR, so the+ # severity is the same whether or not any legacy docstore+ # happens to exist below. Kept as its own line rather than+ # folded into the plaintext-migration summary: a chmod failure+ # (e.g. on a mount that doesn't support it) must not read as+ # "plaintext may remain", which is a different incident.+ logger.exception(+ f"RAG cache: root {root} could not be restricted to 0o700 — "+ "other local OS accounts may still traverse it. Fix the "+ "directory permissions manually."+ )found, scan_errors = _find_legacy_docstores(root)if not found and not scan_errors:logger.debug(f"RAG cache: no legacy docstore files under {root}")@@ -389,6 +405,7 @@ def migrate_legacy_docstores() -> Dict[str, int]:"reindex_fallback": 0,"remaining": 0,"scan_errors": 0,+ "hardening_errors": hardening_errors,}extracted = 0@@ -449,6 +466,7 @@ def migrate_legacy_docstores() -> Dict[str, int]:"reindex_fallback": reindex_fallback,"remaining": len(remaining),"scan_errors": len(rescan_errors),+ "hardening_errors": hardening_errors,}diff --git a/tests/vector_stores/test_legacy_cleanup_edge_failures.py b/tests/vector_stores/test_legacy_cleanup_edge_failures.pyindex f63c62206f..ef411d6af4 100644--- a/tests/vector_stores/test_legacy_cleanup_edge_failures.py+++ b/tests/vector_stores/test_legacy_cleanup_edge_failures.py@@ -104,6 +104,8 @@ def test_migration_survives_root_chmod_failure(Path, "chmod", side_effect=OSError("unsupported"))mocker.patch.object(cleanup, "_extract_map", return_value=False)+ error = mocker.patch.object(cleanup.logger, "error")+ exception = mocker.patch.object(cleanup.logger, "exception")result = cleanup.migrate_legacy_docstores()@@ -115,6 +117,55 @@ def test_migration_survives_root_chmod_failure(chmod.assert_called_once_with(0o700)assert result["deleted"] == 1assert not pkl_path.exists()+ assert result["hardening_errors"] == 1+ # All plaintext WAS removed here, so the plaintext-migration summary must+ # not fire; the only ERROR is the dedicated hardening line, logged via+ # logger.exception() so the traceback is attached.+ messages = [+ str(call.args[0])+ for call in error.call_args_list + exception.call_args_list+ ]+ assert any("could not be restricted to 0o700" in m for m in messages)+ assert not any("did NOT complete cleanly" in m for m in messages)+++def test_migration_reports_root_chmod_failure_on_clean_tree(+ tmp_path: Path, mocker: MockerFixture+) -> None:+ mocker.patch.object(cleanup, "_rag_cache_root", return_value=tmp_path)+ chmod = mocker.patch.object(+ Path, "chmod", side_effect=OSError("unsupported")+ )+ error = mocker.patch.object(cleanup.logger, "error")+ exception = mocker.patch.object(cleanup.logger, "exception")++ result = cleanup.migrate_legacy_docstores()++ # Only the root-hardening chmod runs on a clean tree; pin it so a later+ # chmod elsewhere can't satisfy this test for the wrong reason.+ chmod.assert_called_once_with(0o700)+ assert result["found"] == 0+ assert result["scan_errors"] == 0+ assert result["hardening_errors"] == 1+ # Severity must not depend on whether legacy files happened to exist:+ # the hardening failure is an ERROR even on a clean tree, on its own+ # line, and never phrased as a plaintext-migration failure.+ messages = [+ str(call.args[0])+ for call in error.call_args_list + exception.call_args_list+ ]+ assert any("could not be restricted to 0o700" in m for m in messages)+ assert not any("did NOT complete cleanly" in m for m in messages)+++def test_migration_reports_no_hardening_error_when_chmod_succeeds(+ tmp_path: Path, mocker: MockerFixture+) -> None:+ mocker.patch.object(cleanup, "_rag_cache_root", return_value=tmp_path)++ result = cleanup.migrate_legacy_docstores()++ assert result["hardening_errors"] == 0def test_rekey_rejects_dimension_mismatch_before_reconstruction(