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: Address all PR review comments from djpetti

LearningCircuite56adb7de2c7
diff --git a/src/local_deep_research/advanced_search_system/strategies/browsecomp_entity_strategy.py b/src/local_deep_research/advanced_search_system/strategies/browsecomp_entity_strategy.py
index b84fc14cf1..70f5fb4f46 100644
--- a/src/local_deep_research/advanced_search_system/strategies/browsecomp_entity_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/browsecomp_entity_strategy.py
@@ -834,7 +834,7 @@ Format: SCORE: X.X | REASON: explanation"""
return normalized_results
except Exception:
- logger.exception("Search failed for query")
+ logger.exception(f"Search failed for query '{query}'")
return []
async def _generate_entity_answer(
diff --git a/src/local_deep_research/advanced_search_system/strategies/dual_confidence_strategy.py b/src/local_deep_research/advanced_search_system/strategies/dual_confidence_strategy.py
index d83e9c1552..9c671b404a 100644
--- a/src/local_deep_research/advanced_search_system/strategies/dual_confidence_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/dual_confidence_strategy.py
@@ -319,5 +319,5 @@ UNCERTAINTY: [score]
return total_score
except Exception:
- logger.exception("Error evaluating candidate")
+ logger.exception(f"Error evaluating candidate: {candidate.name}")
return 0.0
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 274893edcb..efcdbec68e 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -381,7 +381,7 @@ class DatabaseManager:
# Store connection
self.connections[username] = engine
- # Note: Since v1 databases are not migratable, we don't attempt
+ # Note: Since v0.x databases are not migratable, we don't attempt
# to add new tables to existing databases. Users will need to
# recreate their database to get new features.
# Future versions will use Alembic for proper migrations.
@@ -439,7 +439,7 @@ class DatabaseManager:
return True
except Exception:
- logger.exception("Integrity check error for user")
+ logger.exception(f"Integrity check error for user: {username}")
return False
def change_password(
@@ -475,7 +475,7 @@ class DatabaseManager:
return True
except Exception:
- logger.exception("Failed to change password for user")
+ logger.exception(f"Failed to change password for user: {username}")
return False
finally:
# Close the connection
diff --git a/src/local_deep_research/memory_cache/warmup.py b/src/local_deep_research/memory_cache/warmup.py
index 8a70e5af24..84ced77264 100644
--- a/src/local_deep_research/memory_cache/warmup.py
+++ b/src/local_deep_research/memory_cache/warmup.py
@@ -90,7 +90,7 @@ class CacheWarmer:
self._warm_user_api_keys(session, user_id)
except Exception:
- logger.exception("Cache warming failed for user")
+ logger.exception(f"Cache warming failed for user: {user_id}")
def _warm_user_settings(self, session, user_id: str) -> None:
"""Warm all user settings."""
diff --git a/src/local_deep_research/news/api.py b/src/local_deep_research/news/api.py
index 456f15d4fc..282b8be09b 100644
--- a/src/local_deep_research/news/api.py
+++ b/src/local_deep_research/news/api.py
@@ -946,6 +946,10 @@ def create_subscription(
import uuid
# Get default refresh interval from settings if not provided
+ # NOTE: This API function accesses the settings DB for convenience when used
+ # within the Flask application context. For programmatic API access outside
+ # the web context, callers should provide refresh_minutes explicitly to avoid
+ # dependency on the settings database being initialized.
if refresh_minutes is None:
try:
from ..utilities.db_utils import get_setting_from_db_main_thread
@@ -954,7 +958,8 @@ def create_subscription(
"news.subscription.refresh_minutes", 240
)
except Exception:
- refresh_minutes = 240 # Fallback to 4 hours
+ # Fallback for when settings DB is not available (e.g., programmatic API usage)
+ refresh_minutes = 240 # Default to 4 hours
with get_user_db_session(user_id) as db_session:
# Create new subscription
diff --git a/src/local_deep_research/news/flask_api.py b/src/local_deep_research/news/flask_api.py
index f71286bb45..52b3e8f660 100644
--- a/src/local_deep_research/news/flask_api.py
+++ b/src/local_deep_research/news/flask_api.py
@@ -103,9 +103,13 @@ def get_news_feed() -> Dict[str, Any]:
# Check for errors in result
if "error" in result and result.get("news_items") == []:
- return jsonify(result), 400 if "must be between" in result[
- "error"
- ] else 500
+ # Sanitize error message before returning to client
+ safe_msg = safe_error_message(
+ Exception(result["error"]), context="get_news_feed"
+ )
+ return jsonify(
+ {"error": safe_msg, "news_items": []}
+ ), 400 if "must be between" in result["error"] else 500
# Debug: Log the result before returning
logger.info(
@@ -333,6 +337,11 @@ def get_current_user_subscriptions() -> Dict[str, Any]:
# Use the API function
result = api.get_subscriptions(user_id)
+ if "error" in result:
+ logger.error(
+ f"Error getting subscriptions for user {user_id}: {result['error']}"
+ )
+ return jsonify({"error": "Failed to retrieve subscriptions"}), 500
return jsonify(result)
except Exception as e:
@@ -400,7 +409,12 @@ def update_subscription(subscription_id: str) -> Dict[str, Any]:
result = api.update_subscription(subscription_id, update_data)
if "error" in result:
- if "not found" in result["error"].lower():
+ # Sanitize error message before returning to client
+ original_error = result["error"]
+ result["error"] = safe_error_message(
+ Exception(original_error), "updating subscription"
+ )
+ if "not found" in original_error.lower():
return jsonify(result), 404
else:
return jsonify(result), 400
@@ -547,6 +561,16 @@ def get_subscription_history(subscription_id: str) -> Dict[str, Any]:
default_limit = settings_manager.get_setting("news.feed.default_limit")
limit = int(request.args.get("limit", default_limit))
result = api.get_subscription_history(subscription_id, limit)
+ if "error" in result:
+ logger.error(
+ f"Error getting subscription history: {result['error']}"
+ )
+ return jsonify(
+ {
+ "error": "Failed to retrieve subscription history",
+ "history": [],
+ }
+ ), 500
return jsonify(result)
except Exception as e:
return jsonify(
@@ -1399,6 +1423,12 @@ def debug_database():
try:
user_id = get_user_id()
result = api.debug_research_items(user_id)
+ if "error" in result:
+ logger.error(
+ f"Debug endpoint error for user {user_id}: {result['error']}"
+ )
+ return jsonify({"error": "Internal server error"}), 500
return jsonify(result)
- except Exception as e:
- return jsonify({"error": safe_error_message(e, "debug endpoint")}), 500
+ except Exception:
+ logger.exception("Exception in debug endpoint")
+ return jsonify({"error": "Internal server error"}), 500
diff --git a/src/local_deep_research/news/web.py b/src/local_deep_research/news/web.py
index 2cd3a2944b..34015b71cb 100644
--- a/src/local_deep_research/news/web.py
+++ b/src/local_deep_research/news/web.py
@@ -166,9 +166,14 @@ def create_news_blueprint():
"database": "connected",
}
)
- except Exception as e:
+ except Exception:
logger.exception("Health check failed")
- return jsonify({"status": "unhealthy", "error": str(e)}), 500
+ return jsonify(
+ {
+ "status": "unhealthy",
+ "error": "An internal error has occurred.",
+ }
+ ), 500
return bp
diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.py
index e472970a9b..9472099d17 100644
--- a/src/local_deep_research/settings/manager.py
+++ b/src/local_deep_research/settings/manager.py
@@ -354,7 +354,7 @@ class SettingsManager(ISettingsManager):
return True
except SQLAlchemyError:
- logger.exception("Error setting value")
+ logger.exception(f"Error setting value for key: {key}")
self.db_session.rollback()
return False
diff --git a/src/local_deep_research/web/routes/metrics_routes.py b/src/local_deep_research/web/routes/metrics_routes.py
index 0ba89f802a..bacd2aafbc 100644
--- a/src/local_deep_research/web/routes/metrics_routes.py
+++ b/src/local_deep_research/web/routes/metrics_routes.py
@@ -1289,7 +1289,7 @@ def api_model_pricing(model_name):
)
except Exception:
- logger.exception("Error getting pricing for model")
+ logger.exception(f"Error getting pricing for model: {model_name}")
return jsonify({"error": "An internal error occurred"}), 500
@@ -1415,7 +1415,9 @@ def api_research_costs(research_id):
)
except Exception:
- logger.exception("Error getting research costs for research")
+ logger.exception(
+ f"Error getting research costs for research: {research_id}"
+ )
return jsonify({"error": "An internal error occurred"}), 500