Repository navigation
fix(browser): fence late registration replies to their guest owner - #21012
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 (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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 Resolution Add all required template sections. Provide a valid linked issue number after 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 7 functions across 4 files. (3 skipped: 3 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 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.
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)inbrowser-page-webview-guest-session.tsrequires a non-null id, an undisposed recovery, the currentwebviewRef, the currentwebviewRegistryentry, and an unchangedgetWebContentsId(), and is applied at registration entry, at reply completion, and after repair. - Post-reply fencing —
handleDidAttachandhandleDomReadycapture the guest id before registering and bail out ofconfirmRegistration,finish,clearGuestRecoveryError,validateAfterResume, and the annotation-bridge sync when ownership no longer holds. - Repair/validation fencing —
validateRegistrationre-checks ownership afterisGuestRegistered(before issuingrepairGuestRegistration) and after the repair reply. - Recovery disposal probe —
browser-page-guest-recovery.tsnow exposesisDisposed()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:createSessionallocates a freshpendingref per session (:73), so this assertion never observed the old listener writing to the replacement's flag (production shares oneguestRecoveryPendingRefacross effect re-runs). The other assertions in that case do exercise the fence; this one just does not add the coverage it implies.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| webContentsId !== null && | ||
| !guestRecovery.isDisposed() && | ||
| webviewRef.current === webview && | ||
| webviewRegistry.get(browserTabId) === webview && |
There was a problem hiding this comment.
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.…tablyai#21012) Co-authored-by: m4air <m4air@Mac.localdomain>

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