Skip to content

fix(terminal): repaint revealed panes stuck behind xterm's paused-render gate - #7614

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/terminal-reveal-paused-render-fix
Jul 7, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/terminal-reveal-paused-render-fix

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

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 calls terminal.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:

public refreshRows(start, end, sync = false, ...) {
  if (this._isPaused) {           // observer hasn't reported the pane as intersecting yet
    this._needsFullRefresh = true;
    return;                       // <-- our refresh() is swallowed
  }
  ...
}

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 _isPaused is still true, so the reveal-repaint's refresh() just latches _needsFullRefresh and returns. The freshly-cleared model never repaints, and the canvas keeps compositing pre-hide pixels. A drag-select recovers it because handleSelectionChanged drives a render that isn't behind the same gate.

Note the sync: true path (already used by the foreground render-settle) does not help — the _isPaused check runs before the sync branch.

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 _isPaused from the entry), so the transient clear is self-correcting.

resetWebglTextureAtlas now calls this first and only falls back to terminal.refresh() when the terminal wasn't gated (preserving current behavior for DOM-rendered panes and non-xterm targets).

All internal access is behind typeof guards and try/catch: an xterm upgrade that renames these internals degrades to the existing refresh() path instead of throwing into a render frame.

Testing

  • New unit suite terminal-render-pause-release.test.ts (5 tests): paused → forces refreshRows(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.
  • Existing pane-reveal-repaint and pane-webgl-renderer suites still pass (fake terminals have no render service → fall through to refresh() unchanged).
  • pnpm typecheck + oxlint clean.

Notes

This is a general fix (the paused-render gate is upstream xterm, and the reveal-repaint machinery is identical on main), so it targets main rather than the orca-performance branch. 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 🐋

…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]>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc9eb53c-7d9b-4eef-bb35-b4391735862f

📥 Commits

Reviewing files that changed from the base of the PR and between 7f52a77 and c698643.

📒 Files selected for processing (1)
  • tests/e2e/terminal-reveal-paused-render-repro.spec.ts

📝 Walkthrough

Walkthrough

This PR adds forceRepaintThroughRenderPause for xterm terminals with a paused internal render service, updates resetWebglTextureAtlas to use that helper before falling back to terminal.refresh(...), and adds unit plus end-to-end coverage for the paused-render reveal path. The new tests cover paused, unpaused, missing-internals, invalid-row-count, and error cases, and the e2e spec probes render ranges and verifies screenshot recovery.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, testing, and notes, but omits the required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections, including screenshots or 'No visual change', cross-platform review details, and a security audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR's main fix: repainting revealed panes when xterm is paused.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/renderer/src/lib/pane-manager/terminal-render-pause-release.ts (2)

1-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Top-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 < 1 doesn't guard against NaN.

NaN < 1 evaluates to false in JS, so a NaN rows value passes this guard and reaches service.refreshRows(0, NaN, true) — not necessarily caught by the surrounding try/catch since a bogus range may not throw. In practice terminal.rows should 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3bf12 and 7f52a77.

📒 Files selected for processing (3)
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts
  • src/renderer/src/lib/pane-manager/terminal-render-pause-release.test.ts
  • src/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]>
@Jinwoo-H

Jinwoo-H commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Reproduction & verification added

I added an e2e reproduction (tests/e2e/terminal-reveal-paused-render-repro.spec.ts) that runs against a real Electron build with a real xterm RenderService — not mocks — so this doesn't have to be merged on faith.

How it proves the mechanism. The spec 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; headless can't reliably race it, so we set it explicitly and drive the exact same gate the real bug hits):

  • Control — clearTextureAtlas() + terminal.refresh() while paused. This is byte-for-byte the pre-fix resetWebglTextureAtlas on main. Result: 0 rows rendered → the stale/missing-bottom-rows bug, reproduced.
  • Fix — the real production reveal path (manager.resetWebglTextureAtlases() → resetWebglTextureAtlas → forceRepaintThroughRenderPause). Result: a full-viewport (0..rows-1) render fires through the gate, and the pause latch is cleared.
  • Pixel check — the recovered surface matches the revealed content.

A/B proof that the assertion actually guards the fix (packaged e2e build, --project electron-headless):

Build state Result
Fix present ✅ 1 passed
Fix neutered (function → return false) ❌ 1 failed — Expected: > 0, Received: 0 (0 renders through the paused gate)
Fix restored ✅ 1 passed

So the test fails without the fix and passes with it — it's a real regression guard, not a tautology.

Note: the deterministic _isPaused flip stands in for the observer-lag timing because headless Electron doesn't reproduce that race on its own (documented for this bug class). The gate being exercised is the real one; only its trigger is forced.

@Jinwoo-H
Jinwoo-H merged commit a6cbd31 into main Jul 7, 2026
3 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/terminal-reveal-paused-render-fix branch July 7, 2026 03:17
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant