Repository navigation
Raise WebGL terminal context budget and recover from context loss - #7064
Conversation
Blink force-loses the oldest active WebGL context past 16 per renderer process. Each attached terminal pane holds one context, and background terminal tabs in the active worktree keep theirs for fast tab switching, so tab x split layouts can exceed the default cap. The evicted pane's context-loss handler then latches it onto the DOM renderer until remount, silently losing GPU acceleration. 128 covers realistic layouts plus transient overlap during worktree switches and split reparenting, while staying bounded so a context leak still surfaces as eviction instead of GPU memory exhaustion. Co-authored-by: Orca <[email protected]>
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you:
Chapters generated by Stage for commit 65358a0 on Jul 2, 2026 3:44am UTC. |
|
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 (6)
📝 WalkthroughWalkthroughThis change adds the 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Context loss previously latched webglDisabledAfterContextLoss until the pane remounted, so a single GPU process reset (sleep/wake, driver crash) silently downgraded every affected terminal to the DOM renderer for the rest of the worktree's life — even after Chromium restored the GPU and fired webglcontextrestored. Rendering resume (worktree foreground, window wake) and explicit GPU-setting changes now clear the latch and retry, bounding retries to discrete recovery events so loss cannot loop. Also adds a session-wide attach backoff: while Chromium refuses context creation (GPU process down, WebGL blocked), forced-on mode retried a new WebglAddon on every terminal title change, flooding the console with full-stack warnings. The first failure now suppresses further attempts until the next recovery boundary, giving at most one attempt per resume. rebuildAttachedWebgl clears the backoff first: its live addon proves creation works, so a stale backoff must not downgrade a healthy pane. Co-authored-by: Orca <[email protected]>
Workspace switches disposed every hidden pane's WebGL context and recreated it on return - ~5ms on macOS but 100-500ms per pane on Windows (ANGLE -> D3D11), paid synchronously on the switch path. The dispose-on-hide policy guarded Chromium's old 16-context budget, which #7064 raised to 128. Suspended panes now keep their live contexts in an LRU (cap 16, evicted panes disposed); resume repaints retained panes instead of recreating contexts. Atlas recovery bursts skip suspended panes so recovery cost scales with visible panes, not total pane count across workspaces.
…ablyai#7064) Co-authored-by: Orca <[email protected]>
Summary
Two related fixes for terminal GPU rendering falling back to the slow DOM renderer.
1. Raise Blink's active-WebGL-context cap to 128. Terminals use xterm's WebGL renderer, but Blink caps active WebGL contexts at 16 per renderer process and force-loses the oldest context beyond that. Each attached terminal pane holds one context, and background terminal tabs within the active worktree intentionally keep theirs for fast tab switching — so heavy tab × split layouts can exceed 16 and evict panes. Raised via Chromium's
max-active-webgl-contextsswitch inenableMainProcessGpuFeatures()beforeapp.whenReady(). 128 covers realistic layouts (active worktree tabs × splits + floating terminal + transient overlap during worktree switches) while staying bounded, so a context leak still surfaces as visible eviction instead of unbounded GPU memory growth. The switch is inert wherever GPU rendering is already off (Linux E2E path, GPU-fallback launches, Wayland/software-renderer auto-policy).2. Recover WebGL after context loss instead of latching panes to the DOM renderer. Context loss previously latched
webglDisabledAfterContextLossuntil pane remount, so one GPU process reset (sleep/wake, driver crash) silently downgraded every affected terminal for the rest of the worktree's life — even after Chromium restored the GPU. Rendering resume (worktree foreground, window wake) and explicit GPU-setting changes now clear the latch and retry. Retries only happen at these discrete recovery boundaries, so loss cannot loop the way immediate re-creation could (the reason the latch was originally permanent).3. Back off failed attach attempts. While Chromium refuses context creation entirely (GPU process down / WebGL blocked after repeated resets), forced-
onmode constructed a newWebglAddonon every terminal title change — agent TUIs retitle constantly, flooding the console with full-stackWebGL2 not supportedwarnings (observed 51× in one session). The first failure now suppresses further attempts until the next recovery boundary, giving at most one attempt per resume instead of one per title change.rebuildAttachedWebglclears the backoff before reattaching: its guard proves a live addon existed, so a stale backoff must not downgrade a healthy pane during font/settings rebuilds.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test— targeted: all 144 test files / 1728 tests undersrc/renderer/src/lib/pane-manager+src/renderer/src/components/terminal-pane, plussrc/main/startup/configure-process.test.ts(23); full suite left to CIpnpm build— not run locally; left to CIpane-webgl-context-recovery.test.tsdrives the productiononContextLosshandler via the real addon's context-loss emitter — full loss → latch → resume → recovery cycle, re-latch on repeated loss, attach backoff and its resume-boundary reset.pane-terminal-gpu-acceleration.test.tscovers latch clearing on mode change (and preservation when mode is unchanged).configure-process.test.tscovers the switch on the default path and its absence on the disabled-GPU path.AI Review Report
Reviewed: (1) loop safety — the original permanent latch existed to prevent context-loss recreation loops; retries are now bound to discrete resume/wake/setting events and each failure re-latches, so a persistent outage costs one attempt per event, never a loop. (2) Backoff staleness — a global backoff could wrongly skip reattach for panes whose contexts provably work; the rebuild path clears it (live-addon evidence), the split-restore path intentionally honors it (a concurrent failure there means creation is failing right now). (3) One-attempt-per-resume — resume clears the backoff before iterating panes, so the first failing pane re-latches it and remaining panes skip construction. (4)
auto-mode semantics unchanged: the session-permanent DOM suggestion after a failed attach still applies; recovery-boundary retries affect forced-onand context-loss latches only. Cross-platform: no shortcuts, labels, paths, or shell behavior; the switch and renderer logic are platform-independent, and Linux Wayland/software paths keep terminal WebGL off via the existing auto-policy. SSH/headless unaffected (rendering is renderer-local; headless disables GPU).Security Audit
Main-process change appends one hardcoded Chromium switch; renderer changes are internal rendering state with no user, config, network, or IPC input. No auth, secrets, path handling, or command execution. Resource bound: a renderer may hold more live WebGL contexts before eviction — deliberately capped at 128.
Notes