Files
Developer ea42165ed2 fix: harden web terminal paste and reconnect
- Queue bounded ordered terminal input so acknowledgements remain responsive
- Prevent stale sockets and retries from replacing healthy connections
- Preserve desktop scrollback behavior and add terminal regression coverage

Quality gates: frontend tests (91 passed), typecheck, lint, build, Python compilation, LSP diagnostics. Backend pytest skipped by user request.
2026-07-17 22:11:24 +00:00

2.4 KiB

Fix Web Terminal Resilience

Summary

Prevent large browser pastes from blocking flow-control acknowledgements, and prevent stale reconnect callbacks from replacing a healthy terminal WebSocket.

Problem

The terminal WebSocket handler awaits each PTY write inline. A large paste can wait for the PTY to become writable while the same handler stops receiving acknowledgement messages. If output flow control has paused PTY reads, the acknowledgement that would resume output remains unread, leaving the terminal apparently frozen.

Separately, reconnect timers and visibility callbacks can create a second socket after a connection becomes healthy. The terminal manager then closes the existing session socket, interrupting active input or rendering.

Scope

  • Queue bounded terminal input onto a single ordered writer so the WebSocket receive loop continues handling acknowledgements, resize, reset, and disconnect messages.
  • Make browser reconnection single-owner: stale socket callbacks and retry timers MUST NOT replace a current healthy socket.
  • Add focused regression tests for the queueing and reconnect behavior.

Non-goals

  • Re-enable desktop normal-buffer scrollback or mouse-wheel scrolling. Desktop continues to use zero scrollback and disabled wheel sensitivity to avoid the known stale TUI-frame regression.
  • Change terminal session persistence, authentication, PTY transport, or mobile touch scrolling behavior.

Risk and rollback

The bounded input queue must preserve input ordering, reject excess input without blocking control messages, and be cancelled when the WebSocket disconnects. Socket ownership checks must not prevent a legitimate reconnect after a real disconnect. Roll back by reverting the backend queue and frontend ownership changes; existing direct PTY input and retry behavior then resumes.

Acceptance Criteria

  • A blocked PTY write does not prevent the WebSocket handler from processing a subsequent flow-control acknowledgement.
  • Input bytes are still written to the PTY in arrival order, and excess queued input is rejected rather than growing without limit.
  • A stale socket close event or retry callback cannot replace an open current socket.
  • Component cleanup cancels pending reconnect timers and closes the current socket.
  • Desktop scrollback and wheel settings remain unchanged.
  • Focused backend/frontend tests and relevant quality gates pass.