Skip to content

Keep long-lived multi-agent workspaces fast with experimental terminal pane eviction (opt-in) - #7448

Closed
brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/terminal-pane-unmount
Closed

brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/terminal-pane-unmount

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Implements Linear STA-1282 (terminal panes not unmounted when switching away — root cause of the 10s workspace in STA-1280).

Status: READY (unmerged per process). 2026-07-07: rebased onto latest main and fully re-reviewed + re-validated — see the Update section at the bottom. Every pipeline stage is complete and green: all verification findings (2 P0, 3 P1, 1 e2e-proven boundary bug, 1 CodeRabbit-caught budget bug) fixed with regression tests; CI passing; CodeRabbit clean; live re-validation certified all 8 matrix items on the final tip with screenshot evidence; and a live Windows/ConPTY pass is clean — flag-off sanity, eviction + restore, streaming Codex TUI restore with no gaps/dupes, resize-while-evicted remount (94x52 -> 14x46), close-while-evicted kills the conhost process, toggle-off with no mass remount. The one Windows non-run: the e2e spec harness (a pre-existing fixture path-separator issue on Windows — test harness, not product; tracked on STA-1372, full Windows report in the PR comments below). Merge when satisfied.

What this changes

Opt-in experimental feature (Settings → Experimental → Terminal pane eviction, default OFF): terminal panes that have been hidden for 5+ minutes (beyond the 12 most-recently-viewed, which always stay live) are unmounted from the renderer — their DOM, xterm instance, listeners, and heap are released — and rebuilt from Orca's always-current main-process terminal mirror when you next view them. The shell/agent process is never touched. With the flag off (everyone, by default), behavior is byte-identical to today — verified by dedicated inertness tests.

Fixes the field report behind STA-1280/STA-1282: a multi-day multi-agent workspace accumulated 350k DOM nodes, 122k listeners, and ~1GB renderer heap, making workspace open/tab switch take ~10 seconds.

ELI5

Orca currently keeps every terminal you've ever opened fully alive in the window, even ones you haven't looked at in days — they just get hidden. After days of multi-agent work that's hundreds of invisible live terminals, and the app slows to a crawl. With this feature turned on, Orca puts terminals to sleep if you haven't looked at them for 5 minutes, and redraws them from its saved copy the moment you click back — like minimizing apps you're not using instead of keeping every window open forever. Your 12 most recently used terminals never sleep, so switching between the things you're actually working on stays instant. The running programs inside the terminals are never stopped — only the picture of them is put away and redrawn. It's off by default; flip it on in Settings → Experimental if your workspaces get slow.

Risk assessment

Who is exposed: nobody, until they opt in. The flag-off path is pinned byte-identical to today by dedicated tests (mount-everything branch, zero new subscriptions/timers). The single highest-severity residual risk in this PR is a gating bug that leaks behavior to flag-off users — which is why flag-off inertness has its own oracle rather than being assumed.

The core risk (rated 9/10 pre-mitigation): restore fidelity. The buffer-replay path previously ran roughly once per app launch (restart restore); for opt-in users it now runs on every re-show of an evicted pane — a frequency change, not a new mechanism. What failure looks like, concretely, in worst-to-likely order:

  • a TUI (Claude/Codex/vim) redraws with a stale or garbled frame until its next output/keypress;
  • a chunk of output is duplicated or missing in scrollback if the agent was streaming at the exact moment of re-show;
  • the pane comes back with blank history but alive and typable (this is the deliberate fail-open floor).

What failure structurally cannot look like: a killed agent/shell (eviction can only take PTY-alive paths; the kill branch is unreachable and outcome-tested), a dead/frozen pane (replay failure degrades to live-blank), or any effect on users who haven't opted in.

Why we believe the replay risk is manageable: the replay source is the main-process mirror that is fed every byte continuously and never disconnects — fresher than the restart path that already ships; the streaming race is closed by reusing the existing sequence-numbered snapshot/drain machinery (the #7173 fix class), with a dedicated e2e that streams monotonically-numbered lines through the entire evict→re-show cycle and asserts contiguity; alt-screen state (frame, cursor, paste/mouse modes) restores via the same rehydrate sequences used by restart restore; geometry reconverges through the existing spawn-time reconcile (different-size re-show → natural SIGWINCH repaint; 0×0 remains impossible).

Containment if fidelity problems escape anyway: per-session 3-strike self-disable (structural replay failures only — an empty terminal is not a failure), a plain kill switch, breadcrumb logs on every evict/re-show/failure so field reports are attributable, and an architectural fallback: the mount-gating/policy/registry machinery is shared with a lower-risk "park the live instance" variant, so if opt-in field evidence demands it, Tier 2 can be downgraded without redoing the feature — trading back the memory win, keeping the speed win.

Known limitation while the flag is ON (documented, accepted): tabs never visited this session don't mount at all, so tab titles and title-based (hookless) agent status for those tabs appear on first visit instead of live. Claude/Codex status is main-side and unaffected. Follow-up candidate: a lightweight parked parser for never-visited live PTYs.

Accepted validation gaps (explicit, not hidden): live Windows/ConPTY pass pending (a machine is available; unit coverage exists for resize-on-remount and the replay path is platform-neutral renderer code); the remote-runtime park path (stream close on claim, host-snapshot channel) is unit-tested but was not driven against a live relay; the exit-during-claim-gap race is locked by a unit test rather than manual reproduction (it is a single-frame window); measured perf-budget latency oracles partially manual (bounded-count oracles automated; live DOM/mount measurements recorded in validation).

Secondary risks: parked-transport leak on close (gate #8: closing an evicted tab kills its PTY promptly — tested); teardown racing a re-show (gate #9: generation-keyed cancel — tested); status/title staleness while evicted (gate #3: parked parser retention — tested); coordinator cost when idle (event-driven, no polling; the only timer is armed when a pane is actually due to age out).

Process summary (Brennan's PR process)

  • Design: tiered eviction (hide → GPU-suspend [ships today] → full evict + mirror replay), pure mount-policy module, park transport state, evicted-session registry. Chosen from the three viable strategies for hidden-terminal DOM: full unmount + replay, LRU warm tiers, and lazy mount. Design-review loop: 5 rounds, 15 code-verified findings fixed (park ≠ bare detach — title/status feed is renderer-only; provider-specific park for remote-runtime; snapshot IPC nil≠error contract required for the fail-open counter; Activity-portal visibility; close-while-evicted reconcile; generation-keyed teardown race), converged READY.
  • Decisions (Brennan, explicit): option 4 (dispose + replay) over park-live-instance; experimental opt-in DEFAULT OFF (field risk rated 9/10); mirror scrollback unchanged at 5k (zero new standing memory).
  • Implementation: ~40 files; policy/coordinator/registry/park/remount/settings per the doc. Notable deviations (all documented): reject-on-error snapshot contract instead of a typed union; lastVisibleAt in coordinator module state (nothing needs it reactively); registry keyed per-pane leaf.
  • Completeness verification: complete-with-gaps → all 5 findings fixed, including the top one (flag-OFF was not byte-identical — now pinned inert by dedicated oracles) and a real product gap found while fixing: a claimed remount whose reattach paints nothing (in-process local PTY) now drives the mirror-snapshot restore instead of silently consuming the claim — otherwise a silent evicted pane remounted blank.
  • Headline behavior: implemented, behind the opt-in flag, both dimensions (inactive worktrees AND hidden tabs of the active worktree).
  • Perf audit: flag-OFF proven inert (never subscribes, no timers, byte-identical mount path — test-covered); flag-ON bounded: no polling, single lazy dwell timer, idle-deferred teardown, hot-path guard test added (50 unrelated store ticks → zero eviction-map churn). Three minor findings fixed on the spot (allocation-free parked-owner signature fold, halved per-recompute policy computation, dead entry field removed); deferred with named follow-ups: per-tick signature scales with hidden-tab count (µs-scale, guard-tested), remote parked panes keep the host stream open (measured under the SSH accepted gap).
  • Code-review loop: 3 rounds, two adversarial reviewers per round (independent thinking + reproduction lanes), round 3 both clean. Verification wave findings, all fixed with tests: 2 P0s from live validation (the visibility report fired inside the mount-gated slot, so the warm set never engaged through the real UI and a closing hidden tab could orphan its PTY — root-fixed with a persistent ungated per-tab reporter + integration-seam test); 3 claim-handoff races from an independent codex review (direct-attach remounts never drove the mirror replay; parked-feed release racing the deferred adoption; remote park leaking the host stream on claim — unified into a claim-takeover protocol with deferred release at the adoption chokepoint); 1 e2e-proven boundary bug (a pre-existing seq-less daemon-reattach paint duplicated one line under load when streaming — eviction remounts now paint from the seq-aligned runtime mirror, gated to claimed remounts so non-opt-in reattach behavior is byte-identical); 1 CodeRabbit-caught budget bug (parked panes silently consumed warm-budget rank slots).
  • Validation (brennan-test-changes): two live Electron passes. First pass proved restore safety (streaming TUI restored contiguously; 24 mounted xterms → 1 on the repro workspace; DOM 2831 → 1566) and caught the 2 P0s. Certified re-run on the final tip, all 8 items PASS with measured evidence: warm set holds exactly visible+4 under aggressive policy with textbook LRU+dwell eviction timing; evict/claim/replay breadcrumbs fire; closing a parked tab kills its PTY; tab titles/status update while parked; toggle-off causes no remount storm and parked panes restore on demand; warm switch-back does no replay; the headline streaming case restored fully contiguous (TICK_374→422, process never stopped, input echoes); the daemon-mirror boundary case shows zero duplicated lines. Uncropped full-window screenshots retained as run evidence (not committed, per policy).
  • Static checks: web+cli typecheck 0 errors (node has one pre-existing main error from Fix CDP Page.printToPDF support #7044, untouched file); 1,539 terminal-pane tests + 211 main pty tests + 3,604-test renderer battery green; oxlint/oxfmt clean.
  • Post-PR stabilization: CI green on the final tip (verify + wayland + golden e2e on earlier commits); CodeRabbit round of 5 comments fully resolved (3 fixed — warm-budget slot theft with regression test, unbound requestIdleCallback, docstring; 2 already addressed by prior commits); zero new comments on the fix commits.

Update (2026-07-07): full post-rebase re-review — verdict: LAND

Main moved ~100 commits under this PR; the branch was rebased twice (conflicts composed with #7476 foreground-agent icons, #7524 revert restoring forceBlankRestoredViewport, and this PR's own claim refactor) and the whole feature was re-reviewed and re-validated on the rebased tip.

Review structure: a 6-round two-lane adversarial review loop (independent thinking + reproduction lanes, final round both-clean), plus two independent read-only cross-checks against the recently-merged terminal-display work. Cross-check verdicts: #7540 atlas-recovery debounce, #7310 ConPTY viewport blanking, #7514 handle reminting, and #7490 exit-waiter teardown are all SAFE against eviction (evidence chains traced end-to-end); #7472 scroll preservation had a real regression on eviction remounts — found, root-caused, fixed (below).

Fixes this round (each with a regression test verified to fail when the fix is reverted):

  • Scroll position restore on eviction remount (two layers): the durable leaf-keyed scroll intent is now enforced in the replay's post-parse write callback (xterm parses asynchronously — a synchronous enforce saw the empty fresh buffer, pinned to row 0, and overwrote the durable intent), and enforceTerminalWriteScrollIntent gained the same transient-shrink guard the sync path had, so the reveal-path enforce cannot clobber the pin either. The remount test mock now models real deferred parsing so CI catches this class.
  • BEL while parked: parked panes now raise tab/worktree unread marks on BEL (previously swallowed; hidden mounted panes mark unread today). ParkedPtySinks.onBell, wired in both transports.
  • Enable-time warm-set seed (HIGH, found independently by both review lanes): flipping the experiment ON with existing hidden panes used to mass-detach them (feeds dark until revisit). The settings toggle now seeds the warm set synchronously before the enabling write; panes later age out through normal parking.
  • Parked-exit parity: parked onPtyExit now mirrors the live exit path (clearPaneForegroundAgent, suppressed-exit consume, runtime title, cache timer, runtime-graph sync) — a respawn no longer inherits a stale agent icon. One adjacent edge (agent exits while parked, shell survives → stale icon until the next command boundary) is deliberately accepted and documented in-code: clearing needs OSC 133;D prompt proof, and a probe could false-clear a live agent's tool subshell.
  • Fail-open completeness: the remount replay-failure counter is now charged on all 8 reattach-failure sites (including SSH-deferred and catch paths), so a flaky-SSH environment actually trips the self-disable.
  • Parked feed parity: parked agent status runs the same suppression/normalization/title pairing as the live handler; a dispose-before-adoption race that could spawn an orphan PTY is guarded.
  • Housekeeping: coordinator split to meet the new max-lines budget (gate-Fix useEffect anti-patterns across renderer #9 signal → terminal-pane-eviction-signal.ts), localization catalog re-synced (rebases drop the keys), one lint fix.

Live Electron validation on the rebased tip (fresh profile, real UI):

  • Enable-time flip via the real Settings toggle: all 7 pre-existing panes stayed mounted through the flip (warm map seeded in the same tick), then aged out through normal parking.
  • Dwell eviction: hidden panes evicted on schedule; mounted panes dropped 7 → 1 while all 7 PTYs stayed alive.
  • Remount fidelity: full scrollback + prompt restored, no duplicated/lost lines.
  • BEL while parked: bell icon on the tab + unreadTerminalTabs store entry, raised while the pane was unmounted.
  • Scroll restore: scrolled to rows 179–229, evicted, remounted → viewport restored to exactly rows 179–229 (screenshot evidence retained, not committed, per policy).

Static checks on the final tip: typecheck clean; oxlint clean on all touched files (two pre-existing errors on main in untouched files); check:max-lines-ratchet OK; localization verifiers pass; full unit suite green.

Final integration (2026-07-07/08): one more rebase onto main composed this PR's named PtyMainBufferSnapshotPayload type with #7329's pendingEscapeTailAnsi (the tail is the final replay write in both scroll branches; the durable-scroll enforce uses only xterm scroll APIs so it cannot abort the dangling sequence). Branch force-pushed with lease; PR is MERGEABLE/CLEAN with all required checks green (verify, golden e2e linux+mac, wayland terminal input).

Mergeability confidence: LAND. Residual gaps, restated honestly: the SSH/remote park path remains unit-tested but never driven against a live relay; the earlier Windows/ConPTY pass predates this rebase (the rebase touched platform-neutral renderer code, so a Windows re-check is optional belt-and-braces); and the agent-exits-while-parked stale-icon edge above is accepted for the experimental phase.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds an experimental terminal pane eviction flow that parks hidden PTYs instead of destroying them, with shared settings, mount-policy logic, a parked-pane registry, coordinator logic, transport parking support, lifecycle integration, store wiring, UI settings, and test coverage. It also updates the pty:getMainBufferSnapshot IPC path so serialization errors reject instead of resolving to null, while nil cases still return null.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides extensive context, rationale, implementation details, risks, testing, and validation results. However, it does not follow the required template and omits a linked issue in the… Reformat the description using all required template headings. Add a linked issue such as Fixes #<issue-number>, attach the required before/after visual proof or write N/A with a reason, complete the AI Disclosure section if applicable,…
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly identifies the main change: an opt-in experimental terminal pane eviction feature for long-lived multi-agent workspaces.
Full details: Description check

Explanation

The description provides extensive context, rationale, implementation details, risks, testing, and validation results. However, it does not follow the required template and omits a linked issue in the required format, visual proof or an explicit N/A statement, AI disclosure details, the agent skill boundary checkbox, and the checklist.

Resolution

Reformat the description using all required template headings. Add a linked issue such as Fixes #&lt;issue-number&gt;, attach the required before/after visual proof or write N/A with a reason, complete the AI Disclosure section if applicable, mark the Agent skill upstream boundary and checklist items, and state any remaining Notes.

  • Fix all pre-merge checks with AI
✨ 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.

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

🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/pane-mount-policy.test.ts (1)

173-206: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing coverage for parked-candidate ranking interaction.

The disabled and remounts a parked pane... suites each test parked panes in isolation. None test a parked candidate alongside several non-parked eligible candidates under a tight warmBudget, which is the scenario that would catch the ranking bug flagged in pane-mount-policy.ts (parked panes consuming warm-budget rank slots).

tests/e2e/terminal-hidden-pane-evict-restore.spec.ts (1)

116-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the repeated "evict tabs + confirm unmount" pattern.

The same block — loop over remaining tabs to push one out of the warm budget, then poll mountedTabIds for the evicted tab's absence — is duplicated across four tests. Extracting a small helper would reduce duplication and centralize the eviction-wait timeout/margin logic.

♻️ Suggested helper
+async function evictTab(page: Page, allTabIds: string[], targetTab: string): Promise<void> {
+  for (const tabId of allTabIds.filter((id) => id !== targetTab)) {
+    await activateTab(page, tabId)
+  }
+  await expect
+    .poll(async () => (await mountedTabIds(page)).includes(targetTab), { timeout: 15_000 })
+    .toBe(false)
+}

Then each call site becomes await evictTab(page, tabIds, firstTab).

Also applies to: 156-162, 231-237, 256-262


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 95f1ba0e-6b20-4659-93cb-8ad220e82103

📥 Commits

Reviewing files that changed from the base of the PR and between 4b2e473 and 4be0b5e.

📒 Files selected for processing (40)
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/settings/ExperimentalPane.tsx
  • src/renderer/src/components/settings/TerminalPaneEvictionExperimentalSetting.tsx
  • src/renderer/src/components/settings/experimental-search.ts
  • src/renderer/src/components/settings/terminal-pane-eviction-experimental-search-entry.ts
  • src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
  • src/renderer/src/components/terminal-pane/evicted-pane-registry.test.ts
  • src/renderer/src/components/terminal-pane/evicted-pane-registry.ts
  • src/renderer/src/components/terminal-pane/pane-mount-policy.test.ts
  • src/renderer/src/components/terminal-pane/pane-mount-policy.ts
  • src/renderer/src/components/terminal-pane/pane-unmount-action.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-breadcrumbs.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-inputs.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal/split-group-mount.test.ts
  • src/renderer/src/store/index.ts
  • src/renderer/src/store/slices/diffComments.test.ts
  • src/renderer/src/store/slices/store-test-helpers.ts
  • src/renderer/src/store/slices/terminal-pane-eviction.ts
  • src/renderer/src/store/types.ts
  • src/shared/constants.ts
  • src/shared/pty-main-buffer-snapshot.ts
  • src/shared/terminal-pane-eviction-settings.test.ts
  • src/shared/terminal-pane-eviction-settings.ts
  • src/shared/types.ts
  • tests/e2e/terminal-hidden-pane-evict-restore.spec.ts
  • tests/e2e/terminal-hidden-tui-visual-restore.spec.ts

@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/renderer/src/components/terminal-pane/pty-connection.test.ts (1)

7969-7993: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Registry reset is skipped if an assertion throws.

__resetEvictedPaneRegistryForTest() at Line 7993 only runs if both expect calls on Lines 7991-7992 pass. If either assertion fails, the parked entry and self-disable counters from registerEvictedPane remain in the module-scoped registry and can pollute later tests in this suite.

♻️ Wrap in try/finally
-    binding.dispose()
-    expect(isPaneParked(paneKey)).toBe(true)
-    expect(releaseForClaim).not.toHaveBeenCalled()
-    __resetEvictedPaneRegistryForTest()
+    try {
+      binding.dispose()
+      expect(isPaneParked(paneKey)).toBe(true)
+      expect(releaseForClaim).not.toHaveBeenCalled()
+    } finally {
+      __resetEvictedPaneRegistryForTest()
+    }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8fec028e-2a03-4938-ab67-ed5d4839ca35

📥 Commits

Reviewing files that changed from the base of the PR and between ce0d42a and 8b8ee5e.

📒 Files selected for processing (5)
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b79fd898-c7ce-42e4-9c9c-bc1af23c8748

📥 Commits

Reviewing files that changed from the base of the PR and between 8b8ee5e and d4ea580.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/terminal-pane-eviction-coordinator.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Result
Branch was already up to date at 27e542523e3f4373446473b1fe82015ae8ef39b9.

  1. Unit battery: PASS
    1599 passed / 128 files for the requested Vitest command.

  2. E2E spec: FAIL, harness setup
    Build and native runtime check passed. The Playwright file failed twice with the same pre-test setup issue: 6 failed / 1 skipped, all failing at Expected e2e repo to be loaded.
    The repo was visibly present in the sidebar, and live probing showed Windows paths are stored as C:/... while the fixture compares the backslash temp path. So this did not reach terminal eviction behavior.

  3. Live Windows/ConPTY pass: PASS
    Evidence folder: C:\Users\neil\orca\workspaces\orca\7448\test-results\live-terminal-pane-eviction-7448

  • Flag OFF/default: PASS. 10 controlled tabs stayed mounted after 75s hidden.
  • Eviction ON, kept ready 4, after 1: PASS. Mounted panes dropped from 10 to 5; intended oldest tabs left window.__paneManagers.
  • Restore scrollback/input: PASS. PowerShell marker replayed and new input echoed immediately.
  • Codex TUI restore while printing: PASS. Screenshot: 05-codex-restored-tui-frame.png. Sample advanced from CODEX-LIVE-1921 to CODEX-LIVE-1986 over 6s with no gaps/dupes in the sampled frame.
  • Resize while evicted: PASS. Remounted from old 94x52 to new 14x46, replayed marker, accepted new echo. Screenshot: 06-resize-evicted-remount-new-size.png.
  • Close while evicted: PASS. PTY PID 19168 disappeared from Orca session list; tasklist reported no matching process.
  • Toggle OFF while evicted: PASS. Mounted count stayed 2 after toggle, no mass remount; evicted tab opened cleanly and accepted input. Screenshot: 08-toggle-off-evicted-tab-restored.png.
  1. Flag-off sanity: PASS
    Confirmed with setting OFF before enabling: no eviction after dwell; hidden tabs stayed live.

Current git status is clean except the requested untracked .env.e2e. I removed the temporary dev-port config and stopped only the live app process tree I launched.

brennanb2025 and others added 12 commits July 7, 2026 17:55
…spaces fast

Hidden terminal panes beyond a 12-tab warm set are unmounted after 5
minutes (xterm/DOM/listeners/heap released) and restored from the
always-current main-process mirror on re-show; the PTY and its
status/title feed stay alive via a parked transport. Experimental,
default OFF. Flag-off behavior is pinned byte-identical to today.

STA-1282

Co-authored-by: Orca <[email protected]>
…ted, harden park claim/title (review round 1)

- Warm set never engaged through the real UI: a visible tab was absent from
  terminalPaneMountByTabId, so it unmounted in the same commit it flipped hidden
  and never reported the hide — the managed/warm/park pipeline was unreachable.
  Include visible tabs in the mount map (and prune stale visible ids on close).
- Activity-page terminal portals: an aged-out worktree opened via Activity never
  re-entered the mounted-worktree set, so its overlay layer (and the portaled
  pane) never rendered. Add portal worktrees to the flag-ON mounted set.
- park() claim race: the parked-entry release happened at bind but adoption is
  deferred to a rAF; a dispose before attach orphaned the live PTY (gate #8).
  Defer the release to bindActivePanePty (the adoption chokepoint).
- Parked split-tab titles: the parked onTitleChange drove the tab title
  unconditionally and skipped synthetic-title suppression; mirror the live
  handler's active-pane + Codex-synthetic guards.

Regression tests added for the warm-set transition and the claim-before-adopt
race. Full terminal unit suites + typecheck green.

Co-authored-by: Orca <[email protected]>
…lose remote parked stream (review round 2)

Round-2 review found the round-1 deferred-claim fix was incomplete and the
remote park path leaks:

- Deferred parked-claim release was wired only into bindActivePanePty, but
  daemon/SSH remounts adopt the PTY inline in handleReattachResult (never
  calling bindActivePanePty). The claim then never released: the stale parked
  feed kept double-driving the store and a later re-park's registry eviction
  would destroy() the LIVE daemon PTY. Extract finalizeEvictionClaim() and call
  it from BOTH adoption points.
- Remote releaseForClaim used park({}), which for a remote transport keeps the
  per-instance multiplexed host stream open — leaking a live subscription +
  parser on every remote evict/remount. Route remote release through detach()
  (closes only this instance's stream, safe for the freshly-subscribed pane);
  local must stay park({}) (its ptyId-keyed handler is shared and already
  overwritten by the fresh attach; detach() would sever the live pane).
- Runtime disable ran an O(managed) prune on every store tick while OFF; drop
  it (warm map is ignored while disabled), keep only the parked close-reconcile.
- Document the accepted Tier-2 gap: OSC-133 command lifecycle is not retained
  while parked (agent completion/title/status/exit ARE).

Tests added: successful-adoption claim release; remote detach() closes the
parked stream. Full terminal unit suites + typecheck green.

Co-authored-by: Orca <[email protected]>
…b reporter (P0-1/P0-2)

The visible->hidden report lived inside the mount-gated overlay slot, which
unmounts the instant a pane goes hidden-and-not-yet-warm. So the hide was never
reported, the warm map stayed {} forever, nothing parked, every switch-back
replayed, and a hidden tab that was closed leaked its live PTY (unmounted =>
no destroy, not parked => no close-reconcile).

Move the report to a persistent TerminalPaneVisibilityReporter that the overlay
layer renders for every terminal tab regardless of the gate, so the transition
is always reported before/without unmounting. It is edge-honest (never-visited
tabs do not report hidden, preserving the mount-storm fix) and flag-OFF inert.
With warming restored, a closing hidden tab always reaches destroy() (warm) or
close-reconcile (parked); resolvePaneUnmountAction already destroys a tab closed
mid-eviction, so no orphan park.

Tests: new overlay integration test drives the real render+gate+coordinator seam
(the unit tests bypassed it by calling noteTerminalPaneVisibility directly);
adds the close-mid-eviction destroy case. Fixes an optional-call typecheck error
in the remote-transport claim-release test.

Co-authored-by: Orca <[email protected]>
…tion path (P1-A)

Codex claim-takeover review, validated against the current code:

P1-A (real): an evicted remount that still owns tab.ptyId adopts via the direct
transport.attach()/spawn path (bindActivePanePty), which never reached the
snapshot/replay logic that only handleReattachResult ran. A silent evicted pane
came back history-blank and the claim outcome never resolved. Fix: after
adoption in bindActivePanePty, drive the same markHiddenOutputRestoreNeeded()/
report-nil path. Idempotent (requestHiddenOutputRestoreIfNeeded dedupes in-flight
snapshots) and exactly-once (the two adoption paths are mutually exclusive per
connect), so it never double-writes the replay.

P1-B and P1-C were already resolved in the review round-2 commit and are NOT
re-patched: the claim is deferred to adoption (the parked feed's exit observer
stays live through the rAF gap and clears tab.ptyId + drops the entry on a
gap exit), and releaseForClaim already closes a remote parked stream via detach()
(local stays park()). Added the missing PTY-exit-during-claim-gap test to lock
that behavior; the direct-attach replay test ships with the P1-A change.

Co-authored-by: Orca <[email protected]>
… mirror, not the daemon reattach snapshot (STA-1282)

Pre-existing replay-tail/live-head overlap exposed at high frequency by
eviction. An evicted daemon-backed pane remounts via a deferred daemon
reattach whose snapshot is a bare string with no sequence; its tail
overlaps the first live chunk and the renderer has no baseline to trim it,
so the evict->remount boundary line duplicates (load-dependent: only when
the main-side buffer races ahead of pty:data delivery).

The daemon TerminalSnapshot carries no byte offset, and the daemon/runtime
byte counters diverge across app relaunch, so a threaded snapshotSeq could
not be proven seq-aligned. Instead, route claimed eviction remounts through
the local runtime mirror (getMainBufferSnapshot), whose snapshot seq shares
the pty:data meta.seq domain — drainPendingLiveChunksAfterSnapshot already
trims the overlap there. Consumption gated to claimed remounts
(evictionRemountReplayPending); flag-off / non-eviction reattach paint is
byte-identical. coldRestore and remote relay-replay keep their paint.

Tests: renderer test asserting a claimed remount with connectResult.snapshot
paints the mirror and never the sequence-less daemon snapshot; runtime
contract test pinning snapshot.seq == getPtyOutputSequence == pty:data seq.
Validated: eviction e2e contiguity passes across repeated full-file runs
(previously duplicated the boundary line 2/4).
- Exclude parked panes from the warm-budget ranking pool: they are always
  classified evict, so counting them silently stole warm slots from live
  hidden panes (+ regression test)
- Invoke requestIdleCallback as a method — an extracted unbound reference
  throws Illegal invocation in Chromium
- Correct the settings hydration docstring (feature defaults OFF)

Co-authored-by: Orca <[email protected]>
- Restore the durable scroll position on eviction remounts: enforce the
  leaf-keyed intent after xterm parses the replay (not against the empty
  pre-parse buffer), and give enforceTerminalWriteScrollIntent the same
  transient-shrink guard syncTerminalScrollIntentFromViewport has so the
  reveal-path enforce cannot clobber the durable pin (live-validated:
  rows 179-229 restored exactly across evict->remount).
- Keep BEL attention working while parked: ParkedPtySinks gains onBell,
  both transports route it, and the parked feed raises the tab/worktree
  unread marks (live-validated: bell icon + unreadTerminalTabs while parked).
- Seed the warm set when the experiment is toggled ON at runtime so
  pre-existing hidden panes park through policy instead of mass-detaching
  in the enable render (live-validated: 7/7 panes stay mounted at flip).
- Parked exit parity: clear paneForegroundAgent, suppressed-exit flag,
  runtime title, cache timer; schedule runtime-graph sync (matches live path).
- Parked feed parity: normalize agent status/titles, keep runtimePaneTitle
  fresh, charge the remount fail-open counter on all 8 reattach-failure
  sites, and guard the direct-deferred catch against dispose races.
- Coordinator hygiene: prune generations/eviction signals on close+re-warm.
- Lint (Number.NaN) + localization catalog parity for the new settings keys.

Co-authored-by: Orca <[email protected]>
…the coordinator

The enable-time warm-set seed pushed the coordinator past the 300-code-line
module budget. Extract the per-tab teardown-invalidation generations + the
evicting signal (terminal-pane-eviction-signal.ts) and the cancelable idle
scheduler (cancelable-idle-callback.ts); consumeTerminalPaneEviction is
re-exported so the pane lifecycle keeps its single import site.

Co-authored-by: Orca <[email protected]>
…oll-restore regression test

The remount write mock mutated the buffer synchronously, which hides the
empty-buffer enforce bug the test pins (real xterm parses on a later
macrotask). Defer the mock's parse + callback and yield real macrotasks
before asserting, so CI catches this class without a live app.

Co-authored-by: Orca <[email protected]>
@brennanb2025
brennanb2025 force-pushed the brennanb2025/terminal-pane-unmount branch from 27e5425 to 81bab51 Compare July 8, 2026 03:48
@Zaradacht

Copy link
Copy Markdown

Field report cross-link: #8652 now includes a production case where remote-runtime PTYs (not only direct SSH PTYs) bypass hidden-view parking. In that case, renderer used heap grew from 215 MB to 1,545 MB over 11.9 hours, with roughly 3.2 GB RSS and sustained 85–103% CPU; a restart returned RSS to roughly 313 MB.

The workspace had 23 unique PTY references, including 15 remote: PTYs that are ineligible for the current parking path. This PR's bounded eviction plus remote-runtime park/restore path appears to address that failure mode.

@iridite

iridite commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Adding a field use case report to support this PR — linked here from issue #8652.

Use case: macOS → Windows SSH, 5–8 tabs, long sessions

On a setup with exclusively SSH connections (ssh:<id>@@pty-<n> IDs), all terminal panes are excluded from canParkTerminalTabRenderer(). With terminalHiddenViewParking: true, no panes ever actually park.

After the rejection-leak fix (PR #8279, now in v1.4.143) eliminated the crash cycle, today's sessions show the baseline growth rate clearly:

Session   Duration    Heap growth    Rejections
─────────────────────────────────────────────
11:22      30 min    23 → 104 MB    0
12:55      71 min    23 →  93 MB    0
14:35     143 min    23 → 215 MB    0   ← peak (2.5 hr session)
17:59      31 min    23 →  82 MB    0

Average ~70 MB/hr with 1000-row scrollback, zero rejections — the growth is purely the un-parkable SSH xterm instances accumulating.

The eviction + mirror-replay approach in this PR would directly fix this: SSH PTYs become evictable because the main-process mirror doesn't depend on a daemon snapshot. The note in the PR description ("the SSH/remote park path remains unit-tested but never driven against a live relay") matches this setup exactly — I'd be happy to test the opt-in flag against live SSH relay connections if that would help close that gap.

@iridite

iridite commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Field data supporting this PR — v1.4.161, Jul 23–30

Adding a data point from a setup that would benefit from this directly: macOS → Windows SSH remote with 7–9 live terminal panes, mix of local macOS worktrees and SSH remote worktrees.

With PR #10625 now in v1.4.162, the fleet-level retention budget (slice B: 12 worktrees, 45 min TTL) bounds how many hidden SSH/remote worktrees stay mounted. But the panes inside those still-mounted worktrees — and all local panes — are not evicted. On high-traffic days the heap still grows at 25–30 MB/hr:

Date Max heap Growth/hr
Jul 27 415 MB +30 MB/hr
Jul 28 348 MB +5 MB/hr
Jul 29 607 MB +26 MB/hr

Jul 29 607 MB is the highest recorded; session had 350 sidebar activations for the week, 7–9 live panes.

The fix in this PR — full pane eviction for terminals hidden beyond 5 min, outside the 12-most-recent warm set — is the next layer that would address this. The two approaches are complementary: #10625 bounds the worktree fleet, #7448 bounds the per-pane cost inside each mounted worktree.

The PR description already marks this READY with full CI green and Windows/ConPTY validation. Field data here confirms the remaining leak path is exactly the class this PR targets.

@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded: always-on hidden-worktree terminal parking (#10625 and follow-ups) covers this without an opt-in flag. Thanks for the STA-1282 investigation.

@nwparker nwparker closed this Oct 14, 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

Development

Successfully merging this pull request may close these issues.

4 participants