Skip to content

fix(browser): fence late registration replies to their guest owner - #21012

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

OrcaWin merged 2 commits into
mainfrom
np-oom-scan-browser-registration-replies

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​361 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​361
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​405 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​397

A browser registration reply can arrive after its page closes and restore the removed guest-ID entry. Old replies also overwrite replacement IDs or run annotation/recovery callbacks against a newer owner; delayed recovery queries can issue repair IPC after the original owner is gone.

Fence registration, repair and their continuations with the existing disposed state, persistent registry/ref identity, and captured WebContents ID. Current hidden guests and remount registration keep working. No new registry or late unregister request is introduced.

Validation

  • Actual renderer session/recovery/registry: 1,000 closed pages retain 1,000 entries and receive 1,000 late annotation calls before; zero after. Explicit unregister count stays unchanged.
  • Portable before/after proof: ten failing cases plus six controls become 16 passing tests.
  • All 196 host-guest tests across 23 files, full web typecheck, lint, formatting and independent review pass.
  • Covers replacement elements, same-element guest changes, disposed/remounted sessions, hidden guests and late repair completion. Source hashes: docs/audits/browser-registration-reply-retention/.

Present in v1.4.198. This is small renderer metadata retention, not evidence of a surviving native guest or the gigabyte growth in #19831/#19768. The independent main destroyed-guest cleanup is #21010.

@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: c94b1c59-bdaa-4b07-9a46-ea423533f829

📥 Commits

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

📒 Files selected for processing (7)
  • docs/audits/browser-registration-reply-retention/README.md
  • docs/audits/browser-registration-reply-retention/fix.patch
  • docs/audits/browser-registration-reply-retention/reproduce.mjs
  • docs/audits/browser-registration-reply-retention/results.json
  • src/renderer/src/components/browser-pane/host-guest/browser-page-guest-recovery.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-registration-ownership.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview-guest-session.ts

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


📝 Walkthrough

Walkthrough

The change adds disposal and ownership checks to browser guest registration. Registration replies are accepted only when the recovery, webview reference, registry entry, and WebContents ID still match. Attach, DOM-ready, validation, and repair paths re-check ownership after asynchronous operations. New tests cover stale and current replies. Audit tooling compares reconstructed baseline behavior with the updated implementation.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 1ee32

The ownership guards and targeted tests support the intended stale-reply behavior, with no actionable merge-blocking issue remaining.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, scope, and validation, but it omits most required template sections. It has no ELI5, What Changed, Why, Visual Proof, AI Disclosure, Review, Agent… Add all required template sections. Provide a valid linked issue number after Fixes #. Add Visual Proof or write N/A with a reason. Complete the Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and final C…
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 7 functions across 4 files. (3 skipped: 3 … 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: preventing late browser registration replies from affecting the wrong guest owner.
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, implementation, scope, and validation, but it omits most required template sections. It has no ELI5, What Changed, Why, Visual Proof, AI Disclosure, Review, Agent skill upstream boundary, Notes, or Checklist sections. The required linked issue is also incomplete because it contains only Fixes #.

Resolution

Add all required template sections. Provide a valid linked issue number after Fixes #. Add Visual Proof or write N/A with a reason. Complete the Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and final Checklist sections.

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 7 functions across 4 files. (3 skipped: 3 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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.

@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

One existing test's ./webview-registry mock was not updated for the new webviewRegistry dependency, so it now throws internally and only stays green because the rejection is swallowed by the recovery catch path. See the inline note. No production-flow defect found.

Reviewed changes — reviewed all 7 files of PR #21012 at 1ee3295, a renderer-only fence around late browser guest registration replies.

  • Ownership predicate — ownsGuest(webContentsId) in browser-page-webview-guest-session.ts requires a non-null id, an undisposed recovery, the current webviewRef, the current webviewRegistry entry, and an unchanged getWebContentsId(), and is applied at registration entry, at reply completion, and after repair.
  • Post-reply fencing — handleDidAttach and handleDomReady capture the guest id before registering and bail out of confirmRegistration, finish, clearGuestRecoveryError, validateAfterResume, and the annotation-bridge sync when ownership no longer holds.
  • Repair/validation fencing — validateRegistration re-checks ownership after isGuestRegistered (before issuing repairGuestRegistration) and after the repair reply.
  • Recovery disposal probe — browser-page-guest-recovery.ts now exposes isDisposed() on the recovery handle.
  • Tests + audit — a new 16-case deferred-reply suite plus a docs/audits/browser-registration-reply-retention/ reproduction harness and results.

I ran the host-guest suite at head (200 tests / 23 files, all passing) and traced the registry/ref invariants through ensureBrowserPageWebview, removePersistentWebview, and the React attach-effect cleanup. The webviewRegistry.get(browserTabId) === webview and skipped-finish() concerns both hold in production: the registry delete only happens after webview.remove(), registration precedes the DOM append, and any successor session re-arms the recovery watchdog. The two notes below are the only fallout.

ℹ️ Nitpicks

  • browser-page-registration-ownership.test.ts:232 — expect(replacement.pending.current).toBe(true) is tautological: createSession allocates a fresh pending ref per session (:73), so this assertion never observed the old listener writing to the replacement's flag (production shares one guestRecoveryPendingRef across effect re-runs). The other assertions in that case do exercise the fence; this one just does not add the coverage it implies.

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

webContentsId !== null &&
!guestRecovery.isDisposed() &&
webviewRef.current === webview &&
webviewRegistry.get(browserTabId) === webview &&

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.

The new webviewRegistry dependency breaks the mock in the existing browser-page-evicted-guest-recovery.test.ts: its vi.mock('./webview-registry', ...) factory does not export webviewRegistry, so ownsGuest throws No "webviewRegistry" export is defined on the reuses a connected registered guest on reactivation case. The test still exits 0 only because the rejection is swallowed by the recovery catch path, so it no longer exercises the reuse-success behavior it names.

Technical details
# Incomplete webview-registry mock after the new dependency

## Affected sites
- `src/renderer/src/components/browser-pane/host-guest/browser-page-webview-guest-session.ts:98` — `ownsGuest` now reads `webviewRegistry.get(browserTabId)`.
- `src/renderer/src/components/browser-pane/host-guest/browser-page-evicted-guest-recovery.test.ts:10-13` — the mock factory returns only `registeredWebContentsIds` and `replacePersistentWebview`.
- Repro (exits 0 while logging the error): `pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/browser-pane/host-guest/browser-page-evicted-guest-recovery.test.ts`

## Required outcome
- The test's `./webview-registry` mock exposes a `webviewRegistry` Map, and `createPage` registers its fixture webview in it (production registers in `ensureBrowserPageWebview` via `registerPersistentWebview`). Then `ownsGuest` holds, `isGuestRegistered: true` returns a real success, and the `reuses a connected registered guest on reactivation` case actually asserts validation success instead of a swallowed rejection.

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