Skip to content

The agent that grows with you

fix(gateway): exempt cron artifacts from the silence-narration drop

kaiompd3b4217b97bd
diff --git a/gateway/delivery.py b/gateway/delivery.py
index fa43db6d0f9..f63c769aeb2 100644
--- a/gateway/delivery.py
+++ b/gateway/delivery.py
@@ -530,7 +530,18 @@ class DeliveryRouter:
# platform adapter regardless of which persona's prompt failed.
# Local/file delivery (_deliver_local) is a separate path and is never
# filtered β€” saved silence has no loop risk.
- if self._filter_silence_narration_enabled() and _is_silence_narration(content):
+ # Cron output is an ARTIFACT, not model chatter: a job whose brief is
+ # legitimately terse ("...", a single πŸ”‡ from a script) has no bot-to-bot
+ # mirror loop to guard against, and dropping it here while returning
+ # {"success": True} is exactly how a cron was logged as delivered with
+ # nothing on the wire (#77763). Cron sends carry job_id in metadata;
+ # every other caller keeps the filter unchanged.
+ is_cron_artifact = "job_id" in (metadata or {})
+ if (
+ self._filter_silence_narration_enabled()
+ and not is_cron_artifact
+ and _is_silence_narration(content)
+ ):
logger.warning(
"Dropped silence-narration outbound to %s (chat=%s): %r",
target.platform.value,
diff --git a/tests/gateway/test_delivery_silence_filter.py b/tests/gateway/test_delivery_silence_filter.py
index 1013e4bc755..11b7ba32965 100644
--- a/tests/gateway/test_delivery_silence_filter.py
+++ b/tests/gateway/test_delivery_silence_filter.py
@@ -124,6 +124,50 @@ async def test_env_override_enables_filter_over_config(tmp_path, monkeypatch):
assert result["filtered"] == "silence_narration"
+# --- Cron artifacts are exempt ----------------------------------------------
+#
+# The filter exists to stop bot-to-bot mirror loops of *model chatter*. Cron
+# output is an artifact: a job that legitimately emits "..." (a quiet script,
+# a terse digest) has no loop partner, and dropping it while returning
+# {"success": True} produced a cron the scheduler logged as delivered and the
+# user never received (#77763). Cron sends carry job_id in metadata.
+
+
+async def test_cron_job_id_metadata_bypasses_the_filter(tmp_path, monkeypatch):
+ monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
+ monkeypatch.delenv("HERMES_FILTER_SILENCE_NARRATION", raising=False)
+ adapter = RecordingAdapter()
+ router = DeliveryRouter(GatewayConfig(), adapters={Platform.DISCORD: adapter})
+ target = DeliveryTarget.parse("discord:99887766")
+
+ result = await router._deliver_to_platform(
+ target, "*(silent)*", metadata={"job_id": "92e639af907f"},
+ )
+
+ assert len(adapter.calls) == 1
+ assert adapter.calls[0]["content"] == "*(silent)*"
+ assert result.get("filtered") is None
+ assert result.get("delivered") is not False
+
+
+async def test_non_cron_metadata_still_filters(tmp_path, monkeypatch):
+ """The exemption keys on job_id alone β€” everything else is unchanged."""
+ monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
+ monkeypatch.delenv("HERMES_FILTER_SILENCE_NARRATION", raising=False)
+ adapter = RecordingAdapter()
+ router = DeliveryRouter(GatewayConfig(), adapters={Platform.DISCORD: adapter})
+ target = DeliveryTarget.parse("discord:99887766")
+
+ result = await router._deliver_to_platform(
+ target, "*(silent)*", metadata={"thread_id": "42", "user_id": "u1"},
+ )
+
+ assert adapter.calls == []
+ assert result["filtered"] == "silence_narration"
+
+
# --- Config round-trip ------------------------------------------------------