From c6c2c32d8c000778605c7d86d59e3c52e6c7b235 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 28 Sep 2026 01:34:09 +0000 Subject: [PATCH] Skip reply alerts for silent scheduled runs A cron run that answers with Hermes's silence marker ([SILENT]) is suppressed on its delivery lane by the scheduler, but the post_llm_call reply alert (added in 2.17.0) still pushed the raw marker to the phone. Scheduled sessions now check the reply with Hermes's own gateway.response_filters.is_autonomous_silence_response, the predicate the scheduler uses, and keep no reply when it matches. That covers both the immediate alert and the on_session_end fallback. Failed runs still alert, and interactive chats are unchanged. Co-Authored-By: Claude Opus 5.5 --- loopdy_plugin/managed_notifications.py | 22 ++++++++++++++++++++-- tests/test_managed_notifications.py | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/loopdy_plugin/managed_notifications.py b/loopdy_plugin/managed_notifications.py index b7e6a75..2f8ff5a 100644 --- a/loopdy_plugin/managed_notifications.py +++ b/loopdy_plugin/managed_notifications.py @@ -43,6 +43,19 @@ _ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$") _PROFILE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$") _CRON_SESSION = re.compile(r"^cron_.+_\d{8}_\d{6}$") + + +def _is_scheduled_silence(response: Any) -> bool: + """True when a scheduled run replied with Hermes's cron silence marker (e.g. ``[SILENT]``). + + Uses the same predicate the cron scheduler uses to skip delivery, so a run that stays + silent on its delivery lane never reaches the phone as a push either. + """ + try: + from gateway.response_filters import is_autonomous_silence_response + except ImportError: + return isinstance(response, str) and response.strip().upper().startswith("[SILENT]") + return is_autonomous_silence_response(response) _EVENT_TYPES = { "session.completed", "session.failed", "scheduled.completed", "scheduled.failed", "approval.required", "clarification.required", "subagent.completed", "subagent.failed", @@ -740,8 +753,14 @@ def _observe(self, hook: str, *, profile: str, **payload: Any): turn = payload.get("turn_id") if hook == "post_llm_call" and isinstance(turn, str) and _ID.fullmatch(turn): coordinate = (profile, session_id, turn) + scheduled = payload.get("platform") == "cron" or _CRON_SESSION.fullmatch(session_id) is not None try: - response_text = self._rich_text(payload.get("assistant_response")) + # A silent scheduled run keeps no reply, so neither this alert nor the + # on_session_end fallback pushes the marker. Failures still alert. + if scheduled and _is_scheduled_silence(payload.get("assistant_response")): + response_text = "" + else: + response_text = self._rich_text(payload.get("assistant_response")) except ManagedNotificationError: response_text = "" if response_text: @@ -754,7 +773,6 @@ def _observe(self, hook: str, *, profile: str, **payload: Any): # reply is saved. on_session_end comes only after post-turn work (external memory # sync, reviews) that can take several seconds, so the reply alert goes out now. if response_text and not child_hook: - scheduled = payload.get("platform") == "cron" or _CRON_SESSION.fullmatch(session_id) is not None try: self._queue_event(profile, session_id, turn, "scheduled.completed" if scheduled else "session.completed", diff --git a/tests/test_managed_notifications.py b/tests/test_managed_notifications.py index 2bc4290..a98da90 100644 --- a/tests/test_managed_notifications.py +++ b/tests/test_managed_notifications.py @@ -234,6 +234,30 @@ def test_scheduled_run_alerts_without_a_session_subscription(self): self.service.drain_pending() self.assertIn("scheduled.completed",[e["eventType"] for e in self.events_sent()]) + def test_silent_scheduled_run_sends_no_alert(self): + # Regression: a cron run answering "[SILENT]" skipped Telegram delivery but + # still reached the phone as a push reading "[SILENT]". + self.grant["eventTypes"]=["scheduled.completed","scheduled.failed","session.completed","session.failed"] + grant_id=str(uuid.uuid4()); self.grant["grantId"]=grant_id; self.grant_id=grant_id + self.service.enroll(grant_id,str(uuid.uuid4())); self.calls.clear() + cron="cron_143638f07ae3_20260927_185802" + for turn,reply in (("turn-s","[SILENT]"),("turn-t","[SILENT] No qualifying restock.")): + self.service.observe("post_llm_call",profile="default",session_id=cron,turn_id=turn,assistant_response=reply,platform="cron") + self.service.observe("on_session_end",profile="default",session_id=cron,turn_id=turn,completed=True,platform="cron") + self.service.drain_pending() + self.assertEqual(self.events_sent(),[]) + self.service.observe("post_llm_call",profile="default",session_id=cron,turn_id="turn-r",assistant_response="Restock: ETB in stock at MSRP.",platform="cron") + self.service.observe("on_session_end",profile="default",session_id=cron,turn_id="turn-r",completed=True,platform="cron") + self.service.observe("on_session_end",profile="default",session_id=cron,turn_id="turn-f",failed=True,error="provider unreachable",platform="cron") + self.service.drain_pending() + self.assertEqual([e["eventType"] for e in self.events_sent()],["scheduled.completed","scheduled.failed"]) + + def test_silence_marker_in_chat_still_alerts(self): + self.service.observe("post_llm_call",profile="default",session_id="desktop-chat",turn_id="turn-a",assistant_response="[SILENT]") + self.service.observe("on_session_end",profile="default",session_id="desktop-chat",turn_id="turn-a",completed=True,platform="desktop") + self.service.drain_pending() + self.assertEqual([e["eventType"] for e in self.events_sent()],["session.completed"]) + def test_subagent_completion_alerts_for_an_unopened_parent_session(self): self.grant["eventTypes"]=["session.completed","session.failed","subagent.completed","subagent.failed"] grant_id=str(uuid.uuid4()); self.grant["grantId"]=grant_id; self.grant_id=grant_id