fix(renderer): disable mouse tracking before raw mode in destroy path#905
Open
agutmanstein-scale wants to merge 1 commit intoanomalyco:mainfrom
Open
fix(renderer): disable mouse tracking before raw mode in destroy path#905agutmanstein-scale wants to merge 1 commit intoanomalyco:mainfrom
agutmanstein-scale wants to merge 1 commit intoanomalyco:mainfrom
Conversation
…eDestroy When a renderer is destroyed, cleanupBeforeDestroy() calls stdin.setRawMode(false) before mouse tracking is disabled. This re-enables terminal ECHO while mouse events are still being sent, causing them to appear as garbled escape sequences in the terminal. The correct ordering already exists in suspend(): disableMouse() is called before setRawMode(false). This commit applies the same pattern to cleanupBeforeDestroy(): 1. Call disableMouse() while raw mode is still on (no ECHO) 2. Drain buffered mouse events from stdin 3. Then disable raw mode Fixes anomalyco#904 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
agutmanstein-scale
added a commit
to agutmanstein-scale/opencode
that referenced
this pull request
Apr 1, 2026
…ragmented input Two bugs cause SGR mouse escape sequences to appear as garbled text: 1. **Post-exit garbling** (new fix): cleanupBeforeDestroy() calls setRawMode(false) before mouse tracking is disabled, creating a window where mouse events echo as raw bytes. Fixed by adding disableMouse() + stdin drain before setRawMode(false), matching the correct ordering already used in suspend(). 2. **In-session garbling** (ported from anomalyco#19520): StdinParser timeout fires mid-mouse-sequence during heavy event loop pressure, leaking individual bytes as KEY events. Fixed by patching three timeout paths with recovery flags and deferred processing. Also bumps DEFAULT_TIMEOUT_MS from 20 to 25ms for defense-in-depth. Patch targets @opentui/core@0.1.95 (current dev dependency). Upstream fix: anomalyco/opentui#905 Closes anomalyco#20458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
18vijayb
pushed a commit
to 18vijayb/opencode
that referenced
this pull request
Apr 2, 2026
…ragmented input Two bugs cause SGR mouse escape sequences to appear as garbled text: 1. **Post-exit garbling** (new fix): cleanupBeforeDestroy() calls setRawMode(false) before mouse tracking is disabled, creating a window where mouse events echo as raw bytes. Fixed by adding disableMouse() + stdin drain before setRawMode(false), matching the correct ordering already used in suspend(). 2. **In-session garbling** (ported from anomalyco#19520): StdinParser timeout fires mid-mouse-sequence during heavy event loop pressure, leaking individual bytes as KEY events. Fixed by patching three timeout paths with recovery flags and deferred processing. Also bumps DEFAULT_TIMEOUT_MS from 20 to 25ms for defense-in-depth. Patch targets @opentui/core@0.1.95 (current dev dependency). Upstream fix: anomalyco/opentui#905 Closes anomalyco#20458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
agutmanstein-scale
added a commit
to agutmanstein-scale/opencode
that referenced
this pull request
Apr 2, 2026
…ragmented input Two bugs cause SGR mouse escape sequences to appear as garbled text: 1. **Post-exit garbling** (new fix): cleanupBeforeDestroy() calls setRawMode(false) before mouse tracking is disabled, creating a window where mouse events echo as raw bytes. Fixed by adding disableMouse() + stdin drain before setRawMode(false), matching the correct ordering already used in suspend(). 2. **In-session garbling** (ported from anomalyco#19520): StdinParser timeout fires mid-mouse-sequence during heavy event loop pressure, leaking individual bytes as KEY events. Fixed by patching three timeout paths with recovery flags and deferred processing. Also bumps DEFAULT_TIMEOUT_MS from 20 to 25ms for defense-in-depth. Patch targets @opentui/core@0.1.95 (current dev dependency). Upstream fix: anomalyco/opentui#905 Closes anomalyco#20458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
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.
Issue for this PR
Closes #904
Type of change
What does this PR do?
When a renderer is destroyed via
destroy()→finalizeDestroy()→cleanupBeforeDestroy(), mouse escape sequences leak into the terminal as garbled text.Root cause:
cleanupBeforeDestroy()callsstdin.setRawMode(false)(re-enabling terminal ECHO) before mouse tracking is disabled. Between these two events, any mouse movement generates escape sequences that get echoed as raw text like35;89;19M35;84;20M35;76;22M35....The correct pattern already exists in
suspend()(line ~2052-2077):disableMouse()— mouse off while raw mode is still on (no ECHO)suspendRenderer()— native cleanupsetRawMode(false)— raw mode off last (safe, mouse already disabled)This PR applies the same ordering to
cleanupBeforeDestroy():disableMouse()while raw mode is still onThe
_useMouseguard ensuresdisableMouse()is only called when mouse tracking was enabled. The stdin drain pattern matchesresume().How did you verify your code works?
cleanupBeforeDestroy()ordering withsuspend()orderingChecklist
🤖 Generated with Claude Code