Repository navigation
fix(terminal): stop phantom pinned-viewport pins from freezing follow-output - #8625
Conversation
…-output A pinnedViewport intent could latch while the viewport was still at the bottom (sub-row trackpad wheel, wheel consumed by a mouse-reporting TUI, plain PageUp/Home delivered to the app). Per-write-batch enforcement then froze the viewport at that absolute line: during agent generation the live TUI region visibly scrolled "underneath" static committed rows, and after a long generation the scroll position sat near the top. Rebuild paths (snapshot replay, fit reflow) additionally restored pinned positions by raw pre-rebuild row numbers into renumbered buffers. - The wheel/keyboard settle tick reclassifies intent from the real viewport instead of preserving a pin the viewport never followed. - Write capture treats a pinned intent whose live viewport is at the bottom as followOutput, so a latched phantom pin can never freeze streaming. - Visibility-resume enforcement follows output for pins recorded at the bottom and restores by bottom offset when the buffer was rebuilt shorter. - Snapshot replay restores by bottom offset; safeFit restores pinned panes through an xterm marker so reflow renumbering cannot misplace them. Deterministic repro harness: unit tests red on the old code for each latch/ freeze/restore shape, plus a stdin-phase-gated streaming e2e fixture — both e2e tests fail without this fix and pass with it. Co-authored-by: Orca <[email protected]>
|
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 (7)
📝 WalkthroughWalkthroughUpdates terminal scroll-intent handling to distinguish viewport-line and bottom-offset restoration, avoid phantom pins, and track buffer base positions. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
…ing snapshot restores Returning to a worktree whose agent kept streaming (Codex "Working…") replays a main-buffer snapshot: the buffer is cleared and rewritten, but xterm parses those bytes asynchronously. Scroll-intent capture/enforce that raced the parse — live stream batches, safeFit, visibility resume, and the restore's own synchronous enforcement — read the half-cleared buffer and re-latched the intent as "pinned at line 0", parking the returned pane at the very top of the scrollback (#8625 does not cover this). - Bracket the snapshot replay with a per-terminal rebuild marker (terminal-scroll-intent-rebuild.ts); while it is in flight, intent capture returns null and enforcement no-ops, so no racer can latch transient coordinates. - Re-apply the pre-replay intent once, in a FIFO-ordered empty-write completion after the replay bytes have parsed (bottom-offset restore), with a timeout fallback so a wedged pipeline cannot suppress intent forever. - Defense-in-depth for unbracketed rebuilds: enforcement no longer re-latches a pinned intent from a scrollback shorter than the stored pin's, and capture only normalizes pinned-at-bottom to follow when the scrollback is at least as long as the pin's. - Split the DOM wheel/pointer tracking into terminal-scroll-intent-dom-tracking.ts (max-lines). Deterministic e2e repro: a synchronized-output streaming fixture, pinned six rows above bottom, worktree switch away and back — settled at viewportY=0 (baseY=284) before this fix, restores near the pin after. Co-authored-by: Orca <[email protected]>
…-output (stablyai#8625) Co-authored-by: Orca <[email protected]>
Symptoms
While an agent TUI (e.g. Codex inline mode) generates output:
Root cause
The scroll-intent system (#6319) can latch
pinnedViewportwhile the viewport is actually at the bottom, and per-write-batch enforcement then actively freezes the viewport at that absolute buffer line:onWheelpins on any upward delta andpreservePinnedAtBottomkeeps the pin even when the viewport provably never moved — sub-row trackpad deltas, wheels consumed by a mouse-reporting TUI (pane-terminal-tui-wheel-reports), and plain PageUp/Home (delivered to the PTY app, never scrolling xterm) all latch a pin at the bottom.applyMainBufferSnapshot) discards and rebuilds the buffer, andsafeFitreflows can renumber every row; restoring the pre-rebuild numericviewportYafterwards points at arbitrary content.Fix
syncTerminalScrollIntentSoon's final settle tick reclassifies from the real viewport (dropspreservePinnedAtBottom), so a wheel/keypress the viewport never followed cannot latch a pin.captureTerminalWriteScrollIntenttreats a pinned intent whose live viewport is at the bottom asfollowOutput— a latched phantom pin can no longer freeze streaming (defense-in-depth for any latch source, including stale durable records).enforceTerminalCurrentScrollIntent(visibility resume) follows output for pins recorded at the bottom, and restores by bottom offset when the live buffer is shorter than the stored intent (buffer was rebuilt).applyMainBufferSnapshotrestores by bottom offset via the newrestoreBy: 'bottomOffset'enforce option.safeFitrestores pinned panes through an xterm marker (same pattern aspane-scroll.ts), so reflow renumbering cannot misplace the restore; follow panes keep scroll-to-bottom.Genuine pins are untouched: scrolling up and staying above the bottom still pins, and output/fit/replay still preserve that position (existing tests cover this; new guard test added).
Deterministic reproduction harness
terminal-scroll-intent.test.ts,pane-tree-ops.test.ts): 5 new behavior tests were red on the old code — phantom-pin settle, pinned-at-bottom write freeze (two batches), resume-follow for bottom pins, bottom-offset restore across a shrunk rebuild, marker restore across fit reflow — plus a guard test (green before and after) that a real pin still sticks.terminal-scroll-intent-follow.spec.ts+streaming-scrollback-fixture.cjs): a stdin-phase-gated streaming fixture makes the failure order-deterministic. Test 1: a sub-row (−2px) wheel-up that never moves the viewport, then phase-2 streaming. Test 2: a plainHomekeypress mid-stream (its escape bytes double as the phase-2 release). Both fail without the fix and pass with it (verified by stashing the src changes and re-running).Verification
vitestpane-manager + terminal-pane suites: 206 files, 2492 tests pass.pnpm typecheckandpnpm lintpass.Made with Orca 🐋