Skip to content

The agent that grows with you

fix(tui_gateway): Stop during a manual compaction keeps the busy claim

kshitijk4poor8e315d00b3e6
diff --git a/tests/tui_gateway/test_busy_compression_demotion.py b/tests/tui_gateway/test_busy_compression_demotion.py
index c6187e077cb..04d44ce2dbd 100644
--- a/tests/tui_gateway/test_busy_compression_demotion.py
+++ b/tests/tui_gateway/test_busy_compression_demotion.py
@@ -199,7 +199,7 @@ def test_submit_during_manual_compress_is_queued_and_reply_persists(monkeypatch)
monkeypatch.setattr(server, "_run_prompt_submit", fake_turn)
monkeypatch.setattr(server, "_load_busy_input_mode", lambda: "interrupt")
for name in ("_status_update", "_emit", "_sync_session_key_after_compress", "_persist_queued_user_row",
- "_replace_queued_user_row_for_turn"):
+ "_replace_queued_user_row_for_turn", "_clear_pending", "_announce_cancelled_gateway_approvals"):
monkeypatch.setattr(server, name, lambda *a, **k: None)
monkeypatch.setattr(server, "_session_uses_compute_host", lambda _s: False)
monkeypatch.setattr(server, "_session_info", lambda *a, **k: {})
@@ -214,6 +214,8 @@ def test_submit_during_manual_compress_is_queued_and_reply_persists(monkeypatch)
rpc = threading.Thread(target=server._methods["session.compress"], args=("r1", {"session_id": "sid"}))
rpc.start()
assert entered.wait(5)
+ server._interrupt_session_turn("sid", session) # Stop mid-compaction must not release the busy claim
+ assert session["running"] is True
resp = server._handle_busy_submit("r2", "sid", session, "question", "ws-1")
gate.set()
rpc.join(5)
diff --git a/tui_gateway/session_lifecycle.py b/tui_gateway/session_lifecycle.py
index d124ed258a6..f8943fdc159 100644
--- a/tui_gateway/session_lifecycle.py
+++ b/tui_gateway/session_lifecycle.py
@@ -693,7 +693,10 @@ def _interrupt_session_turn(
caller, never from request_id prefix sniffing — a future orphan caller may use another id (#106678).
"""
use_compute_host = _session_uses_compute_host(session)
- should_interrupt = bool(session.get("running"))
+ # A manual compaction holds `running` with no run thread and its own finally releases it: Stop must not
+ # abort it nor clear `running` under it, or the next submit is admitted idle and loses its reply (#133504).
+ compressing = bool(session.get("_manual_compress_active"))
+ should_interrupt = bool(session.get("running")) and not compressing
run_thread_alive = False
if use_compute_host:
# The host owns the live turn (parent `running` can lag a blocked tool), so let it decide. Gate on
@@ -735,7 +738,7 @@ def _interrupt_session_turn(
interrupt_for_session(
origin_ui_session_id=_lifecycle_own_sid(session, sid), reason="user_stop",
parent_session_id=str(getattr(session.get("agent"), "session_id", "") or ""))
- if not run_thread_alive:
+ if not run_thread_alive and not compressing:
with session["history_lock"]:
if session.get("running"):
session["running"] = False