Skip to content

The agent that grows with you

fix(gateway): a classic-CLI-driven loop repaints the session's other viewers

Teknium9678e5f4375f
diff --git a/gateway/session_viewer_automation.py b/gateway/session_viewer_automation.py
index 945a8e2b549..825f523cf16 100644
--- a/gateway/session_viewer_automation.py
+++ b/gateway/session_viewer_automation.py
@@ -28,6 +28,7 @@ _CALLS = {
"goal_blocks_tick"}),
"heartbeat": frozenset({"state", "set", "pause", "resume", "clear", "due_prompt", "abandon_fire"}),
}
+_READS = frozenset({"state", "is_waiting", "goal_blocks_tick"})
_FIELDS = frozenset({"session_id", "profile", "kind", "call", "args", "kwargs"})
_ERRORS = (RuntimeError, ValueError, IndexError)
@@ -158,4 +159,9 @@ async def automation(connection, ref, params):
with _profile_runtime_scope(home), _session_workspace(runner, live.source):
return invoke(runner, kind, target, call, args, kwargs)
# The judge and gates block for seconds: off the loop, with the caller's context (profile scope).
- return await asyncio.to_thread(run)
+ result = await asyncio.to_thread(run)
+ if call not in _READS:
+ # The classic CLI drives this session's automation: other viewers (Ink, Desktop) repaint from the event.
+ from gateway.session_control_actions import publish
+ publish(authority, ref.session_id)
+ return result
diff --git a/tests/gateway/test_session_viewer_automation.py b/tests/gateway/test_session_viewer_automation.py
index 4880a728a6f..17c4a1a3a33 100644
--- a/tests/gateway/test_session_viewer_automation.py
+++ b/tests/gateway/test_session_viewer_automation.py
@@ -103,3 +103,18 @@ async def test_loop_and_heartbeat_ticks_are_claimed_on_the_owner(owner):
async def test_unknown_calls_are_refused(owner):
assert (await owner.call('goal', '_save'))['message'] == 'invalid_params'
assert (await owner.call('cron', 'state'))['message'] == 'invalid_params'
+
+
+async def test_cli_driven_loop_changes_repaint_the_other_viewers(owner):
+ """A classic-CLI viewer drives its /loop through this verb; an Ink or Desktop viewer of the same
+ session paints the loop bar from ``session.control.update``, so every mutation publishes it (reads don't)."""
+ updates = []
+ owner.authority.sessions[owner.ref.session_id].event_stream.observers.add(
+ lambda frame: frame['params']['type'] == 'session.control.update' and updates.append(frame['params']['payload']))
+ await owner.call('loop', 'set', 'check the queue', interval_seconds=60)
+ await owner.call('loop', 'fire_tick')
+ assert [u['control']['loop']['awaiting_response'] for u in updates] == [False, True]
+ await owner.call('loop', 'state')
+ await owner.call('loop', 'goal_blocks_tick')
+ assert len(updates) == 2