~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
chore(db): log cleanup errors in journal_quality/db.py instead of silent pass (#3570)
LearningCircuitd581ce8b1a62
diff --git a/src/local_deep_research/journal_quality/db.py b/src/local_deep_research/journal_quality/db.pyindex dbdbc0ff67..d4c04fe7e6 100644--- a/src/local_deep_research/journal_quality/db.py+++ b/src/local_deep_research/journal_quality/db.py@@ -278,14 +278,30 @@ class JournalQualityDB:@staticmethoddef _unlink_unusable_db(path: Path) -> None:+ """Best-effort cleanup of a corrupted / schema-drifted DB file.++ Corruption was already logged by the caller (``_validate_existing_db``).+ Both operations below are best-effort — on failure we *log and+ continue* rather than raise, because the build path will rebuild+ the file regardless. But we don't silence: if chmod / unlink+ fails (permissions, read-only mount, file held open on Windows)+ the next build will likely also fail and the user needs the+ warning to diagnose the real problem.+ """try:os.chmod(path, 0o644)except OSError:- pass+ logger.warning(+ f"Could not chmod 0644 on unusable DB {path} before "+ f"unlink (continuing to unlink attempt)"+ )try:path.unlink()except OSError:- pass+ logger.warning(+ f"Could not unlink unusable DB {path} (will be "+ f"overwritten on next build)"+ )def _build_or_raise(self, path: Path) -> None:"""Lazy-build the DB on first access if it's missing."""@@ -1135,10 +1151,17 @@ def build_db(# Atomically swap tmp into place. os.replace is atomic on POSIX and# overwrites an existing output_path if present.if output_path.exists():+ # Prior file is chmod 0444 from the previous build — relax it+ # so os.replace can overwrite. Best-effort: if chmod fails+ # (e.g. read-only mount), os.replace will raise and surface+ # the real problem. Log so the cause is visible.try:os.chmod(output_path, 0o644)except OSError:- pass+ logger.warning(+ f"Could not chmod 0644 on existing {output_path} before "+ f"os.replace; if the replace fails this is likely why"+ )os.replace(tmp_path, output_path)# OS-level read-only flag — third layer of write protection.@@ -1183,7 +1206,14 @@ def build_db(def _sweep_stale_tmp_files(directory: Path, base_name: str) -> None:- """Remove journal_quality.db.tmp-* files older than 1h."""+ """Remove journal_quality.db.tmp-* files older than 1h.++ Per-file OSError (vanished between glob+stat, no permission, etc.)+ is logged at debug — the sweep is best-effort and shouldn't stop+ the build, but silent-pass on filesystem errors hides the cause of+ accumulating stale tmp files that would otherwise eat disk over+ time.+ """if not directory.exists():returncutoff = time.time() - 3600@@ -1193,7 +1223,7 @@ def _sweep_stale_tmp_files(directory: Path, base_name: str) -> None:tmp.unlink()logger.info(f"Swept stale temp build file: {tmp.name}")except OSError:- pass+ logger.debug(f"Could not sweep stale tmp file {tmp.name}")# ---------------------------------------------------------------------------diff --git a/tests/journal_quality/test_db.py b/tests/journal_quality/test_db.pyindex f6d78b18a8..044910b391 100644--- a/tests/journal_quality/test_db.py+++ b/tests/journal_quality/test_db.py@@ -682,3 +682,57 @@ class TestReadOnlyEnforcement:with pytest.raises(OperationalError, match="readonly"):s.commit()s.rollback()+++# ---------------------------------------------------------------------------+# Cleanup-path logging+# ---------------------------------------------------------------------------+++class TestUnlinkUnusableDbLogs:+ """``_unlink_unusable_db`` does best-effort corruption-recovery+ cleanup. Previously swallowed OSError silently; now logs so a+ chmod/unlink failure surfaces in the ops log instead of quietly+ masking the real underlying problem (read-only mount, Windows+ file-in-use, permissions).+ """++ def test_chmod_failure_logs_warning(self, tmp_path, loguru_caplog):+ from local_deep_research.journal_quality.db import JournalQualityDB++ dead_path = tmp_path / "nonexistent.db" # chmod will raise FileNotFound+ # 30 == WARNING in the stdlib level numbering that loguru_caplog+ # maps from (see tests/conftest.py::loguru_caplog fixture).+ with loguru_caplog.at_level(30):+ JournalQualityDB._unlink_unusable_db(dead_path)++ # Both chmod and unlink fail on a missing file — we expect a+ # warning mentioning the path, not silent success.+ assert any(+ "chmod" in rec.message.lower() and str(dead_path) in rec.message+ for rec in loguru_caplog.records+ ), "chmod failure on cleanup must be logged, not silenced"+ assert any(+ "unlink" in rec.message.lower() and str(dead_path) in rec.message+ for rec in loguru_caplog.records+ ), "unlink failure on cleanup must be logged, not silenced"++ def test_success_path_is_silent(self, tmp_path, loguru_caplog):+ """Happy path: both chmod and unlink succeed → nothing logged+ above WARNING level. Otherwise we'd pollute logs on every+ schema-drift rebuild.+ """+ from local_deep_research.journal_quality.db import JournalQualityDB++ path = tmp_path / "doomed.db"+ path.write_text("x")+ path.chmod(0o444) # simulate the real post-build chmod+ with loguru_caplog.at_level(30): # WARNING+ JournalQualityDB._unlink_unusable_db(path)+ assert not path.exists()+ # No WARNING records for chmod / unlink in success case.+ assert not any(+ "unlink" in rec.message.lower() or "chmod" in rec.message.lower()+ for rec in loguru_caplog.records+ if rec.levelname == "WARNING"+ )