Repository navigation
fix(terminal): keep redraw transcript cursors stable - #9081
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: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe 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)
✨ 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 |
9beba15 to
5c60822
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)
971-975: 🚀 Performance & Scalability | 🔵 TrivialRetained terminal memory roughly doubles per connected PTY.
Each PTY/leaf record now retains a bounded transcript (
tailTranscriptBuffer, up toMAX_TAIL_LINES/MAX_TAIL_CHARS= 2,000 lines / 256 KiB) in addition to the existingtailBuffer. 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 viapruneDisconnectedPtyTranscript. For hosts with many highly-active terminals this doubles peak retained tail memory; worth keeping an eye on with the existingDISCONNECTED_PTY_RECORD_MAXarchive bound and terminal-list caps if memory pressure surfaces inorca servedeployments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2d273dae-acd1-4f91-8f65-fb4c103d3354
📒 Files selected for processing (3)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/retained-tail-redraw-window.equivalence.test.ts
Co-authored-by: Orca <[email protected]>
5c60822 to
bd5ffdf
Compare
Co-authored-by: Orca <[email protected]>
Summary
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,
tailLinesTotalkept increasing whileoldestCursorwas 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:
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:nodepnpm run typecheck:clipnpm exec oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/retained-tail-redraw-window.equivalence.test.tspnpm run check:max-lines-ratchetTrade-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