The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): stop queued dispatch after session close
Eva089b437b35dd
diff --git a/tests/test_tui_gateway_queue_on_busy.py b/tests/test_tui_gateway_queue_on_busy.pyindex 4b42a2d6de9..86edf8aa598 100644--- a/tests/test_tui_gateway_queue_on_busy.py+++ b/tests/test_tui_gateway_queue_on_busy.py@@ -660,6 +660,24 @@ def test_drain_compute_host_forwards_queued_image_paths(monkeypatch):+def test_drain_preserves_queued_prompt_when_session_is_closing(monkeypatch):+ """A compute-host completion must not dispatch a successor after close."""+ monkeypatch.setattr(server, "_session_uses_compute_host", lambda _session: True)+ monkeypatch.setattr(+ server,+ "_submit_prompt_to_compute_host",+ lambda *_args, **_kwargs: (_ for _ in ()).throw(+ AssertionError("closing session must not dispatch")+ ),+ )+ queued = {"text": "queued-after-close", "transport": "ws-9"}+ session = _session(_closing=True, queued_prompt=queued)++ assert server._drain_queued_prompt("r1", "sid", session) is False+ assert session["queued_prompt"] is queued+ assert session["running"] is False++def test_drain_releases_running_on_dispatch_failure(monkeypatch):def _boom(*a, **k):raise RuntimeError("dispatch failed")@@ -762,4 +780,3 @@ def test_drain_continues_with_later_queued_prompt_after_dispatch_failure(monkeypassert session["queued_prompt"] is Noneassert session.get("queued_prompts") is None-diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex b176628c900..b57e63ca010 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -8074,6 +8074,8 @@ def _drain_queued_prompt(rid, sid: str, session: dict) -> bool:claim-under-lock pattern used by the goal-continuation re-fire."""with session["history_lock"]:+ if session.get("_closing"):+ return Falsequeued = session.get("queued_prompt")if not queued or session.get("running"):return False