Skip to content

The agent that grows with you

fix(gateway): an automation turn a gateway stop interrupts is never told to resend

Tekniumf5b16e1bd9e9
diff --git a/gateway/session_settlement_recovery.py b/gateway/session_settlement_recovery.py
index b6da9cd2496..bec411d9f99 100644
--- a/gateway/session_settlement_recovery.py
+++ b/gateway/session_settlement_recovery.py
@@ -99,7 +99,7 @@ def _publish_completion(authority, live, ref, row, settled, response, captured):
except Exception:
logger.exception('Terminal control cleanup failed for admission %s', row['admission_id'])
complete = completion_payload(row, settled, response, captured)
- notice = owner_stop_notice(captured, settled['outcome'])
+ notice = owner_stop_notice(captured, settled['outcome'], row)
if notice and not complete.get('warning'):
# ``warning`` is the slot every surface already renders on message.complete (Ink activity
# line, Desktop toast), so a turn the owner's stop cut short says why (#134889 F1).
@@ -113,17 +113,25 @@ SHUTDOWN_INTERRUPT_NOTICE = ('Gateway shutting down: this turn was interrupted a
'Send your message again once Hermes is back.')
-def owner_stop_notice(captured, outcome):
+def owner_stop_notice(captured, outcome, row=None):
"""The named notice for a turn the owner's restart/stop interrupted, or None. With the default
``agent.restart_drain_timeout: 0`` a restart interrupts in-flight turns at once; the admission
- settles ``interrupted`` and is never replayed, so the viewer is told the restart did it."""
+ settles ``interrupted`` and is never replayed, so the viewer is told the restart did it.
+ An unattended ``row`` (cron, automation, webhook) has nobody to resend it, so it gets the
+ neutral automation copy instead of resend advice (#134889 GW-20, GW-10's rule)."""
# The cause is the one the turn recorded when it was interrupted (stop() interrupts with these
# reasons), never the runner's flags at publication: a user Stop whose settlement was delayed
# until after shutdown began is still the user's Stop.
from gateway.run import _INTERRUPT_REASON_GATEWAY_RESTART, _INTERRUPT_REASON_GATEWAY_SHUTDOWN
cause = ((captured or {}).get('result') or {}).get('interrupt_message') if outcome == 'interrupted' else None
- return {_INTERRUPT_REASON_GATEWAY_RESTART: RESTART_INTERRUPT_NOTICE,
- _INTERRUPT_REASON_GATEWAY_SHUTDOWN: SHUTDOWN_INTERRUPT_NOTICE}.get(cause)
+ notice = {_INTERRUPT_REASON_GATEWAY_RESTART: RESTART_INTERRUPT_NOTICE,
+ _INTERRUPT_REASON_GATEWAY_SHUTDOWN: SHUTDOWN_INTERRUPT_NOTICE}.get(cause)
+ if notice is not None and row is not None:
+ from gateway.session_unattended_unknown import is_unattended
+ if is_unattended(row):
+ from agent.turn_failure_copy import AUTOMATION_INTERRUPTED_NOTICE
+ return AUTOMATION_INTERRUPTED_NOTICE
+ return notice
def _release_media(authority, row):
diff --git a/tests/gateway/test_restart_interrupt_notice.py b/tests/gateway/test_restart_interrupt_notice.py
index d818398f3b8..ab0219aa716 100644
--- a/tests/gateway/test_restart_interrupt_notice.py
+++ b/tests/gateway/test_restart_interrupt_notice.py
@@ -302,3 +302,23 @@ def test_restart_after_a_pending_redirect_still_gets_the_restart_notice():
assert notice == RESTART_INTERRUPT_NOTICE, (agent._interrupt_message, notice)
finally:
set_interrupt(False)
+
+
[email protected]('cause', ['Gateway restarting', 'Gateway shutting down'])
+ {'principal_id': 'cron-owner', 'payload': {'text': 'job'}},
+ {'principal_id': 'automation:agent:main:telegram:dm:x', 'payload': {'text': 'done'}},
+ {'principal_id': 'person', 'payload': {'text': 'hook', 'native_text_v1': {'webhook_delivery': {}}}},
+])
+def test_automation_turn_the_owner_stop_interrupted_is_never_asked_to_resend(cause, row):
+ """#134889 GW-20: nobody sent an unattended turn, so the owner-stop notice is the neutral
+ automation copy (GW-10's rule), never "Send your message again"."""
+ from agent.turn_failure_copy import AUTOMATION_INTERRUPTED_NOTICE
+ stream = _Stream()
+ live = SimpleNamespace(controls=SimpleNamespace(snapshot=lambda *a: None), event_stream=stream)
+ _publish_completion(SimpleNamespace(runner=None), live, SimpleNamespace(session_id='s'),
+ {'admission_id': 'adm-1', 'request_id': 'sub-1', **row},
+ {'outcome': 'interrupted'}, '', _cause(cause))
+ (frame,) = stream.frames
+ assert frame['warning'] == AUTOMATION_INTERRUPTED_NOTICE
+ assert 'again' not in frame['warning'].replace('not run again', '')