Repository navigation
fix(terminal): stop the reveal fit from reflow-garbling inline TUIs on minimize→restore - #10158
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughTerminal pane fitting now records the last successful client size and adds reveal-fit routing for resized, unchanged, or grid-diverged panes. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Confirmed on macOS with Orca v1.4.152 (relay 0.1.0+a1d6a28ba0ae) and Codex 0.145.0.
This behavior and the good-v1.4.148 / bad-v1.4.152 boundary look consistent with the reveal-fit reflow mechanism in this PR. I can retest a macOS build containing the patch. I omitted screenshots because the terminal content includes local project details. |
grok (and other inline-viewport TUIs like Codex) render garbled after the floating terminal is minimized and brought back up. On reveal the resume path fit xterm synchronously right after re-attaching WebGL, whose cell metrics differ from the DOM renderer's — so it could propose a one-column-off grid, reflow xterm, then snap back a frame later (a net-zero resize "wiggle"). xterm's main-buffer wrap→unwrap is not a perfect inverse, and an inline TUI that diff-paints its pinned region redraws over the corrupted buffer. Replace the unconditional synchronous reveal fit (fitAllPanes) with a gated fit (PaneManager.fitAllPanesStable → fitRevealedPane): - fit synchronously only when the fit element's pixels actually changed while hidden (a real resize the app must reflow for anyway, kept ahead of the async PTY size reassert so it can't forward a stale grid); - if the pixels are unchanged but the grid diverged while hidden (snapshot / SSH-reattach direct terminal.resize, or an appearance/DPI change), repair it on a steady grid (requestStablePaneFit) so a sustained mismatch refits while a transient cell-metric wobble does not reflow; - otherwise leave the pane alone. The common minimize→restore is now a hard no-op with zero reflow. Also applied to the window-wake reveal path.
…ealedPanes
Quality pass: make fitRevealedPane the single canonical explanation of the
reveal wobble and reduce the duplicated comments at the call sites to short
pointers; rename PaneManager.fitAllPanesStable -> fitAllRevealedPanes ("stable"
only described one of its three branches); symmetric early-returns in
fitRevealedPane. No behavior change.
7fac6c1 to
4ee0f66
Compare
…n minimize→restore (stablyai#10158) * fix(terminal): stop the reveal fit from reflow-garbling inline TUIs grok (and other inline-viewport TUIs like Codex) render garbled after the floating terminal is minimized and brought back up. On reveal the resume path fit xterm synchronously right after re-attaching WebGL, whose cell metrics differ from the DOM renderer's — so it could propose a one-column-off grid, reflow xterm, then snap back a frame later (a net-zero resize "wiggle"). xterm's main-buffer wrap→unwrap is not a perfect inverse, and an inline TUI that diff-paints its pinned region redraws over the corrupted buffer. Replace the unconditional synchronous reveal fit (fitAllPanes) with a gated fit (PaneManager.fitAllPanesStable → fitRevealedPane): - fit synchronously only when the fit element's pixels actually changed while hidden (a real resize the app must reflow for anyway, kept ahead of the async PTY size reassert so it can't forward a stale grid); - if the pixels are unchanged but the grid diverged while hidden (snapshot / SSH-reattach direct terminal.resize, or an appearance/DPI change), repair it on a steady grid (requestStablePaneFit) so a sustained mismatch refits while a transient cell-metric wobble does not reflow; - otherwise leave the pane alone. The common minimize→restore is now a hard no-op with zero reflow. Also applied to the window-wake reveal path. * refactor(terminal): tighten reveal-fit comments + rename to fitAllRevealedPanes Quality pass: make fitRevealedPane the single canonical explanation of the reveal wobble and reduce the duplicated comments at the call sites to short pointers; rename PaneManager.fitAllPanesStable -> fitAllRevealedPanes ("stable" only described one of its three branches); symmetric early-returns in fitRevealedPane. No behavior change.
What & why
grok(and other inline-viewport TUIs like Codex) render badly garbled — overlapping / duplicated / misaligned frames — after Orca's floating terminal is minimized and brought back up. Reported in Slack ("grok is pretty fucked in floating terminal after minimize + bring back up").Root cause. On reveal, the resume path fit xterm synchronously right after
resumeRendering()re-attaches the WebGL renderer. WebGL rounds cell dimensions to device pixels differently from the DOM renderer, so for a frameFitAddon.proposeDimensions()can return a one-column-off grid. The synchronous fit commits it, reflowing xterm, and the ~150 ms containerResizeObserverfits it back — a net-zero resize "wiggle". xterm's main-buffer wrap→unwrap is not a perfect inverse, and an inline TUI that only diff-paints its pinned region (never a full clear, unless it detects a multiplexer) redraws over the corrupted buffer. The reveal fit was the one fit path that skipped the stability gate the ResizeObserver and drift-check paths already use.Fix. Replace the unconditional synchronous reveal fit (
fitAllPanes) with a gated one —PaneManager.fitAllPanesStable()→fitRevealedPane(pane):safeFit— the app must reflow anyway, and doing it now keeps xterm ahead of the async{fit:false}PTY size reassert so it can't forward a stale gridterminal.resize, or an appearance/DPI change)requestStablePaneFit— repair on a steady grid, so a sustained mismatch refits but a transient metric wobble does not reflowThe pixel comparison measures the actual element FitAddon fits (
xtermContainer), rounded to whole pixels so sub-pixel jitter never reads as a resize. Same gate applied to the window-wake reveal path.The result: the reported minimize→restore is now a hard no-op with zero reflow.
ELI5
grok draws its screen by only touching the characters that changed since last frame (it trusts everything else to stay put). When you minimized and reopened the floating terminal, Orca briefly told the terminal it was one column narrower, then a column wider again — snapping the text back and forth. The terminal's text-rewrapping isn't perfectly reversible, so the "everything else stays put" assumption broke, and grok painted new text on top of shuffled old text → garbage.
The fix: on reopen, Orca now only re-measures the terminal when the window actually changed size. If it's the same size (the usual case), it leaves the terminal exactly as it was — no snap, no garbage.
Proof of fix
Reproduced end-to-end with real grok in a real PTY piped into the same
@xterm/headlessbuild Orca ships, then isolated the trigger:120→80→120(transient wrong-size fit, net size unchanged)[1X/[40Xerase-patch fragments and footer text bleeding across the border (matches the screenshot)120→120(same-size fit, no-op)So a resize that lands back on the original size is the worst case (grok's
autoresizeonly clears when the area actually changes, so returning to a known size triggers no clear). The fix guarantees the same-size reveal never resizes xterm at all → no wiggle. A same-size fit was already a no-op insafeFit, so no needed SIGWINCH is lost; only the transient wiggle is removed.Also confirmed deterministically via a recorded grok byte-stream replayed through xterm with the wiggle vs. a clean control (4 corrupted rows vs. 0).
Regressions — none expected
safeFitwas already a no-op on same-size, so removing the synchronous reveal fit for unchanged panes loses no legitimate resize/SIGWINCH.safeFit), preserving the existing convergence guarded bytests/e2e/terminal-inline-tui-reveal-convergence.spec.ts(incl. its "reveal after a hidden-time window resize" case).requestStablePaneFit), which forwards the corrected grid to the PTY (fit runs before the parked continuation flushes).isActivecases as before).SYNC_FIT_PANES_EVENT, ResizeObserver, splits) still funnels throughsafeFit, which records the pixel baseline — so a genuine reveal resize can't be misclassified as "unchanged."Adversarial review
Ran a 3-round adversarial review loop with two independent frontier reviewers (Claude Fable + GPT‑5.6). Findings surfaced and fixed along the way: a fit↔PTY-reassert timing race, measuring the wrong (outer) element, a residual transient-commit in the stable fitter, and a snapshot-divergence repair regression. Final round: both reviewers confirm all concrete/blocking findings closed; the only remaining items are narrow, self-healing, explicitly non-blocking edges (a rare transient double-SIGWINCH on the uncommon divergence branch that self-corrects within a frame).
Tests
pane-reveal-fit.test.ts(all four routing branches incl. snapshot-divergence repair + unmeasurable) andpane-fit.test.ts(paneFitClientSizeChanged: no-baseline, same-size, resized, sub-pixel jitter, inner-host shrink, unmeasurable). Manager/visibility paths assert the reveal routes through the stable fit and never the rawfitAllPanes.pane-manager+ affectedterminal-panesuites: 624 pass / 1 skipped.oxlintclean.tsc(renderer) clean.Note on scope
The fix lives entirely on Orca's side (hosting inline TUIs correctly across reveal);
grok/grok-buildwas used only to reproduce and understand the corruption, not modified.Made with Orca 🐋