Skip to content

fix(tui): force terminal reset on any exit path - #48782

Closed
kraso wants to merge 2 commits into
anomalyco:devfrom
kraso:fix/tui-terminal-reset-on-exit
Closed

kraso wants to merge 2 commits into
anomalyco:devfrom
kraso:fix/tui-terminal-reset-on-exit

Conversation

@kraso

@kraso kraso commented Sep 13, 2026 •

Copy link
Copy Markdown

fix(tui): force terminal reset on any exit path

Fixes #48776 · Refs #45938

Problem

When opencode exits inside a ConPTY stack on Windows (Alacritty + zellij-windows),
the terminal can be left with leaked raw-mode state: alternate screen not exited,
mouse tracking / kitty keyboard still enabled, garbled input (characters repeated
or echoed). Tracked in #48776 (Windows) and #45938 (macOS).

Root cause: destroyRenderer() only runs on the graceful path (scoped release,
/exit, SIGHUP). If the process exits via process.exit() elsewhere, or dies from
a signal (e.g. the kill -1 scenario in #45938), the renderer teardown is bypassed
entirely and nothing resets the terminal. Even on the graceful path, @opentui/core
does not emit a kitty-keyboard disable (CSI < u) on destroy, and its restore
bytes can be dropped by the ConPTY/zellij pipe once the process ends.

Change

Verification

  • bun run --cwd packages/tui typecheck — passes (tsgo, 0 errors)
  • bunx oxlint ... — 0 errors, 5 pre-existing warnings (untouched lines)
  • Smoke test: createCliRenderer → destroyRenderer leaves isDestroyed: true
    and restores cursor/altscreen/mouse; confirms kitty-keyboard reset (CSI < u)
    is now emitted (opentui's own destroy does not).

Repro video (Windows, Alacritty + zellij-windows)

Opencode_issue.mp4

@github-actions

Copy link
Copy Markdown
Contributor

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 github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

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 Sep 13, 2026
@github-actions github-actions Bot closed this Sep 13, 2026
@kraso

kraso commented Sep 13, 2026

Copy link
Copy Markdown
Author

Validation on the actual broken stack (Windows: Alacritty + zellij via ConPTY)

Reproduced with the release binary built from this branch. The startup sequence enables:

  • ?9001\ (ConPTY Win32 input mode)
  • ?1004\ (focus reporting)

neither of which the original reset list disabled. With those left active after exit, the next session in the same pane misbehaved (intermittent corruption that 'only failed on the 2nd/3rd run'). Those modes are now part of the symmetric reset (commit 2ff699c).

Consecutive enter/exit cycles are clean and zellij is left intact. Also covers ?1005/?1015 (legacy mouse) and ?2026 (synchronized output) defensively.

Builder note (not part of the diff): local Windows builds must use the repo-pinned [email protected] — bun 1.4.2's bundler produces a broken binary (a.name TypeError during SystemPrompt.environment). Builds are reproducible with the ran repo toolchain.

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.

TUI leaves terminal in raw/corrupted state on /exit under Alacritty + zellij-windows (Windows ConPTY)

1 participant