Skip to content

fix(tui): patch mouse garbling on SIGTSTP suspend and exit + PTY reproducers#20587

Closed
18vijayb wants to merge 3 commits intoanomalyco:devfrom
18vijayb:patched-mouse-fixes
Closed

fix(tui): patch mouse garbling on SIGTSTP suspend and exit + PTY reproducers#20587
18vijayb wants to merge 3 commits intoanomalyco:devfrom
18vijayb:patched-mouse-fixes

Conversation

@18vijayb
Copy link
Copy Markdown

@18vijayb 18vijayb commented Apr 2, 2026

Summary

Combines and verifies the three mouse garbling fixes:

Test scripts added

  • sigtstp-mouse-pty.py — PTY wrapper that auto-sends SIGTSTP after TUI startup and checks for ?1003l in the output. Shows FAIL → PASS across the PR fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend #20507 fix.
  • post-exit-mouse-pty.py — PTY wrapper that snapshots the slave PTY ECHO state at the moment ?1003l arrives. Structural verification is covered by test-destroy-mouse-cleanup.mjs (5/5 passing).

Verification

# SIGTSTP: FAIL on unpatched, PASS on patched
python3 packages/opencode/test/cli/tui/sigtstp-mouse-pty.py opencode

# Post-exit structural test
bun run packages/opencode/test/cli/tui/test-destroy-mouse-cleanup.mjs

🤖 Generated with Claude Code

agutmanstein-scale and others added 3 commits April 1, 2026 20:01
…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>
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>
- 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>
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found:

This PR (20587) is a consolidation/combination PR that references and builds upon two earlier PRs:

  1. PR fix(tui): patch @opentui/core to prevent mouse garbling on exit and fragmented input #20462 - fix(tui): patch @opentui/core to prevent mouse garbling on exit and fragmented input

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

These are not duplicates but rather prerequisite PRs that are being combined and verified together in PR #20587. The current PR consolidates and adds test coverage for both fixes.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 2, 2026
@github-actions github-actions bot closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants