Skip to content

fix(terminal): prevent transparent WebGL flicker (#6491) - #6597

Closed
nwparker wants to merge 1 commit into
mainfrom
nwparker/fix-6491
Closed

nwparker wants to merge 1 commit into
mainfrom
nwparker/fix-6491

Conversation

@nwparker

@nwparker nwparker commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #6491.

Transparent WebGL terminals were blending each semi-transparent redraw over the previous framebuffer, so ordinary output made the background step toward opaque and visibly flicker. This PR patches @xterm/[email protected] at its renderer boundary:

  • when allowTransparency is enabled, set separate alpha blending, clear the framebuffer to transparent, then draw backgrounds, glyphs, and the cursor;
  • preserve the existing RGB blend while using ONE for source alpha, so configured opacity a remains a instead of becoming a²;
  • skip the block entirely for opaque terminals;
  • keep the TypeScript source, CommonJS bundle, ESM bundle, pnpm patch hash, and lockfile in parity;
  • register a permanent source/bundle boundary test in the existing xterm-addon.boundary-containment reliability gate.

Evidence

Reproduction and fix proof

A live Electron pixel/count harness exercised the real Orca WebGL path at 50% opacity:

  • suppressing only the new clear reproduced accumulation on repeated frames: [192,192,192,192] → [224,224,224,224] → [240,240,240,240] → [248,248,248,248] → [252,252,252,252] → [254,254,254,254];
  • with the fix, repeated transparent frames stayed at [128,128,128,128];
  • transparent frames made exactly one blend-state update and one clear per frame;
  • opaque frames made zero new blend/clear calls and stayed at alpha 255;
  • toggling back to transparent restored alpha 128;
  • live CommonJS and ESM bundle runs both restored alpha 128 after context recreation;
  • the restored blend state was [770,771,1,771], i.e. SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE_MINUS_SRC_ALPHA.

Lifecycle coverage also passed five repeated WebGL context-loss cycles on split panes, floating-workspace reopen/atlas recovery, and document-visibility resume.

Post-rebase checks on pushed SHA 18bf54ffcc28f9f5e285ac7f33d97610096364cb

  • range-diff against the prior reviewed commit: content-identical;
  • frozen offline install: lockfile and patch application passed with zero downloads on the fresh run;
  • focused boundary suite: 9 files / 44 tests passed;
  • pnpm typecheck:web passed;
  • pnpm check:reliability-gates passed for 34 gates;
  • pnpm check:max-lines-ratchet passed;
  • changed-file oxlint, test-file oxfmt, and git diff --check passed;
  • independent final correctness/GL reviewer: clean, no findings;
  • independent final lifecycle/performance reviewer: clean, no findings.

ELI5

Imagine drawing on a half-transparent sheet of glass. Previously, Orca kept laying the new sheet over the old one, so it became darker every time the terminal redrew. Now Orca wipes the glass clear before drawing the latest frame, so 50% transparent stays 50% transparent.

Trade-offs

No end-user regression was observed in the tested paths. Opaque terminals pay only one false allowTransparency branch and make no additional GL calls. Transparent terminals add one blend-state update and one framebuffer clear per rendered frame, which is the work required to prevent stale-frame accumulation.

The inherent blast radius is high because this is a version-pinned patch in xterm's render hot path. Residual risk is moderate after deterministic tests, live Electron evidence, performance sampling, and two clean independent reviews. The patch must be maintained or removed deliberately when xterm is upgraded.

Reliability proof

  • Reliability class / gate: xterm-addon.boundary-containment.
  • Invariant: every transparent WebGL frame starts from a transparent framebuffer and renders the current full viewport exactly once; opaque frames retain the existing path.
  • Failure source: [Bug]: Terminal background flickers on every redraw when background transparency is enabled #6491 and the reproduced repeated-redraw opacity accumulation.
  • Material impact: prevents ordinary terminal output, cursor redraws, visibility resume, and WebGL recovery from progressively changing configured background opacity.
  • Product change type: runtime hardening plus a deterministic regression gate.
  • Oracle: stable transparent RGBA values and exact per-frame GL call counts across redraw, opacity toggle, CJS/ESM runtime, context loss, floating reopen, and visibility resume.
  • Diagnostics: existing WebGL context-loss and atlas-recovery diagnostics remain in place; no new polling or raw terminal-output logging is added.
  • Manifest status: the existing gate remains partial; this PR adds source/CJS/ESM patch-parity coverage without claiming cross-platform live-GPU completeness.

Performance risk inventory and no-regression evidence

Touched surface: the xterm WebGL renderRows hot path. This PR does not add polling, scheduling, listeners, timers, caches, scans, allocations, startup awaits, provider fanout, IPC/RPC, subprocesses, telemetry, output buffering, or a new lifecycle owner.

Exact-patch macOS samples were approximately 241–278 µs/frame with the fix enabled and 237–263 µs/frame with only the clear suppressed. Medians were 247 µs enabled versus 254.7 µs suppressed; the ranges overlap, so the run did not isolate a performance regression. This evidence is intentionally narrower than a claim of universal zero cost.

Provider and platform coverage

  • Desktop local / daemon / SSH / WSL / remote runtime: use the shared desktop renderer path, so the patch has no provider-specific filesystem, process, path, or protocol assumptions. Live GPU validation was local macOS; the other provider cells are code-path covered but not independently live-tested.
  • macOS: live Electron, pixel, lifecycle, CJS, ESM, and performance evidence collected.
  • Linux / Windows: deterministic/shared-path coverage only; live GPU behavior remains an accepted gap.
  • Mobile / relay: unaffected. Mobile pins a separate @xterm/addon-webgl beta and does not enable terminal transparency.
  • Git providers: unaffected; this change does not touch source-control behavior.

Residual gaps

  • Linux and Windows live GPU runs were not collected.
  • The permanent regression test proves the installed source and runtime-bundle shape/order; the pixel oracle remains live macOS evidence rather than a committed GPU test.
  • The version-pinned package patch requires review on every xterm WebGL upgrade.

Promotion status and rollback / demotion rule

Keep xterm-addon.boundary-containment at partial. Do not promote based on this PR alone; promotion requires stable CI history and representative Linux/Windows GPU evidence.

Revert or demote this slice if monitoring or follow-up testing shows blank frames, context-loss loops, incorrect alpha after opacity toggles, a platform-specific WebGL regression, or a repeatable frame-time regression outside the measured overlap. An xterm upgrade must either carry forward an equivalent verified invariant or remove the patch because upstream now provides it.

Made with Orca

@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added a test that verifies transparent-only clearing appears before renderBackgrounds() in the WebGL renderer source and exactly once before the same boundary in both generated bundles. Registered the test and its expected assertion in the terminal-addon.boundary-containment reliability gate.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR summary only shows a new gate and regression test, not the renderer change needed to stop transparency flicker in #6491. Include the actual renderer-side transparent-clear fix or show it in the reviewed diff, then verify it directly resolves the flicker described in #6491.
Description check ⚠️ Warning The description is detailed, but it does not follow the required template sections for Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite the PR description to match the template headings and add the missing Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The added gate and test are directly tied to the transparent WebGL flicker fix and do not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately summarizes the main change: preventing transparent WebGL flicker.
✨ 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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Verification evidence (#6491)

Unit tests (vitest)

$ ./node_modules/.bin/vitest run --config config/vitest.config.ts \
    src/renderer/src/lib/pane-manager/pane-webgl-renderer.test.ts \
    src/renderer/src/lib/pane-manager/pane-rendering-control.test.ts

✓ shouldUseTerminalWebgl > forces DOM rendering under transparency even when GPU acceleration is forced on
✓ shouldUseTerminalWebgl > forces DOM rendering under transparency on the auto policy
✓ shouldUseTerminalWebgl > allows WebGL when transparency is off and GPU is forced on
✓ shouldUseTerminalWebgl > allows WebGL when transparency is off and auto policy permits it
✓ setPaneTerminalTransparency > tears down WebGL and switches to DOM when transparency is enabled
✓ setPaneTerminalTransparency > re-attaches WebGL when transparency is disabled and GPU is on
✓ setPaneTerminalTransparency > is a no-op when the transparency flag already matches

 Test Files  2 passed (2)
      Tests  7 passed (7)

Full src/renderer/src/lib/pane-manager/ suite: 261 passed. Lint (oxlint, changed files) clean; typecheck (tsgo -p config/tsconfig.tc.web.json) clean.

Live app validation (Electron over CDP, dev build of this branch)

Attached to a dev build of nwparker/fix-6491 (verified via window.api.app.getIdentity() → devRepoRoot: /private/tmp/orca-bb/6491), opened a terminal pane, and inspected the live xterm renderer DOM directly (WebGL addon renders into unclassed <canvas> layers; DOM renderer produces .xterm-rows).

Setting Renderer DOM observed Renderer
terminalBackgroundOpacity = 1 (baseline) 2 render <canvas> layers, hasRowsDiv: false, rowDivs: 0 WebGL (no regression)
terminalBackgroundOpacity = 0.85 (transparency on) render canvases gone, hasRowsDiv: true, rowDivs: 61 DOM (flicker fixed)
0.85 → 1 (live toggle) render canvases back, hasRowsDiv: false, rowDivs: 0 WebGL re-attached, no remount

Raw eval output at opacity 0.85:

{"opacity":0.85,"canvasCount":1,"canvasInfo":["xterm-decoration-overview-ruler"],"hasRowsDiv":true,"rowDivs":61}

(the remaining xterm-decoration-overview-ruler canvas is the slim scrollbar, unrelated to the renderer.)

Before/after reasoning: Before this fix, shouldUseTerminalWebgl had no transparency gate, so WebGL stayed active at opacity < 1 and re-blended the changed rows' semi-transparent backgrounds over the persisted framebuffer each partial redraw, accumulating alpha (the flicker). After the fix, transparency forces the DOM renderer (confirmed by .xterm-rows replacing the WebGL canvas above), which composites the full background each frame — no accumulation, no flicker — and WebGL is restored the moment opacity returns to 1.

Screenshot of the terminal rendering cleanly at opacity 0.85 (DOM renderer) saved locally under the gitignored validation-screenshots/. The renderer-DOM state table above is the load-bearing evidence; the bug is a per-frame compositing artifact that a static screenshot cannot capture, so the canvas-vs-rows DOM inspection is the authoritative proof that the renderer switched.

@nwparker nwparker changed the title fix(terminal): disable WebGL renderer under background transparency (#6491) fix(terminal): prevent transparent WebGL flicker (#6491) Jun 30, 2026
@nwparker

Copy link
Copy Markdown
Contributor Author

Follow-up pushed in 96372d3.

What changed:

  • Transparent terminals now keep WebGL acceleration when the current @xterm/addon-webgl renderer shape is present.
  • Orca clears the WebGL alpha canvas before xterm's renderRows, preventing rgba background accumulation/flicker.
  • DOM rendering remains only as a guarded compatibility fallback if the transparent WebGL clear hook cannot be installed.
  • Fixed the previous failing terminal-cursor-inactive-style.test.ts manager mock.

Tradeoff status: the reported user-facing tradeoff is eliminated for the current supported xterm WebGL addon. The remaining honest caveat is implementation-level: xterm has no public transparent-frame clear API, so the WebGL-preserving path is guarded and falls back to DOM if a future xterm version changes the private renderer shape.

Validation:

  • Focused renderer/CI-failure suites: 5 files, 38 tests passing
  • Full src/renderer/src/lib/pane-manager suite: 32 files, 268 tests passing
  • pnpm typecheck:web: clean
  • Targeted oxlint on changed files: clean
  • git merge-tree origin/main HEAD: clean

@nwparker
nwparker force-pushed the nwparker/fix-6491 branch from 96372d3 to 18bf54f Compare July 11, 2026 09:38

@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)
config/scripts/xterm-webgl-transparent-frame-patch.test.mjs (2)

7-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated patch representation risks silent drift.

The exact source snippet (lines 7-20) and the exact minified bundle snippet (line 21-22) are both manually maintained copies of the same patch content, independent from the actual patch file (config/patches/@[email protected]). Any future patch edit requires updating three places in sync (patch file + these two hardcoded strings); missing one silently weakens the containment test rather than failing loudly.

Consider deriving the expected snippets from the patch file itself (e.g., parsing added lines from the .patch) so there is a single source of truth, or at minimum add a comment pointing back to the patch file with a reminder to keep them in sync.


21-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Exact minified-string matching is brittle to bundler/minifier changes.

transparentClearBundle (lines 21-22) must match byte-for-byte against generated bundle output. Any change in the minifier's formatting (spacing, semicolon insertion, argument ordering) across a toolchain version bump would break this test even though the patch's actual behavior is unchanged, producing noise unrelated to the real invariant being protected.

Also applies to: 41-46


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 74ec957d-c7ea-4bac-8fb0-1112e29e1b00

📥 Commits

Reviewing files that changed from the base of the PR and between dcfa919 and 18bf54f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • config/patches/@[email protected]
  • config/reliability-gates.jsonc
  • config/scripts/xterm-webgl-transparent-frame-patch.test.mjs

@OrcaWin
OrcaWin marked this pull request as draft October 27, 2026 09:52
@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-11T09:43:57Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

@nwparker

nwparker commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #36580, which adds Opaque, Translucent and Blurred window materials on macOS, Windows and Linux (plus Reduce Visual Effects) and fixes the transparent-terminal flicker. Thank you for this PR, it shaped the design.

@nwparker nwparker closed this Nov 2, 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.

[Bug]: Terminal background flickers on every redraw when background transparency is enabled

2 participants