Skip to content

Park hidden terminal views behind a byte watcher - #5075

Closed
nwparker wants to merge 10 commits into
nwparker/term-speed-2-perf-report-comparisonfrom
nwparker/term-speed-2-hidden-view-parking
Closed

nwparker wants to merge 10 commits into
nwparker/term-speed-2-perf-report-comparisonfrom
nwparker/term-speed-2-hidden-view-parking

Conversation

@nwparker

@nwparker nwparker commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 1 of the terminal model/view architecture (design: docs/reference/terminal-hidden-view-parking.md).

  • hidden terminal tabs park after a 30s hysteresis (5min hot-retain working set, bounded retain limits): the pane subtree unmounts — releasing the xterm instance, buffers, DOM, and WebGL/addon resources — while the PTY, daemon model, and tab state survive (the same teardown tab-group moves already exercise)
  • a pane-less parked byte watcher (dispatcher sidecar) keeps each parked PTY's side effects alive with no xterm: OSC titles (all-titles ordering + normalization), the OSC-aware BEL detector (unread marks + bell notifications), the working→idle agent tracker (completion notifications + cache timer, seeded with the pane's last known title so agents that finish while parked still notify), DECSET-2031 theme replies, and GitHub PR-link detection
  • reveal rides the existing reattach path: fresh xterm, daemon model snapshot > replay > cold restore, replay-guarded, with watcher disposal ordered before pane handlers re-register
  • eligibility excludes visible/measuring/portal/pending-startup/floating tabs, remote-runtime and SSH PTYs, daemon-less local PTYs, and any tab the watcher cannot cover (no coverage → no parking, so notifications can never silently die)
  • kill switch: settings.terminalHiddenViewParking (default on)

Why

Hidden panes previously kept full xterm instances alive; at many-worktree scale that is the dominant renderer memory cost. The main-process model already ingests every byte and serves restorable snapshots, so a long-hidden pane's renderer view is redundant state. A previous parking attempt was reverted the same day; the post-mortem (recorded in the design doc) found parked agents could never notify because unmounting the pane killed the renderer's byte parsers. The watcher is the structural fix for that failure mode.

Review hardening

A 3-lens adversarial review of the implementation found and fixed, with regression tests:

  • PTY exit in a parked multi-leaf tab no longer closes the whole tab (single-leaf exit parity preserved; dead leaf's title slot cleared)
  • watcher-written runtime title slots are cleared on dispose so a stale 'working' title cannot pin worktree status after reveal
  • shutdownWorktreeTerminals now synchronously disposes parked watchers so sleep/shutdown teardown flushes cannot fire phantom unread marks or OS notifications (required extracting terminal-parked-watcher-registry.ts to break a store import cycle)
  • daemon-less separator-less PTY ids are no longer parkable (reveal would have silently respawned a fresh shell)
  • spec-scoped fixture launch env (orcaAppExtraEnv) replaces module-scope process.env mutation, fixing cross-spec leakage of the fast-park override

Validation

  • typecheck clean; parking + adjacent regression unit suites green (258 tests; broader renderer sweep 1176, shared 1038)
  • new e2e terminal-hidden-view-parking.spec.ts 3/3: park + rich synchronized TUI restore with working input, bell/title side effects live while parked, exclusions respected
  • full visual gates green alongside parking: hidden TUI visual restore 4/4, long-table 3/3, sleep/wake 1/1, terminal rendering golden 2/2 — including the previously-failing spec order (cross-spec leak) now 7/7
  • agent-tracker seeding test verified red without the fix

Cut-off

Independently mergeable. Next phases (side-effect authority to main, gating hidden delivery, model query authority) build on this but are not required by it.

Made with Orca 🐋

@nwparker

Copy link
Copy Markdown
Contributor Author

Phase 2 memory benchmark added: terminal-parked-memory.spec.ts (2/2 passing). With 8 heavy hidden tabs: parking releases all 8 renderer xterm instances/pane managers (9 → 1 live), heapUsedMB 87.8 vs 89.1 (V8-heap delta is modest by design — xterm scrollback rows live in typed-array stores outside usedJSHeapSize; the structural release is the signal, and prior-art RSS profiling measured −76.2 MB for the same mechanism). Metrics flow through the budget gate and over-time report (new heapUsedMB/liveTerminals/livePaneManagers columns).

nwparker added 2 commits June 16, 2026 15:25
…rker/term-speed-2-hidden-view-parking

# Conflicts:
#	src/preload/e2e-config.ts
#	src/renderer/src/components/Terminal.tsx
#	src/renderer/src/store/slices/terminals.ts
#	tests/e2e/helpers/orca-app.ts
@ghost

ghost commented Jun 16, 2026 •

Copy link
Copy Markdown

@nwparker

Copy link
Copy Markdown
Contributor Author

Closing as superseded by merged PR #7214 (merge e84a8dd), which explicitly revived the complete term-speed-2 model/view chain into current main and then added newer scheduler, producer flow-control, snapshot, and reliability work. This old component/rollup branch no longer has an independent delta to rebase.

@nwparker nwparker closed this Jul 11, 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.

1 participant