Skip to content

fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend#20507

Open
agutmanstein-scale wants to merge 2 commits intoanomalyco:devfrom
agutmanstein-scale:fix/sigtstp-mouse-garble
Open

fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend#20507
agutmanstein-scale wants to merge 2 commits intoanomalyco:devfrom
agutmanstein-scale:fix/sigtstp-mouse-garble

Conversation

@agutmanstein-scale
Copy link
Copy Markdown

Issue for this PR

Closes #20506

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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.tsx after renderer creation:

  • SIGTSTP handler: calls renderer.suspend() (disables mouse, raw mode), removes itself, re-raises SIGTSTP
  • SIGCONT handler: re-registers SIGTSTP handler, calls renderer.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?

  • The handlers delegate to renderer.suspend()/resume() which are proven correct (used by the existing suspend keybind)
  • Includes test-sigtstp-mouse.sh reproduction script:
    # Terminal 1: run opencode
    # Terminal 2: ./test-sigtstp-mouse.sh $(pgrep -f opencode)
    # Terminal 1: move mouse → should be clean (no garbled text)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mouse garbling after inactivity — missing SIGTSTP handler

1 participant