fix: gate the stalled-redraw close on socket identity, not session.attached

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.
This commit is contained in:
teknium1
2026-09-14 21:24:25 -07:00
committed by Teknium
parent 7a1d278528
commit 64aeb5dd1a
+4 -3
View File
@@ -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