Skip to content

The agent that grows with you

fix(gateway): session.control publishes session.control.update to every viewer

unsupportedpastels9085061a8ce1
diff --git a/gateway/session_control_actions.py b/gateway/session_control_actions.py
index 8723c9d69fd..6d8a0e813e4 100644
--- a/gateway/session_control_actions.py
+++ b/gateway/session_control_actions.py
@@ -81,4 +81,7 @@ async def control(connection, ref, params):
result = await execute_command(connection, ref, {**scope, 'name': name, 'arg': arg}, dispatch=True)
from gateway.session_ancillary import read
snapshot = await read(connection, ref, scope, kind='control')
+ # Other viewers (another Desktop window, Ink) repaint their cards from this event, not the reply.
+ connection.authority.sessions[ref.session_id].event_stream.publish(
+ ref.session_id, snapshot, event_type='session.control.update')
return {**snapshot, 'dispatch': {key: result.get(key) for key in _ENVELOPE}}
diff --git a/tests/gateway/fixtures/tui_desktop_routes_peer.py b/tests/gateway/fixtures/tui_desktop_routes_peer.py
index 825d70c5d81..e85d90c2c42 100644
--- a/tests/gateway/fixtures/tui_desktop_routes_peer.py
+++ b/tests/gateway/fixtures/tui_desktop_routes_peer.py
@@ -107,6 +107,10 @@ async def _control(authority, ws, reader, sid, marker, receipt):
assert 'result' in typed, (command, typed)
denied = await _call(reader, 'session.control', session_id=sid, action='goal.pause')
assert _error(denied) == 'permission_denied', denied
+ # Every other viewer of the session: what its card repaints from.
+ updates = []
+ authority.sessions[sid].event_stream.observers.add(
+ lambda frame: frame['params']['type'] == 'session.control.update' and updates.append(frame['params']))
for action, check in [
('goal.pause', lambda c: c['goal']['status'] == 'paused'),
('goal.resume', lambda c: c['goal']['status'] == 'active'),
@@ -120,6 +124,8 @@ async def _control(authority, ws, reader, sid, marker, receipt):
assert set(reply['result']['dispatch']) == {'type', 'output', 'notice', 'message', 'display'}, reply
read = await rpc(ws, 'session.control.read', session_id=sid)
assert read['result']['control'] == reply['result']['control'], (action, read, reply)
+ assert updates and updates[-1]['session_id'] == sid, (action, updates)
+ assert updates.pop()['payload'] == {'control': reply['result']['control']}, (action, reply)
# Free subgoal text is a criterion, never a /subgoal verb.
added = await control('subgoal.add', text='clear the cache first')
assert added['result']['control']['goal']['subgoals'] == ['clear the cache first'], added