The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): session.close always returns a messages list and keeps its tui_close reason
teknium1919b8bfc102e
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.pyindex 41572ed70bc..18f52f44b61 100644--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@ -4987,7 +4987,7 @@ def test_session_close_releases_resume_lock_before_slow_teardown(monkeypatch):server._sessions.pop("slow-close", None)assert not thread.is_alive()- assert response["result"] == {"closed": True}+ assert response["result"] == {"closed": True, "messages": []}def test_session_close_settles_active_turn_before_teardown(monkeypatch):@@ -5040,7 +5040,7 @@ def test_session_close_settles_active_turn_before_teardown(monkeypatch):assert not close_thread.is_alive()assert teardown_started.is_set()- assert response["result"] == {"closed": True}+ assert response["result"] == {"closed": True, "messages": []}def test_ws_orphan_reap_interrupts_isolated_turn_then_reaps(monkeypatch):diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.pyindex 123e80d4b32..03e8bc5b192 100644--- a/tui_gateway/methods_session.py+++ b/tui_gateway/methods_session.py@@ -2203,7 +2203,8 @@ def _(rid, params: dict, session: dict) -> dict:def _(rid, params: dict) -> dict:with _session_resume_lock: # lock only the ownership claim; finalization must not block resumessession = _pop_session_by_id(params.get("session_id", ""))- return _ok(rid, {"closed": _teardown_popped_session(session), "messages": (session or {}).get("_end_msgs", [])})+ closed = _teardown_popped_session(session, end_reason="tui_close")+ return _ok(rid, {"closed": closed, "messages": list((session or {}).get("_end_msgs") or [])})@_session_method("session.branch", live=True)diff --git a/tui_gateway/session_lifecycle.py b/tui_gateway/session_lifecycle.pyindex af9ce87453c..cb090ac0f79 100644--- a/tui_gateway/session_lifecycle.py+++ b/tui_gateway/session_lifecycle.py@@ -396,7 +396,7 @@ def _finalize_session(session: dict | None, end_reason: str = "tui_close") -> Nosession_key = session.get("session_key")session_id = getattr(agent, "session_id", None) or session_key# Returned to the client by ``session.close`` (the TUI shows them after its /new reset); reaper paths have no client.- session["_end_msgs"] = _notify_session_boundary("on_session_finalize", session_id, _session_source(session))+ session["_end_msgs"] = _notify_session_boundary("on_session_finalize", session_id, _session_source(session)) or []# End the state.db row so it doesn't linger as a ghost in /resume. Use session_id (agent.session_id), not# session_key: after compression the key may be the stale ended parent while session_id is the live continuation.# Fix for #20001.