Fix #3998: discard input for dead terminal panes
Summary
- add a regression test for key input after a terminal child has exited
- track terminal input lifecycle separately from the Ghostty surface pointer
- discard keyboard and socket input once the child-exited state is observed
Local reproduction
- Normal
exitand externalkill -9of the pane shell both auto-closed the workspace/pane on the current debug build before it could be typed into. - A controlled no-consumer case reproduced the same routing fault: create a new focused workspace and send socket text while
debug-terminalsreports the focused surface withtty=nil; observed input was still accepted/rendered into the terminal grid instead of being dropped until a live PTY consumer exists. - This matches the issue's failure mode at the input-routing boundary: input was gated only on a Ghostty surface pointer, not terminal/PTY liveness.
Testing
- Not run locally, per repo policy. Regression and fix are split into two commits so CI can show the test-only commit red and the fix commit green.
[!NOTE]
Medium Risk
Touches terminal input routing, lifecycle, and concurrency around Ghostty surface callbacks; regressions could drop valid input or affect panel close/restore behavior.
Overview
Fixes dead-pane input by introducing an explicit terminal input lifecycle in GhosttyTerminalView (locked) that flips to child-exited from Ghostty callbacks/close paths, clears queued socket input, and blocks further sendText/sendInput/sendNamedKey and view key handling with process_exited semantics.
Also forces Ghostty wait_after_command off (no inheritance and overridden at runtime surface creation) so exited PTYs aren’t kept focusable, and updates bash/zsh shell integration to reset keyboard protocols at every prompt (with a Kitty alias).
Adds/updates regression tests covering dead-pane socket + key rejection, suppression of key forwarding to Ghostty, keyboard reset emission correctness, and ensuring startup-command tabs/splits don’t request/enable wait_after_command.
Reviewed by Cursor Bugbot for commit 53bb46d37841fe696ef12da1dc6007ea60e4e83b. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Stops all input to dead terminal panes and returns process_exited for control‑socket and v2 API commands. Also disables wait_after_command everywhere and resets terminal keyboard protocols at each shell prompt to prevent garbled input; aligns with issue-3998.
- Bug Fixes
- Add a terminal input lifecycle with a lock: mark child‑exited in Ghostty callbacks and TabManager, clear queued socket input, gate create/attach/flush and all input paths, preserve the first teardown reason, and lock the pending socket‑input startup check to avoid races.
- Gate input end‑to‑end:
sendText/sendInput/sendNamedKey/paste and viewkeyDown/keyUp/flagsChanged/paste readiness respect ready/blocked/unavailable; dead panes swallow events before Ghostty; skip readiness waits when blocked. - Control‑socket and v2:
surface.send_text/surface.send_keyand legacysendreturnprocess_exitedfor dead panes andsurface_unavailablewhen closed; refresh only when input applies; fix queued vs blocked reporting. - Shell integrations (bash/zsh): reset terminal keyboard protocols at each prompt; add
_cmux_reset_kitty_keyboard_protocolalias; remove duplicate helpers. Tests verify the reset sequence and that typing “chart” emits plain bytes (no Kitty CSI‑u). - Disable
wait_after_commandglobally: never inherit it and force false at runtime. Tests cover startup‑command tabs/splits, initial workspaces, remote splits, and templates that request it; runtime override verified.
Summary by CodeRabbit
-
Bug Fixes
- Terminal input is blocked after a child process exits, preventing input and new surface/attachment creation for dead panes.
- DEL (0x7F) is correctly treated as Delete and discarded once a pane is marked dead.
-
New Features
- Shell integrations now reset terminal keyboard protocol at each prompt to recover from crashed TUIs.
-
Tests
- Added tests ensuring dead-pane key events are not forwarded and a regression preventing mis-encoded typed text.