Repository navigation
fix(terminal): per-pane WebGL attach latch and fit-anchored reattach - #12945
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPane 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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.
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 winKeep 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
webglAttachFailedSinceRecoverysuppress 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
📒 Files selected for processing (10)
src/renderer/src/lib/pane-manager/pane-fit-client-size.tssrc/renderer/src/lib/pane-manager/pane-fit-webgl-attach-signal.tssrc/renderer/src/lib/pane-manager/pane-fit.tssrc/renderer/src/lib/pane-manager/pane-manager-types.tssrc/renderer/src/lib/pane-manager/pane-manager.tssrc/renderer/src/lib/pane-manager/pane-rendering-control.tssrc/renderer/src/lib/pane-manager/pane-terminal-gpu-acceleration.tssrc/renderer/src/lib/pane-manager/pane-webgl-reattach.tssrc/renderer/src/lib/pane-manager/pane-webgl-renderer.test.tssrc/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.
There was a problem hiding this comment.
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 winRemove 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 newpane.webglAttachFailedSinceRecoverylatch 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
📒 Files selected for processing (2)
src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.tssrc/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
Live Electron QA — per-pane WebGL latch + fit-anchored reattachHEAD tested: Verdict summary
1. BaselineOpened terminal with 2. Per-pane latch isolation (core fix)Split vertical → 2 panes. Forced
Under the old module-global latch, the right pane would also have been forced to DOM. Observed isolation: 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 ( Before (DOM stuck):
After (fit-anchored reattach):
4. No gutter after healPost-heal single-pane edge markers ( 5. Normal-use regression check (PR 11338 flash/lost-content risk)
Backing state checked
Unverified / gaps
Merge confidenceVisible 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): |
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).
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
…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).






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) = 16device 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:
Per-pane attach-failure latch.
webglAttachFailedSinceRecoverywas 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).Fit-anchored reattach. A successful
safeFitnow 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) becausepane-webgl-rendereralready importspane-fit.A
webgl-fit-attachdiagnostic 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.tstopane-fit-client-size.tsto 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 lintpnpm typecheckpnpm test— targeted suites run locally: all ofsrc/renderer/src/lib/pane-manager/(640 tests) and all ofsrc/renderer/src/components/terminal-pane/(245 files / 3154 tests); full suite left to CIpnpm build— left to CIAI 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
getContextper pane per boundary), and the fit pump never retries a latched pane; (2) import cyclepane-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), andrebuildAttachedWebglall clear the per-pane latch exactly where the global was cleared before; (4)attachWebgl's ineligible-pathdisposeWebglis 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_diagnosticsink.Notes
pane-fit.tsimport block, so whichever lands second needs a trivial rebase.getContext, bounded by pane count.