The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui_gateway): hold the /goal continuation after Stop too
Herman Bohdanov9521d6de5551
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.pyindex 148b159cc90..2c659bc6f12 100644--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@ -18801,6 +18801,20 @@ def test_notification_poller_starts_no_turn_after_stop(monkeypatch):server._sessions.pop("sid_stopped", None)+def test_goal_continuation_starts_no_turn_after_stop(monkeypatch):+ """A Stop that lands after the model answered but before the post-turn follow-ups+ must not let an active /goal chain its continuation turn."""+ started = []+ sess = _session(running=False, _turn_cancel_requested=True)+ monkeypatch.setattr(server, "_emit", lambda *a, **kw: None)+ monkeypatch.setattr(server, "_run_prompt_submit", lambda *a, **kw: started.append(a) or True)++ server._run_post_turn_followups("r", "sid_goal_stopped", sess, {}, "keep going")++ assert started == []+ assert sess["running"] is False++def test_notification_poller_requeues_when_busy(monkeypatch):"""When the agent is busy, the poller requeues the event."""import queue as _queue_moddiff --git a/tui_gateway/prompt_turn.py b/tui_gateway/prompt_turn.pyindex c1ce7547664..e938bcc3776 100644--- a/tui_gateway/prompt_turn.py+++ b/tui_gateway/prompt_turn.py@@ -445,6 +445,8 @@ def _run_post_turn_followups(with _session_turn_admission(session) as admitted:if not admitted or session.get("running"):return # user already sent something — their turn wins+ if session.get("_turn_cancel_requested"):+ return # the user pressed Stop; the goal resumes after their next promptsession["running"] = True_dispatch_followup_turn(rid, sid, session, goal_followup, "goal continuation dispatch")# Safety net for completion events that arrived mid-turn. Ownership is positive-proofdiff --git a/tui_gateway/session_notifications.py b/tui_gateway/session_notifications.pyindex 5e4396a2a41..b3540b743c8 100644--- a/tui_gateway/session_notifications.py+++ b/tui_gateway/session_notifications.py@@ -632,6 +632,8 @@ def _poll_bot_live_delivery_once(sid: str, session: dict) -> bool:if not has_mailbox(home):return Falsewith _session_turn_admission(session) as admitted:+ # No _turn_cancel_requested here: a delivery is a person's message, not an automatic turn,+ # and only a local prompt clears the latch, so gating it would park the sender until then.if not admitted or any(session.get(key) for key in ("running", "_closing", "_finalized", "queued_prompt", "queued_prompts","_auto_continue_scheduled")) or session.get("agent") is None: