fix: shadow xterm v6.0.0 DECRQM handler to stop terminal freeze on new sessions - #159
Merged
Conversation
…w sessions xterm.js v6.0.0's built-in `requestMode` CSI `$p` handler throws `ReferenceError: t is not defined` after Vite minification. Claude Code's Ink UI emits `CSI ? 2026 $ p` (synchronized-output probe) during startup, which crashes xterm's parser mid-write. The crash leaves unprocessed chunks in the WriteBuffer and no `_innerWrite` is rescheduled, so the browser terminal freezes on whatever was drawn right before the crash — for new sessions, that's the `WARNING: Loading development channels` page. Resumed sessions survived because their Ink probe had already been written and rendered in an earlier browser session before the faulty sequence arrived; freshly-spawned sessions hit the probe every time you mount them, which is why "existing sessions work, new sessions are stuck." Fix: register no-op CSI handlers for `$ p` and `? $ p` in createXtermBackend so they short-circuit before xterm's built-in buggy handler runs. Added a defense-in-depth try/catch around terminal.write() — it can't catch the async parser throws xterm uses via setTimeout, but protects against any future sync parser exceptions. Regression tests verify: - No DECRPM response is emitted for `CSI ? 2026 $ p` (our shadow returns true) - No DECRPM response is emitted for `CSI 4 $ p` - Subsequent writes continue processing after a DECRQM sequence Tests fail if the shadow handlers are removed (xterm's built-in handler would emit a response via onData, or throw in a minified build). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nox-0x
approved these changes
Apr 21, 2026
nox-0x
left a comment
Collaborator
There was a problem hiding this comment.
Solid fix — the DECRQM shadow handlers are the right approach for the xterm.js v6.0.0 minification bug, and the regression tests provide genuine coverage. The defensive try/catch around terminal.write() is a reasonable belt-and-suspenders addition even though it cant catch async xterm throws. Approved.
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.
Problem
Existing (resumed) agent sessions work fine, but brand-new sessions are stuck on the
WARNING: Loading development channelspage — keystrokes do nothing, Enter doesn't dismiss the warning. Reverting source code didn't help because the bug is innode_modules, not source.Root cause
@xterm/xtermv6.0.0's built-inrequestModeCSI$phandler throwsReferenceError: t is not definedafter Vite minification. Claude Code's Ink UI emitsCSI ? 2026 $ p(DEC Request Mode, mode 2026 — synchronized-output probe) during startup. The throw happens asynchronously inside xterm'sWriteBuffer._innerWriteloop, which means:_innerWrite's scheduledsetTimeoutis never entered — the throw escapes to the event loop._innerWriteis only re-scheduled when the WriteBuffer is empty, but it's now stuck with unprocessed chunks, so no further writes ever render.The browser terminal freezes on whatever was drawn right before the crash. For new sessions that's the channels warning page; resumed sessions survived because their Ink probe had already been processed in an earlier mount.
Why only new sessions: existing sessions had already written their Ink probes before the browser tab was last opened, so their terminals were already past the crash point.
Fix
Register no-op
CSI $ pandCSI ? $ phandlers increateXtermBackend()that returntrue, short-circuiting xterm's built-in buggy handler before it runs. Also added a defense-in-depth try/catch aroundterminal.write()— it won't catch xterm's asyncsetTimeout-scheduled throws, but guards against any future synchronous parser exceptions.Test plan
Added
xterm-backend.test.tswith three regression tests verifying:CSI ? 2026 $ p(our shadow returns true)CSI 4 $ pTests fail if the shadow handlers are removed — xterm's built-in handler would either emit a response via
onData(unminified) or throw (minified).bun vitest run src/terminal/xterm-backend.test.ts— 3 passedbunx tsc --noEmitcleanstore.test.tsfailures (not related to this PR)Risks
Alternatives considered
6.1.0-beta.197— unknown whether the bug is fixed; betas aren't recommended for prod.build.rollupOptions.output.manualChunks+ per-chunk terser opts; larger blast radius.terminal.write()— doesn't work because xterm's parser runs async via setTimeout; uncaught throws escape our try/catch.The shadow handler is the narrowest, most targeted fix.
🤖 Generated with Claude Code