Repository navigation
fix(terminal): invalidate cached glyphs when WebGL atlas changes - #8899
Conversation
Detects the buffer-clean/render-stale glyph garble class in the field: per
visible WebGL pane, compare the cells the xterm buffer says hold glyphs
against the ink actually present on the canvas, sampled in the same task as
a forced synchronous redraw so a divergence proves the render model/atlas is
wrong rather than a missed present. A trip requires the same screen cells to
stay divergent across three samples (real desync is pinned; scroll lag moves),
then records a webgl-render-desync breadcrumb, stashes evidence (canvas PNG +
buffer text) for bug reports, and runs the same shared-atlas recovery a tab
reveal performs, so a stuck-garbled pane self-heals within seconds.
Off by default; arm on any build via
localStorage.setItem('orca:render-desync-sentinel', '1') and reload.
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a localStorage-gated WebGL render-desynchronization sentinel for terminal panes, with live-pane enumeration, canvas-versus-buffer sampling, diagnostics, evidence persistence, and atlas recovery. It also adds an atlas replacement regression test, investigation documentation, and tooling for terminal replay, production reproduction, frame analysis, and terminal reference recovery. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dcbaae52-a8fe-4118-a7f5-8e5ba7d9e3c7
📒 Files selected for processing (4)
src/renderer/src/components/terminal-pane/terminal-freeze-breadcrumbs.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.test.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.tssrc/renderer/src/lib/pane-manager/pane-manager-registry.ts
| const forEachLivePaneForDesyncSentinel = vi.fn() | ||
| const resetAndRefreshAllTerminalWebglAtlases = vi.fn() | ||
| vi.mock('@/lib/pane-manager/pane-manager-registry', () => ({ | ||
| forEachLivePaneForDesyncSentinel: ( | ||
| ...args: Parameters<typeof forEachLivePaneForDesyncSentinel> | ||
| ) => forEachLivePaneForDesyncSentinel(...args), | ||
| resetAndRefreshAllTerminalWebglAtlases: () => resetAndRefreshAllTerminalWebglAtlases() | ||
| })) | ||
|
|
||
| const recordTerminalWebglDiagnostic = vi.fn() | ||
| vi.mock('../../../../shared/terminal-webgl-diagnostics', () => ({ | ||
| recordTerminalWebglDiagnostic: (...args: Parameters<typeof recordTerminalWebglDiagnostic>) => | ||
| recordTerminalWebglDiagnostic(...args) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '1,120p' src/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.test.tsRepository: stablyai/orca
Length of output: 4321
🏁 Script executed:
rg -n "vi\.hoisted|vi\.mock\(" src/renderer/src/components/terminal-pane -g '*.test.ts' -g '*.test.tsx'Repository: stablyai/orca
Length of output: 18826
🏁 Script executed:
python3 - <<'PY'
# Lightweight semantic probe is not possible without repo execution, so just record
# the key Vitest hoisting rule we're checking against:
# - vi.mock is hoisted to the top of the module.
# - top-level const/let referenced inside a hoisted factory can TDZ if initialized later.
print("noop")
PYRepository: stablyai/orca
Length of output: 156
Create these shared mocks with vi.hoisted()
vi.mock() is hoisted, so these factories can hit a TDZ when they close over top-level const mocks declared later in the file. Move them into vi.hoisted(), as in the other terminal-pane tests.
| const history = missingHistoryByPane.get(paneKey) ?? [] | ||
| history.push(divergence.missingCells) | ||
| while (history.length > PERSISTENT_SAMPLES) { | ||
| history.shift() | ||
| } | ||
| missingHistoryByPane.set(paneKey, history) | ||
|
|
||
| if (divergence.missPct < MISSING_PCT_THRESHOLD || history.length < PERSISTENT_SAMPLES) { | ||
| return | ||
| } | ||
| for (let i = 1; i < history.length; i++) { | ||
| if (!missingSetsOverlap(history[i - 1], history[i])) { | ||
| return | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Require three fully qualifying, persistent samples.
History is appended before missPct validation, so two subthreshold samples followed by one threshold breach can trip. Adjacent-only overlap also permits a gradually moving set to pass. Clear history on subthreshold samples and require common overlap across the complete window.
Reproduce the WebGL atlas identity mismatch with two live terminals and force cached geometry to rebuild whenever a different shared atlas is attached. Persist flag-gated render-desync evidence and retain the investigation tooling used to validate the field signature.
There was a problem hiding this comment.
Actionable comments posted: 11
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5f9cdb66-ee67-4a2e-9e6e-f3552757ac5a
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (18)
TERMINAL-GARBLE-INVESTIGATION.mdconfig/patches/@[email protected]src/main/ipc/register-core-handlers.test.tssrc/main/ipc/register-core-handlers.tssrc/main/ipc/terminal-render-desync-evidence.test.tssrc/main/ipc/terminal-render-desync-evidence.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-frame.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.test.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.tssrc/renderer/src/web/web-preload-api.tssrc/shared/terminal-render-desync-evidence.tstests/e2e/terminal-webgl-atlas-budget.spec.tstools/terminal-garble-frame-analysis.mjstools/terminal-garble-production-repro.mjstools/terminal-garble-react-terminal-recovery.mjstools/terminal-garble-session-replay.mjs
| - Live-rig tooling (replayer for Orca terminal-history logs, CDP driver): | ||
| `/tmp/garble-rig/` — do not rerun without stubbing `shell.openUrl` |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Name the actual Electron API in the safety warning.
The tool patches shell.openExternal, not shell.openUrl. Point readers to shell.openExternal and the --stub-open-url option so the warning is actionable.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
package.json (1)
193-193: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winMove
pngjstodevDependencies. It’s only imported from scripts, tools, and tests, so keeping it in productiondependenciesadds unnecessary install and packaging weight.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 02240612-1179-43cc-9f78-aa09de64cbbb
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (15)
TERMINAL-GARBLE-INVESTIGATION.mdconfig/reliability-gates.jsoncpackage.jsonsrc/main/ipc/terminal-render-desync-evidence.test.tssrc/main/ipc/terminal-render-desync-evidence.tssrc/main/ipc/ui.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-frame.test.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-frame.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.test.tssrc/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.tssrc/renderer/src/lib/pane-manager/pane-manager-registry.test.tssrc/renderer/src/lib/pane-manager/pane-manager-registry.tstools/terminal-garble-frame-analysis.mjstools/terminal-garble-production-repro.mjstools/terminal-garble-session-replay.mjs
🚧 Files skipped from review as they are similar to previous changes (6)
- tools/terminal-garble-session-replay.mjs
- src/renderer/src/lib/pane-manager/pane-manager-registry.ts
- src/renderer/src/components/terminal-pane/terminal-render-desync-frame.ts
- tools/terminal-garble-frame-analysis.mjs
- src/renderer/src/components/terminal-pane/terminal-render-desync-sentinel.ts
- tools/terminal-garble-production-repro.mjs
| also redrew before measuring and waited three five-second samples; either choice | ||
| could erase a failure that self-heals in about five seconds. The revised design |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Clarify the sampling wording.
“Waited three five-second samples” is awkward and ambiguous. Use “waited for three five-second sampling intervals” instead.
🧰 Tools
🪛 LanguageTool
[grammar] ~71-~71: Ensure spelling is correct
Context: ...currence. The initial #8899 design also redrew before measuring and waited three five-...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
Source: Linters/SAST tools
…blyai#8899) * feat(terminal): add flag-gated render-desync sentinel for WebGL panes Detects the buffer-clean/render-stale glyph garble class in the field: per visible WebGL pane, compare the cells the xterm buffer says hold glyphs against the ink actually present on the canvas, sampled in the same task as a forced synchronous redraw so a divergence proves the render model/atlas is wrong rather than a missed present. A trip requires the same screen cells to stay divergent across three samples (real desync is pinned; scroll lag moves), then records a webgl-render-desync breadcrumb, stashes evidence (canvas PNG + buffer text) for bug reports, and runs the same shared-atlas recovery a tab reveal performs, so a stuck-garbled pane self-heals within seconds. Off by default; arm on any build via localStorage.setItem('orca:render-desync-sentinel', '1') and reload. * fix(terminal): invalidate glyph cache on atlas replacement Reproduce the WebGL atlas identity mismatch with two live terminals and force cached geometry to rebuild whenever a different shared atlas is attached. Persist flag-gated render-desync evidence and retain the investigation tooling used to validate the field signature. * fix(terminal): harden render desync diagnostics * docs(reliability): clarify Linux WebGL evidence gap
What
Fix terminal glyph garbling caused by cached WebGL vertices surviving a shared glyph-atlas replacement.
This PR now:
GlyphRendererattaches a different atlas,WebGL remains enabled. The diagnostic sentinel remains off by default.
Root cause
GlyphRenderer.setAtlas()attached a replacement shared atlas and set_lastSeenClearModelGenerationto that atlas's current generation. Cached vertices still held page and UV coordinates from the previous atlas, but when both atlases happened to have the same generation, the next frame considered the cached geometry synchronized and sampled unrelated glyphs.The fix sets
_lastSeenClearModelGenerationto-1when atlas identity changes, forcing the cached geometry to rebuild. This matches current upstream xterm behavior.Deterministic reproduction
The regression test:
The existing sampler-budget and eviction scenario also remains green.
Review hardening
A deep correctness, security, and performance review also fixed the following issues in the flag-gated diagnostics and investigation tooling:
Reliability contract
terminal-render.atlas-identity-invalidationinconfig/reliability-gates.jsonc.Field evidence
The failure signature and violated invariant agree with the reported rc.2 corruption. That build did not capture renderer-internal atlas identity/generation data, so the historical occurrence cannot be retrospectively proven to have taken this exact transition. The fix is nevertheless high confidence because the corruption is deterministic, the rendered signature matches, and upstream xterm independently uses the same invalidation behavior.
Validation
pnpm typecheckgit diff --check