Skip to content

fix(renderer): release parked terminal scroll intents - #20924

Merged
OrcaWin merged 3 commits into
mainfrom
np-oom-scan-scroll-intent
Sep 18, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np-oom-scan-scroll-intent

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

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

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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 0c480

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 check… Complete the required template sections. Add an ELI5 summary, a linked issue after Fixes #, Visual Proof or N/A with a reason, testing details and checkbox status, applicable AI Disclosure information, Review, Agent skill upstream bound…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: releasing scroll-intent entries for parked terminal tabs.
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.
Full details: Description check

Explanation

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 Fixes #, Visual Proof or N/A with a reason, testing details and checkbox status, applicable AI Disclosure information, Review, Agent skill upstream boundary status, Notes, and Checklist responses.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ff108cd1-166c-40b1-bdc1-8f16829a4b81

📥 Commits

Reviewing files that changed from the base of the PR and between 7ec2986 and 007f4e4.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-parked-watcher-reconciliation.test.ts
  • src/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.

Comment on lines 225 to 235
}
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)
}
}

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.

📐 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.

@pullfrog pullfrog 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.

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 — retireParkedTerminalTab now iterates the captured panes and calls releaseTerminalScrollIntentKey per leaf, so closed parked tabs stop leaking one strong key per leaf.
  • Release scroll intents on worktree pruning — pruneParkedTerminalWatchers releases 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 asserting bindings too would pin the full contract.
  • No test exercises the pruneParkedTerminalWatchers release path, though it carries the same stale-capture exposure.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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)

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.

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.

@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.

⚠️ Outside the diff (1)

🟠 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 win

Extract and use one captured-pane cleanup helper. The live use-terminal-watcher-effects.ts path calls syncParkedTerminalTabWatchersForWorkspaces. When a tab is absent from its live set, that function disposes watcher state and then deletes capturedPanesByTabId without releasing each captured pane.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

📥 Commits

Reviewing files that changed from the base of the PR and between 007f4e4 and 0c4809b.

📒 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.

@OrcaWin
OrcaWin merged commit bd40418 into main Sep 18, 2026
34 checks passed
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