Repository navigation
Stop hidden terminal panes from exhausting renderer memory (experimental opt-in, default off) #7375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ff5833d
Stop hidden terminal panes from exhausting renderer memory (hidden-vi…
brennanb2025 5312357
Route e2e global-setup logs to stderr so JSON reporters stay parseabl…
brennanb2025 80a4487
Address review round 1: shutdown watcher disposal, e2e fixture flake-…
brennanb2025 15ec98b
Address review round 2: restore TEST_REPO_PATH_FILE import in split e…
brennanb2025 e39355d
Align the parking doc body with this build (byte mode only, #7214 pha…
brennanb2025 badd6f2
Dispose parked watchers on agent-pane hibernation kill (CodeRabbit)
brennanb2025 1d4e70e
Merge origin/main into brennanb2025/oom-hidden-pane-parking
brennanb2025 ed552cf
Fix e2e fixture repo matching on Windows (canonicalized-path comparison)
brennanb2025 20390d7
Make the parked side-effects e2e spec emit via a script file (Windows…
brennanb2025 e152f98
Merge origin/main into brennanb2025/oom-hidden-pane-parking; default …
brennanb2025 964bf15
Make hidden-view parking an experimental opt-in (default off, === tru…
brennanb2025 7047877
Reword parking toggle copy: lead with audience, drop fidelity caveat
brennanb2025 ad99976
Sync localization catalog for parking settings keys; restore best-eff…
brennanb2025 425fb71
Merge remote-tracking branch 'origin/main' into brennanb2025/oom-hidd…
brennanb2025 8a4a652
Clear a parked PTY's pre-handler backlog on watcher dispose
brennanb2025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Terminal Hidden View Parking | ||
|
|
||
| Status: Shipped standalone (byte mode only, extracted from PR #7214), kill | ||
| switch `terminalHiddenViewParking` **default off** — opt-in until the memory | ||
| win is confirmed in a soak, then a follow-up flips it on. The companion doc | ||
| `terminal-model-view-contract.md` (invariants this design extends and the full | ||
| phase list) ships with PR #7214 together with the fact-mode main emitter; in | ||
| this build `terminalMainSideEffectAuthority` must stay `false` (see | ||
| `src/shared/constants.ts`). | ||
|
|
||
| ## Problem | ||
|
|
||
| Hidden terminal panes keep a full renderer xterm instance alive (buffer, | ||
| scrollback, DOM, addons). At many-worktree scale this is the dominant renderer | ||
| memory cost, and it forces every hidden byte through renderer-side write/skip | ||
| decisions. The main-process model (daemon + runtime headless emulators) already | ||
| ingests every byte and can serve restorable snapshots, so the renderer view for | ||
| a long-hidden pane is redundant state. | ||
|
|
||
| A previous attempt shipped and was reverted the same day. The post-mortem | ||
| finding: parking unmounted the pane component, which also tore down the | ||
| renderer's PTY byte parsers — and those parsers are the only source of bell | ||
| notifications, title-transition agent-complete notifications, and tab titles. | ||
| A parked worktree whose agent finished would never notify. This design keeps | ||
| those side effects alive while parked. | ||
|
|
||
| ## Design | ||
|
|
||
| ### Park policy (renderer) | ||
|
|
||
| A pure policy module decides which hidden terminal tabs may park: | ||
|
|
||
| - Cold-park hysteresis: a tab must be hidden for 30s before parking. | ||
| - Hot-retain working set: recently visible worktrees/tabs are retained | ||
| (5 minutes, bounded count) so quick tab switches never pay a re-hydrate. | ||
| - Eligibility excludes: visible panes, hidden-measuring startup probes, | ||
| activity-portal panes, tabs with pending startup commands or pending | ||
| activation spawns, floating-panel tabs, and any tab whose PTY is not | ||
| snapshot-backed (remote-runtime `remote:` PTYs and SSH PTYs are excluded). | ||
| - Kill switch: `settings.terminalHiddenViewParking === false` disables parking | ||
| entirely. | ||
|
|
||
| ### Park mechanics | ||
|
|
||
| Parking a tab unmounts its `TerminalPane` React subtree (the overlay layer | ||
| renders null for parked tabs). This is the same teardown that tab-group moves | ||
| already exercise: transports detach but the PTY session, daemon model, and tab | ||
| state all survive. The xterm instance, its buffers, DOM, and WebGL/addon | ||
| resources are released. | ||
|
|
||
| ### Parked watcher (the piece the reverted attempt lacked) | ||
|
|
||
| While a tab is parked, a pane-less watcher | ||
| (`parked-terminal-byte-watcher.ts`) keeps the pane's side effects alive. Its | ||
| consumption mode is decided once at watcher start: | ||
|
|
||
| - **Main side-effect authority on (arrives with PR #7214; forced off in this | ||
| build):** the watcher is purely | ||
| fact-driven — it registers exactly one `pty:sideEffect` fact consumer and | ||
| parses no bytes. Titles, agent working/idle/exited transitions, BEL | ||
| attention, and PR links arrive as main-tracker facts and drive the same | ||
| policy callbacks a mounted pane uses. With the hidden-delivery gate also on, | ||
| the watcher marks the PTY hidden so main stops renderer byte delivery | ||
| entirely; the DECSET 2031 color-scheme subscribe arrives as main's | ||
| `2031-subscribe` fact and the watcher replies out-of-band via | ||
| `transport.sendInput`. | ||
| - **Kill switch off (this build's only mode — see the status note above):** | ||
| the watcher subscribes to raw bytes through the | ||
| dispatcher sidecar mechanism (the same mechanism background agent launches | ||
| use) and runs the transport-level byte parsers with no xterm — OSC 0/1/2 | ||
| titles (all-titles ordering, live-path normalization), the title-transition | ||
| agent tracker (completion notification, prompt-cache timer), the OSC-aware | ||
| stateful BEL detector, the GitHub PR link scan, and a dedicated DECSET 2031 | ||
| byte responder (`parked-terminal-mode2031-responder.ts`, whose | ||
| `subscribeToPtyData` registration doubles as the delivery-interest signal). | ||
|
|
||
| The two modes drive one shared policy-callback block, so flipping the kill | ||
| switch never changes notification semantics. Main's synthetic | ||
| agent-title/permission frames feed the main tracker directly and arrive as | ||
| facts; the legacy synthetic `pty:data` copy exists only in kill-switch-off | ||
| mode. | ||
|
|
||
| Out of scope while parked: OSC 52 clipboard writes. Terminal queries inside | ||
| hidden-dropped chunks are answered by main's model responder | ||
| (`terminal-query-authority.md`, ships with PR #7214); in kill-switch-off byte | ||
| mode only the 2031 reply is answered and Command Code output is not scraped, | ||
| matching the pre-gate status quo. | ||
|
|
||
| ### Reveal | ||
|
|
||
| Revealing a parked tab remounts the pane subtree and rides the existing | ||
| reattach path: fresh xterm via `openTerminal` (unicode provider activation | ||
| before any write), daemon model snapshot > relay replay > cold restore | ||
| precedence, replay-guarded so snapshot-embedded queries never answer, then | ||
| `POST_REPLAY_REATTACH_RESET` hygiene, fit, and PTY resize. The watcher is | ||
| disposed before the pane handlers re-register. | ||
|
|
||
| ## Invariants | ||
|
|
||
| 1. PTY reads never stop; parking only changes renderer-side view lifetime. | ||
| 2. Bell, agent-completion, title, and PR-link side effects keep working while | ||
| parked (watcher parity tests). | ||
| 3. Reveal shows model-correct output (visual gates: hidden TUI restore, long | ||
| table, rendering golden) and accepts input immediately. | ||
| 4. Sleep/wake, pane close, and PTY restart while parked must not leak watchers | ||
| or strand parked state. | ||
| 5. Memory: parked tabs hold no xterm buffers; renderer memory scales with | ||
| visible panes. | ||
|
|
||
| ## Relation to later phases (ship with PR #7214, not this build) | ||
|
|
||
| Side-effect authority in main (Phase 3) replaces the watcher's byte parsing | ||
| with the `pty:sideEffect` fact consumer; the hidden-delivery gate (Phase 4) | ||
| stops hidden byte delivery in main, moving the parked 2031 reply from the | ||
| byte sidecar to the `2031-subscribe` fact; the model query responder | ||
| (Phase 5) answers queries in hidden-dropped chunks. None of that main-process | ||
| machinery exists in this build — the watcher's byte-parser mode is the only | ||
| mode until #7214 lands, and it remains the fallback behind the kill switches | ||
| afterwards. Parking still excludes | ||
| remote-runtime and SSH PTYs (no local snapshot to restore from); the watcher | ||
| would return as a byte parser only if remote-runtime tabs — whose bytes never | ||
| transit local main — ever became parkable. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.