Skip to content

The agent that grows with you

fix(gateway): a local viewer's sticky notice clears on recovery

Teknium9d99a1c89c16
diff --git a/gateway/run_turn_progress.py b/gateway/run_turn_progress.py
index f42d24e8cf4..ad0d9eb8147 100644
--- a/gateway/run_turn_progress.py
+++ b/gateway/run_turn_progress.py
@@ -880,6 +880,11 @@ class GatewayTurnProgressMixin:
"ttl_ms": notice.ttl_ms, "key": notice.key, "id": notice.id}),
platform=ctx.source.platform, user_config=ctx.user_config, diagnostic=is_diagnostic_notice(notice))
+ def _local_notice_clear_callback_sync(self, key) -> None:
+ """Recovery -> ``notification.clear`` for local viewers (main's TUI payload)."""
+ if key and self._status_live():
+ self._publish_execution("notification.clear", {"key": str(key)})
+
def _status_live(self) -> bool:
"""Status adapter present and this run is still the current generation."""
return bool(self._ctx._status_adapter) and self._ctx._run_still_current()
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.py
index 3927e9394d7..f6c8c8105c4 100644
--- a/gateway/run_turn_runner.py
+++ b/gateway/run_turn_runner.py
@@ -406,7 +406,8 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):
if api_execution.get() is not None:
# The API request's SSE observes reasoning/status/commentary through its admission.
wire_api_observers(agent, self._approval_owner, want_interim_messages)
- agent.notice_clear_callback = None # sends can't be retracted
+ # A platform send can't be retracted; a local viewer withdraws the keyed notice.
+ agent.notice_clear_callback = self._local_notice_clear_callback_sync if local_viewer_turn(self) else None
agent.event_callback = ctx._event_callback_sync
agent.reasoning_config, agent.service_tier = reasoning_config, runner._service_tier
self._merge_turn_request_overrides(agent, turn_route)
diff --git a/tests/gateway/fixtures/local_status_notice_peer.py b/tests/gateway/fixtures/local_status_notice_peer.py
index 86d5fb66be8..ebb578b5432 100644
--- a/tests/gateway/fixtures/local_status_notice_peer.py
+++ b/tests/gateway/fixtures/local_status_notice_peer.py
@@ -50,6 +50,7 @@ async def probe():
self._emit_warning('PROBE_WARNING_STATUS')
self._emit_status('PROBE_LIFECYCLE_STATUS')
self._emit_notice(AgentNotice(text='PROBE_NOTICE', level='warn', key='probe', id='probe'))
+ self._emit_notice_clear('probe') # recovery withdraws the sticky notice (main: notification.clear)
return original(self, *args, **kwargs)
run_agent.AIAgent.run_conversation = run_conversation
@@ -88,7 +89,7 @@ async def probe():
view._dispatch_event(params['type'], params.get('admission_id'), params.get('payload', {}))
Path(os.environ['HERMES_HOME'], 'receipt.json').write_text(json.dumps({
'events': [[p['type'], p.get('payload')] for p in events if p['type'] in (
- 'status.update', 'notification.show')], 'cli_stderr': printed.getvalue()}))
+ 'status.update', 'notification.show', 'notification.clear')], 'cli_stderr': printed.getvalue()}))
finally:
await ws.close()
await stop_gateway_api(api)
diff --git a/tests/gateway/test_local_viewer_status_notice.py b/tests/gateway/test_local_viewer_status_notice.py
index 306290ce8f9..4ac8521d6d8 100644
--- a/tests/gateway/test_local_viewer_status_notice.py
+++ b/tests/gateway/test_local_viewer_status_notice.py
@@ -16,6 +16,7 @@ SHOWN = [['status.update', {'kind': 'warn', 'text': 'PROBE_WARNING_STATUS'}],
['status.update', {'kind': 'lifecycle', 'text': 'PROBE_LIFECYCLE_STATUS'}],
['notification.show', {'text': 'PROBE_NOTICE', 'level': 'warn', 'kind': 'sticky', 'ttl_ms': None,
'key': 'probe', 'id': 'probe'}]]
+CLEARED = ['notification.clear', {'key': 'probe'}]
@pytest.mark.parametrize('mode', ['default', 'suppress'])
@@ -32,6 +33,7 @@ def test_local_viewer_receives_agent_status_and_notices(tmp_path, mode):
assert result.returncode == 0, result.stdout + '\n' + result.stderr
receipt = json.loads((state / 'receipt.json').read_text())
# display.suppress_warning_notifications still hides the diagnostics (warn status, warn notice).
- expected = SHOWN if mode == 'default' else [SHOWN[1]]
+ # The recovery clear always reaches the viewer, as main's TUI emitted it (clearing nothing is a no-op).
+ expected = (SHOWN if mode == 'default' else [SHOWN[1]]) + [CLEARED]
assert receipt['events'] == expected
- assert receipt['cli_stderr'].split() == [payload['text'] for _, payload in expected]
+ assert receipt['cli_stderr'].split() == [payload['text'] for _, payload in expected if 'text' in payload]