#641

fix(core): restore terminal on every exit

Openwiiiimmwants to merge intofrom

Summary

claim_screen
  enter 1049 → mouse on → hide → clear → home

normal quit / signal / panic / child handoff
  delete images → pop keyboard → SCREEN_RESTORE
    mouse off → reports off → sync end → cursor on → reset
    clear (fallback) → home → leave 1049 (shell screen and scrollback)

launcher SIGINT / SIGTERM / SIGHUP
  forward to child → 1 s grace → SIGKILL if needed
  reap → restore pre-child termios → parent screen restore → child exit code

Normal cleanup is idempotent, so Keyboard::restore followed by restore_screen cannot clear the shell after the first restore. Signal transitions hold the terminal thread's guard across 1049 output; worker-delivered requests defer to that thread instead of racing another restore. Fatal requests are sticky, while suspend/resume uses latest-state coalescing. Cleanup no longer drains under the signal hold, and it works when only stdout is a tty. Panic reasons and requested backtraces print after restoration, including with RUST_BACKTRACE=0 behaving as disabled. Suspend/resume and child reclaim enter a fresh alternate screen. The no-write hang-up exception is unchanged. Widgets still construct no exit escapes, and widgets/tests/check.rs enforces the shared route.

Evidence

  • Before: panic restored only termios/mouse, 2J could leave frames in scrollback, and a killed launcher could orphan its widget. After: all thirteen pty scenarios pass in widgets/tests/exit.rs: required q/SIGINT/SIGTERM/panic/launcher routes, direct and interactive launchers, SIGHUP parent cleanup, stubborn-child SIGKILL after the grace period, enabled and disabled backtraces, redirected-stdin panic cleanup, normal menu child return, and suspend/resume. Launcher and resume tests also assert restored termios.
  • After: full cargo test passes, including 71 check.rs tests, the thirteen pty tests, hang-up, notices, npm, and doc tests.
  • After: cargo build --release passes; ldd target/release/{matrix,opscope} still shows only the existing libc/libm/libgcc runtime set.
  • After: isolated tmux release-binary checks pass for q, SIGTERM, forced panic and launcher SIGTERM. Pre-existing shell text remains, no widget footer enters scrollback, and the panic reason survives on the restored main screen.
  • Still to check by hand: Kitty and a plain xterm-compatible terminal; neither binary is available in this environment.
  • Pre-existing, unchanged: core/tests/terminal_protocol.py currently loses its first image in scroll_clears_previous_image_region. The same failure was reproduced against an untouched origin/main archive; its exploratory changes were not kept in this PR.

Merge Danger

Door: two-way — revert the PR to restore the previous terminal lifecycle.

Blast Radius: collection-wide terminal entry/exit and launcher child supervision. Widget drawing and data acquisition are unchanged. No dependencies were added.

Refs OPS-236 Closes #513

Activity

5
coderabbitai[bot]10d ago

WARNING

Review limit reached

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 89 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5c044b22-fb9b-4016-ab3a-63e66e0792cd
Commits

Reviewing files that changed from the base of the PR and between 1cd1cdf88ebfc6e3dfc0b154bb8048fe456d4c8f and fe35176f731d038032aab11227c76ea7cd6150f7.

Files selected for processing: 11

  • AGENTS.md
  • core/examples/terminal_probe.rs
  • core/src/lib.rs
  • core/src/palette.rs
  • core/src/settings.rs
  • core/src/terminal.rs
  • docs/terminal-rendering.md
  • widgets/src/launcher/main.rs
  • widgets/src/widgets/matrix/main.rs
  • widgets/tests/check.rs
  • widgets/tests/exit.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
linear-code[bot]10d ago
chatgpt-codex-connector[bot]10d ago
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-11-18T08:44:00.184464Zfe35176Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.