Skip to content

Raise WebGL terminal context budget and recover from context loss - #7064

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/webgl-context
Jul 2, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/webgl-context

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

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-contexts switch in enableMainProcessGpuFeatures() before app.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 webglDisabledAfterContextLoss until 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-on mode constructed a new WebglAddon on every terminal title change — agent TUIs retitle constantly, flooding the console with full-stack WebGL2 not supported warnings (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. rebuildAttachedWebgl clears 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 lint
  • pnpm typecheck
  • pnpm test — targeted: all 144 test files / 1728 tests under src/renderer/src/lib/pane-manager + src/renderer/src/components/terminal-pane, plus src/main/startup/configure-process.test.ts (23); full suite left to CI
  • pnpm build — not run locally; left to CI
  • New tests: pane-webgl-context-recovery.test.ts drives the production onContextLoss handler 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.ts covers latch clearing on mode change (and preservation when mode is unchanged). configure-process.test.ts covers 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-on and 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

  • Recovery boundaries are worktree foregrounding and window wake. A pane that loses its context while visible rejoins WebGL on the next such event rather than instantly — deliberate, to keep retries loop-proof. macOS sleep/wake GPU resets recover automatically via the existing window-wake path.
  • The context-loss → DOM fallback flow was validated with unit tests that fire the real xterm addon context-loss event through the production handler; a genuine GPU process crash was not reproduced end-to-end locally.

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]>
@ghost

ghost commented Jul 2, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Raise WebGL context budget in main process
2 Implement WebGL attachment backoff and recovery
3 Wire recovery boundaries to rendering lifecycle
4 Verify WebGL recovery and latching logic
Open in Stage

Chapters generated by Stage for commit 65358a0 on Jul 2, 2026 3:44am UTC.

@coderabbitai

coderabbitai Bot commented Jul 2, 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: 76be8798-e30a-4f06-95db-d3370b359d3c

📥 Commits

Reviewing files that changed from the base of the PR and between c15aa81 and 65358a0.

📒 Files selected for processing (6)
  • src/renderer/src/lib/pane-manager/pane-rendering-control.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.test.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-context-recovery.test.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-reattach.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts

📝 Walkthrough

Walkthrough

This change adds the max-active-webgl-contexts Electron switch with a value of 128 in enableMainProcessGpuFeatures, and updates tests for the enabled and Linux GPU-disabled paths. In the renderer, it adds a WebGL attach backoff latch, clears that latch during recovery and resume flows, resets pane WebGL disable state on GPU mode changes, and expands test coverage for attach retry and context-loss recovery behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: raising the WebGL context budget and improving context-loss recovery.
Description check ✅ Passed The description follows the required template and includes complete Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
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.

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]>
@Jinwoo-H Jinwoo-H changed the title Raise WebGL terminal context budget to 128 Raise WebGL terminal context budget and recover from context loss Jul 2, 2026
@Jinwoo-H
Jinwoo-H merged commit c29bf6f into main Jul 2, 2026
21 of 29 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/webgl-context branch July 2, 2026 06:43
Jinwoo-H added a commit that referenced this pull request Jul 2, 2026
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.
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