Skip to content

The agent that grows with you

refactor(cron,gateway): count suppressed targets locally; import the wake predicate once

kshitijk4poor5b6876ccc852
diff --git a/cron/scheduler_delivery.py b/cron/scheduler_delivery.py
index 6bcf2ed1d18..124f9672f87 100644
--- a/cron/scheduler_delivery.py
+++ b/cron/scheduler_delivery.py
@@ -1777,7 +1777,6 @@ def _deliver_result(
standalone fallback. ``for_failure=True`` routes failure-category notices through the job's
``failure_deliver`` override when present (NS-788). Returns None on success, else an error."""
job.pop("_bot_chat_delivery_receipts", None)
- job.pop("_notification_suppressed_targets", None)
job.pop("_notification_all_targets_suppressed", None)
targets = _resolve_delivery_targets(job, for_failure=for_failure)
if not targets:
@@ -1867,19 +1866,19 @@ def _deliver_result(
return msg
delivery_errors = []
+ suppressed_targets = 0 # local: `job` is snapshotted into durable deferred records mid-loop
for target in targets:
# A failure notice for a platform that hides warning notifications is a suppressed
# disposition, not a send; requested (non-failure) results are never gated.
from gateway.warning_notifications import warning_notifications_enabled
if (for_failure and target["platform"] != BOT_CHAT_PLATFORM
and not warning_notifications_enabled(target["platform"], user_cfg)):
- job.setdefault("_notification_suppressed_targets", []).append(dict(target))
+ suppressed_targets += 1
continue
# Bot Chat owns admission; never concurrently resume a live owner's transcript.
if target["platform"] == BOT_CHAT_PLATFORM:
bot_chat_error = _deliver_to_bot_chat(job, content, target["chat_id"], for_failure=for_failure)
- if job.pop("_notification_all_targets_suppressed", False):
- job.setdefault("_notification_suppressed_targets", []).append(dict(target))
+ suppressed_targets += job.pop("_notification_all_targets_suppressed", False)
if bot_chat_error:
receipt_target = f"bot-chat:{target['chat_id'] or '(own)'}"
receipt = job.get("_bot_chat_delivery_receipts", {}).get(receipt_target)
@@ -1907,7 +1906,7 @@ def _deliver_result(
# Filter-time drops apply to every target; report them once. A run whose every target was
# suppressed sent nothing, so there is no drop to report.
- if len(job.get("_notification_suppressed_targets", [])) == len(targets):
+ if suppressed_targets == len(targets):
job["_notification_all_targets_suppressed"] = True
else:
delivery_errors.extend(policy_drop_errors)
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py
index 36887f80d47..d29f5d01cb7 100644
--- a/gateway/platforms/base.py
+++ b/gateway/platforms/base.py
@@ -387,6 +387,7 @@ from gateway.platforms.helpers import fence_state_after
from gateway.platforms.base_exec_approval import (
EA_HEADER_TEXT, EA_REASON_LABEL_TEXT, approval_timeout_seconds, format_approval_deadline_line)
from gateway.platforms.event import MessageEvent, MessageType, ProcessingOutcome
+from gateway.warning_notifications import diagnostic_wake_muted
from gateway.session import SessionSource, build_session_key
from gateway.session_transcript import TranscriptReadError
from hermes_constants import get_default_hermes_root, get_hermes_dir, get_hermes_home
@@ -4080,7 +4081,6 @@ class BasePlatformAdapter(ABC):
"""Tell the user a turn failed rather than leaving radio silence (last resort:
a failing notice is logged, never raised). Returns the thread metadata used."""
_thread_metadata = None
- from gateway.warning_notifications import diagnostic_wake_muted
try:
_thread_metadata = _thread_metadata_for_event(event)
error_detail = str(e)[:300] if str(e) else "no details available"
@@ -4238,7 +4238,6 @@ class BasePlatformAdapter(ABC):
response = await self._message_handler(event)
# A muted diagnostic wake ran for the session; its reply is not presented. The
# policy read binds the routed profile; delivery itself stays in the launch scope.
- from gateway.warning_notifications import diagnostic_wake_muted
with self._media_delivery_scope(event.source):
if diagnostic_wake_muted(event):
response = None