Repository navigation
fix(renderer): release parked terminal scroll intents - #20924
Conversation
📝 WalkthroughWalkthroughThe parked terminal watcher registry now releases each captured pane's scroll-intent key when a parked tab is retired or its worktree is pruned. Reconciliation tests verify that both cleanup paths reduce retained scroll intent from one entry to zero. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Removing terminals during workspace synchronization can retain stale scroll state and increase renderer memory usage across repeated terminal churn; the shared cleanup should be fixed before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, the implemented cleanup, and the validation command, but it omits most required template sections. It lacks ELI5, Linked Issue, Visual Proof or N/A, testing checkboxes and platform details, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist responses. Resolution Complete the required template sections. Add an ELI5 summary, a linked issue after
✨ Finishing Touches 💡 1📝 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ff108cd1-166c-40b1-bdc1-8f16829a4b81
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/terminal-parked-watcher-reconciliation.test.tssrc/renderer/src/components/terminal-pane/terminal-parked-watcher-registry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| } | ||
| for (const [tabId, capture] of capturedPanesByTabId) { | ||
| if (!liveWorktreeIds.has(capture.worktreeId)) { | ||
| for (const pane of capture.panes) { | ||
| // Worktree removal can bypass closeTab while panes are parked; release | ||
| // the same strong scroll-intent keys as explicit tab retirement. | ||
| releaseTerminalScrollIntentKey(pane.leafId) | ||
| } | ||
| capturedPanesByTabId.delete(tabId) | ||
| } | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a worktree-pruning regression test. use-terminal-watcher-effects.ts calls pruneParkedTerminalWatchers, but no test combines this path with keyed scroll state. The retirement test calls the separate retireParkedTerminalTab branch, so it would still pass if pruning lost releaseTerminalScrollIntentKey. Write both keyed intent and binding, capture the pane, prune the removed worktree, and assert that both retention counts return to baseline.
There was a problem hiding this comment.
Important
The release reads capturedPanesByTabId, an unmount-time snapshot that is never refreshed on reveal. For a tab that was parked, then revealed, then had a pane detached into another tab, closing it now releases that still-live leaf's key and drops its pin.
Reviewed changes
- Release scroll intents on parked-tab retirement —
retireParkedTerminalTabnow iterates the captured panes and callsreleaseTerminalScrollIntentKeyper leaf, so closed parked tabs stop leaking one strong key per leaf. - Release scroll intents on worktree pruning —
pruneParkedTerminalWatchersreleases the same keys for captures whose worktree no longer exists. - Regression test — writes a keyed intent, captures a parked pane, retires the tab, and asserts key retention falls back to zero.
️ Nitpicks
- The new test asserts only
readTerminalScrollIntentKeyRetention().intents; the fix clears both maps, so assertingbindingstoo would pin the full contract. - No test exercises the
pruneParkedTerminalWatchersrelease path, though it carries the same stale-capture exposure.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // strong scroll-intent keys here or every closed parked tab leaks one per | ||
| // leaf for the renderer lifetime. | ||
| for (const pane of capture.panes) { | ||
| releaseTerminalScrollIntentKey(pane.leafId) |
There was a problem hiding this comment.
This releases straight from the unmount snapshot, which can be stale. A leaf captured while the tab was parked may since have been detached into another tab — detachManagedPaneForExternalMove preserves the leafId and deliberately keeps its keyed intent — so closing the source tab drops the pin of a leaf that is still live elsewhere.
Technical details
# Stale capture releases a live leaf's keyed scroll intent
## Affected sites
- `src/renderer/src/components/terminal-pane/terminal-parked-watcher-registry.ts:144-151` — trusts `capture.panes` verbatim. The capture is written only at `TerminalPane` unmount (`terminal-pane-mount-cleanup.ts:73-89`) and is never refreshed or deleted on reveal; the only deletion before death is for tabs absent from the live set (`terminal-parked-tab-watchers.ts:323-328`).
- `src/renderer/src/components/terminal-pane/terminal-parked-watcher-registry.ts:226-235` — `pruneParkedTerminalWatchers` has the same raw-capture iteration (lower reachability, but a stale `capture.worktreeId` after a tab rehome could hit it).
- `src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.ts:116-135` — preserves the source leafId in the new tab; `pane-split-close.ts:183-188` deliberately skips the release for the `'detach'` reason so the new host can still restore the pin.
## Required outcome
- Closing a parked tab releases only the keys actually retired with it; a leaf that migrated to another tab keeps its keyed intent (and binding), per the invariant at `pane-split-close.ts:184-186` and asserted in `terminal-scroll-intent-key-retention.test.ts:139-158`.
- `releaseTerminalScrollIntentKey` deletes the binding too; once it is gone, `isTerminalScrollIntentKeyBindingCurrent` returns false for the still-mounted successor (`terminal-scroll-intent.ts:128-139`) and its dispose skips persisting the pin (`terminal-scroll-intent-dom-tracking.ts:240-242`).
## Suggested approach (optional)
- On detach, drop the migrated leaf from the source tab's `capturedPanesByTabId` entry so the retirement release set stays disjoint from live leaves.
- Alternatively, gate each release on whether the leaf is still referenced by any live tab layout.There was a problem hiding this comment.
🟠 Major · Extract and use one captured-pane cleanup helper.
src/renderer/src/components/terminal-pane/terminal-parked-watcher-registry.ts:144-153
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winExtract and use one captured-pane cleanup helper. The live
use-terminal-watcher-effects.tspath callssyncParkedTerminalTabWatchersForWorkspaces. When a tab is absent from its live set, that function disposes watcher state and then deletescapturedPanesByTabIdwithout releasing each capturedpane.leafId. The keyed store holds strong intent and binding maps, so those entries can remain for the renderer lifetime. Make one helper release every captured leaf ID and delete the capture, then use it for explicit retirement, worktree pruning, and workspace synchronization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 48d4ac29-1c46-419f-8dec-4bf92b60b098
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/terminal-parked-watcher-reconciliation.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Closed parked terminal tabs and removed worktrees bypass PaneManager close teardown, leaving strong scroll-intent Map entries for every captured leaf. Release those keys during parked-tab retirement and worktree pruning.\n\nValidation: pnpm test src/renderer/src/components/terminal-pane/terminal-parked-watcher-reconciliation.test.ts