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.

Merge branch 'dev' into fix/issue-594-remove-settings-wrapper

LearningCircuit1ebcb389c618
diff --cc src/local_deep_research/utilities/db_utils.py
index d4db48a67e,d9b5597d28..53bd56dd2a
--- a/src/local_deep_research/utilities/db_utils.py
+++ b/src/local_deep_research/utilities/db_utils.py
@@@ -141,3 -143,64 +143,66 @@@ def no_db_settings(func: Callable[...,
manager.db_session = db_session
return wrapper
+
+
++
+ def get_setting_from_db_main_thread(
+ key: str, default_value: Any | None = None, username: str | None = None
+ ) -> str | Dict[str, Any] | None:
+ """
+ Get a setting from the database with fallback to default value
+
+ Args:
+ key: The setting key.
+ default_value: If the setting is not found, it will return this instead.
+ username: Optional username for thread context (e.g., background research threads).
+
+ Returns:
+ The setting value.
+
+ """
+ # In fallback LLM mode, always return default values without database access
+ if use_fallback_llm():
+ logger.debug(
+ f"Using default value for {key} in fallback LLM environment"
+ )
+ return default_value
+
+ # CRITICAL: Detect if we're in a background thread and raise an error
+ import threading
+
+ # Check if we're in a background thread
+ thread_name = threading.current_thread().name
+
+ # Allow MainThread during startup, but not other threads
+ if not has_app_context() and thread_name != "MainThread":
+ thread_id = threading.get_ident()
+ raise RuntimeError(
+ f"get_db_setting('{key}') called from background thread '{thread_name}' (ID: {thread_id}). "
+ f"Database access from threads is not allowed. Use settings_snapshot or thread-local settings context."
+ )
+
+ try:
+ # Use the new session context to ensure proper database access
+ from ..database.session_context import get_user_db_session
+
+ try:
+ with get_user_db_session(username) as db_session:
+ if db_session:
+ # Use the unified settings manager
+ settings_manager = get_settings_manager(
+ db_session, username
+ )
+ return settings_manager.get_setting(
+ key, default=default_value
+ )
+ except Exception:
+ # If we can't get a session, fall back to default
+ pass
+
+ except Exception:
+ logger.exception(f"Error getting setting {key} from database")
+
+ logger.warning(f"Could not read setting '{key}' from the database.")
+ return default_value
++