Skip to content

fix(terminal): present cursor-free synchronized frames without waiting - #52969

Merged
nwparker merged 1 commit into
stablyai:mainfrom
STiFLeR7:fix/52839-complete-sync-frames
Nov 30, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
STiFLeR7:fix/52839-complete-sync-frames

Conversation

@STiFLeR7

@STiFLeR7 STiFLeR7 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On Windows, some terminal apps (like Claude Code in fullscreen) draw their screen as a series of complete "frames". Orca was holding each finished frame for up to a second, in case the app was about to put the cursor back somewhere. Frames that never touch the cursor have nothing to wait for, so Orca now shows them right away, and the animation stops freezing and jumping.

What Changed

  • Before: on native Windows ConPTY panes (shouldProtectNativeWindowsSynchronizedOutput), every DEC 2026 synchronized frame end that was not latency sensitive was written with coalesceForeground: true. The writer then held it for a later cursor restore: up to 1 s, or the 250 ms hold safety for split frames. A ~20 fps synchronized animation painted only when those fallbacks fired, so it froze for 0.5-1 s and then jumped.
  • After: a frame that never toggles cursor visibility (?25h/?25l) presents at its end marker, whether it arrives whole or split across ConPTY reads.
  • Mechanism:
    • bindWritePtyOutputToXterm tracks session.synchronizedForegroundFrameTogglesCursor across every chunk of an open frame. The flag is initialized in connect-pane-pty.ts and cleared when no frame is open.
    • A new shared helper, containsCursorVisibilityToggle(data, carriedTail), makes one pass over the shared \x1b[?25 prefix. It reuses the existing 7-char marker tail, so a toggle split across a chunk boundary still counts.
    • scanSynchronizedOutput now also reports unmatchedEnd (an end marker with no known open frame) and openFrameContentOffset (where the frame still open at the end of the chunk began, if it began in this chunk). The binder uses the offset to scope the toggle flag to frame boundaries: when one chunk closes a frame and opens the next, the new frame's flag comes only from bytes after its start marker.
    • coalesceForeground stays true when the frame toggled the cursor, when the end is unmatched, or when the end is latency sensitive (those stay on the queued drain, as on main).
    • A frame whose start the pane did not see (for example, one that began while the pane was hidden) counts as toggling, so it keeps the old wait.
    • The writer, the fix(terminal): break the ConPTY foreground livelock that froze a repainting TUI #12463 fixed deadline, the [Bug]: Orca don't render flutter command in Codex session without refreshing the tab #8754 marker-tail handling and the Fix Windows Codex terminal cursor rendering #4669/Fix Codex input echo lag after synchronized output #4708 restore detection are unchanged.

Why

The restore wait exists for #4669 and #4708: Codex-style ?25l ... CUP ?25h ESU frames, where the real cursor restore comes in a later chunk. A frame with no visibility toggle cannot owe that restore, so the wait only delays the paint.

The upstream source was checked rather than assumed. Claude Code's default fullscreen frame is BSU + patches + ESU with a plain CUP for the final cursor and no ?25h/?25l; it emits cursor hide/show only in native-cursor mode (accessibility, screen reader, CLAUDE_CODE_NATIVE_CURSOR). Codex's custom_terminal.rs hides and shows the cursor on every draw, so Codex keeps the wait.

The first revision handled only frames that arrive whole in one chunk. Full repaints larger than 8 KiB arrive split across ConPTY reads, so this version tracks the flag across the whole frame and scopes it per frame.

Linked Issue

Refs #52839

This is a partial fix. Frames that toggle the cursor (Codex, and Claude Code with its native cursor) still take the existing restore wait. The reporter's real ConPTY stream has not been captured, so #52839 stays open.

Visual Proof

N/A. This path runs only on local native Windows ConPTY panes, and no Windows machine was available for this revision (macOS never enters it). The behavior is covered by tests and a replay through the real binder and scheduler (see Testing). The contributor posted Windows replay recordings of the first revision in the original description of this PR.

Testing

  • I manually tested these changes locally (Windows-only path; a manual Windows check is still recommended before merge: Claude Code fullscreen with CLAUDE_CODE_ALT_SCREEN_FULL_REPAINT=1, and Codex typing)

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • New write-pty-output-to-xterm.test.ts runs the real binder and the real scheduler under fake timers:

    • A cursor-free frame in one chunk paints at once.
    • A cursor-free frame split across chunks paints at its end marker.
    • A Codex-style frame whose ?25l is split across the chunk boundary still waits for the 1 s restore fallback (dropping the carried tail makes this fail).
    • A cursor-free frame that opens in the same chunk its predecessor closes is released at its own end marker.
    • An unmatched end marker before a complete frame still waits for the restore.
  • The first two cases fail on main and on the first revision of this PR.

  • New terminal-cursor-restore.test.ts tests the helper on ?25h/?25l, on ?250h (which must not match) and on toggles split across chunks.

  • Replay of 40 frames at 47 ms intervals through the real binder and scheduler, counting frames painted before the next frame arrives:

Frame shape main First revision This PR
Claude default, 4 KB, whole 0/40 40/40 40/40
Claude default, 17 KB, split at 8 KiB 0/40 0/40 40/40
BSU/ESU marker split mid-sequence 0/20 0/20 20/20
Codex shape / Claude native cursor waits waits waits (same as main)
#4669 transient show, then a restore 1 merged write 1 1
  • vitest on pty-connection, shared/terminal/protocol/escape and lib/pane-manager/terminal-output: 8 files, 37 tests pass. oxfmt, oxlint, the anti-slop, native-plugin and ast-grep gates, and the changed-code quality gate are clean on the touched files.
  • Platforms: macOS (unit tests only). The contributor's first revision was replayed on Windows.

Performance

This runs on the renderer terminal stream hot path, but only for protected native Windows chunks inside a DEC 2026 frame. Plain output is untouched.

  • Toggle scan: one pass per chunk, stopping at the first toggle; the two scans in a close-and-reopen chunk cover disjoint slices. About 1 us per 4 KB, 2 us per 8 KB and 66 us per 256 KiB (adversarial). The existing scanSynchronizedOutput costs 3.7 / 7.0 / 243 us on the same chunks.
  • Frame-boundary scoping: split cursor-free 8K+4K frame 1.00 vs 1.03 us per chunk, plain 8K 0.33 vs 0.34 us, adversarial 1 MB ?250h spam 1.90 vs 1.97 ms (medians of 5 runs). scanSynchronizedOutput alone, also used by main-process delivery paths, is unchanged within noise.
  • Whole binder call, median per chunk: Claude 4 KB whole went from 9-10 us to 10.5-11.6 us. Codex split and plain output are unchanged. The worst case is well under 16 ms.
  • Paint count: xterm writes go from 108 to 400 over 400 frames. That is one paint per frame, which is the point of the fix.
  • Removed waits: cursor-free frames no longer start the 1 s coalesce timer.
  • Scaling: the state is per pane session. A chunk on one pane does no work for the others, so N=200 panes costs 1 call on the writing pane and 0 elsewhere, the same as N=1. No store, selector or memo changes.
  • No new timers, polling, sync I/O, subprocesses or queue rescans.

Risk

Level: Low

  • Riskiest part: an app might leave the cursor visible, emit a cursor-free frame, and then send a separate ?25l CUP ?25h restore in a later chunk. That now takes two xterm writes, which can show a one-frame cursor flash. Native terminals behave the same way, and no real app was found that does this.
  • Frames that toggle the cursor, unmatched end markers, and frames whose start the pane did not see behave exactly as on main.
  • Windows-only path; macOS, Linux, SSH and mobile are unaffected.
  • A plain revert restores the previous timing.

Review

Reviewed by Claude, Codex and Antigravity reviewers across several rounds, plus a review of the contributor's frame-boundary follow-up. Landed as one squashed commit on current main.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @STiFLeR7 in #52969, including the latencySensitive hoist and the frame-boundary scoping follow-up; the change was generalized to frames split across chunks. Reported by rumoii in #52839.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker force-pushed the fix/52839-complete-sync-frames branch from 1f679e1 to 8020ae0 Compare November 30, 2026 07:31
@nwparker nwparker changed the title fix(terminal): present complete synchronized frames without waiting fix(terminal): present cursor-free synchronized frames without waiting Nov 30, 2026
@nwparker
nwparker marked this pull request as ready for review November 30, 2026 07:35
@STiFLeR7

Copy link
Copy Markdown
Contributor Author

I replayed the revised 8020ae0fbf5 against its parent c6993d27d58 on Windows using the real Orca binder and scheduler with headless xterm 6.1.0-beta.338.

Fixture Parent Revised head
Complete cursor-free frame, end marker to xterm write 1,020 ms 7 ms
Split start marker, end marker to xterm write 1,014 ms <1 ms
Split frame body, end marker to xterm write 249 ms <1 ms

A normal ?25l and a ?25l split across deliveries both waited for the later cursor restore on each revision. The two saved native ConPTY captures (100×28 and 200×60) replayed all 40 frame markers each in order and had byte-identical xterm input between revisions. The widest capture still had about 47 ms p95 marker-arrival-to-write on both revisions.

A direct synthetic replay of CSI ? 25 ; 1004 l can bypass the literal toggle check and reach xterm with the cursor hidden before its later restore. In a separate native ConPTY capture, Windows emitted an ordinary ?25l for that control and also for CSI ? 1004 ; 25 l, so I did not establish that the compound sequence reaches the protected path verbatim. This exercises the scheduler and parser. The packaged Claude Code and Codex checks in the description remain open.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9ed4fd04-c26f-41a5-85c1-6ea214ae8ba7
Commits

Reviewing files that changed from the base of the PR and between 14d3d9b and cf9a342.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

The change adds detection for cursor hide and show sequences, including sequences split across output chunks. PTY output handling tracks whether synchronized foreground frames contain these toggles and uses that state when deciding whether to coalesce frame endings. Tests cover frames with and without cursor toggles.

Merge Risk: Low · previous review 14d3d

Some cursor-free synchronized frames on native Windows ConPTY panes may still wait for a cursor restore when a cursor toggle follows the frame end in the same delivery. This is the previous behavior, not a regression. It is low risk and worth tightening before or after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: cursor-free synchronized frames are presented without waiting. It matches the main change in the terminal output path, which removes the cursor-restore wait for …
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure (left empty, which is acceptable for an i…
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.
Full details: Title check

Explanation

The title names the fix and its scope: cursor-free synchronized frames are presented without waiting. It matches the main change in the terminal output path, which removes the cursor-restore wait for frames that never toggle cursor visibility. The title is specific and uses the conventional fix(terminal) prefix. It does not mention the Windows/ConPTY scope, but that detail is acceptable for a summary.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, AI Disclosure (left empty, which is acceptable for an internal-style section), Review, Agent skill boundary, Notes, and Checklist. The before/after mechanism, risk level, and performance analysis are explained in detail. Two items need attention: the Linked Issue uses 'Refs #52839' rather than 'Fixes #', which the template says is insufficient for outside contributors, and the Risk section's 'Level' is set to Low without a checkbox for the template's Level field being fully confirmed. The manual Windows verification and the lint/typecheck/test/build checklist item remain unchecked, which the author discloses.

Resolution

Consider linking a closing issue (the template requires an actual issue for outside contributors; 'Refs' is noted as insufficient). Complete a manual Windows check before merge, as the description itself recommends, and tick the lint/typecheck/test/build item once those pass.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a28b686-fbee-469c-b376-3798a14d04b0
Commits

Reviewing files that changed from the base of the PR and between d949313 and 8020ae0.

Files selected for processing: 5

  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/output/write-pty-output-to-xterm.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/output/write-pty-output-to-xterm.ts
  • src/shared/terminal/protocol/escape/terminal-cursor-restore.test.ts
  • src/shared/terminal/protocol/escape/terminal-cursor-restore.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 70b3871b-5841-4a98-837f-9e7021abbb51
Commits

Reviewing files that changed from the base of the PR and between 8020ae0 and 14d3d9b.

Files selected for processing: 3

  • src/renderer/src/components/terminal-pane/pty-connection/output/write-pty-output-to-xterm.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/output/write-pty-output-to-xterm.ts
  • src/shared/terminal/protocol/escape/terminal-synchronized-output-scan.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

((session.synchronizedForegroundOutputActive &&
session.synchronizedForegroundFrameTogglesCursor) ||
containsCursorVisibilityToggle(
trailingFrameContentOffset === null ? data : data.slice(0, trailingFrameContentOffset),

@coderabbitai coderabbitai Bot Nov 30, 2026 •

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.

Minor · Functional Correctness · Quick win

Exclude output outside the frame from toggle detection.

With BSU + payload + ESU + '\x1b[?25l', the scan returns no trailing opening offset. This line scans the entire delivery, including the hide after ESU. It therefore sets coalesceForeground=true for a cursor-free frame.

Use frame-content boundaries for toggle detection. Preserve carried detection for an already open frame. The PR objective requires cursor-free frames to take the immediate presentation path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced this on Windows with Orca's binder and scheduler and headless xterm. With a cursor-free frame followed by ?25l in the same delivery, the write took 1,070 ms on the PR code and 29 ms with the local frame-range scan. The writer and scanner are identical in the merged deb2a887. Toggles before or between closed frames also triggered the wait, including when the close marker was split.

The local scan checks only the bytes within each frame. A split toggle inside the frame and an unmatched closing marker still waited. The reporter's four recorded captures each retained all 60 frame markers in order and identical output bytes with the patch. These are scheduler-to-xterm measurements.

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.

@STiFLeR7 Thanks for the measurements. The local frame-range scan avoids the reproduced delay and preserves the reported fallback behavior and output bytes.

I’m not marking the finding as addressed because the scan is described as a local patch.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.

You are interacting with an AI system.

On native Windows ConPTY panes, every DEC 2026 frame end took the
cursor-restore coalesce wait (up to 1 s, or the 250 ms hold safety for
split frames), so a ~20 fps synchronized animation froze and then
jumped. That wait exists for frames that toggle cursor visibility and
send the restore later (stablyai#4669, stablyai#4708). A frame with no ?25h/?25l is
treated as owing no restore.

Track whether the open frame has toggled cursor visibility across every
chunk it spans, using the carried marker tail to catch a ?25h/?25l split
at a chunk boundary. Scope that flag to frame boundaries, so a chunk
that closes one frame and opens the next starts the new frame clean.
Cursor-free frames, whole or split by ConPTY reads, now present at their
end marker. Frames that toggle the cursor, frames whose start the pane
did not see, and unmatched end markers keep the existing restore wait.

Partial: frames that toggle the cursor (Codex, Claude Code native
cursor) still wait for the restore fallback.

Refs stablyai#52839

Co-authored-by: STiFLeR7 <[email protected]>
@nwparker
nwparker force-pushed the fix/52839-complete-sync-frames branch from 14d3d9b to cf9a342 Compare November 30, 2026 08:55
@nwparker
nwparker merged commit deb2a88 into stablyai:main Nov 30, 2026
57 checks passed
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.

2 participants