Repository navigation
Fix stale terminal frames on worktree return: clear alt screen on snapshot restore + WebGL reveal hardening - #7133
Conversation
Returning to a worktree (or clicking its non-active terminal tab) while an agent had been writing to the hidden pane could composite pre-hide pixels over the final frame until a selection or resize forced a repaint. Three defects lined up: - attachWebgl's bail path nulled the addon reference without disposing, so a still-loaded addon kept painting stale frames while atlas resets, reattach checks, and diagnostics all treated the pane as DOM-rendered. - resetWebglTextureAtlas returned early for panes without an addon reference, skipping even the plain refresh. - Reveal recovery fired redraw requests before the revealed pane was attached and measured, where the WebGL renderer drops them silently. Fix: dispose on every attach bail and before attaching a replacement (single-addon invariant), refresh even when no addon is referenced, and schedule a pane-scoped clear+refresh on a settled frame after every tab reveal, worktree resume, and window wake. No PTY resize, so the grid never drifts. Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis change adds a settled-frame repaint scheduler for revealed terminal panes, exposes it through Related Issues: None specified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 723c98ee-46ac-4c81-9c48-182701d753ac
📒 Files selected for processing (8)
src/renderer/src/components/terminal-pane/terminal-visibility-resume.test.tssrc/renderer/src/components/terminal-pane/terminal-visibility-resume.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.tssrc/renderer/src/lib/pane-manager/pane-manager.tssrc/renderer/src/lib/pane-manager/pane-reveal-repaint.test.tssrc/renderer/src/lib/pane-manager/pane-reveal-repaint.tssrc/renderer/src/lib/pane-manager/pane-webgl-renderer.test.tssrc/renderer/src/lib/pane-manager/pane-webgl-renderer.ts
Live capture of a reproduced case showed the frozen/overlapping tab is a cell-level merge INSIDE the renderer's buffer: the pre-hide frame (banner, prompt echo) bleeding through every blank cell of the restored final frame. The rendering stack was innocent — it faithfully painted a merged buffer. The hidden-output restore deliberately skips the destructive clear for alternate-screen snapshots to protect normal-buffer scrollback. But the snapshot's own ?1049h is a no-op on a pane that is already on the alternate screen, and the serialized frame skips blank cells entirely (cursor-forward jumps), so nothing ever erases the pre-hide frame. Fresh terminals enter the alt screen via ?1049h — which clears it — which is why the bug never reproduced in fresh windows. Fix: for alternate-screen snapshots, write \x1b[?1049h\x1b[2J\x1b[H before the snapshot data. \x1b[2J on the alt buffer clears only the alt screen; the normal buffer's scrollback (what the skip was protecting) is untouched. Verified live on the reproduced specimen: writing the same snapshot with this preamble repaired the pane pixel-perfectly. Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
4397-4401: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueComment exceeds the 1–2 line guideline.
This "why" comment spans 5 lines. As per coding guidelines: "Keep comments short — one or two lines, capturing only the non-obvious reason."
✏️ Suggested tightening
- // Why: the snapshot's own ?1049h is a no-op when the pane is already on - // the alternate screen, and the serialized frame skips blank cells — so - // without clearing the alt screen the pre-hide frame bleeds through - // every cell the final frame leaves blank. \x1b[2J on the alt buffer - // does not touch the normal buffer's scrollback the TUI returns to. + // Why: snapshot's ?1049h is a no-op if already alt; clear the alt + // buffer directly so blank cells don't leak the pre-hide frame.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e58a20f5-197d-49bc-8f3c-3463473275c2
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
One pane throwing mid-loop would silently skip repainting the remaining panes in the same reveal batch. Also skip the settled-frame repaint after manager destroy: repainting disposed panes could throw in attach and latch the global WebGL attach backoff for unrelated new panes. Co-authored-by: Orca <[email protected]>
…pshot restore + WebGL reveal hardening (stablyai#7133) Co-authored-by: Orca <[email protected]>
Symptom
Start two agents in a worktree's terminal tabs, switch to another worktree while they work, come back when they're done, and check the tabs: one shows the frozen/overlapping mid-work frame (old prompt echo and banner text bleeding through the final output) until you select text or resize. Reported by @brennanb2025; reproduced twice, and the second reproduction was captured live and dissected layer by layer.
Root cause (proven on the live specimen)
The corrupted pane is a cell-level merge inside the renderer's xterm buffer: the pre-hide frame (banner + prompt echo) bleeding through every cell the final frame leaves blank. The render model matched the buffer exactly, the WebGL context was healthy, and a forced full redraw reproduced the same pixels — the rendering stack was faithfully painting a merged buffer.
The merge happens in the hidden-output restore (
applyMainBufferSnapshot):\x1b[2J\x1b[3J\x1b[H) is deliberately skipped, to protect the normal buffer's scrollback.?1049his a no-op on a pane that's already on the alternate screen, and the serialized frame skips blank cells (cursor-forward jumps) — so nothing ever erases the pre-hide frame. Every skipped cell keeps its stale content.?1049henters-and-clears the alt screen — which is why this never reproduced in fresh windows and survived earlier fix attempts (Prevent hidden terminal TUI overlap #7054, reverted Prevent stale terminal pixels on tab reveal #7058).Live proof both ways: byte capture of the snapshot stream shows
?1049h+ modes +[H+ cursor-jump content with no clear; and writing the same snapshot prefixed with an alt-screen clear repaired the corrupted pane pixel-perfectly.Fix
Primary —
pty-connection.ts: for alternate-screen snapshots, write\x1b[?1049h\x1b[2J\x1b[Hbefore the snapshot data.\x1b[2Jon the alt buffer clears only the alt screen; the normal buffer's scrollback (what the original guard was protecting) is untouched, and there is still no\x1b[3J.Hardening — WebGL reveal path (first commit, kept): a related render-level variant (buffer clean, pixels stale) was captured in an earlier session. Three defects fixed:
attachWebglcould orphan a live addon on its bail path (making every recovery sweep a silent no-op for exactly the broken pane),resetWebglTextureAtlasearly-returned without refreshing when the addon ref was null, and reveal recovery could fire redraw requests before the revealed pane was attached/measured (where the renderer drops them without retry). Now: dispose-on-bail + single-addon invariant, refresh-always, and a settled-frame pane-scoped repaint on tab reveal / worktree resume / window wake. No PTY resize anywhere, so the grid never drifts.Relationship to #7054 / #7058 / #7073
#7054's hidden-output skip machinery is what makes the restore path load-bearing; #7058 (reverted in #7073) retriggered global atlas resets on reveal, which cannot repair either variant (the buffer merge is below the renderer; the render variant's per-pane reset no-op'd on orphaned refs). This PR supersedes that approach and does not re-land it.
Tests
pty-connection.test.ts— alt-screen restore now asserts the alt-only clear is written before the snapshot data, and still asserts the destructive3Jclear is not.pane-webgl-renderer.test.ts,pane-reveal-repaint.test.ts,terminal-visibility-resume.test.ts— reveal-hardening regression tests (dispose-on-bail, repaint ordering, all three reveal seams).verify:localization-catalogfails on main for an unrelatedWorktreeListkey).