Skip to content

fix(terminal): per-pane WebGL attach latch and fit-anchored reattach - #12945

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/terminal-per-pane-webgl-attach-recovery
Aug 6, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/terminal-per-pane-webgl-attach-recovery

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Fixes the other route into the P0 "terminal stuck on bold/blurry font until resize" reports (Slack, Aug 5): a pane left on the DOM renderer when it should be on WebGL. The two renderers differ visibly by design — WebGL floors the device cell width (floor(8.4287 × 2) = 16 device px at SF Mono 14 / dpr 2, i.e. 8.0 css px vs the DOM renderer's 8.43) and rasterizes through the glyph atlas rather than browser AA — so a DOM-stuck pane reads as bolder, ~5% wider text at the same wrap column.

Two changes:

  1. Per-pane attach-failure latch. webglAttachFailedSinceRecovery was module-global: one pane's failed WebGL context creation stranded every other pane on the DOM renderer until the next recovery boundary. It is now per-pane (ManagedPaneInternal.webglAttachFailedSinceRecovery), cleared per-pane at the existing boundaries (rendering resume, GPU-setting change, live-addon rebuild).

  2. Fit-anchored reattach. A successful safeFit now offers a reattach to a pane that is WebGL-eligible but addon-less (a late mount that missed the coalesced reveal repaint, or a stale fallback). This makes recovery event-anchored — the fit proves the pane is measurable — instead of relying on wall-clock reveal bursts, and it means a user resize genuinely heals a DOM-stuck pane. The per-pane failure latch is honored: genuinely failed attaches still retry only at recovery boundaries, never per-fit. Wired through a small signal module (pane-fit-webgl-attach-signal.ts) because pane-webgl-renderer already imports pane-fit.

A webgl-fit-attach diagnostic records each late attach, and pane rendering diagnostics now include the per-pane latch — the stuck state finally shows up in telemetry.

Client-size fit helpers moved from pane-fit.ts to pane-fit-client-size.ts to stay under the max-lines cap (no behavior change in the move).

Screenshots

No visual change in the normal path; the fix removes a wrong-renderer state. The bold/wider DOM-fallback signature was verified in a CDP rig by forcing suspendRendering() on a live pane and measuring the text extent shift (74 device px / 5.3% at SF Mono 14, dpr 2).

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — targeted suites run locally: all of src/renderer/src/lib/pane-manager/ (640 tests) and all of src/renderer/src/components/terminal-pane/ (245 files / 3154 tests); full suite left to CI
  • pnpm build — left to CI
  • Added or updated high-quality tests that would catch regressions: per-pane latch isolation (healthy pane attaches after another pane's failure — fails under the old global latch), latch honored until cleared (no repeat canvas burn), fit-anchored reattach (attaches eligible addon-less pane; skips latched/suspended/context-loss panes; leaves a live addon untouched)

AI Review Report

Reviewed by the implementing agent with the repo's WebGL-recovery history in context (#7064 introduced the global latch, #11864's coalesced reveal repaint created the late-mount gap). Main risks checked: (1) attach storms on a broken GPU — bounded: each pane attempts once per recovery boundary (previously one pane attempted; the delta is at most one failed getContext per pane per boundary), and the fit pump never retries a latched pane; (2) import cycle pane-fit ↔ pane-webgl-renderer — broken via the registration signal module; hook exceptions are swallowed so a reattach failure cannot fail the fit that triggered it; (3) recovery-boundary semantics preserved — resumePaneRendering, applyTerminalGpuAcceleration (mode change), and rebuildAttachedWebgl all clear the per-pane latch exactly where the global was cleared before; (4) attachWebgl's ineligible-path disposeWebgl is a no-op for addon-less panes, so the fit pump adds no churn. Cross-platform: explicitly considered Windows ANGLE → D3D11 context creation cost (100–500 ms/pane) — the fit pump attaches only when the addon is missing and unlatched, a rare one-shot heal, not a per-fit cost; macOS/Linux identical logic; no shortcuts, labels, paths, or shell behavior touched.

Security Audit

Renderer-internal state only. No input handling, command execution, path handling, auth, secrets, dependency, or IPC changes. Diagnostics carry only numeric pane ids and booleans through the existing terminal_webgl_diagnostic sink.

Notes

  • Companion PR (deferred metric-option writes for hidden panes) fixes the other route into the same reports; independent, either order. Both touch the pane-fit.ts import block, so whichever lands second needs a trivial rebase.
  • Windows note: with the per-pane latch, a machine whose GPU process is genuinely down pays up to one failed attach per pane per recovery boundary instead of one globally; each is a canvas + failed getContext, bounded by pane count.
  • Follow-ups deliberately out of scope: reducing reveal-time atlas resets, and the parking/unmount architecture discussion (keeping WebGL alive for hot-retained panes).

The attach-failure latch was module-global: one pane's failed WebGL context
creation stranded every other pane on the DOM renderer — whose cell metrics
and rasterization differ visibly (bolder, ~5% wider text) — until the next
recovery boundary. The latch is now per-pane.

A successful fit additionally offers an event-anchored reattach: a pane that
is WebGL-eligible but addon-less (late mount that missed the coalesced reveal
repaint, stale fallback) regains WebGL the moment it proves measurable, so a
user resize now heals a DOM-stuck pane instead of leaving it. Failed attaches
still retry only at recovery boundaries. A webgl-fit-attach diagnostic records
each late attach so the stuck state is finally visible in telemetry.

Client-size fit helpers move to pane-fit-client-size.ts to stay under the
pane-fit.ts line cap.
@coderabbitai

coderabbitai Bot commented Aug 6, 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 Plus

Run ID: 99daf079-ac1a-47f3-bfd3-4c6de3d0ee07

📥 Commits

Reviewing files that changed from the base of the PR and between f3c577d and c969386.

📒 Files selected for processing (1)
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.ts

📝 Walkthrough

Walkthrough

Pane fitting now measures and records positive client dimensions and emits a successful-fit signal. WebGL attach-failure backoff is tracked per pane and exposed through rendering diagnostics. Recovery, rendering resume, GPU mode changes, and WebGL reattachment clear pane-specific backoff. Successful fits can reattach eligible missing WebGL renderers. Tests cover failure isolation, retry clearing, fit-triggered attachment, and excluded pane states.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the per-pane WebGL latch and fit-triggered reattach changes.
Description check ✅ Passed The description includes all required sections, testing status, AI review, security audit, platform checks, and follow-up notes.
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 💡 1
📝 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts (1)

228-233: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep attach failures per pane in auto mode.

Line 231 sets suggestedRendererType = 'dom' after one auto-mode pane fails. shouldUseTerminalWebgl() then rejects WebGL for every auto-mode pane. Rendering resume clears the pane latch, but it does not clear this global DOM decision.

Remove this global fallback from the attach-failure path. Let webglAttachFailedSinceRecovery suppress retries only for the failed pane. Add tests for a healthy auto-mode pane after another pane fails and for retry on rendering resume.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba73eb2d-2bfc-42ef-acf1-b83841220b27

📥 Commits

Reviewing files that changed from the base of the PR and between f6d0bde and d0b0f44.

📒 Files selected for processing (10)
  • src/renderer/src/lib/pane-manager/pane-fit-client-size.ts
  • src/renderer/src/lib/pane-manager/pane-fit-webgl-attach-signal.ts
  • src/renderer/src/lib/pane-manager/pane-fit.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
  • src/renderer/src/lib/pane-manager/pane-manager.ts
  • src/renderer/src/lib/pane-manager/pane-rendering-control.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-reattach.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts

The fit that triggers the reattach measures DOM cell metrics; WebGL floors
the device cell width, so healing a DOM-stuck pane left it on the DOM-derived
column count — an unpainted right gutter and a PTY narrower than the pane.
Refit on the next frame, mirroring the dispose-side refreshDimensions.

Also cover the real wiring: the existing fit-anchored tests drive the signal
module directly, so they stay green even if safeFit stops calling it. The new
suite goes through safeFit, which is also what proves the import-time hook
registration works.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts (1)

253-253: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Remove the module-global DOM fallback from the attach-failure path.

The attach-failure handler still sets suggestedRendererType = 'dom' for an auto-mode pane. Line 50 then rejects WebGL for every auto-mode pane. The new pane.webglAttachFailedSinceRecovery latch does not isolate failures.

Remove the global assignment and its global gate. Keep the failure latch on the affected pane. Add a test with one failing auto-mode pane and one healthy auto-mode pane. (raw.githubusercontent.com)

Proposed fix
-let suggestedRendererType: 'dom' | undefined
-
-  suggestedRendererType = undefined
-
-  if (pane.terminalGpuAcceleration !== 'auto' || suggestedRendererType === 'dom') {
+  if (pane.terminalGpuAcceleration !== 'auto') {
     return false
   }

-    if (pane.terminalGpuAcceleration === 'auto') {
-      suggestedRendererType = 'dom'
-    }
     pane.webglAttachFailedSinceRecovery = true

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 295d4840-c609-43dc-b6bf-68d092011615

📥 Commits

Reviewing files that changed from the base of the PR and between d0b0f44 and f3c577d.

📒 Files selected for processing (2)
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.ts
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Live Electron QA — per-pane WebGL latch + fit-anchored reattach

HEAD tested: f3c577dc58 (brennanb2025/terminal-per-pane-webgl-attach-recovery)
Instance verified: Orca: brennanb2025/terminal-per-pane-webgl-attach-recovery @ worktree pr-12945-per-pane-webgl-attach (CDP 9333 / renderer 5176, VITE_EXPOSE_STORE=true)
Probe ground truth: pane.terminal._core._renderService._renderer.value has _charAtlas ⇒ WebGL; .xterm-rows present ⇒ DOM. Cross-checked with mgr.getRenderingDiagnostics().hasWebgl and internal pane.webglAddon.

Verdict summary

Scenario Result Key probe
1. Baseline WebGL PASS single pane hasWebgl: true, _charAtlas, no .xterm-rows, cols=135
2. Per-pane latch isolation PASS latched pane stayed DOM; sibling reached WebGL
3. Fit-anchored heal PASS DOM cols=63 → after fitAllPanes WebGL cols=66 (Δ+3)
4. No gutter after heal PASS healed pane settled onto wider WebGL grid; edge-marker lines reach right edge
5. No regression (split/close/switch) PASS no blank panes; WebGL retained; worktree switch returned clean

1. Baseline

Opened terminal with terminalGpuAcceleration: 'on'. Pane on WebGL immediately (addon + char atlas). Full app window:

01-baseline-webgl-full.png

2. Per-pane latch isolation (core fix)

Split vertical → 2 panes. Forced webglAttachFailedSinceRecovery = true on left only, disposed both, re-enabled GPU via setPaneGpuRendering (calls attachWebgl, honors latch).

Pane Renderer Latch cols (same ~544px box)
Left (failing) DOM (hasWebgl: false, .xterm-rows) true 63
Right (healthy) WebGL (hasWebgl: true, _charAtlas) false 66

Under the old module-global latch, the right pane would also have been forced to DOM. Observed isolation:

02-per-pane-latch-isolation.png

3. Fit-anchored heal (user-visible fix)

Forced target pane onto DOM (gpu dispose + temporary latch to hold DOM for screenshot), painted content, then cleared latch and drove a successful fit (mgr.fitAllPanes() → attachWebglAfterFitIfMissing → refit).

Before (DOM stuck):

  • webgl: false, domRows: true, cols: 63

03-dom-stuck-before-heal.png

After (fit-anchored reattach):

  • webgl: true, domRows: false, cols: 66 (Δ +3 on same container width)

04-webgl-after-fit-heal.png

4. No gutter after heal

Post-heal single-pane edge markers (·…| to last col). WebGL grid used full width; cols=135 on ~1097px container; no unpainted right gutter visible:

05-no-gutter-healed-fullwidth.png

5. Normal-use regression check (PR 11338 flash/lost-content risk)

  • Wrote multi-line output into the pane
  • Split + close panes
  • Switched to another worktree and back
  • Observed: no blank panes, no lost buffer on return, WebGL still attached (hasWebgl: true), no visible flash/jank during the scripted path

06-normal-use.png

Backing state checked

  • window.api.app.getIdentity() → this worktree/branch
  • window.api.e2e.getConfig().exposeStore === true → __paneManagers available
  • Internal mgr.panes Map (public getPanes() strips WebGL fields)
  • getRenderingDiagnostics() per pane: hasWebgl, webglAttachFailedSinceRecovery, gpuRenderingEnabled, deferred/loss flags
  • Renderer probe: _charAtlas vs .xterm-rows
  • Col metrics before/after heal (DOM 63 → WebGL 66) match the cell-flooring story (~5% wider DOM cells)

Unverified / gaps

  • Did not drive a real mouse drag on a pane divider or OS-level window resize; heal was exercised through fitAllPanes() / the same fit-success hook a resize uses (attachWebglAfterFitIfMissing).
  • Did not force a genuine Chromium WebGL context-creation failure (latch was set in-process to simulate the post-failure state).
  • Did not multi-hour soak / many-pane stress for context budget.
  • Visual “de-bold” is clearer at high zoom; the col count shift (63→66) is the hard quantitative signature of DOM→WebGL metrics.

Merge confidence

Visible behavior + backing renderer state both checked for the five scenarios above. Remaining gaps are listed; nothing found that contradicts the PR’s claimed fixes on this machine.

Local screenshot paths (also embedded above):
/tmp/pr12945-qa/01-baseline-webgl-full.png … 06-normal-use.png

The existing suites stub requestAnimationFrame synchronously, so the window
in which the refit handle is live never exists there — nothing covered the
two properties that window has to hold. With a deferred stub:

- disposing the pane cancels the refit, so it cannot fit (and forward a PTY
  resize for) an already-disposed terminal;
- the deferred fit re-enters the hook exactly once and settles, so there is
  no fit -> attach -> fit cycle.

Both fail against mutated production code (handle kept out of the
cancellable slot; addon-less guard dropped).
@brennanb2025
brennanb2025 merged commit 01d3bc5 into main Aug 6, 2026
brennanb2025 added a commit that referenced this pull request Aug 7, 2026
Conflict was the predicted one in pane-fit.ts: #12945 and this branch
each split the file differently to stay under the max-lines cap.

Resolution keeps both splits:
- main's pane-fit-client-size.ts extraction (readFitClientSize is now
  re-exported from there; the local copies are dropped)
- this branch's pane-fit-measurability.ts extraction (canMeasurePaneForFit
  and getProposedPaneDimensions), so main's local getProposedDimensions
  and duplicate min-size constants are dropped
- main's notifyPaneFitSucceeded in safeFit, alongside the deferred metric
  flush and post-flush fit-floor re-check in performSafeFit
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#12945)

* fix(terminal): per-pane WebGL attach latch and fit-anchored reattach

The attach-failure latch was module-global: one pane's failed WebGL context
creation stranded every other pane on the DOM renderer — whose cell metrics
and rasterization differ visibly (bolder, ~5% wider text) — until the next
recovery boundary. The latch is now per-pane.

A successful fit additionally offers an event-anchored reattach: a pane that
is WebGL-eligible but addon-less (late mount that missed the coalesced reveal
repaint, stale fallback) regains WebGL the moment it proves measurable, so a
user resize now heals a DOM-stuck pane instead of leaving it. Failed attaches
still retry only at recovery boundaries. A webgl-fit-attach diagnostic records
each late attach so the stuck state is finally visible in telemetry.

Client-size fit helpers move to pane-fit-client-size.ts to stay under the
pane-fit.ts line cap.

* fix(terminal): refit onto WebGL cell metrics after a fit-anchored attach

The fit that triggers the reattach measures DOM cell metrics; WebGL floors
the device cell width, so healing a DOM-stuck pane left it on the DOM-derived
column count — an unpainted right gutter and a PTY narrower than the pane.
Refit on the next frame, mirroring the dispose-side refreshDimensions.

Also cover the real wiring: the existing fit-anchored tests drive the signal
module directly, so they stay green even if safeFit stops calling it. The new
suite goes through safeFit, which is also what proves the import-time hook
registration works.

* test(terminal): gate the fit-anchored refit frame on a deferred rAF

The existing suites stub requestAnimationFrame synchronously, so the window
in which the refit handle is live never exists there — nothing covered the
two properties that window has to hold. With a deferred stub:

- disposing the pane cancels the refit, so it cannot fit (and forward a PTY
  resize for) an already-disposed terminal;
- the deferred fit re-enters the hook exactly once and settles, so there is
  no fit -> attach -> fit cycle.

Both fail against mutated production code (handle kept out of the
cancellable slot; addon-less guard dropped).
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