The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep approval prompts interim instead of tagging them notify
kshitijk4poor943d4caa4720
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex 00aeb82ac22..9b8c663fd0c 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -1475,11 +1475,7 @@ class TurnRunner:fut = self._schedule(adapter.send_exec_approval(chat_id=ctx._status_chat_id, command=cmd, session_key=ctx.session_key or "",- description=desc,- # Push, don't silently deliver (#132516): a card that lands with- # disable_notification=True is indistinguishable from "no prompt" and- # burns the whole approval window. Mirrors the cron-delivery convention.- metadata={**(ctx._status_thread_metadata or {}), "notify": True}, **flags,+ description=desc, metadata=ctx._status_thread_metadata, **flags,),"send_exec_approval scheduling error",)@@ -1540,9 +1536,9 @@ class TurnRunner:# in Slack threads and reserved by Matrix clients.msg = _format_exec_approval_fallback(cmd, desc, getattr(adapter, "typed_command_prefix", "/"), **flags)try:- # Mark as approval prompt so WeCom routes through the control lane; notify=True so- # "important"-mode Telegram pushes instead of silently delivering the prompt (#132516).- metadata = {**(ctx._status_thread_metadata or {}), "notify": True, "is_approval_prompt": True}+ # Mark as approval prompt: WeCom routes it through the control lane and Telegram pushes it+ # in "important" mode (#132516). Never ``notify`` — A2A reads that as the turn-final reply.+ metadata = {**(ctx._status_thread_metadata or {}), "is_approval_prompt": True}fut = self._schedule(adapter.send(ctx._status_chat_id, msg, metadata=_interim_metadata(metadata)), "Approval text-send scheduling error",)diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.pyindex 8ba2b4eef33..2e3dcf95288 100644--- a/plugins/platforms/telegram/adapter.py+++ b/plugins/platforms/telegram/adapter.py@@ -889,14 +889,9 @@ class TelegramAdapter(BasePlatformAdapter):self._schedule_held_inbound_redispatch()def _notification_kwargs(self, metadata: Optional[Dict[str, Any]]) -> Dict[str, Any]:- """In "important" mode return disable_notification=True unless ``metadata["notify"]``.-- An approval prompt never counts as "unimportant": silently delivered prompts are- indistinguishable from "no prompt" and cost the full approval window before the- command is refused (#132516)."""- meta = metadata or {}- if (getattr(self, "_notifications_mode", "important") != "important"- or meta.get("notify") or meta.get("is_approval_prompt")):+ """In "important" mode return disable_notification=True unless ``notify`` or ``is_approval_prompt`` (#132516)."""+ if getattr(self, "_notifications_mode", "important") != "important" or (metadata or {}).get("notify") \+ or (metadata or {}).get("is_approval_prompt"):return {}return {"disable_notification": True}diff --git a/tests/gateway/test_exec_approval_timeout_notice.py b/tests/gateway/test_exec_approval_timeout_notice.pyindex f222af5ff2c..5cf54458d00 100644--- a/tests/gateway/test_exec_approval_timeout_notice.py+++ b/tests/gateway/test_exec_approval_timeout_notice.py@@ -30,7 +30,6 @@ class _ButtonAdapter:def __init__(self, *, editable: bool = True) -> None:self.sends: List[str] = []self.edits: List[tuple] = []- self.card_metadata: List[Any] = []self.send_metadata: List[Any] = []self._editable = editable@@ -38,7 +37,6 @@ class _ButtonAdapter:return Noneasync def send_exec_approval(self, *a: Any, **k: Any) -> SendResult:- self.card_metadata.append(k.get("metadata"))return SendResult(success=True, message_id="card-1")async def send(self, chat_id: str, message: str, **k: Any) -> SendResult:@@ -125,22 +123,12 @@ def test_other_settle_reasons_post_nothing(pending_entry, reason):assert adapter.edits == [] and adapter.sends == []-def test_button_prompt_metadata_carries_notify(pending_entry):- """#132516: the button card send must carry notify=True — a card that lands with- disable_notification=True (Telegram "important" mode) is indistinguishable from- "no prompt" and burns the whole approval window before failing closed."""- adapter = _ButtonAdapter()- _runner(adapter)._approval_notify_sync(dict(pending_entry.data))-- assert adapter.card_metadata == [{"thread_id": "t1", "notify": True}]--def test_text_fallback_metadata_carries_notify_and_approval_marker(pending_entry):- """#132516: the plain-text fallback must carry notify=True (push, don't silently- deliver) plus the is_approval_prompt marker WeCom's control lane keys on."""+def test_text_fallback_is_an_interim_approval_prompt(pending_entry):+ """#132516: the plain-text fallback carries the is_approval_prompt marker (Telegram pushes+ it, WeCom routes it via the control lane) and stays interim — ``notify`` is the turn-final+ marker A2A resolves the caller's task on, so it must not ride an approval prompt."""adapter = _PlainAdapter()_runner(adapter)._approval_notify_sync(dict(pending_entry.data))- assert adapter.send_metadata == [- {"thread_id": "t1", "notify": True, "is_approval_prompt": True, "_interim_send": True}]- assert adapter.send_exec_approval is None # really the fallback lane+ assert adapter.send_metadata == [{"thread_id": "t1", "is_approval_prompt": True, "_interim_send": True}]diff --git a/tests/plugins/platforms/telegram/test_notification_kwargs.py b/tests/plugins/platforms/telegram/test_notification_kwargs.pyindex e23e2cf4f4c..67259b4045e 100644--- a/tests/plugins/platforms/telegram/test_notification_kwargs.py+++ b/tests/plugins/platforms/telegram/test_notification_kwargs.py@@ -1,41 +1,22 @@-"""Telegram notification-mode gating for approval prompts (#132516).--In "important" mode every send carries disable_notification=True unless the metadata-opts out. An approval prompt is the one payload that must ALWAYS opt out: a silently-delivered prompt is indistinguishable from "no prompt" and costs the full-approvals.timeout before the command is refused.+"""Telegram notification-mode gating (#132516): "important" mode silences ordinary sends, but a+human-decision prompt (``is_approval_prompt``) must always push — a silently delivered prompt is+indistinguishable from "no prompt" and costs the full approvals.timeout before the command is refused."""+import pytest+from plugins.platforms.telegram.adapter import TelegramAdapter-def _adapter(mode):[email protected]("mode,metadata,expected", [+ ("important", None, {"disable_notification": True}),+ ("important", {"thread_id": "t1"}, {"disable_notification": True}),+ ("important", {"notify": True}, {}),+ ("important", {"thread_id": "t1", "is_approval_prompt": True}, {}),+ ("all", None, {}),+ ("all", {"is_approval_prompt": True}, {}),+])+def test_notification_kwargs(mode, metadata, expected):adapter = object.__new__(TelegramAdapter)adapter._notifications_mode = mode- return adapter---def test_important_mode_silences_plain_sends():- assert _adapter("important")._notification_kwargs({"thread_id": "t1"}) == {- "disable_notification": True}---def test_important_mode_pushes_notify_marked_sends():- assert _adapter("important")._notification_kwargs({"notify": True}) == {}---def test_important_mode_pushes_approval_prompts():- """#132516: is_approval_prompt must defeat disable_notification even without an- explicit notify marker — covers every surface that marks the prompt."""- assert _adapter("important")._notification_kwargs({"is_approval_prompt": True}) == {}- assert _adapter("important")._notification_kwargs(- {"thread_id": "t1", "is_approval_prompt": True}) == {}---def test_none_metadata_in_important_mode_stays_silent_for_plain_sends():- assert _adapter("important")._notification_kwargs(None) == {"disable_notification": True}---def test_all_mode_never_disables_notifications():- for metadata in (None, {}, {"is_approval_prompt": True}, {"notify": False}):- assert _adapter("all")._notification_kwargs(metadata) == {}+ assert adapter._notification_kwargs(metadata) == expected