From 64aeb5dd1a7ae271a1fd853b9944e6453ca67e14 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Mon, 14 Sep 2026 21:24:25 -0700 Subject: [PATCH] fix: gate the stalled-redraw close on socket identity, not session.attached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When viewer A's replay fails because viewer B superseded it mid-send, attach(A) returns False while session.attached is True for B. The handler then logged a misleading "pty input stalled … recycling terminal session" warning and issued a second close on A. Checking `session._ws is ws` limits the close to the one case it exists for: this socket is still attached and its redraw write stalled. Review finding: superseded socket's failed replay logged a stall and re-closed itself because the gate tested session-wide state. --- hermes_cli/web_routers/chat_ws.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hermes_cli/web_routers/chat_ws.py b/hermes_cli/web_routers/chat_ws.py index 9673cd6887..55f59b7ddd 100644 --- a/hermes_cli/web_routers/chat_ws.py +++ b/hermes_cli/web_routers/chat_ws.py @@ -518,9 +518,10 @@ async def pty_ws(ws: WebSocket) -> None: # A fresh xterm can't rebuild the TUI from an arbitrary tail of alternate- # screen differential output; reused PTYs emit a full frame after replay. if not await session.attach(ws, force_redraw=not _created): - # attach() detaches itself when the client dropped mid-replay; only a - # stalled redraw write leaves this socket attached and worth closing. - if session.attached: + # attach() detaches itself when the client dropped mid-replay, and a socket + # superseded during replay is already closed by its replacement; only a + # stalled redraw write leaves THIS socket attached and worth closing. + if session._ws is ws: await _close_stalled_pty_input(ws, path="keepalive-redraw") PTY_REGISTRY.detach(attach_token, ws) return