Skip to content

Recover terminal rendering after risky output - #6949

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-display-stuck
Jun 30, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-display-stuck

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Terminal rendering now recovers from renderer-risk foreground output after xterm has parsed the bytes, then runs a bounded WebGL atlas reset-and-refresh burst. The same reset-and-refresh invariant is used for terminal visibility recovery so tab/worktree/window returns repaint from the canonical xterm buffer.

Boundary: the exact original unrecoverable screenshot state was not reproduced locally. This PR hardens the renderer/atlas/resume failure class that matched the recent regression history; it does not change PTY byte transport, SSH transport, mobile terminal rendering, or disable WebGL for complex-script output.

Design approach

  • Treat the xterm buffer as the source of truth and make renderer recovery repaint from that buffer.
  • Replace paste-only WebGL recovery with a general atlas recovery module while preserving image-paste callers.
  • Detect foreground renderer-risk output when chunks contain CSI or non-ASCII text, filtered through the existing complex-script/background-render classifier.
  • Schedule atlas recovery only after foreground xterm parse completion.
  • Reset every successfully reached live manager before refreshing those managers, so shared glyph-atlas state cannot be cleared after the final repaint.
  • Keep output-driven recovery bounded to one active burst: one animation-frame recovery plus two delayed recoveries over 500 ms.
  • Preserve SSH and remote behavior because recovery runs after bytes reach xterm.

Design review outcome

Brennan's PR process design review completed clean after tightening:

  • reset-then-refresh as the atlas recovery invariant
  • post-parse output-driven recovery
  • split CSI tail handling
  • coalescing/count expectations
  • explicit risks around the unreproduced exact screenshot state

Implementation

  • Added terminal-webgl-atlas-recovery.ts for shared image-paste and terminal-output WebGL atlas recovery.
  • Updated PTY foreground refresh decisions to catch plain CJK/complex-script output without CSI and split bare ESC + following CSI chunks.
  • Added scheduler support for onForegroundParsed so atlas recovery starts after xterm parses renderer-risk output.
  • Added resetAndRefreshAllTerminalWebglAtlases() to reset all successful managers before refreshing them.
  • Updated light tab resume to request backlog recovery and schedule the coalesced reset-and-refresh burst.
  • Updated heavy/window wake recovery to use reset-and-refresh after fit/focus.
  • Renamed paste recovery tests to atlas recovery tests and expanded coverage.

Deviation from design: light hidden-output recovery still does not expose a parse-completion signal to the visibility-resume module. The implementation keeps synchronous drain/fit off the light tab path, requests backlog recovery first, and runs the bounded multi-shot reset-and-refresh burst. Product validation specifically exercised light tab return, but this remains an accepted residual risk rather than a claimed deterministic reproduction of the original screenshot.

Completeness verification

Completeness verification result: verified.

  • Production code implements the headline behavior, not only tests.
  • Image paste callers still use the preserved recovery export.
  • Reset-and-refresh ordering is global.
  • Plain CJK without CSI recovers; safe non-ASCII stays on the normal path.
  • No unapproved narrowing of Brennan's original request was found.

Headline behavior

Status: implemented.

What works:

  • Renderer-risk foreground output refreshes xterm rows and schedules WebGL atlas recovery after parse completion.
  • Plain CJK/complex-script output without CSI is covered.
  • Split CSI introducers across PTY chunks are covered.
  • Light/heavy visibility recovery now uses reset-and-refresh semantics.
  • Output storms coalesce recovery work.

What is not claimed:

  • The exact screenshot corruption was not reproduced locally.
  • This PR does not prove or fix a hypothetical PTY byte-ordering or buffer-corruption bug.

Broad app consistency

Source of truth compared: xterm's parsed buffer is canonical, and visible desktop/floating terminal renderers should recover to match it after risky output, replay/paste, tab switching, worktree/window visibility changes, document visibility, and focus/wake.

Surfaces compared:

  • desktop terminal pane output/write path
  • image paste path
  • light terminal tab resume
  • heavy worktree/window resume and wake recovery
  • floating/shared WebGL atlas registry behavior
  • SSH/remote display path after bytes reach xterm
  • terminal GPU acceleration policy

Mismatch fixed:

  • Heavy visibility recovery reset the atlas, but light tab resume previously did not. Light resume now schedules the same coalesced reset-and-refresh burst while keeping synchronous drain/fit off the tab-switch path.

Deferred/preserved:

  • Mobile terminal WebView rendering is separate and unchanged.
  • Terminal settings, labels, actions, command palette, provider flows, PR/MR flows, and review/checks surfaces are unchanged.

Risks, ambiguities, and non-goals

  • Exact original corruption was not reproduced.
  • Live SSH validation was skipped because the diff is renderer-side after bytes reach xterm; SSH transport code is unchanged.
  • Image paste recovery was covered by import resolution and atlas recovery tests, not by manual image clipboard paste in this pass.
  • Light hidden-output recovery lacks a parse-completion signal; validation stressed the available behavior and tab return path.
  • Non-goal: rewrite xterm WebGL internals.
  • Non-goal: disable WebGL for all complex-script output.
  • Non-goal: add a user-facing repair action or setting.

Perf audit

Perf audit result: clean.

Touched hot paths:

  • foreground PTY output classification
  • terminal-output scheduler parsed callbacks
  • WebGL atlas recovery timers
  • terminal visibility resume
  • live pane-manager registry reset/refresh

Perf findings:

  • No unbounded timer fanout: output-driven recovery is capped to one active burst.
  • Ordinary safe output avoids recovery timers/refreshes.
  • Global reset/refresh is O(live managers/panes), but bounded to recovery triggers rather than every chunk.
  • No new polling, subprocesses, persistence work, startup work, or store subscribers.
  • A deterministic timer-count test was tightened during perf review.

Code review loop

Code review loop result: clean after 3 rounds.

Fixed findings:

  • High: output-driven WebGL atlas recovery could run before xterm finished parsing. Fixed by carrying onForegroundParsed through the scheduler.
  • High: CSI tail scanner missed a split bare ESC followed by [ in the next PTY chunk. Fixed by preserving trailing bare ESC tails.

Final round: both fresh reviewers returned clean.

Brennan test changes

Merge-confidence validation result: land.

Electron identity:

{
  "name": "Orca: brennanb2025/fix-display-stuck",
  "isDev": true,
  "devLabel": "steelhead @ brennanb2025/fix-display-stuck",
  "devBranch": "brennanb2025/fix-display-stuck",
  "devWorktreeName": "steelhead",
  "devRepoRoot": "/Users/thebr/orca/workspaces/orca/steelhead"
}

Manual app validation used demo-project in a temporary app profile and exercised a visible terminal with:

  • plain CJK without CSI
  • bare ESC followed by delayed CSI
  • shaded CSI/status output
  • in-place rewrite/status output
  • ordinary safe non-ASCII output
  • switching to a second terminal tab and back

The terminal stayed readable, prompt recovered, and the backing buffer snapshot contained the validation markers and CJK/status text.

Screenshot evidence, kept out of git:

  • .playwright-cli/steelhead-empty-profile-2026-06-30.png
  • .playwright-cli/terminal-risk-output-visible-2026-06-30.png
  • .playwright-cli/terminal-after-tab-switch-2026-06-30.png

Log inspection:

  • Playwright console: 0 errors.
  • No terminal WebGL/context-loss errors observed.
  • One xterm task-queue deadline warning during stress output; no visible failure followed.

Screenshots

Manual validation screenshots are local evidence files and are intentionally not committed:

  • .playwright-cli/steelhead-empty-profile-2026-06-30.png
  • .playwright-cli/terminal-risk-output-visible-2026-06-30.png
  • .playwright-cli/terminal-after-tab-switch-2026-06-30.png

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts src/renderer/src/lib/pane-manager/terminal-complex-script.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.test.ts
  • pnpm run ensure:electron-runtime && npx playwright test tests/e2e/terminal-tab-switch-visual-restore.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1
  • pnpm run typecheck
  • pnpm run lint
  • pnpm exec oxlint <changed files>
  • pnpm exec tsgo --noEmit -p config/tsconfig.tc.web.json
  • git diff --check

AI Review Report

  • Design review completed clean after the design was tightened around reset-then-refresh ordering, post-parse recovery, split CSI chunks, bounded recovery timers, and honest non-reproduction language.
  • Completeness verification returned verified.
  • Perf audit returned clean.
  • Code review loop ran 3 rounds. Two high-severity findings were fixed before the final round returned clean from both reviewers.
  • Merge-confidence validation returned land.

Security Audit

  • No auth, provider, token, shell-command generation, network API, telemetry, persistence, or permission model behavior is changed.
  • Terminal bytes are still parsed by the existing xterm/PTY path; this PR changes renderer recovery after bytes reach xterm.
  • New callbacks are local renderer callbacks and do not cross privilege boundaries.
  • Screenshot evidence was kept out of git.

Cross-Platform Review

  • macOS/Linux/Windows desktop terminals use the same renderer recovery path after bytes reach xterm.
  • Existing Windows CJK/ConPTY repaint logic is preserved.
  • Existing Linux WebGL auto fallback policy is preserved.
  • SSH/remoting transport is unchanged; renderer recovery applies after remote bytes reach xterm.
  • Mobile terminal WebView rendering is separate and unchanged.

Post-PR stabilization

  • First CodeRabbit review requested a Why: comment for foreground parse callback ordering; fixed in follow-up commit e7559ba7e.
  • Refreshed CodeRabbit review reported no actionable comments.
  • CodeRabbit's description check passed after adding explicit Screenshots, Testing, AI Review Report, Security Audit, and Cross-Platform Review sections.
  • CodeRabbit's generic docstring coverage warning is treated as non-actionable for this TypeScript diff because repository style does not require broad docstring insertion for these focused renderer functions.
  • Required PR checks pass: verify, golden e2e linux experiment, golden e2e mac experiment, and wayland terminal input.

@ghost

ghost commented Jun 30, 2026 •

Copy link
Copy Markdown

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

Title
1 Implement global WebGL atlas reset-and-refresh
2 Refactor paste recovery into general atlas recovery
3 Add parse-completion callbacks to output scheduler
4 Detect renderer-risk output and schedule recovery
5 Update visibility resume to use reset-and-refresh
Open in Stage

Chapters generated by Stage for commit e7559ba on Jun 30, 2026 10:18pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR replaces the paste-only WebGL atlas recovery module with a new terminal-webgl-atlas-recovery module that exposes paste-triggered and terminal-output-triggered recovery scheduling. pane-manager-registry adds a combined reset-and-refresh helper, and terminal visibility resume now uses it in resume and wake paths. pty-connection adds renderer-risk detection for foreground output and schedules atlas recovery after parsing via a new onForegroundParsed callback threaded through the terminal output scheduler. Associated tests are added and updated across the affected files.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% 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 Short, specific, and accurately summarizes the main change: terminal rendering recovery after risky output.
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.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and notes content with ample implementation detail.
✨ 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.

@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 (1)
src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.ts (1)

653-663: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short Why: comment for the callback ordering.

Running enforceTerminalWriteScrollIntent() before options.onParsed?.() is the non-obvious part of the new contract here. A one-line Why: comment would make that ordering harder to accidentally undo in a later cleanup.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6aabd9c7-5beb-4a68-bb45-1b331e681b26

📥 Commits

Reviewing files that changed from the base of the PR and between 4e6a8b9 and 480115b.

📒 Files selected for processing (14)
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-visibility-resume.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-paste-recovery.test.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-paste-recovery.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-registry.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.test.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.ts
💤 Files with no reviewable changes (2)
  • src/renderer/src/components/terminal-pane/terminal-webgl-paste-recovery.test.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-paste-recovery.ts

@brennanb2025
brennanb2025 merged commit 945b270 into main Jun 30, 2026
4 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/fix-display-stuck branch June 30, 2026 22:51
nwparker added a commit that referenced this pull request Aug 30, 2026
resetAllTerminalWebglAtlases and presentAllTerminalPanesWithoutAtlasClear have
no callers, and had none at cadfc55 either — the last call site went in
#6949, which routed reveal recovery through
resetAndRefreshAllTerminalWebglAtlases instead. Only a comment in
pane-manager.ts still named the first one; it now points at the live entry
point. scheduleRevealPresent leaves the registry's structural type with them,
though the manager method stays: terminal-visibility-resume.ts calls it
directly.

This is dead-code removal, not a consequence of the xterm bump. The live
recovery path is unchanged.

resetAndRefreshAllTerminalWebglAtlases stays, and so does the reveal-time
escalation in pane-reveal-repaint.ts. Upstream 299 does make a pane-local
clearTexture bump pageLayoutVersion so siblings rebuild on their next frame,
which is the bug the escalation was written for, but I could not demonstrate
that removing it is safe: with the escalation removed,
floating-workspace-shared-glyph-atlas.spec.ts still passed headful, and it also
passed with upstream's mechanism deliberately disabled (pageLayoutVersion
pinned to 0 in the installed bundle, verified present in the built renderer).
A guard that passes with the fix disabled cannot license removing the
workaround, so the escalation stays until that spec can reproduce the garbling.

Verified: pane-manager and terminal-pane suites (4,713 tests), typecheck, the
headful shared-atlas spec, and the three headless WebGL specs.
nwparker added a commit that referenced this pull request Aug 30, 2026
resetAllTerminalWebglAtlases and presentAllTerminalPanesWithoutAtlasClear have
no callers, and had none at cadfc55 either — the last call site went in
#6949, which routed reveal recovery through
resetAndRefreshAllTerminalWebglAtlases instead. Only a comment in
pane-manager.ts still named the first one; it now points at the live entry
point. scheduleRevealPresent leaves the registry's structural type with them,
though the manager method stays: terminal-visibility-resume.ts calls it
directly.

This is dead-code removal, not a consequence of the xterm bump. The live
recovery path is unchanged.

resetAndRefreshAllTerminalWebglAtlases stays, and so does the reveal-time
escalation in pane-reveal-repaint.ts. Upstream 299 does make a pane-local
clearTexture bump pageLayoutVersion so siblings rebuild on their next frame,
which is the bug the escalation was written for, but I could not demonstrate
that removing it is safe: with the escalation removed,
floating-workspace-shared-glyph-atlas.spec.ts still passed headful, and it also
passed with upstream's mechanism deliberately disabled (pageLayoutVersion
pinned to 0 in the installed bundle, verified present in the built renderer).
A guard that passes with the fix disabled cannot license removing the
workaround, so the escalation stays until that spec can reproduce the garbling.

Verified: pane-manager and terminal-pane suites (4,713 tests), typecheck, the
headful shared-atlas spec, and the three headless WebGL specs.
nwparker added a commit that referenced this pull request Aug 30, 2026
* Upgrade xterm to 6.1.0-beta.303 and generate the addon patches

Takes the current xterm beta line: xterm 287 -> 303, addon-webgl 286 -> 299,
addon-serialize 287 -> 300, headless 302, the remaining addons -> 300, and the
same set on mobile. All four packages stamp upstream commit d3e32b3.

The reasons are upstream #6042/#6043/#6055 (a shared glyph atlas no longer
garbles sibling panes on a page merge, clear, or sampler-budget overflow) and
Note that core 303 is not image-addon-only over 302: it carries the buffer perf
work, including the new BufferLineStringCache.

addon-webgl and addon-serialize move into the patch generator
--------------------------------------------------------------
Both were hand-edited minified bundles, which is what the Known Gaps section of
docs/reference/xterm-patch-regeneration.md described. Both reproduce byte for
byte from the pinned commit, so they are now manifest entries generated from a
source patch like @xterm/xterm already was. Their sourcemaps now move with their
bundles; before this they shipped maps whose offsets did not match the code
beside them.

The webgl patch shrinks from a 1.06 MB hand-edited bundle to a 6.6 KB source
patch, because upstream took the invalidation half Orca had backported. What is
left is only what upstream still lacks: the fragment-shader else branch for a
v_texpage past the sampler budget, the clearTexture guard that no-ops once a
merged page holds index 0, spending the merge retry budget before beginFrame
latches the version it saw, and Orca's font-weight probe.

The serialize source patch is byte-for-byte the same fixes as before; upstream
changed nothing in that addon between 287 and 300.

Generator fixes, each of which failed silently
----------------------------------------------
- `--relative` was appended after the `--` separator in CHECKOUT_DIFF_FLAGS, so
  git read it as a pathspec and kept repo-root-relative paths, dropping every
  source hunk from an addon's patch.
- `git apply` run from a package subdirectory still resolves patch paths from
  the repo root, skips every hunk and exits 0. It now runs from the root with
  `--directory=<packageDir>`, and a source patch that leaves the checkout
  unchanged is a hard failure rather than an empty patch.
- An addon's own `tsgo -p .` has empty files/include and only project
  references, so it emits nothing and the addon webpack then fails on a missing
  ./out/. The root build now runs first.
- versionStampFile is optional; publish.js stamps an addon's package.json, which
  overlayBuildOutput never patches.
- On a version bump the lockfile has no entry under the new key yet, so --write
  reports the gap instead of aborting mid-run. --check still fails on it.

Adding the two addons pushed the generator and the Electron packaging contract
test over max-lines, so the patch-text helpers move to xterm-patch-text.mjs
(pure text: no checkout, no build) and the vendored-xterm assertions move out of
the packaging contract into xterm-webgl-runtime-contract.test.mjs.

Tests
-----
Four tests asserted upstream bugs that are now fixed, not Orca behaviour:

- xterm-user-scrolling-contract pinned headless and core by version string.
  Upstream bumps each package only when its own output changes, so headless 302
  and core 303 are the same source. It now asserts they share a commit.
- Five CSI 3 J assertions expected a reader stranded at the top after an erase.
  Upstream #6081 clears isUserScrolling there, so the erase releases them to the
  bottom instead. Orca's pin still lands them correctly, because its parser
  handler observes the erase before xterm's own handler runs.
- The IME transaction test hard-coded the xterm version; it now reads the
  installed package, since the point is that bundle, map and version agree.
- The Electron runtime contract asserted Orca's old clearModelGeneration. Shared
  atlas invalidation is upstream's now, so it asserts pageLayoutVersion on the
  resolved dependency, plus the Orca-only hunks on the patch.

Verified: 66,008 unit tests, mobile's 3,863, the four WebGL atlas e2e specs, and
`regenerate-xterm-patches.mjs --check` in sync on all three packages.

Left alone deliberately: resetAllTerminalWebglAtlases still fans out globally
even though clearTexture now self-heals siblings, and upstream #6068
(WebglAddon.dispose leaks the GL context) is still open.

* Drop the two unused WebGL atlas fan-out exports

resetAllTerminalWebglAtlases and presentAllTerminalPanesWithoutAtlasClear have
no callers, and had none at cadfc55 either — the last call site went in
#6949, which routed reveal recovery through
resetAndRefreshAllTerminalWebglAtlases instead. Only a comment in
pane-manager.ts still named the first one; it now points at the live entry
point. scheduleRevealPresent leaves the registry's structural type with them,
though the manager method stays: terminal-visibility-resume.ts calls it
directly.

This is dead-code removal, not a consequence of the xterm bump. The live
recovery path is unchanged.

resetAndRefreshAllTerminalWebglAtlases stays, and so does the reveal-time
escalation in pane-reveal-repaint.ts. Upstream 299 does make a pane-local
clearTexture bump pageLayoutVersion so siblings rebuild on their next frame,
which is the bug the escalation was written for, but I could not demonstrate
that removing it is safe: with the escalation removed,
floating-workspace-shared-glyph-atlas.spec.ts still passed headful, and it also
passed with upstream's mechanism deliberately disabled (pageLayoutVersion
pinned to 0 in the installed bundle, verified present in the built renderer).
A guard that passes with the fix disabled cannot license removing the
workaround, so the escalation stays until that spec can reproduce the garbling.

Verified: pane-manager and terminal-pane suites (4,713 tests), typecheck, the
headful shared-atlas spec, and the three headless WebGL specs.

* Give the shared glyph atlas spec a trigger that can fail

floating-workspace-shared-glyph-atlas.spec.ts guards the corruption where one
terminal wiping the module-global atlas leaves sibling terminals drawing from
stale texture coordinates. Both of its tests drive that through a floating
panel reveal, and Orca's reveal paths escalate to a registry-wide atlas reset
that repaints every pane — so the recovery under test heals the damage before
the assertion runs, and the tests pass whether or not xterm propagates the
invalidation at all.

The new test clears the shared atlas straight through the floating manager with
the panel closed, so nothing else repaints the workspace terminal, then repaints
it with terminal.refresh(). That is the load-bearing detail: _updateModel skips
cells whose content is unchanged, so the refresh reuses vertices baked against
the pages that were just wiped, which is exactly the state the fix has to
recover from.

Verified as a discriminator rather than assumed. Pinning ITextureAtlas's
pageLayoutVersion getter to 0 in the installed bundle, which disables the
per-renderer invalidation upstream added in addon-webgl 0.20.0-beta.299, and
confirming that reached the built renderer:

  fix intact:   siblingClearIntact=true   1 passed
  fix disabled: siblingClearIntact=false  1 failed

The failure renders the workspace terminal completely blank — stale coordinates
into a wiped atlas sample nothing. The two reveal tests pass unchanged in both
configurations, which is the gap this closes.

* Compare shared-atlas screenshots with tolerance instead of byte equality

Byte equality fails on sub-pixel antialiasing noise that leaves every glyph
legible, so the headful spec flaked under xterm 303. Reuse the existing
compareTerminalScreenshots helper: real stale-model corruption blanks the
terminal at ~3% of pixels, twice the helper's 1.5% threshold, so the looser
oracle keeps its teeth. Log the ratio so failures are diagnosable.

* fix(xterm): cancel empty deferred IME compositions

* test(xterm): strengthen runtime patch contracts
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Upgrade xterm to 6.1.0-beta.303 and generate the addon patches

Takes the current xterm beta line: xterm 287 -> 303, addon-webgl 286 -> 299,
addon-serialize 287 -> 300, headless 302, the remaining addons -> 300, and the
same set on mobile. All four packages stamp upstream commit d3e32b3.

The reasons are upstream stablyai#6042/stablyai#6043/stablyai#6055 (a shared glyph atlas no longer
garbles sibling panes on a page merge, clear, or sampler-budget overflow) and
Note that core 303 is not image-addon-only over 302: it carries the buffer perf
work, including the new BufferLineStringCache.

addon-webgl and addon-serialize move into the patch generator
--------------------------------------------------------------
Both were hand-edited minified bundles, which is what the Known Gaps section of
docs/reference/xterm-patch-regeneration.md described. Both reproduce byte for
byte from the pinned commit, so they are now manifest entries generated from a
source patch like @xterm/xterm already was. Their sourcemaps now move with their
bundles; before this they shipped maps whose offsets did not match the code
beside them.

The webgl patch shrinks from a 1.06 MB hand-edited bundle to a 6.6 KB source
patch, because upstream took the invalidation half Orca had backported. What is
left is only what upstream still lacks: the fragment-shader else branch for a
v_texpage past the sampler budget, the clearTexture guard that no-ops once a
merged page holds index 0, spending the merge retry budget before beginFrame
latches the version it saw, and Orca's font-weight probe.

The serialize source patch is byte-for-byte the same fixes as before; upstream
changed nothing in that addon between 287 and 300.

Generator fixes, each of which failed silently
----------------------------------------------
- `--relative` was appended after the `--` separator in CHECKOUT_DIFF_FLAGS, so
  git read it as a pathspec and kept repo-root-relative paths, dropping every
  source hunk from an addon's patch.
- `git apply` run from a package subdirectory still resolves patch paths from
  the repo root, skips every hunk and exits 0. It now runs from the root with
  `--directory=<packageDir>`, and a source patch that leaves the checkout
  unchanged is a hard failure rather than an empty patch.
- An addon's own `tsgo -p .` has empty files/include and only project
  references, so it emits nothing and the addon webpack then fails on a missing
  ./out/. The root build now runs first.
- versionStampFile is optional; publish.js stamps an addon's package.json, which
  overlayBuildOutput never patches.
- On a version bump the lockfile has no entry under the new key yet, so --write
  reports the gap instead of aborting mid-run. --check still fails on it.

Adding the two addons pushed the generator and the Electron packaging contract
test over max-lines, so the patch-text helpers move to xterm-patch-text.mjs
(pure text: no checkout, no build) and the vendored-xterm assertions move out of
the packaging contract into xterm-webgl-runtime-contract.test.mjs.

Tests
-----
Four tests asserted upstream bugs that are now fixed, not Orca behaviour:

- xterm-user-scrolling-contract pinned headless and core by version string.
  Upstream bumps each package only when its own output changes, so headless 302
  and core 303 are the same source. It now asserts they share a commit.
- Five CSI 3 J assertions expected a reader stranded at the top after an erase.
  Upstream stablyai#6081 clears isUserScrolling there, so the erase releases them to the
  bottom instead. Orca's pin still lands them correctly, because its parser
  handler observes the erase before xterm's own handler runs.
- The IME transaction test hard-coded the xterm version; it now reads the
  installed package, since the point is that bundle, map and version agree.
- The Electron runtime contract asserted Orca's old clearModelGeneration. Shared
  atlas invalidation is upstream's now, so it asserts pageLayoutVersion on the
  resolved dependency, plus the Orca-only hunks on the patch.

Verified: 66,008 unit tests, mobile's 3,863, the four WebGL atlas e2e specs, and
`regenerate-xterm-patches.mjs --check` in sync on all three packages.

Left alone deliberately: resetAllTerminalWebglAtlases still fans out globally
even though clearTexture now self-heals siblings, and upstream stablyai#6068
(WebglAddon.dispose leaks the GL context) is still open.

* Drop the two unused WebGL atlas fan-out exports

resetAllTerminalWebglAtlases and presentAllTerminalPanesWithoutAtlasClear have
no callers, and had none at 45233ef either — the last call site went in
stablyai#6949, which routed reveal recovery through
resetAndRefreshAllTerminalWebglAtlases instead. Only a comment in
pane-manager.ts still named the first one; it now points at the live entry
point. scheduleRevealPresent leaves the registry's structural type with them,
though the manager method stays: terminal-visibility-resume.ts calls it
directly.

This is dead-code removal, not a consequence of the xterm bump. The live
recovery path is unchanged.

resetAndRefreshAllTerminalWebglAtlases stays, and so does the reveal-time
escalation in pane-reveal-repaint.ts. Upstream 299 does make a pane-local
clearTexture bump pageLayoutVersion so siblings rebuild on their next frame,
which is the bug the escalation was written for, but I could not demonstrate
that removing it is safe: with the escalation removed,
floating-workspace-shared-glyph-atlas.spec.ts still passed headful, and it also
passed with upstream's mechanism deliberately disabled (pageLayoutVersion
pinned to 0 in the installed bundle, verified present in the built renderer).
A guard that passes with the fix disabled cannot license removing the
workaround, so the escalation stays until that spec can reproduce the garbling.

Verified: pane-manager and terminal-pane suites (4,713 tests), typecheck, the
headful shared-atlas spec, and the three headless WebGL specs.

* Give the shared glyph atlas spec a trigger that can fail

floating-workspace-shared-glyph-atlas.spec.ts guards the corruption where one
terminal wiping the module-global atlas leaves sibling terminals drawing from
stale texture coordinates. Both of its tests drive that through a floating
panel reveal, and Orca's reveal paths escalate to a registry-wide atlas reset
that repaints every pane — so the recovery under test heals the damage before
the assertion runs, and the tests pass whether or not xterm propagates the
invalidation at all.

The new test clears the shared atlas straight through the floating manager with
the panel closed, so nothing else repaints the workspace terminal, then repaints
it with terminal.refresh(). That is the load-bearing detail: _updateModel skips
cells whose content is unchanged, so the refresh reuses vertices baked against
the pages that were just wiped, which is exactly the state the fix has to
recover from.

Verified as a discriminator rather than assumed. Pinning ITextureAtlas's
pageLayoutVersion getter to 0 in the installed bundle, which disables the
per-renderer invalidation upstream added in addon-webgl 0.20.0-beta.299, and
confirming that reached the built renderer:

  fix intact:   siblingClearIntact=true   1 passed
  fix disabled: siblingClearIntact=false  1 failed

The failure renders the workspace terminal completely blank — stale coordinates
into a wiped atlas sample nothing. The two reveal tests pass unchanged in both
configurations, which is the gap this closes.

* Compare shared-atlas screenshots with tolerance instead of byte equality

Byte equality fails on sub-pixel antialiasing noise that leaves every glyph
legible, so the headful spec flaked under xterm 303. Reuse the existing
compareTerminalScreenshots helper: real stale-model corruption blanks the
terminal at ~3% of pixels, twice the helper's 1.5% threshold, so the looser
oracle keeps its teeth. Log the ratio so failures are diagnosable.

* fix(xterm): cancel empty deferred IME compositions

* test(xterm): strengthen runtime patch contracts
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