Skip to content

The agent that grows with you

refactor(gateway): name the machinery display kind once; drop a dead isinstance guard

kshitijk4poor54d3217578bd
diff --git a/gateway/response_filters.py b/gateway/response_filters.py
index aaa53900bae..5d495e9f7c1 100644
--- a/gateway/response_filters.py
+++ b/gateway/response_filters.py
@@ -14,10 +14,10 @@ from typing import Any
# error/empty-response path, not silence.
LIVE_GATEWAY_SILENT_MARKERS = frozenset({"[SILENT]", "SILENT", "NO_REPLY", "NO REPLY"})
-# Only these persisted user-row kinds may vanish on a bare marker; a human turn must get a
-# visible fallback instead. "internal_notification" is the only value gateway/run_turn.py
-# ever passes as persist_user_display_kind (self-injected MessageEvent(internal=True) turns).
-MACHINERY_DISPLAY_KINDS = frozenset({"internal_notification"})
+# The persisted user-row kind of a self-injected MessageEvent(internal=True) turn — the only
+# machinery kind the gateway produces; only these may vanish on a bare silence marker.
+INTERNAL_NOTIFICATION_DISPLAY_KIND = "internal_notification"
+MACHINERY_DISPLAY_KINDS = frozenset({INTERNAL_NOTIFICATION_DISPLAY_KIND})
# Longer than any marker could plausibly be, even with stray punctuation.
_MARKER_LENGTH_CAP = 64
@@ -87,7 +87,7 @@ def is_intentional_silence_agent_result(agent_result: dict | None, response: Any
def display_kind_for_event(event: Any) -> str | None:
"""The persisted user-row kind for a gateway turn: only self-injected events are machinery."""
- return "internal_notification" if getattr(event, "internal", False) else None
+ return INTERNAL_NOTIFICATION_DISPLAY_KIND if getattr(event, "internal", False) else None
def is_machinery_display_kind(display_kind: Any) -> bool:
diff --git a/gateway/run_turn.py b/gateway/run_turn.py
index c005e41ea30..ec69fa87f6c 100644
--- a/gateway/run_turn.py
+++ b/gateway/run_turn.py
@@ -1386,9 +1386,7 @@ class GatewayTurnMixin:
_intentional_silence = self._is_intentional_silence(agent_result, response)
# A queued (/queue) chain's TERMINAL turn owns the silence verdict, not the event that
# opened the chain: an internal follow-up may go silent, a human one must not.
- _silence_kind = persist_user_display_kind
- if isinstance(agent_result, dict) and "queued_terminal_display_kind" in agent_result:
- _silence_kind = agent_result["queued_terminal_display_kind"]
+ _silence_kind = agent_result.get("queued_terminal_display_kind", persist_user_display_kind)
if _intentional_silence and not is_machinery_display_kind(_silence_kind):
logger.warning(
"silence marker rejected on a user turn: platform=%s chat=%s",