Repository navigation
fix(terminal): repaint revealed panes stuck behind xterm's paused-render gate - #7614
Conversation
…der gate On tab/worktree reveal, resetWebglTextureAtlas clears the WebGL render model and calls terminal.refresh() to force a full repaint. But xterm's RenderService gates refreshRows() on its IntersectionObserver: while the observer still reports the just-revealed screen element as not intersecting (a frame it can lag, worse under load), refresh() early-returns and only latches _needsFullRefresh. The cleared model never repaints, so the canvas keeps compositing stale rows — the 'bottom rows missing until you drag-select' symptom, where selection forces handleSelectionChanged past the same gate and the rows finally draw. Add forceRepaintThroughRenderPause(): when the render service is paused, clear the pause latch and drive one synchronous full-viewport render, then let the observer reassert authority on its next callback. Behind typeof guards so an xterm upgrade that renames these internals degrades to the existing refresh() path instead of throwing into a render frame. 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 (1)
📝 WalkthroughWalkthroughThis PR adds 🚥 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.
🧹 Nitpick comments (2)
src/renderer/src/lib/pane-manager/terminal-render-pause-release.ts (2)
1-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTop-of-file comment exceeds the "1-2 lines" guideline.
This JSDoc block is ~14 lines of narrative. As per coding guidelines,
**/*.{ts,tsx,js,jsx}should "Keep comments short — one or two lines, capturing only the non-obvious reason." Consider trimming to the core non-obvious rationale (the paused-render swallow mechanism) and moving the detailed narrative to a PR description/design doc if needed for posterity.Source: Coding guidelines
57-60: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value
rows < 1doesn't guard againstNaN.
NaN < 1evaluates tofalsein JS, so aNaNrowsvalue passes this guard and reachesservice.refreshRows(0, NaN, true)— not necessarily caught by the surroundingtry/catchsince a bogus range may not throw. In practiceterminal.rowsshould always be a valid positive integer, so this is a low-probability edge case, but a small defensive tweak removes the gap entirely.🛡️ Proposed fix
- const rows = (terminal as TerminalWithRenderService).rows - if (typeof rows !== 'number' || rows < 1) { + const rows = (terminal as TerminalWithRenderService).rows + if (typeof rows !== 'number' || !Number.isFinite(rows) || rows < 1) { return false }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 13590da2-ea12-43fa-a118-84d6fd990673
📒 Files selected for processing (3)
src/renderer/src/lib/pane-manager/pane-webgl-renderer.tssrc/renderer/src/lib/pane-manager/terminal-render-pause-release.test.tssrc/renderer/src/lib/pane-manager/terminal-render-pause-release.ts
Drives the REAL production reveal path (manager.resetWebglTextureAtlases ->
resetWebglTextureAtlas -> forceRepaintThroughRenderPause) against a real xterm
Terminal + RenderService in headless Electron. Instruments RenderService._renderRows
to record which row ranges actually reach the renderer, then deterministically
forces the _isPaused gate (the observer-lag state the field bug hits, which
headless can't reliably race) and:
- control: clearTextureAtlas + terminal.refresh (byte-for-byte the PRE-FIX
resetWebglTextureAtlas) renders 0 rows while paused — bug reproduced;
- fix: the real reveal repaint drives a full-viewport (0..rows-1) render
through the gate and clears the pause latch;
- pixel check: recovered surface matches the revealed content.
Verified A/B against a packaged e2e build: fix present -> PASS; fix neutered
-> FAIL (0 renders through the paused gate); fix restored -> PASS. The
assertion genuinely guards the fix, not incidental behavior.
Co-authored-by: Orca <[email protected]>
Reproduction & verification addedI added an e2e reproduction ( How it proves the mechanism. The spec instruments
A/B proof that the assertion actually guards the fix (packaged e2e build,
So the test fails without the fix and passes with it — it's a real regression guard, not a tautology. Note: the deterministic |
…der gate (stablyai#7614) Co-authored-by: Orca <[email protected]>
Problem
When switching back to a workspace/tab, a TUI (e.g. Claude Code) sometimes shows stale/missing rows near the bottom that only reappear when you right-click-drag to select the missing area. It happens more often when the machine is under load.
Root cause
On reveal,
resetWebglTextureAtlas(pane-webgl-renderer.ts) clears xterm's WebGL render model (clearTextureAtlas()) and callsterminal.refresh(0, rows-1)to force a full repaint from the buffer.But xterm's
RenderService.refreshRows()has an early-return gated on its IntersectionObserver:When a pane is revealed it is DOM-visible, but the observer's callback can lag a frame (more likely under load, when layout/overlay settle is slower). In that window
_isPausedis stilltrue, so the reveal-repaint'srefresh()just latches_needsFullRefreshand returns. The freshly-cleared model never repaints, and the canvas keeps compositing pre-hide pixels. A drag-select recovers it becausehandleSelectionChangeddrives a render that isn't behind the same gate.Note the
sync: truepath (already used by the foreground render-settle) does not help — the_isPausedcheck runs before thesyncbranch.Fix
Add
forceRepaintThroughRenderPause(): when the render service is paused, clear the pause latch and drive one synchronous full-viewport render ourselves, rather than waiting on the observer. xterm's observer reasserts authority on its next callback (it always recomputes_isPausedfrom the entry), so the transient clear is self-correcting.resetWebglTextureAtlasnow calls this first and only falls back toterminal.refresh()when the terminal wasn't gated (preserving current behavior for DOM-rendered panes and non-xterm targets).All internal access is behind
typeofguards andtry/catch: an xterm upgrade that renames these internals degrades to the existingrefresh()path instead of throwing into a render frame.Testing
terminal-render-pause-release.test.ts(5 tests): paused → forcesrefreshRows(0, rows-1, true)+ clears both latches; not-paused → untouched, returns false; missing internals → false; invalid row count → false; forced render throws → false but latch still cleared.pane-reveal-repaintandpane-webgl-renderersuites still pass (fake terminals have no render service → fall through torefresh()unchanged).pnpm typecheck+oxlintclean.Notes
This is a general fix (the paused-render gate is upstream xterm, and the reveal-repaint machinery is identical on
main), so it targetsmainrather than theorca-performancebranch. It also plausibly addresses the teammate-reproduced garbled/glyph output when pasting right after the app was unfocused — same paused-render-gate class.Made with Orca 🐋