Repository navigation
fix(browser): release page callbacks when a guest is destroyed - #21010
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds ownership-checked cleanup for destroyed primary guests. It preserves cleanup rules for non-primary guests. It adds download-specific unregister behavior so active downloads retain routing until they settle. It adds fixtures and tests for guest, replacement, popup, reload, restoration, shared-session, and download lifecycles. It also adds a reproducible baseline comparison and records its results. Priority: ➖ Normal Merge Risk: 🔵 Low · up to The retention audit can report success after an unexpected subprocess failure if its parsed counts still match. Add explicit expected exit-code checks before relying on this audit result. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 8 files. (2 skipped: 2 unsupported.) Full details: Description checkExplanation The description clearly explains the behavior change and validation results, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, AI Disclosure, Review, Notes, and the checklist confirmations. Resolution Rewrite the description using the repository template. Add the required linked issue, explain the rationale and mechanism, provide Visual Proof or state N/A with a reason, complete the testing and checklist items, and address AI disclosure and compatibility considerations.
✨ 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: b434a3a4-0f1e-4076-8855-2d9e39568430
📒 Files selected for processing (6)
docs/audits/browser-destroyed-guest-retention/README.mddocs/audits/browser-destroyed-guest-retention/reproduce.mjsdocs/audits/browser-destroyed-guest-retention/results.jsonsrc/main/browser/browser-manager-destroyed-guest-test-fixture.tssrc/main/browser/browser-manager-destroyed-guest.test.tssrc/main/browser/browser-manager-guest-navigation-policy.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| const passed = | ||
| before.passed === 6 && | ||
| before.failed === 3 && | ||
| after.passed === 9 && | ||
| after.failed === 0 && | ||
| before.counts.length === 9 && | ||
| after.counts.length === 9 && | ||
| before.counts[0].counts.contextMenus === 1000 && | ||
| before.counts[1].counts.contextMenus === 1000 && | ||
| after.counts[0].counts.contextMenus === 0 && | ||
| after.counts[1].counts.contextMenus === 0 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Validate both subprocess exit codes.
The passed predicate ignores before.exitCode and after.exitCode. A runner-level failure can therefore produce "passed": true when the JSON assertion counts still match.
Require the expected baseline and fixed exit codes.
Proposed fix
const passed =
- before.passed === 6 &&
+ before.exitCode === 1 &&
+ after.exitCode === 0 &&
+ before.passed === 6 &&
before.failed === 3 &&📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const passed = | |
| before.passed === 6 && | |
| before.failed === 3 && | |
| after.passed === 9 && | |
| after.failed === 0 && | |
| before.counts.length === 9 && | |
| after.counts.length === 9 && | |
| before.counts[0].counts.contextMenus === 1000 && | |
| before.counts[1].counts.contextMenus === 1000 && | |
| after.counts[0].counts.contextMenus === 0 && | |
| after.counts[1].counts.contextMenus === 0 | |
| const passed = | |
| before.exitCode === 1 && | |
| after.exitCode === 0 && | |
| before.passed === 6 && | |
| before.failed === 3 && | |
| after.passed === 9 && | |
| after.failed === 0 && | |
| before.counts.length === 9 && | |
| after.counts.length === 9 && | |
| before.counts[0].counts.contextMenus === 1000 && | |
| before.counts[1].counts.contextMenus === 1000 && | |
| after.counts[0].counts.contextMenus === 0 && | |
| after.counts[1].counts.contextMenus === 0 |
There was a problem hiding this comment.
ℹ️ No critical issues — two test-coverage nitpicks inline.
Reviewed changes
- Destroyed primary guests now take the full unregister path:
handleDestroyedlooks up the tab withtabIdByWebContentsId, and only when that tab's current primary guest is still this exact WebContents does it callunregisterGuest(tab)and return; replaced guests, popups, and pre-registration destruction keep the policy-onlycleanupGuestPolicyAttachmentfallback. - Ablation-verified regression suite:
browser-manager-destroyed-guest.test.ts(9 tests) plus aBrowserManagerfixture. I re-ran it with the guard deleted and confirmed exactly 3 tests fail (1,000 destructions,unregisterAllpath, sibling page), so the assertions pin the leak rather than passing vacuously. - Audit bundle added:
docs/audits/browser-destroyed-guest-retention/(README.md,reproduce.mjsin-memory ablation,results.jsonbefore 6/3 → after 9/0).
I also checked the plausible regressions: renderer re-registration resends workspaceId/worktreeId/sessionProfileId so wiping tab metadata on destroy is safe, and the offscreen backend's existing unregisterGuest on destroyed is now preceded by the policy handler's idempotent call.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
|
||
| it('preserves live guest ownership when its renderer process needs reload recovery', () => { | ||
| const guest = register('renderer-recovery') | ||
| guest.emit('render-process-gone', {}, { reason: 'crashed', exitCode: 1 }) |
There was a problem hiding this comment.
This control can't fail for the reason its name implies: BrowserManager never subscribes to render-process-gone, so emitting it is a no-op and expectRetainedCount(1) holds whether or not the destroyed-guest guard exists. Consider exercising the actual recovery path (e.g. that a subsequent destroyed still resolves the fresh registration), or renaming it to say it only pins that a non-destroyed event doesn't tear the guest down.
| const old = register('replacement') | ||
| const [oldDestroyed] = old.listeners('destroyed') | ||
| expect(oldDestroyed).toBeTypeOf('function') | ||
| const replacement = register('replacement') |
There was a problem hiding this comment.
This control doesn't actually pin the === guest.id clause it appears to target: register('replacement') calls retireStaleGuestWebContents, which already removes tabIdByWebContentsId[old.id], so the stale callback falls through on the browserTabId truthiness check alone. I confirmed all 9 tests still pass with the guard reduced to if (browserTabId). If the equality check is intentional defense-in-depth that's fine, but worth noting the scenario as written can't distinguish it.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Destroyed primary guests now route through a guest-retirement path:
handleDestroyedcallsunregisterGuest(tab, 'guest-destroyed')only when the destroyed WebContents is still the exact primary owner, so per-page callbacks are released without the previous behavior of canceling in-flight downloads. - Downloads survive guest destruction and drain their renderer route:
unregisterGuestgained areasonparameter; onguest-destroyedit keepsrendererWebContentsIdByTabIdwhile any non-terminal download for the tab remains, andreleaseRetiredDownloadRendererreleases that route once the last bound download settles. - Replacement/race guards: the release helper refuses to delete a route that a replacement guest or a newer routing owner installed, and
unregisterAllstill cancels every download first (releasing retained routes before the tab loop). - Nine download-lifetime tests (
browser-manager-destroyed-guest-downloads.test.ts) plus updated audit source hashes and README.
I re-ran all 1818 src/main/browser tests and pnpm tc:node (both pass), and ablation-checked the new webContentsIdByTabId.has(browserTabId) clause: removing it fails the replacement-routing test, so the guard is genuinely pinned rather than passing vacuously.
Two prior Pullfrog test-coverage nitpicks on browser-manager-destroyed-guest.test.ts remain open; this commit does not touch that file.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…yai#21010) * fix(browser): release page callbacks when a guest is destroyed * fix: address memory PR review regressions and withdraw false positives --------- Co-authored-by: m4air <m4air@Mac.localdomain>

Behavior
Release page callbacks and guest-owned maps when the primary browser guest is destroyed. Preserve downloads already owned by the still-open logical page and keep only their existing renderer routing until the final download settles. Explicit page close continues to cancel downloads, including after guest destruction.
Validation
Fifty-five combined tests and 43 exact corrected-head tests pass. New controls cover completion, cancellation, errors, multiple downloads, explicit close after destruction, replacement guests and renderer loss. Node typecheck and lint pass; the portable nine-case comparison is refreshed.
Merge decision
Tests observe Orca's cancellation and routing behavior with controlled native download items; they do not establish Chromium download survival on every OS. No download-history cap changes. Required CI must pass on the corrected head.
Audit evidence