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.

refactor: Move all notification logic to notification module

LearningCircuit903932f68be2
diff --git a/src/local_deep_research/notifications/__init__.py b/src/local_deep_research/notifications/__init__.py
index bce1ed2f49..d0ef598e7b 100644
--- a/src/local_deep_research/notifications/__init__.py
+++ b/src/local_deep_research/notifications/__init__.py
@@ -22,6 +22,7 @@ from ..security.url_validator import URLValidator, URLValidationError
from .queue_helpers import (
send_queue_notification,
send_queue_failed_notification,
+ send_queue_failed_notification_from_session,
)
__all__ = [
@@ -38,4 +39,5 @@ __all__ = [
"URLValidationError",
"send_queue_notification",
"send_queue_failed_notification",
+ "send_queue_failed_notification_from_session",
]
diff --git a/src/local_deep_research/notifications/queue_helpers.py b/src/local_deep_research/notifications/queue_helpers.py
index cec685b216..d649d19686 100644
--- a/src/local_deep_research/notifications/queue_helpers.py
+++ b/src/local_deep_research/notifications/queue_helpers.py
@@ -109,3 +109,53 @@ def send_queue_failed_notification(
f"Failed to send failed notification for {research_id}: {e}"
)
return False
+
+
+def send_queue_failed_notification_from_session(
+ username: str,
+ research_id: str,
+ query: str,
+ error_message: str,
+ db_session,
+) -> None:
+ """
+ Send a research failed notification, fetching settings from db_session.
+
+ This is a convenience wrapper for the queue processor that handles
+ settings snapshot retrieval, logging, and error handling internally.
+ All notification logic is contained within this function.
+
+ Args:
+ username: User who owns the research
+ research_id: UUID of the research
+ query: Research query string
+ error_message: Error message to include in notification
+ db_session: Database session to fetch settings from
+ """
+ try:
+ from ...settings import SettingsManager
+
+ # Get settings snapshot from database session
+ settings_manager = SettingsManager(db_session)
+ settings_snapshot = settings_manager.get_settings_snapshot()
+
+ # Send notification using the helper function
+ success = send_queue_failed_notification(
+ username=username,
+ research_id=research_id,
+ query=query,
+ error_message=error_message,
+ settings_snapshot=settings_snapshot,
+ )
+
+ if success:
+ logger.info(f"Sent failure notification for research {research_id}")
+ else:
+ logger.debug(
+ f"Failed to send failure notification for {research_id} (disabled or rate limited)"
+ )
+
+ except Exception:
+ logger.exception(
+ f"Failed to send failure notification for {research_id}"
+ )
diff --git a/src/local_deep_research/web/queue/processor.py b/src/local_deep_research/web/queue/processor.py
index d66184da0b..aafc5352b0 100644
--- a/src/local_deep_research/web/queue/processor.py
+++ b/src/local_deep_research/web/queue/processor.py
@@ -13,7 +13,9 @@ from ...database.models import (
UserActiveResearch,
)
from ...database.models.memory_queue import get_memory_queue_tracker
-from ...notifications.queue_helpers import send_queue_failed_notification
+from ...notifications.queue_helpers import (
+ send_queue_failed_notification_from_session,
+)
from ..routes.globals import active_research, termination_flags
from ..services.research_service import (
run_research_process,
@@ -577,32 +579,13 @@ class QueueProcessor:
# Send failure notification if status is 'failed'
if op_data["status"] == "failed":
- try:
- from ...settings import SettingsManager
-
- # Get settings snapshot from database session
- settings_manager = SettingsManager(db_session)
- settings_snapshot = settings_manager.get_settings_snapshot()
-
- # Send notification using the helper function
- success = send_queue_failed_notification(
- username=op_data["username"],
- research_id=research_id,
- query=research.query or "Unknown query",
- error_message=op_data.get(
- "error_message", "Unknown error"
- ),
- settings_snapshot=settings_snapshot,
- )
-
- if success:
- logger.info(
- f"Sent failure notification for research {research_id}"
- )
- except Exception:
- logger.exception(
- f"Failed to send failure notification for {research_id}"
- )
+ send_queue_failed_notification_from_session(
+ username=op_data["username"],
+ research_id=research_id,
+ query=research.query or "Unknown query",
+ error_message=op_data.get("error_message", "Unknown error"),
+ db_session=db_session,
+ )
except Exception:
logger.exception(