Skip to content

The agent that grows with you

fix(tui): post-turn control publish only when automation state exists (keeps plain-session event stream unchanged)

Teknium9a5a78187ab9
diff --git a/tui_gateway/methods_session_control.py b/tui_gateway/methods_session_control.py
index 51996ffc0c7..4160ecf1748 100644
--- a/tui_gateway/methods_session_control.py
+++ b/tui_gateway/methods_session_control.py
@@ -214,15 +214,18 @@ def _goal_blocks_loop_tick(session_key: str) -> bool:
_SESSION_CONTROL_SLASHES = frozenset({"goal", "heartbeat", "loop", "subgoal"})
-def _publish_session_control_snapshot(sid: str, session: dict | None) -> None:
+def _publish_session_control_snapshot(sid: str, session: dict | None, *, only_if_present: bool = False) -> None:
"""Best-effort ``session.control.update`` for one live session. Also called after the post-turn hooks,
because the goal judge and loop tick evaluation mutate persisted state AFTER ``message.complete`` — a
- client refresh keyed on that event reads the pre-judge turn count."""
+ client refresh keyed on that event reads the pre-judge turn count. ``only_if_present`` keeps the
+ post-turn event stream of a session with no automation state byte-identical to today's."""
if not session or not (session_key := str(session.get("session_key") or "")):
return
try:
with _session_profile_runtime_scope(session):
control = _snapshot_control(session_key)
+ if only_if_present and not control["revision"]:
+ return
_emit("session.control.update", sid, {"control": control})
except Exception:
logger.debug("session.control.update publish failed for %s", sid, exc_info=True)
diff --git a/tui_gateway/prompt_turn.py b/tui_gateway/prompt_turn.py
index 3832590448c..01469557423 100644
--- a/tui_gateway/prompt_turn.py
+++ b/tui_gateway/prompt_turn.py
@@ -802,7 +802,7 @@ def _run_prompt_submit(
_after_complete_turn(sid, session, st, raw)
# Goal judge + loop tick evaluation mutate persisted state AFTER message.complete: publish the
# structured control snapshot now so the Desktop card never paints the pre-judge turn count.
- _publish_session_control_snapshot(sid, session)
+ _publish_session_control_snapshot(sid, session, only_if_present=True)
except Exception as e:
_recover_turn_exception(sid, session, st, e)
finally: