Skip to content

The agent that grows with you

fix(gateway): publish the background review summary to local viewers

Teknium35e14dd88748
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.py
index 65110d9fd81..87fa6b06429 100644
--- a/gateway/run_turn_runner.py
+++ b/gateway/run_turn_runner.py
@@ -273,7 +273,19 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):
pending: list[str] = []
pending_lock = threading.Lock()
+ owner = self._approval_owner
+ local_viewer = owner is not None and getattr(ctx.source, "platform", None) == Platform.LOCAL
+
def deliver(message: str) -> None:
+ if local_viewer and owner is not None:
+ # LocalSessionAdapter.send publishes nothing, so a local viewer only sees the
+ # summary as the in-process TUI's review.summary frame. Not generation-fenced:
+ # the review fork finishes after this turn's running claim has settled.
+ authority, session_id, _generation = owner
+ live = authority.sessions.get(session_id)
+ if live is not None:
+ live.event_stream.publish(session_id, {"text": str(message)}, event_type="review.summary")
+ return
if self._status_live():
self._send_status_text(
message,
@@ -290,6 +302,11 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):
deliver(message)
def send(message: str) -> None:
+ if local_viewer:
+ # Same as the in-process TUI: no post-delivery hold (the local route has no
+ # platform send to wait for) and no run-generation gate.
+ deliver(message)
+ return
if not self._status_live():
return
if not release_evt.is_set():
diff --git a/tests/gateway/test_local_review_summary_event.py b/tests/gateway/test_local_review_summary_event.py
new file mode 100644
index 00000000000..0a708a1c28f
--- /dev/null
+++ b/tests/gateway/test_local_review_summary_event.py
@@ -0,0 +1,58 @@
+"""A local viewer sees the background review's summary as a ``review.summary`` event.
+
+LocalSessionAdapter.send publishes nothing (TurnRunner owns the canonical stream), so the
+"💾 Self-improvement review: …" line handed to the status adapter reached no Desktop/TUI
+viewer once every local turn ran through the session authority. The in-process tui_gateway
+emitted it as ``review.summary``; the authority route must publish the same frame.
+"""
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+from gateway.config import Platform
+from gateway.run_turn_runner import TurnRunner
+
+
+def _runner(platform, published):
+ turn = object.__new__(TurnRunner)
+ adapter_sends = []
+
+ async def send(chat_id, text, metadata=None):
+ adapter_sends.append(text)
+
+ turn._ctx = SimpleNamespace(
+ source=SimpleNamespace(platform=platform),
+ _status_adapter=SimpleNamespace(send=send),
+ _status_chat_id='chat',
+ _status_thread_metadata=None,
+ _run_still_current=lambda: True,
+ )
+ live = SimpleNamespace(event_stream=SimpleNamespace(
+ publish=lambda sid, payload, event_type: published.append((sid, event_type, payload)) or True))
+ authority = SimpleNamespace(sessions={'s': live})
+ turn._approval_owner = (authority, 's', 3)
+ turn._schedule = lambda coro, _msg: coro.close()
+ return turn, adapter_sends
+
+
+def test_local_review_summary_is_a_review_summary_event_even_after_the_turn_settled():
+ published = []
+ turn, adapter_sends = _runner(Platform.LOCAL, published)
+ turn._ctx._run_still_current = lambda: False # the review fork outlives the turn
+ send, _release = turn._make_bg_review_callbacks()
+ send('💾 Self-improvement review: memory updated')
+ # No post-delivery hold on the local route (nothing ever fires it there), as in-process.
+ assert published == [('s', 'review.summary', {'text': '💾 Self-improvement review: memory updated'})]
+ assert adapter_sends == []
+
+
+def test_platform_review_summary_still_waits_for_the_post_delivery_release():
+ published = []
+ turn, _ = _runner(Platform.TELEGRAM, published)
+ sent = []
+ turn._send_status_text = lambda text, metadata, msg: sent.append(text)
+ send, release = turn._make_bg_review_callbacks()
+ send('💾 Memory updated')
+ assert sent == []
+ release()
+ assert sent == ['💾 Memory updated'] and published == []