Repository navigation
fix(renderer): handle SIGTSTP to prevent mouse garbling on external suspend - #907
agutmanstein-scale wants to merge 2 commits into
Conversation
…uspend When a process receives SIGTSTP from an external source (e.g., job control, terminal multiplexer, code-server), the process is suspended by the kernel without any terminal cleanup. Mouse tracking, Kitty keyboard protocol, and raw mode remain active, causing mouse events to appear as garbled escape sequences in the shell. Add SIGTSTP/SIGCONT signal handlers that call suspend()/resume() to properly clean up terminal state before suspension and restore it after resuming. The SIGTSTP handler removes itself before re-raising the signal to allow the default suspend behavior. The handlers are registered alongside exit listeners and removed symmetrically in suspend(), resume(), and cleanupBeforeDestroy(). Fixes anomalyco#906 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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) <[email protected]>
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) <[email protected]>
… input When SIGCONT arrives without a prior SIGTSTP through our handler (e.g., terminal refocus/reconnect in code-server), calling resume() adds a duplicate stdin listener — every keystroke is delivered twice. Guard resume() with _suspendedBySigtstp so it only runs if our SIGTSTP handler actually called suspend(). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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) <[email protected]>
|
/review |
|
Opencode is currently handling suspend/resume manually. This needs to be aligned. |
|
There are scenarios, like a user alt-tabbing, that can cause the TUI to receive a SIGTSTP. This is designed to address external scenarios. Resume cannot be triggered in the same terminal window because opentui is still ingesting mouse input @kommander |
|
Thank you for this. We are closing this pull request because the |
Issue for this PR
Closes #906
Type of change
What does this PR do?
When a process receives SIGTSTP from an external source (job control, terminal multiplexer, code-server), the process is suspended by the kernel without any terminal cleanup. Mouse tracking and raw mode remain active, causing mouse events to echo as garbled text in the shell.
This PR adds SIGTSTP/SIGCONT signal handlers to the renderer that call
suspend()/resume()— the same cleanup that the manual suspend keybind uses.Implementation:
sigtstpHandler: callssuspend()to disable mouse/raw mode, removes itself, re-raises SIGTSTP for default suspend behaviorsigcontHandler: re-registers the SIGTSTP handler, callsresume()to restore terminal stateaddSigtstpListeners()/removeSigtstpListeners(): symmetric lifecycle management matchingaddExitListeners()/removeExitListeners()suspend(),cleanupBeforeDestroy(); re-added inresume()How did you verify your code works?
suspend()/resume()which are already well-testedReproduction without fix
Checklist
🤖 Generated with Claude Code