Skip to content

fix(terminal): keep redraw transcript cursors stable - #9081

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/repro-8745-terminal-read-cuu
Jul 18, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/repro-8745-terminal-read-cuu

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Summary

  • keep the redraw-coalesced terminal preview separate from cursor-paginated completed output
  • retain bounded, immutable transcript entries before a later CUU redraw can rewrite the same screen rows
  • preserve transcript identity across arbitrary PTY chunk boundaries and report the real retained cursor window

Root cause

The retained tail was serving two incompatible roles. CUU handling correctly mutates the text projection used for readable TUI previews, but cursor pagination treated those mutable rows as a contiguous append-only transcript. After a redraw deleted lower projected rows, tailLinesTotal kept increasing while oldestCursor was recomputed from the shorter row array. That silently reassigned old content to previously issued cursors.

ELI5: Orca numbered lines in a notebook, then let a terminal redraw erase and move notebook rows without preserving the numbered history. A reader returning to bookmark 2 could receive an older line again and miss the line that originally owned bookmark 2.

Fix

Each completed line is now emitted into a separate bounded transcript before later controls in the same PTY chunk can redraw it. Uncursored reads continue using the coalesced preview; cursored reads use the stable transcript. The transcript keeps the existing 2,000-line and 256 KiB bounds, with incremental character accounting to avoid another full-buffer scan per completion.

For the deterministic regression:

initial transcript: A, B, C
first page:        A, B       nextCursor=2
live CUU screen:   A, B2, C
resume cursor 2:  C, B2      oldest=0 next=4 truncated=false

The regression also covers the initial output and redraw arriving in one PTY chunk, plus a 2,100-line multiline-redraw burst to pin bounded retention metadata.

Tests

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/retained-tail-redraw-window.equivalence.test.ts src/main/runtime/orca-runtime-tail-wait-memo.test.ts src/cli/handlers/terminal.test.ts src/main/runtime/runtime-rpc.test.ts (781 passed)
  • pnpm run typecheck:node
  • pnpm run typecheck:cli
  • pnpm exec oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/retained-tail-redraw-window.equivalence.test.ts
  • pnpm run check:max-lines-ratchet

Trade-offs

The runtime now retains a second bounded line array for cursor history. PTY and leaf mirrors share the array on the normal path, and both projections remain capped. No UI behavior changes: redraw coalescing is preserved for uncursored previews.

Fixes #8745

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a7c06e44-0140-4825-8a73-aaee68dd1c1c

📥 Commits

Reviewing files that changed from the base of the PR and between 5c60822 and bd5ffdf.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/retained-tail-redraw-window.equivalence.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/runtime/retained-tail-redraw-window.equivalence.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

📝 Walkthrough

Walkthrough

The runtime now tracks completed terminal transcript lines separately from the visible tail, propagates newly completed lines through retained-tail parsing and redraw windowing, and applies transcript truncation during PTY and leaf updates. Terminal-tail reads distinguish preview lines from completed transcript lines, while disconnected states clear transcript retention. Tests cover CUU redraw pagination, PTY chunk ordering, bounded multiline redraws, and equivalence of windowed and unwindowed parsing.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and directly summarizes the main change: stabilizing terminal cursor behavior during redraws.
Description check ✅ Passed The description covers the summary, root cause, fix, tests, trade-offs, and issue link, though it omits several template sections.
Linked Issues check ✅ Passed The changes address #8745 by separating stable transcript reads from redraw-coalesced preview, preserving cursor mapping and adding regression tests.
Out of Scope Changes check ✅ Passed The PR changes stay focused on terminal tail/cursor pagination and related tests, with no clear unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/repro-8745-terminal-read-cuu branch from 9beba15 to 5c60822 Compare July 17, 2026 19:06

@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/main/runtime/orca-runtime.ts (1)

971-975: 🚀 Performance & Scalability | 🔵 Trivial

Retained terminal memory roughly doubles per connected PTY.

Each PTY/leaf record now retains a bounded transcript (tailTranscriptBuffer, up to MAX_TAIL_LINES/MAX_TAIL_CHARS = 2,000 lines / 256 KiB) in addition to the existing tailBuffer. In the mirror case leaf shares the PTY's transcript reference, so the incremental cost is ~256 KiB extra per active PTY (worst case), bounded and cleared on disconnect via pruneDisconnectedPtyTranscript. For hosts with many highly-active terminals this doubles peak retained tail memory; worth keeping an eye on with the existing DISCONNECTED_PTY_RECORD_MAX archive bound and terminal-list caps if memory pressure surfaces in orca serve deployments.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d273dae-acd1-4f91-8f65-fb4c103d3354

📥 Commits

Reviewing files that changed from the base of the PR and between 1c54171 and 5c60822.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/retained-tail-redraw-window.equivalence.test.ts

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/repro-8745-terminal-read-cuu branch from 5c60822 to bd5ffdf Compare July 17, 2026 21:58
@Jinwoo-H
Jinwoo-H merged commit cbdd750 into main Jul 18, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant