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.

fix: annotate silent except-pass patterns to prevent hidden bugs (#2964)

LearningCircuitd0949569bbd3
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f679225742..97410d586b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -179,6 +179,14 @@ repos:
files: \.py$
exclude: ^tests/
description: "Ensure close() methods log cleanup failures instead of silently passing"
+ - id: check-silent-exceptions
+ name: Check for silent exception swallowing
+ entry: .pre-commit-hooks/check-silent-exceptions.py
+ language: script
+ files: \.py$
+ exclude: ^(tests/|examples/)
+ description: "Flag except Exception: pass without logging — use logger.debug()
+ or # noqa: silent-exception to suppress"
- id: check-service-context-managers
name: Check services use context managers
entry: .pre-commit-hooks/check-service-context-managers.py
diff --git a/.pre-commit-hooks/check-silent-exceptions.py b/.pre-commit-hooks/check-silent-exceptions.py
new file mode 100755
index 0000000000..fac6870798
--- /dev/null
+++ b/.pre-commit-hooks/check-silent-exceptions.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+"""
+Pre-commit hook to detect silent exception swallowing.
+
+Flags ``except Exception: pass`` and ``except: pass`` patterns where no
+logging, re-raise, or meaningful handling occurs. At minimum a
+``logger.debug()`` should be present so failures are traceable.
+
+Legitimate suppression (e.g. optional cleanup, best-effort parsing)
+should use an inline ``# noqa: silent-exception`` comment to opt out.
+"""
+
+import ast
+import sys
+
+
+NOQA_MARKER = "noqa: silent-exception"
+
+
+class SilentExceptionChecker(ast.NodeVisitor):
+ """AST visitor that flags except handlers whose body is only ``pass``."""
+
+ def __init__(self, filename: str, lines: list[str]):
+ self.filename = filename
+ self.lines = lines
+ self.issues: list[tuple[int, str]] = []
+
+ def visit_ExceptHandler(self, node: ast.ExceptHandler):
+ # Only flag broad catches: bare ``except:`` or ``except Exception:``
+ if node.type is not None and not (
+ isinstance(node.type, ast.Name) and node.type.id == "Exception"
+ ):
+ self.generic_visit(node)
+ return
+
+ if self._is_silent(node) and not self._has_noqa(node):
+ kind = "except:" if node.type is None else "except Exception:"
+ self.issues.append(
+ (
+ node.lineno,
+ f"Silent `{kind} pass` — add at least "
+ f"`logger.debug(...)` or `# {NOQA_MARKER}` to suppress",
+ )
+ )
+
+ self.generic_visit(node)
+
+ # ------------------------------------------------------------------
+
+ @staticmethod
+ def _is_silent(handler: ast.ExceptHandler) -> bool:
+ """True when the handler body contains only ``pass`` statements."""
+ for stmt in handler.body:
+ if isinstance(stmt, ast.Pass):
+ continue
+ # Any raise, call, assignment, etc. counts as handling
+ return False
+ return True
+
+ def _has_noqa(self, handler: ast.ExceptHandler) -> bool:
+ """True when the ``except`` or handler body lines have a noqa comment."""
+ # Check the except line itself and all body lines
+ for node in [handler] + handler.body:
+ idx = node.lineno - 1
+ if 0 <= idx < len(self.lines):
+ if NOQA_MARKER in self.lines[idx]:
+ return True
+ return False
+
+
+def check_file(filepath: str) -> list[tuple[int, str]]:
+ try:
+ with open(filepath, encoding="utf-8") as f:
+ source = f.read()
+ except Exception as exc:
+ return [(0, f"Cannot read file: {exc}")]
+
+ try:
+ tree = ast.parse(source, filename=filepath)
+ except SyntaxError:
+ return []
+
+ lines = source.splitlines()
+ checker = SilentExceptionChecker(filepath, lines)
+ checker.visit(tree)
+ return checker.issues
+
+
+def main() -> int:
+ exit_code = 0
+ for filepath in sys.argv[1:]:
+ for lineno, msg in check_file(filepath):
+ print(f"{filepath}:{lineno}: {msg}")
+ exit_code = 1
+
+ if exit_code:
+ print()
+ print(
+ "Hint: add logging (logger.debug/warning) or "
+ f"suppress with `# {NOQA_MARKER}`"
+ )
+
+ return exit_code
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/src/local_deep_research/advanced_search_system/constraint_checking/strict_checker.py b/src/local_deep_research/advanced_search_system/constraint_checking/strict_checker.py
index 60fa82ffa0..8d40680239 100644
--- a/src/local_deep_research/advanced_search_system/constraint_checking/strict_checker.py
+++ b/src/local_deep_research/advanced_search_system/constraint_checking/strict_checker.py
@@ -254,6 +254,8 @@ Score:
if match:
return max(0.0, min(float(match.group(1)), 1.0))
except Exception:
- pass
+ logger.debug(
+ "best-effort score parsing from LLM response", exc_info=True
+ )
return 0.0
diff --git a/src/local_deep_research/advanced_search_system/strategies/mcp_strategy.py b/src/local_deep_research/advanced_search_system/strategies/mcp_strategy.py
index f04e55008d..bfff6a4e55 100644
--- a/src/local_deep_research/advanced_search_system/strategies/mcp_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/mcp_strategy.py
@@ -1385,7 +1385,7 @@ class MCPSearchStrategy(BaseSearchStrategy):
name = class_name.replace("SearchEngine", "").lower()
return name
except Exception:
- pass
+ logger.debug("best-effort class name extraction", exc_info=True)
return ""
def _execute_specialized_search(
diff --git a/src/local_deep_research/benchmarks/datasets/browsecomp.py b/src/local_deep_research/benchmarks/datasets/browsecomp.py
index 063f6d280a..a4700efaeb 100644
--- a/src/local_deep_research/benchmarks/datasets/browsecomp.py
+++ b/src/local_deep_research/benchmarks/datasets/browsecomp.py
@@ -115,7 +115,10 @@ class BrowseCompDataset(BenchmarkDataset):
)
break
except Exception:
- pass
+ logger.debug(
+ "best-effort decryption attempt with candidate key",
+ exc_info=True,
+ )
processed["answer"] = decrypted_answer
processed["correct_answer"] = decrypted_answer
diff --git a/src/local_deep_research/benchmarks/datasets/utils.py b/src/local_deep_research/benchmarks/datasets/utils.py
index 618ae947d4..2f00bfa79f 100644
--- a/src/local_deep_research/benchmarks/datasets/utils.py
+++ b/src/local_deep_research/benchmarks/datasets/utils.py
@@ -75,7 +75,10 @@ def decrypt(ciphertext_b64: str, password: str) -> str:
)
return result
except Exception:
- pass
+ logger.debug(
+ "best-effort decryption, falls through to next method",
+ exc_info=True,
+ )
# Alternative method 2 - try using the GUID part
try:
@@ -97,7 +100,10 @@ def decrypt(ciphertext_b64: str, password: str) -> str:
)
return result
except Exception:
- pass
+ logger.debug(
+ "best-effort decryption, falls through to next method",
+ exc_info=True,
+ )
# Alternative method 3 - hardcoded key for BrowseComp
try:
@@ -113,7 +119,10 @@ def decrypt(ciphertext_b64: str, password: str) -> str:
)
return result
except Exception:
- pass
+ logger.debug(
+ "best-effort decryption, falls through to failure handling",
+ exc_info=True,
+ )
# If all attempts fail, return the original
logger.debug(
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index 327dee87fa..b82a71e739 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -912,6 +912,9 @@ def wrap_llm_without_think_tags(
_close_base_llm(self.base_llm)
except Exception:
- pass
+ logger.debug(
+ "best-effort cleanup of HTTP clients on shutdown",
+ exc_info=True,
+ )
return ProcessingLLMWrapper(llm)
diff --git a/src/local_deep_research/content_fetcher/fetcher.py b/src/local_deep_research/content_fetcher/fetcher.py
index 2982ae91b9..3494d6d951 100644
--- a/src/local_deep_research/content_fetcher/fetcher.py
+++ b/src/local_deep_research/content_fetcher/fetcher.py
@@ -233,7 +233,11 @@ class ContentFetcher:
try:
metadata = downloader.get_metadata(url)
except Exception:
- pass
+ logger.debug(
+ "Failed to fetch metadata for %s",
+ url,
+ exc_info=True,
+ )
return {
"status": "success",
diff --git a/src/local_deep_research/llm/providers/implementations/custom_openai_endpoint.py b/src/local_deep_research/llm/providers/implementations/custom_openai_endpoint.py
index b0afbbb76b..e741b53721 100644
--- a/src/local_deep_research/llm/providers/implementations/custom_openai_endpoint.py
+++ b/src/local_deep_research/llm/providers/implementations/custom_openai_endpoint.py
@@ -55,7 +55,7 @@ class CustomOpenAIEndpointProvider(OpenAICompatibleProvider):
return True
except Exception:
logger.debug(
- f"Error reading API key setting '{cls.api_key_setting}'",
+ "Error checking provider availability",
exc_info=True,
)
diff --git a/src/local_deep_research/mcp/client.py b/src/local_deep_research/mcp/client.py
index 8bafe3524a..5d0684e7b4 100644
--- a/src/local_deep_research/mcp/client.py
+++ b/src/local_deep_research/mcp/client.py
@@ -390,7 +390,10 @@ class MCPClientManager:
try:
await ctx.__aexit__(None, None, None)
except Exception:
- pass
+ logger.debug(
+ "best-effort cleanup of partially-entered async context",
+ exc_info=True,
+ )
try:
yield self
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.py
index 31d5da561b..d023c549bf 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -2077,7 +2077,10 @@ def index_collection(collection_id):
cleanup_current_thread()
except Exception:
- pass
+ logger.debug(
+ "best-effort thread-local DB session cleanup",
+ exc_info=True,
+ )
thread = threading.Thread(target=index_in_thread)
thread.start()
diff --git a/src/local_deep_research/security/file_integrity/integrity_manager.py b/src/local_deep_research/security/file_integrity/integrity_manager.py
index 2843a9e12f..6cf88d1bc1 100644
--- a/src/local_deep_research/security/file_integrity/integrity_manager.py
+++ b/src/local_deep_research/security/file_integrity/integrity_manager.py
@@ -455,7 +455,11 @@ class FileIntegrityManager:
actual_checksum = verifier.calculate_checksum(file_path)
file_size = file_path.stat().st_size
except Exception:
- pass # Checksum calculation failed, leave as None
+ logger.debug(
+ "Checksum calculation failed for %s",
+ file_path,
+ exc_info=True,
+ )
failure = FileVerificationFailure(
file_record_id=record.id,
diff --git a/src/local_deep_research/security/url_validator.py b/src/local_deep_research/security/url_validator.py
index 7a066d1448..d9e8f6ab1d 100644
--- a/src/local_deep_research/security/url_validator.py
+++ b/src/local_deep_research/security/url_validator.py
@@ -248,7 +248,10 @@ class URLValidator:
for domain in URLValidator.TRUSTED_ACADEMIC_DOMAINS
)
except Exception:
- pass
+ logger.debug(
+ "URL parsing may fail on malformed input; treat as non-academic",
+ exc_info=True,
+ )
return False
diff --git a/src/local_deep_research/utilities/db_utils.py b/src/local_deep_research/utilities/db_utils.py
index 0066a9263e..73d1df8e3e 100644
--- a/src/local_deep_research/utilities/db_utils.py
+++ b/src/local_deep_research/utilities/db_utils.py
@@ -75,8 +75,9 @@ def get_db_session(
if user_session:
return user_session
except Exception:
- # Error accessing Flask context
- pass
+ logger.debug(
+ "Flask context unavailable (CLI/background threads)", exc_info=True
+ )
# No shared database - return None to allow SettingsManager to work without DB
logger.warning(
@@ -192,8 +193,9 @@ def get_setting_from_db_main_thread(
key, default=default_value
)
except Exception:
- # If we can't get a session, fall back to default
- pass
+ logger.debug(
+ "fall back to default if session unavailable", exc_info=True
+ )
except Exception:
logger.exception(f"Error getting setting {key} from database")
diff --git a/src/local_deep_research/utilities/llm_utils.py b/src/local_deep_research/utilities/llm_utils.py
index 524143ddba..00875a33fc 100644
--- a/src/local_deep_research/utilities/llm_utils.py
+++ b/src/local_deep_research/utilities/llm_utils.py
@@ -61,11 +61,7 @@ def get_ollama_base_url(
),
settings_snapshot=settings_snapshot,
)
- return (
- normalize_url(raw_base_url)
- if raw_base_url
- else DEFAULT_OLLAMA_URL
- )
+ return normalize_url(raw_base_url) if raw_base_url else DEFAULT_OLLAMA_URL
def get_server_url(settings_snapshot: Optional[Dict[str, Any]] = None) -> str:
diff --git a/src/local_deep_research/utilities/log_utils.py b/src/local_deep_research/utilities/log_utils.py
index 0d5fbe2731..997c5b9585 100644
--- a/src/local_deep_research/utilities/log_utils.py
+++ b/src/local_deep_research/utilities/log_utils.py
@@ -140,8 +140,7 @@ def _process_log_queue():
except queue.Empty:
continue
except Exception:
- # Don't let logging errors crash the processor
- pass
+ pass # noqa: silent-exception — must not let logging errors crash the log processor thread
def _write_log_to_database(log_entry: dict) -> None:
@@ -167,8 +166,7 @@ def _write_log_to_database(log_entry: dict) -> None:
db_session.add(db_log)
db_session.commit()
except Exception:
- # Ignore database errors in logging
- pass
+ pass # noqa: silent-exception — DB errors in the logging path must not propagate or recurse
def database_sink(message: loguru.Message) -> None:
@@ -250,7 +248,7 @@ def flush_log_queue():
except queue.Empty:
break
except Exception:
- pass
+ pass # noqa: silent-exception — DB errors during log flush must not propagate
if flushed > 0:
logger.debug(f"Flushed {flushed} queued log entries to database")
diff --git a/src/local_deep_research/web/queue/processor_v2.py b/src/local_deep_research/web/queue/processor_v2.py
index 14c726789f..dbf6762ad7 100644
--- a/src/local_deep_research/web/queue/processor_v2.py
+++ b/src/local_deep_research/web/queue/processor_v2.py
@@ -437,7 +437,9 @@ class QueueProcessorV2:
cleanup_current_thread()
except Exception:
- pass
+ logger.debug(
+ "thread-local cleanup on shutdown", exc_info=True
+ )
# Periodic dead-thread sweep (every ~60 seconds).
# See encrypted_db.cleanup_dead_thread_engines() for
@@ -451,7 +453,9 @@ class QueueProcessorV2:
try:
cleanup_dead_threads()
except Exception:
- pass
+ logger.debug(
+ "periodic dead-thread sweep", exc_info=True
+ )
time.sleep(self.check_interval)
diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.py
index b82fab39bc..e7bf9aad5d 100644
--- a/src/local_deep_research/web/routes/research_routes.py
+++ b/src/local_deep_research/web/routes/research_routes.py
@@ -1606,7 +1606,7 @@ def upload_pdf():
try:
file.close()
except Exception:
- pass
+ logger.debug("best-effort file stream close", exc_info=True)
# Prepare response
response_data = {
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index 1257ccd3b2..30a35ab8d5 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -1975,9 +1975,7 @@ def check_ollama_status():
"llm.ollama.url", DEFAULT_OLLAMA_URL
)
base_url = (
- normalize_url(raw_base_url)
- if raw_base_url
- else DEFAULT_OLLAMA_URL
+ normalize_url(raw_base_url) if raw_base_url else DEFAULT_OLLAMA_URL
)
response = safe_get(
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
index 24c7be057e..cc80634fdf 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
@@ -91,7 +91,10 @@ class NasaAdsSearchEngine(BaseSearchEngine):
settings_snapshot=settings_snapshot,
)
except Exception:
- pass
+ logger.debug(
+ "Failed to read nasa_ads.api_key from settings snapshot",
+ exc_info=True,
+ )
# Handle "False" string for api_key
self.api_key = (
@@ -140,7 +143,10 @@ class NasaAdsSearchEngine(BaseSearchEngine):
if year.isdigit(): # Only add if it's a valid year
filters.append(f"year:{year}-9999")
except Exception:
- pass # Skip invalid date formats
+ logger.debug(
+ "best-effort date parsing, invalid formats skipped",
+ exc_info=True,
+ )
if self.min_citations > 0:
filters.append(f"citation_count:[{self.min_citations} TO *]")
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
index c0a5f876b5..6255c47745 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
@@ -90,7 +90,10 @@ class OpenAlexSearchEngine(BaseSearchEngine):
settings_snapshot=settings_snapshot,
)
except Exception:
- pass
+ logger.debug(
+ "Failed to read openalex.email from settings snapshot",
+ exc_info=True,
+ )
# Handle "False" string for email
self.email = email if email and email != "False" else None
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py
index ed85a56a1b..f90517c6bd 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py
@@ -89,7 +89,10 @@ class SemanticScholarSearchEngine(BaseSearchEngine):
settings_snapshot=settings_snapshot,
)
except Exception:
- pass
+ logger.debug(
+ "Failed to read semantic_scholar.api_key from settings snapshot",
+ exc_info=True,
+ )
self.api_key = api_key
self.year_range = year_range
diff --git a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
index c21a74305e..b05be7ff57 100644
--- a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
+++ b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
@@ -204,7 +204,10 @@ def create_rate_limited_llm_wrapper(base_llm, provider: Optional[str] = None):
_close_base_llm(self.base_llm)
except Exception:
- pass
+ logger.debug(
+ "best-effort cleanup of HTTP clients on shutdown",
+ exc_info=True,
+ )
def __str__(self):
return f"RateLimited({str(self.base_llm)})"