Repository navigation
Stop terminal flicker during active Claude Code sessions - #7540
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 9b6c106dfcd39dc34260409fc4d04ffc6ae30de6 and 5786193. 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe PR splits WebGL atlas recovery into a tab-reveal path and a terminal-output path. Tab reveal now uses Changes
Related issues: None referenced. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts (2)
5-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winComment blocks exceed the "one or two lines" guideline.
Several "Why" comments here run 5-8 lines (Lines 5-11, 48-54, 57-65). While the context is valuable, consider trimming to the essential non-obvious rationale and moving extended design discussion (e.g., "Brennan-approved", numeric fire-count history) to the PR description or a linked doc.
As per coding guidelines,
**/*.{ts,tsx,js,jsx}: "Keep comments short — one or two lines, capturing only the non-obvious reason."Also applies to: 48-54, 57-65
Source: Coding guidelines
57-72: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winPure trailing-edge debounce has no upper bound — verify unbounded deferral is intentional.
scheduleTerminalWebglAtlasRecoveryre-arms on every call with nomaxWait. If terminal output never leaves a 200ms gap (e.g., a long-running command with continuous output),resetAtlasesAndRefreshPanes()could be deferred for the entire duration, leaving stale/garbled glyphs uncorrected until the stream pauses. The PR's macOS validation (39→0 fires) suggests natural gaps exist in practice, but a hard-cappedmaxWait(similar to lodashdebounce'smaxWaitoption) would guard against pathological sustained-output cases without reintroducing flicker.♻️ Optional maxWait guard
+const TERMINAL_OUTPUT_RECOVERY_MAX_WAIT_MS = 2000 +let terminalOutputRecoveryFirstPendingAt: number | null = null + export function scheduleTerminalWebglAtlasRecovery(): void { if (terminalOutputRecoveryDebounceTimer != null) { globalThis.clearTimeout(terminalOutputRecoveryDebounceTimer) } - terminalOutputRecoveryDebounceTimer = globalThis.setTimeout(() => { - terminalOutputRecoveryDebounceTimer = null - resetAtlasesAndRefreshPanes() - }, TERMINAL_OUTPUT_RECOVERY_QUIET_MS) + const now = Date.now() + terminalOutputRecoveryFirstPendingAt ??= now + const remainingBudget = TERMINAL_OUTPUT_RECOVERY_MAX_WAIT_MS - (now - terminalOutputRecoveryFirstPendingAt) + const delay = Math.max(0, Math.min(TERMINAL_OUTPUT_RECOVERY_QUIET_MS, remainingBudget)) + terminalOutputRecoveryDebounceTimer = globalThis.setTimeout(() => { + terminalOutputRecoveryDebounceTimer = null + terminalOutputRecoveryFirstPendingAt = null + resetAtlasesAndRefreshPanes() + }, delay) }Could you confirm via web search or docs whether a
maxWait-style cap is a common/recommended pattern for this kind of debounce, and whether unbounded deferral was an accepted tradeoff in the design discussion?
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 52f3f187-2802-443f-85cb-cec257ba818e
📥 Commits
Reviewing files that changed from the base of the PR and between 3b081c1 and 9b6c106dfcd39dc34260409fc4d04ffc6ae30de6.
📒 Files selected for processing (4)
src/renderer/src/components/terminal-pane/terminal-visibility-resume.test.tssrc/renderer/src/components/terminal-pane/terminal-visibility-resume.tssrc/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.tssrc/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts
…ecovery An alternate-screen TUI (Claude Code, vim) emits an in-place-rewrite chunk on every streaming frame, and the renderer-risk path does the same for CJK/ translated output. Each chunk requested a global WebGL glyph-atlas clear + all-pane repaint, which during an active agent session fired several times a second (measured 39 global repaints over 8.5s of streaming), reading as a terminal-wide flicker that stops the moment output goes static. Debounce the terminal-output recovery to the trailing edge: a sustained redraw stream coalesces to a single clear+refresh that runs only after 200ms of quiet, so no atlas clear ever lands during visible streaming. A resumed stream re-arms (and cancels) the one debounce timer, so a pause-then-resume can't leak a clear mid-stream. Tab-reveal recovery keeps its own immediate burst (decoupled from the streaming debounce so a background stream can't defer a revealed tab's rebuild); the image-paste, OS-wake and context-loss paths are unchanged. STA-1365 Co-authored-by: Orca <[email protected]>
9b6c106 to
5786193
Compare
|
Thanks @coderabbitai — addressed both: Comment length: trimmed the three "Why" blocks in
|
|
Tip For best results, initiate chat on the files or code changes.
On the comment trimming — appreciate the cleanup, keeping the rationale concise in-code while the fuller design discussion stays in the PR description is a reasonable trade-off. On the (=^・ω・^=) ノ ✏️ Learnings added
|
✅ Windows validation — mid-stream terminal flicker fixValidated on Windows 11 against this branch (dev build, worktree
Before / after (identical focused-window conditions)
Native rendering intact / no visible flicker
Note on automation artifactWhen the Orca window is occluded/backgrounded under headless CDP automation, Chromium throttles renderer timers to ~1 Hz, batching PTY delivery so the debounce legitimately settles once per batch (~8 fires). Bringing the window to the foreground (real-world usage) gives the clean 1 fire. Either way the debounce coalesces correctly — the pre-fix burst path fires 3× per request regardless. Verdict: fix works as designed on Windows — mid-stream flicker eliminated (42 → 1 atlas clear during streaming), native CJK/ConPTY rendering unaffected. |
74 commits from main, including the STA-1278 ai-vault transcript perf work, terminal flicker fix (#7540), renderer V8 heap raise (#7531), scrollbar position preservation (#7472), and the per-delivery debug-snapshot allocation removal (#7541). Conflict resolutions (our structure, main's semantics): - agent-detection: kept the split-module barrel; grafted main's Gemini/Pi title-detection refinements (path-fragment false positives, legacy Pi synthetic titles) into agent-title-core, dropped the superseded PI_IDLE_PREFIX. - orca-runtime wait-blocked detection: kept the throttled scheduleWaitBlockedCheck (branch §1 optimization) and ported it to main's new cached TerminalTailWaitState API; main's per-chunk cached scan stays on the leaf mismatch path where it auto-merged. pty.tailWaitState is deliberately never populated on this branch (throttle owns the pty record), so the leaf mirror copy invalidates rather than shares — the fromTail exactness contract is never violated by stale state. - recordPtyRendererDeliveryPressure: took main's allocation-free peak update (#7541) and derived per-pty in-flight from this branch's cumulative sent/acked accounting instead of the removed rendererInFlightCharsByPty map. - rpc/methods/terminal detach: kept both sides — our flushAllAckPendingOutput and main's exitWaiterAbort release. - pty-connection: kept our single-policy handleCommandFinished (invariant) alongside main's new sampleVisiblePaneForegroundAgent (bodies were byte-identical where they overlapped). - e2e pressure scenarios: kept the Phase-4 hidden-gate contract assertions and the extracted pressure-script module; adopted main's MAX_WORST_KEY_LATENCY_UNDER_LOAD_MS budget. Also documents the renderer-pull delivery watchdog in the branch guide. Gates: typecheck clean; ipc/daemon/terminal-pane/pane-manager suites 4256 passed; both fuzz suites pass. Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
What changes
While an agent (Claude Code, or any alternate-screen TUI) streams output inside an Orca terminal, the terminal area no longer flickers. The flash was a real, measurable redraw storm — not a perception issue.
Root cause: xterm's WebGL renderer keeps a module-global glyph atlas shared by all same-config terminals. Orca ran a recovery that clears that shared atlas and repaints every pane. One caller drove it from terminal output: on every alternate-screen in-place-rewrite chunk (standalone
\r/\b/ erase-line) and every CJK/"renderer-risk" chunk, it re-armed a coalescer that fired the global clear+repaint burst repeatedly. A streaming agent emits such a chunk on essentially every frame, so during an active session the whole terminal cleared and repainted several times a second, and stopped the instant output went static — exactly the report.Fix: debounce the terminal-output recovery to the trailing edge. A sustained redraw stream coalesces into a single clear+refresh that runs only after 200 ms of quiet, so no atlas clear ever lands during visible streaming. A resumed stream re-arms (and cancels) the one debounce timer, so a pause-then-resume can't leak a clear mid-stream.
What does NOT change: tab-reveal recovery keeps its own immediate burst (deliberately decoupled from the streaming debounce so a background stream can't defer a just-revealed tab's atlas rebuild); the image-paste, OS/window-wake, and WebGL context-loss recovery paths are unchanged and still immediate.
Reproduction / evidence (macOS)
Instrumented the recovery with a fire-timestamp counter and drove a synthetic alternate-screen redraw stream (~20 fps in-place rewrites) in a real Orca terminal:
(Flicker is a sub-frame temporal artifact; the fire-count is the authoritative before/after measurement. Screenshots of the streaming state and the settled state are attached to the PR conversation.)
Design approach & review
Trailing-edge debounce, keeping a single settle-edge recovery (not a 3-stage burst) so a clear can only ever run after global quiet. Design was reviewed through Brennan's PR process (design-review loop → implementation → completeness verify → perf → two-reviewer code-review loop → live validation). The design-review loop raised and resolved: a burst-cancelation hole (eliminated by the single-recovery choice), a hidden-output shared-timer analysis, and a required Windows/CJK validation item.
Consistency across recovery surfaces
Compared every caller of the shared atlas recovery: streaming output (fixed), light-tab resume (moved to the immediate reveal path so it is NOT debounced), image paste (immediate, unchanged), hidden→visible reveal / OS-wake / context-loss (unchanged). No user-visible surface loses recovery; only the streaming path changed cadence.
Headline behavior: implemented
The production path (
pty-connectionforeground/hidden write →scheduleTerminalWebglAtlasRecovery) is debounced, verified live (0 mid-stream fires).Risks / non-goals
Provider / platform
The trigger is client-side content analysis in the renderer, so behavior is identical across local / daemon / SSH / remote / WSL / mobile. The Windows CJK variant (STA-1385,
#7475) funnels through the same debounced scheduler and is covered by this fix; a live Windows/CJK run is being done separately to confirm.Validation
terminal-webgl-atlas-recovery.test.ts(no mid-stream recovery; single recovery at settle; no clear on pause-then-resume; reveal stays immediate; cross-caller single-timer) +terminal-visibility-resume.test.ts(reveal recovery immediate). Adjacent suites green:pty-connection.test.ts(323),pane-manager-registry.test.ts.Closes STA-1365. Related: STA-1385 /
#7475(same cause, Windows CJK).Made with Orca 🐋