Repository navigation
Preserve terminal scrollbar position after tab switches - #7472
Conversation
Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis change extends terminal scroll-intent detection to treat xterm scrollbar and slider interactions like viewport pointer activity, adds tests for intent switching and viewport restoration, and records the behavior in a new reliability gate. It also removes an unrelated exhaustive-switch default branch from a settings component. Changes
Related issues: None found. Related PRs: None found. Suggested labels: renderer, terminal, tests, config Suggested reviewers: None identified from provided data. 🚥 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 (1)
src/renderer/src/lib/pane-manager/terminal-scroll-intent.ts (1)
128-136: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRedundant
classList.containscheck —closest()already matches the element itself.
Element.closest()includes the element itself in its ancestor search, sotarget.classList.contains(className)is dead logic. Also, iterating and callingclosest()once per class does up to three separate ancestor walks per pointerdown; a single combined selector does it in one pass.♻️ Proposed simplification
function isTerminalScrollIntentPointerTarget(target: EventTarget | null): target is Element { if (typeof Element === 'undefined' || !(target instanceof Element)) { return false } // xterm's custom scrollbar uses separate thumb/track nodes from the viewport. - return XTERM_SCROLL_INTENT_POINTER_TARGET_CLASSES.some( - (className) => target.classList.contains(className) || target.closest(`.${className}`) !== null - ) + const selector = XTERM_SCROLL_INTENT_POINTER_TARGET_CLASSES.map((className) => `.${className}`).join(',') + return target.closest(selector) !== null }Note: this requires the test file's
TestElement.closest()polyfill to support comma-separated selectors (it currently only handles a single.classselector), so update that fixture alongside this change if adopted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c440f7ea-beb4-4890-b402-6e3e3abffff2
📒 Files selected for processing (4)
config/reliability-gates.jsoncsrc/renderer/src/components/settings/SourceControlActionRepoOverrideNote.tsxsrc/renderer/src/lib/pane-manager/terminal-scroll-intent.test.tssrc/renderer/src/lib/pane-manager/terminal-scroll-intent.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/settings/SourceControlActionRepoOverrideNote.tsx
Co-authored-by: Orca <[email protected]>
✅ WSL validation (Windows + WSL2) — PASSVerified on Windows that the scrollbar-drag position is preserved across terminal-tab switches when the terminal is genuinely WSL-backed (PTY = Truly WSL-backed — confirmed three independent ways
Backing mechanism: opened a workspace whose folder is a WSL UNC path, so Orca's EnvironmentWindows 11 Pro 10.0.26100 · WSL 2.7.8.0 (kernel 6.18.33.1-microsoft-standard-WSL2) · Ubuntu-24.04 (24.04.4 LTS) · Orca 1.4.123-rc.1 (Electron 42.3.3, Chrome 148) · Node v24.16.0 / pnpm 10.24.0 · fresh dev profile. ReproWSL-backed workspace + 2 WSL terminal tabs. Terminal 1 seeded with 700 lines via a bash loop (
Screenshot after returning shows Terminal 1 still at mid-scrollback ( Static checks (branch, unchanged)
This complements an earlier native-Windows-terminal pass with identical results (before |
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]>
Summary
Preserves terminal scroll position after the user drags xterm's scrollbar thumb or track, then switches tabs or returns from visibility/layout resume. This fixes STA-1341's stale-scroll-intent shape: a dragged viewport could snap back to an older pinned line.
This does not change wheel/trackpad scrolling, Codex/TUI mouse-reporting behavior, hidden-output replay, output scheduling, or terminal styling.
Design Approach
.xterm-scrollbarand.xterm-slideras user scroll-intent sources, alongside the existing.xterm-viewportpath.viewportY.terminal-scroll.intent-preservationas an experimental/partial reliability gate.Design review completed clean after tightening the reliability gate, provider/platform gap language, and Electron validation selector.
Implementation
terminal-scroll-intent.tsnow classifies xterm viewport, scrollbar, and slider pointer targets as scroll-intent targets.terminal-scroll-intent.test.tscovers scrollbar/slider pointer-driven scroll intent and proves a dragged viewport restores instead of stale top intent.config/reliability-gates.jsoncadds the experimental/partialterminal-scroll.intent-preservationgate.SourceControlActionRepoOverrideNote.tsxremoves an unnecessary exhaustive-switchdefaultthat blocked repo-wide lint.No implementation deviations from the reviewed design, except the small unrelated lint cleanup required to get
pnpm run lintpassing.Completeness
Headline behavior: implemented.
Independent completeness verification found no blockers. The stale-top regression test would fail under the old
.xterm-viewport-only classifier because.xterm-sliderpointerdown would not refresh stored intent.Broad app consistency: the source-of-truth behavior is terminal scroll intent architecture: user-driven scroll position is authoritative, and tab/workspace visibility changes should not become scroll operations. Desktop terminal panes share the renderer/xterm path; mobile/relay is unaffected by desktop xterm DOM scrollbar pointer events. No header/footer/overflow/command-palette/review/settings actions changed.
Reliability
Reliability invariant: a user-driven xterm scrollbar thumb or track scroll updates live terminal scroll intent before tab, visibility, or layout resume enforces intent.
Gate:
terminal-scroll.intent-preservation, experimental/partial.Correctness evidence:
.xterm-scrollbar/.xterm-sliderpointer intent and restores the dragged line instead of stale top intent.Provider/platform coverage:
Performance
Perf audit clean. The runtime change is bounded to three
classList.contains/closestchecks on existingpointerdownhandling. No polling, timers, output parsing, IPC, PTY listing, provider scans, resize churn, startup awaits, hidden-pane wake loops, or listener fanout were added.Review
Validation
pnpm run lintpassed, with existing warnings only.pnpm run typecheckpassed.pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.tspassed, 17 tests.pnpm run check:reliability-gatespassed, 28 gates.git diff --checkpassed.top: 0px -> 467px;Terminal 2 -> Terminal 3 -> Terminal 2, it stayed attop: 467px.node:22-bookwormDocker container,remotePlatform: linux;ssh:ssh-1783310567594-y6qz85@@pty-1;baseY: 652;viewportY 0 -> 387and slidertop: 40px -> 489px;viewportYstayed387and slidertopstayed489px.10.0.26100, Nodev24.16.0, pnpm10.24.0, Orca1.4.123-rc.1(Electron42.3.3, Chrome148);brennanb2025/sta-1341-codex-terminal-scrollatC:\Users\neil\orca\workspaces\orca\7472;17/17;.xterm-scrollable-element > .xterm-scrollbar.xterm-vertical > .xterm-slider;viewportY 0 -> 296,baseY: 651, and slidertop: 40px -> 390px;viewportYstayed296and slidertopstayed390px.10.0.26100, WSL2.7.8.0, kernel6.18.33.1-microsoft-standard-WSL2, Ubuntu24.04.4 LTS, Orca1.4.123-rc.1;uname=Linux, OS process table showing both PTYs aswsl.exechildren ofelectron.exe, and workspace path\\wsl.localhost\Ubuntu-24.04\root\orca-wsl-sta1341;.xterm-scrollable-element > .xterm-scrollbar.xterm-vertical > .xterm-slider;viewportY 0 -> 296,baseY: 653, and slidertop: 40px -> 390px;viewportYstayed296and slidertopstayed390px..tmp/validation-evidence/sta-1341-terminal-scrollbar-after-tab-switch.png, withviewportY 0 -> 431 -> 431after tab switch.verifypassed.golden e2e linux experimentpassed.golden e2e mac experimentpassed.Screenshots
.tmp/validation-evidence/sta-1341-terminal-scrollbar-after-tab-switch.png..tmp/validation-evidence/sta-1341-ssh-linux-lite-terminal-scrollbar-after-tab-switch.png.C:\Users\neil\AppData\Local\Temp\orca-sta1341-evidence\terminal1-after-return.png, showing Terminal 1 preserved aroundSTA1341_WIN_LINE_0294through_0345after switching away and back.STA1341_WSL_LINE_0292through_0343, matchingviewportY=296.Testing Checklist
AI Review Report
Security Audit
No security-sensitive behavior changes. This PR changes renderer-side xterm DOM event classification, renderer-unit tests, a reliability manifest entry, and an exhaustive-switch lint cleanup. It adds no network calls, filesystem access, shell/process execution, authentication, permission, or provider-identity behavior.
Notes
The first Linux golden experiment failed once in an unrelated terminal-rendering golden test with
Execution context was destroyedduring setup; the refreshed run after the follow-up push passed.SSH/Linux validation used a minimal synthetic remote workspace state after establishing a real Orca SSH target and relay-backed PTY. The earlier full
repos:addRemoteharness caused unrelated remote repo watcher/mux churn before reaching the scrollbar assertion; the passing lite harness still exercised the real renderer, xterm, tab switch, SSH target, Linux relay, and remote PTY path for this scroll behavior.Risks And Gaps