fix(apps): restore terminal on apps shell exit (stop clobbering the shell)#22
Merged
Merged
Conversation
… shell)
Exiting `opper apps shell` left the local terminal in a broken input mode:
every keypress produced CSI-u byte soup (";1:3u") and zsh spat "command not
found". Cause: restore() only did setRawMode(false). The remote PTY (ttyd +
whatever ran in it) enables terminal modes via output bytes we forward to
stdout — most painfully the kitty keyboard protocol — and nothing ever turned
them back off, so they persisted after disconnect.
restore() now also writes the matching "disable" sequences (pop kitty keyboard
flags, bracketed paste off, mouse reporting off, show cursor, normal keypad) —
all no-ops on modes that weren't set. Made it idempotent and also run it on
exit/SIGINT/SIGTERM/SIGHUP, so an abrupt disconnect (not just a clean one)
restores the terminal too.
Found by hitting the clobber live after an `apps shell` session.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
After running
opper apps shelland disconnecting, the local terminal is left broken — every keypress emits CSI-u byte soup and the shell errors:Those
;1:3ufragments are the kitty keyboard protocol (CSI-u key events). The remote PTY (ttyd + whatever ran in it) enabled it via output bytes we forward to stdout, andrestore()only calledsetRawMode(false)— it never sent the sequences to turn those modes back off. So they persisted after disconnect and clobbered the shell. This happened even on a clean exit (the.finally()ran, but did nothing about the escape modes).Fix
restore()now also writes the matching "disable" sequences, all no-ops on modes that weren't set:\e[<u— pop kitty keyboard protocol flags (the;1:3ugarble)\e[?2004l— bracketed paste off\e[?1000l \e[?1002l \e[?1003l \e[?1006l— mouse reporting off\e[?25h— show cursor\e>— normal keypadAlso made
restore()idempotent and registered it onexit/SIGINT/SIGTERM/SIGHUP, so an abrupt disconnect (Ctrl-, terminal hang-up, kill) restores the terminal too — not just the clean-exit path.Immediate remedy if you're stuck now: run
reset(orstty sane; printf '\e[<u').Tests
tsctypecheck + build clean; full suite 381 passing. Verified the sequences compile intodist/. (Theapps shellcommand opens a live WebSocket/PTY, so this path isn't unit-tested; the change is a focused set of known terminal-reset escapes on the existing cleanup path.)Found live this session, right after the
apps shellclobber.🤖 Generated with Claude Code