Skip to content

fix(browser): release page callbacks when a guest is destroyed - #21010

Merged
OrcaWin merged 2 commits into
mainfrom
np-oom-scan-browser-destroyed-guest
Sep 18, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np-oom-scan-browser-destroyed-guest

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

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

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 097805f2-76ac-4dd6-a097-fa50c129999a

📥 Commits

Reviewing files that changed from the base of the PR and between c8f5623 and 2c57430.

📒 Files selected for processing (9)
  • docs/audits/browser-destroyed-guest-retention/README.md
  • docs/audits/browser-destroyed-guest-retention/reproduce.mjs
  • docs/audits/browser-destroyed-guest-retention/results.json
  • src/main/browser/browser-manager-destroyed-guest-downloads.test.ts
  • src/main/browser/browser-manager-destroyed-guest-test-fixture.ts
  • src/main/browser/browser-manager-download-lifecycle.ts
  • src/main/browser/browser-manager-guest-navigation-policy.ts
  • src/main/browser/browser-manager-registration.ts
  • src/main/browser/browser-manager-state.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/audits/browser-destroyed-guest-retention/README.md
  • docs/audits/browser-destroyed-guest-retention/results.json

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The 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 2c574

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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,… 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 …
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the primary change: releasing page callbacks when a browser guest is destroyed.
Full details: Docstring Coverage

Explanation

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 check

Explanation

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.

  • 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: b434a3a4-0f1e-4076-8855-2d9e39568430

📥 Commits

Reviewing files that changed from the base of the PR and between 291b4dd and c8f5623.

📒 Files selected for processing (6)
  • docs/audits/browser-destroyed-guest-retention/README.md
  • docs/audits/browser-destroyed-guest-retention/reproduce.mjs
  • docs/audits/browser-destroyed-guest-retention/results.json
  • src/main/browser/browser-manager-destroyed-guest-test-fixture.ts
  • src/main/browser/browser-manager-destroyed-guest.test.ts
  • src/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.

Comment on lines +127 to +137
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

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.

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

Suggested change
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

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

ℹ️ No critical issues — two test-coverage nitpicks inline.

Reviewed changes

  • Destroyed primary guests now take the full unregister path: handleDestroyed looks up the tab with tabIdByWebContentsId, and only when that tab's current primary guest is still this exact WebContents does it call unregisterGuest(tab) and return; replaced guests, popups, and pre-registration destruction keep the policy-only cleanupGuestPolicyAttachment fallback.
  • Ablation-verified regression suite: browser-manager-destroyed-guest.test.ts (9 tests) plus a BrowserManager fixture. I re-ran it with the guard deleted and confirmed exactly 3 tests fail (1,000 destructions, unregisterAll path, sibling page), so the assertions pin the leak rather than passing vacuously.
  • Audit bundle added: docs/audits/browser-destroyed-guest-retention/ (README.md, reproduce.mjs in-memory ablation, results.json before 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.

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

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 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')

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

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

✅ No new issues found.

Reviewed changes

  • Destroyed primary guests now route through a guest-retirement path: handleDestroyed calls unregisterGuest(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: unregisterGuest gained a reason parameter; on guest-destroyed it keeps rendererWebContentsIdByTabId while any non-terminal download for the tab remains, and releaseRetiredDownloadRenderer releases 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 unregisterAll still 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit bdad0e0 into main Sep 18, 2026
28 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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>
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