fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend#20507
Open
agutmanstein-scale wants to merge 2 commits intoanomalyco:devfrom
Open
fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend#20507agutmanstein-scale wants to merge 2 commits intoanomalyco:devfrom
agutmanstein-scale wants to merge 2 commits intoanomalyco:devfrom
Conversation
When opencode receives SIGTSTP from an external source (code-server terminal management, job control, kill -TSTP), the process is suspended without terminal cleanup. Mouse tracking remains enabled, causing mouse events to echo as garbled escape sequences in the shell. Register SIGTSTP/SIGCONT handlers after renderer creation that call renderer.suspend()/resume() — the same cleanup the manual suspend keybind uses. The SIGTSTP handler removes itself before re-raising to allow default suspend behavior. Includes test-sigtstp-mouse.sh reproduction script. Upstream fix: anomalyco/opentui#907 Closes anomalyco#20506 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
- sigtstp-mouse-pty.py: wraps a command in a PTY, waits for mouse tracking to be enabled, sends SIGTSTP to the process group, then checks whether ?1003l was emitted before suspension. Demonstrates FAIL→PASS across PR anomalyco#20507. - post-exit-mouse-pty.py: wraps a command in a PTY and snapshots the slave PTY's ECHO flag at the moment ?1003l arrives at the master. Structural verification for PR anomalyco#20462 ordering is covered by test-destroy-mouse-cleanup.mjs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When SIGCONT arrives without a prior SIGTSTP through our handler (e.g., code-server terminal refocus/reconnect), calling resume() adds a duplicate stdin listener — every keystroke is delivered twice, causing double character input like "ooppeennccooddee". Guard resume() with a suspendedBySigtstp flag so it only runs if our SIGTSTP handler actually called suspend(). Co-Authored-By: Claude Opus 4.6 (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.
Issue for this PR
Closes #20506
Type of change
What does this PR do?
When opencode receives SIGTSTP from an external source (code-server terminal management during inactivity, job control,
kill -TSTP), the process is suspended without terminal cleanup. Mouse tracking remains enabled, causing mouse events to echo as garbled escape sequences in the shell.This PR registers SIGTSTP/SIGCONT handlers in
app.tsxafter renderer creation:renderer.suspend()(disables mouse, raw mode), removes itself, re-raises SIGTSTPrenderer.resume()This is the same cleanup pattern the manual suspend keybind already uses.
Upstream fix: anomalyco/opentui#907
How did you verify your code works?
renderer.suspend()/resume()which are proven correct (used by the existing suspend keybind)test-sigtstp-mouse.shreproduction script:Checklist
🤖 Generated with Claude Code