Skip to content

Prevent stale terminal pixels on tab reveal - #7058

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/overlapping-tui-output
Jul 2, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/overlapping-tui-output

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR prevents stale WebGL terminal pixels from surviving a regular terminal tab reveal when hidden-output recovery is already in flight.

The previous fix covered hidden TUI output parsing, but the reproduced failure is visual-only at the reveal boundary: the canonical terminal buffer is clean while the returned tab can keep stale rendered pixels until another repaint source repairs it.

Design Approach

  • Keep terminal-output WebGL recovery coalesced for TUI output storms.
  • Add a separate visibility-owned recovery scheduler for tab reveal.
  • Use that visibility recovery from the light regular-tab resume path.
  • Preserve the heavy worktree/window resume path, including its direct resetAndRefreshAllTerminalWebglAtlases() call.

Design-review result: Brennan's PR process reviewed the design and tightened the gate around proving the visual-only failure before treating deterministic WebGL injection as regression coverage.

Implementation

  • terminal-webgl-atlas-recovery.ts now has separate output and visibility recovery latches.
  • terminal-visibility-resume.ts calls the visibility-specific recovery path for light tab resumes.
  • Unit tests cover light versus heavy resume and prove visibility recovery is not suppressed by an in-flight output recovery.
  • A headful E2E regression creates regular terminal tabs, waits for hidden-output recovery to be in flight, injects stale WebGL pixels while the returned tab is hidden, then verifies tab reveal schedules an independent reset that repaints from the tab's own xterm buffer.

Headline behavior status: implemented.

Repro Evidence

  • Live visual-only repro: .tmp/live-overlap-captures/orca-window-bad-pane-returned.png
  • Bad terminal: term_c4f457e2-c569-4800-ad99-a2571392b706
  • Worktree: /Users/thebr/orca/workspaces/orca/auto-discord-feedback-triage-7am-3pm-pt-run-2-20260630T2200
  • orca terminal read for the same terminal returned only blank/status content while the screenshot showed stale Claude transcript pixels.

That proves the failure is not PTY routing or xterm buffer contamination.

Consistency And Reliability

Source-of-truth behavior: terminal pixels must be a projection of that pane's xterm buffer.

Compared surfaces: regular terminal tabs, split panes sharing the global atlas reset path, heavy worktree/window resume, terminal GPU settings, floating terminal recovery, and non-terminal tabs. The PR changes only regular terminal tab reveal recovery; labels, actions, tab order, command palette behavior, terminal menus, and non-terminal surfaces are unchanged.

Reliability classes: xterm-addon.boundary-containment, terminal-visibility.hidden-to-visible-resume, and renderer-gpu.recovery-containment.

Invariant: revealing a regular terminal tab repaints from that tab's own xterm buffer and is not coalesced away by hidden-output recovery already in progress.

Performance

Perf audit result: pass.

The change adds no hidden-byte loop, polling, foreground flush, fit, PTY resize, or provider call. Work remains a bounded atlas reset/refresh burst on tab reveal, independently coalesced for rapid switches.

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts src/renderer/src/components/terminal-pane/terminal-visibility-resume.test.ts
  • pnpm exec oxlint src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.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-visibility-resume.test.ts tests/e2e/terminal-tab-switch-overlap-repro.spec.ts
  • git diff --check
  • pnpm exec playwright test tests/e2e/terminal-tab-switch-overlap-repro.spec.ts --config tests/playwright.config.ts --project=electron-headful -g "repairs returned tab pixels"
  • pnpm run typecheck
  • pnpm run lint

Merge-confidence validation result: land after PR hygiene. Exact PR worktree was launched and identified; console check reported 0 errors and 2 warnings.

Manual/E2E artifact evidence:

  • Live repro screenshot: .tmp/live-overlap-captures/orca-window-bad-pane-returned.png
  • Deterministic fixed-state screenshot: playwright-report/data/e2b51aa62c8692f868e64d8d04b75d78c0672a3d.png

Screenshots

No app UI controls or layouts change. Screenshot evidence is terminal-renderer validation:

  • Live stale-pixel repro: .tmp/live-overlap-captures/orca-window-bad-pane-returned.png
  • Fixed deterministic reveal state: playwright-report/data/e2b51aa62c8692f868e64d8d04b75d78c0672a3d.png

AI Review Report

  • Design review: completed; required a real visual-only repro before relying on deterministic WebGL injection.
  • Completeness verification: completed; implementation matches the terminal-tab reveal recovery design.
  • Perf audit: pass; no polling, hidden-byte loop, fit, resize, or provider work added.
  • Code review loop: completed before PR; follow-up CodeRabbit comments were addressed in 3f5582b81.
  • Cross-platform review: implementation uses browser timing APIs and shared renderer recovery only. macOS headful validation passed. Linux/Windows are covered by API reasoning; no path, shell, keyboard, or platform-specific process behavior changed.

Security Audit

No new IPC surface, permissions, network calls, filesystem access, shell execution, auth handling, telemetry, or provider contract is introduced. The E2E creates temporary local test scripts in the disposable Playwright repo only.

Gaps And Non-Goals

  • Fresh synthetic and opt-in real Claude E2E probes did not naturally reproduce the original artifact in a fresh app. The true repro evidence is the long-lived production window plus clean canonical-buffer proof.
  • SSH/remote/WSL live smoke was not run. The diff does not touch SSH, relay, remote PTY, runtime environment, or provider contracts; remote terminals share this renderer path after bytes reach xterm.
  • Mobile validation is not claimed.
  • This does not change PTY routing, hidden output parsing, backlog restore, or xterm serialization.

Post-PR Stabilization

Round 1: CodeRabbit reported three actionable E2E hardening comments and one PR-description warning. The E2E hardening comments were fixed in 3f5582b81; this body now includes the requested screenshots, AI review, security, and notes sections.

Final stabilization result: refreshed CodeRabbit review reported no actionable comments, and PR check verify passed.

Notes

The PR is intentionally scoped to the renderer/reveal boundary. It does not change terminal byte routing, hidden output parsing, backlog restore, or provider behavior.

@ghost

ghost commented Jul 2, 2026 •

Copy link
Copy Markdown

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

Title
1 Separate visibility and output recovery latches
2 Wire visibility recovery into tab resume
3 Add E2E regression coverage for tab reveal
Open in Stage

Chapters generated by Stage for commit d03f972 on Jul 2, 2026 5:07am UTC.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR separates terminal WebGL recovery for output redraws from visibility-driven tab resume recovery. scheduleAtlasRecoveryBurst now supports onFirstReset and onComplete callbacks, and visibility recovery uses separate frame and delayed scheduling state. resumeTerminalVisibility now calls scheduleTerminalVisibilityWebglRecovery on the light-tab path. The PR also adds unit tests for both recovery flows and a new Playwright e2e spec with shared helpers, reset instrumentation, timeout stretching, and three terminal tab overlap scenarios.

Related PRs: None identified.

Suggested labels: terminal, testing, e2e

Suggested reviewers: None identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing stale terminal pixels during tab reveal.
Description check ✅ Passed The description includes all required sections and covers summary, screenshots, testing, AI review, security, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts (1)

59-77: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Visibility scheduler intentionally uses a narrower coalescing window than output recovery — worth a one-line clarifying note.

terminalOutputRecoveryScheduled stays true for the entire burst (cleared in onComplete), but terminalVisibilityRecoveryScheduled is cleared as soon as the first (next-frame) reset fires (onFirstReset). This means a rapid second tab reveal can start a second full burst of delayed resets that overlaps with the first burst's still-pending timers — this is what the "allows another tab reveal after the previous reveal reaches its first reset" test confirms is intended, but the existing "Why" comment only explains why output recovery must not suppress the reveal, not that overlapping delayed-timer bursts are an accepted tradeoff. A short addition would help future maintainers who touch ATLAS_RECOVERY_DELAYS_MS or add new callers avoid mistaking this for a bug.

📝 Suggested comment addition
   // Why: tab reveal is a separate repaint boundary from hidden-output parsing,
   // so an in-flight output recovery must not suppress the returned tab's repaint.
+  // Note: clearing the flag on the first reset (not burst completion) means rapid
+  // consecutive reveals can run overlapping delayed-reset bursts; this is intentional.
   scheduleAtlasRecoveryBurst({

Source: Coding guidelines

tests/e2e/terminal-tab-switch-overlap-repro.spec.ts (1)

613-628: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Name or briefly document the visual/timing thresholds.

Values like 140, 150, + 100, 180, 330, and 0.035 encode regression heuristics. Please extract them into named constants or add one-line “why” comments so future threshold changes stay intentional.

As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Also applies to: 713-723, 781-781

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 23a5a724-76bd-4040-8d9c-2b8cfeb15805

📥 Commits

Reviewing files that changed from the base of the PR and between d7322ec and 3e4c1be.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/terminal-visibility-resume.test.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
  • tests/e2e/terminal-tab-switch-overlap-repro.spec.ts

@brennanb2025
brennanb2025 merged commit 347f444 into main Jul 2, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/overlapping-tui-output branch July 2, 2026 05:14

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: da1b593f-d26a-4bb9-b83e-0ef36ed62791

📥 Commits

Reviewing files that changed from the base of the PR and between 3f5582b and d03f972.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts
  • tests/e2e/terminal-recovery-reset-counters.ts
  • tests/e2e/terminal-recovery-timeout-stretch.ts
  • tests/e2e/terminal-tab-switch-overlap-repro.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts

Comment on lines +399 to +407
if (corrupted > 0) {
break
}
}
gl.activeTexture(gl.TEXTURE0)
if (corrupted > 0) {
break
}
}

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Document the early-break rationale.

The two added breaks stop corruption after the first successfully-written texture unit/canvas, relying on the (non-obvious) assumption that the glyph atlas is shared across same-config terminals, so further canvases don't need separate corruption. As per coding guidelines, **/*.{ts,tsx,js,jsx}: "add a comment explaining why the code behaves the way it does" for non-obvious constraints.

📝 Proposed comment addition
+        // Why: the glyph atlas is shared across same-config terminals, so
+        // corrupting one bound texture is sufficient; no need to touch every
+        // canvas/unit once corruption is confirmed.
         if (corrupted > 0) {
           break
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (corrupted > 0) {
break
}
}
gl.activeTexture(gl.TEXTURE0)
if (corrupted > 0) {
break
}
}
if (corrupted > 0) {
break
}
}
gl.activeTexture(gl.TEXTURE0)
// Why: the glyph atlas is shared across same-config terminals, so
// corrupting one bound texture is sufficient; no need to touch every
// canvas/unit once corruption is confirmed.
if (corrupted > 0) {
break
}
}

Source: Coding guidelines

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