Repository navigation
fix(browser): load newly opened background tabs - #19633
Conversation
There was a problem hiding this comment.
Important
The mechanism works for the startup-restore path, but the admission registry leaks — release is wired only to closeBrowserPage, not the other teardown paths that remove pages.
Reviewed changes
This PR fixes background-tab browser guests by adding an ephemeral mount-admission registry plus two useSyncExternalStore hooks, and folding admission into the two existing mount gates:
browser-page-mount-admission.ts— module-globaladmittedPageIdsSet withadmit/release/useAnyBrowserPageMountAdmission(and an unused singularuseBrowserPageMountAdmission).browser-page-create-actions.ts/browser-tab-actions.ts— admit a page oncreateBrowserPage/createBrowserTabwhen it is a local URL page (!browserRuntimeEnvironmentId && !docLocation); release oncloseBrowserPage.BrowserPaneOverlayLayer.tsx—isPaintablegains|| isMountAdmittedso the whole pane chrome mounts for a background tab.browser-workspace-pane.tsx— per-pageisBrowserPagePanePaintablegains|| hasAdmittedPageso the page's own webview mounts.
I verified the core claim: hydrateBrowserSession (browser/browser-hydration-actions.ts) rebuilds browser state directly and does not pass through createBrowserTab/createBrowserPage, so startup-restored pages stay lazy. The reopening paths (reopenClosedBrowserTab / reopenClosedBrowserPage) do pass through the create actions and will now mount eagerly, which is reasonable for an explicit user action.
ℹ️ No tests cover the registry or its lifecycle
The diff adds no test files, and the admission/release lifecycle is the kind of state that regresses silently: admit-on-create and release-on-close are one-liners, and the leak in the inline comment is exactly the sort of thing a closeBrowserTab-releases-admission test would catch. A small store-level test asserting admittedPageIds is empty after a tab close and after a page close would pin it.
ℹ️ Nitpicks
useBrowserPageMountAdmission(singular) is exported but has zero call sites — either use it for the per-page fix in the inline comment or drop it.- Both hooks ignore the
useSyncExternalStorereturn value and recompute the snapshot (return admittedPageIds.has(pageId)/pageIds.some(…)); thevoid versionis a no-op.return useSyncExternalStore(subscribe, () => admittedPageIds.has(pageId), () => false)is simpler and returns the store's tearing-safe snapshot directly.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| }, | ||
|
|
||
| closeBrowserPage: (pageId) => { | ||
| releaseBrowserPageMount(pageId) |
There was a problem hiding this comment.
Release is wired only here, but pages are removed without releasing admission in closeBrowserTab and shutdownWorktreeBrowsers (both in browser-close-actions.ts), and in convertBrowserPage (browser-page-conversion-actions.ts), which swaps the page for a fresh id. Each of those leaves a stale id in the module-level admittedPageIds Set for the rest of the session — page ids are one-shot UUIDs, so nothing reuses or re-admits them. Mirror the existing releaseDocPreviewGrant handling, which closeBrowserTab already releases per closed page.
Technical details
# Admission registry leaks on tab/worktree/page teardown
## Affected sites
- `src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts:24` — `releaseBrowserPageMount` is the only teardown.
- `src/renderer/src/store/slices/browser/browser-close-actions.ts:51` — `closeBrowserTab` deletes the workspace's pages from `browserPagesByWorkspace` without releasing admission (it does release `releaseDocPreviewGrant` for doc pages at line 179).
- `src/renderer/src/store/slices/browser/browser-close-actions.ts:229` — `shutdownWorktreeBrowsers` delegates to `closeBrowserTab`, same leak.
- `src/renderer/src/store/slices/browser/browser-page-conversion-actions.ts:44` — `convertBrowserPage` replaces the page under a fresh id via `planBrowserPageConversion`; the old admission is never released.
## Required outcome
- `admittedPageIds` must not retain ids for pages no longer present in the store. Every path that removes a page (tab close, worktree shutdown, conversion) must release its admission.
## Suggested approach (optional)
- In `closeBrowserTab`, collect `closedPages` ids and call `releaseBrowserPageMount` for each, alongside the existing `releaseDocPreviewGrant` loop.
- In `convertBrowserPage`, release `plan.oldPage.id` when the conversion succeeds.|
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 (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared browser page mount admission registry with React hooks. Page and tab creation admit eligible pages, while page closure releases them. The browser overlay and workspace pane include admitted pages in their paintability checks. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to This change mounts newly created background browser pages and releases their admission on close, but runtime-backed page classification and admission-state updates may still produce incorrect browser pane behavior. Resolve these concerns before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the regression, fix, and validation, but it omits several required template sections. It does not provide a valid Linked Issue entry, a dedicated Visual Proof section, testing checkboxes and platform details, or the required checklist and compatibility notes. Resolution Add the missing template sections and required information. Provide a real
✨ 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: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: e94d8de4-3193-4539-b793-257b36d7430e
📒 Files selected for processing (5)
src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.tsxsrc/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsxsrc/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.tssrc/renderer/src/store/slices/browser/browser-page-create-actions.tssrc/renderer/src/store/slices/browser/browser-tab-actions.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| useSyncExternalStore( | ||
| (listener) => { | ||
| listeners.add(listener) | ||
| return () => listeners.delete(listener) | ||
| }, | ||
| () => { | ||
| void version | ||
| return admittedPageIds.has(pageId) | ||
| }, | ||
| () => false | ||
| ) | ||
| return admittedPageIds.has(pageId) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 18733
🏁 Script executed:
#!/bin/bash
set -eu
file='src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts'
printf '%s\n' '--- target file ---'
cat -n "$file"
printf '%s\n' '--- related symbols ---'
rg -n -C 3 'useBrowserPageMountAdmission|admittedPageIds|browser-page-mount-admission|useSyncExternalStore' src/renderer/srcRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -eu
file='src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts'
cat -n "$file"
printf '%s\n' '--- related symbols ---'
rg -n -C 3 'useBrowserPageMountAdmission|admittedPageIds|browser-page-mount-admission|useSyncExternalStore' src/renderer/srcRepository: stablyai/orca
Length of output: 50369
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 44583
Return the useSyncExternalStore snapshot from both hooks. useBrowserPageMountAdmission and useAnyBrowserPageMountAdmission discard React’s snapshot and read admittedPageIds again. This can diverge during concurrent rendering and bypasses the false getServerSnapshot during server rendering. Return the hook result directly.
| if (!options?.browserRuntimeEnvironmentId && !options?.docLocation) { | ||
| admitBrowserPageMount(page.id) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 19149
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- changed call sites ---'
sed -n '1,90p' src/renderer/src/store/slices/browser/browser-page-create-actions.ts
sed -n '1,90p' src/renderer/src/store/slices/browser/browser-tab-actions.ts
sed -n '180,225p' src/renderer/src/store/slices/browser/browser-tab-actions.ts
printf '%s\n' '--- resolver and related symbols ---'
rg -n -C 5 "getBrowserPageRuntimeEnvironmentId|admitBrowserPageMount|browserRuntimeEnvironmentId" src/renderer/srcRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- exact resolver definition/usages ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
"getBrowserPageRuntimeEnvironmentId" src
printf '%s\n' '--- runtime-owner helpers ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
"getRuntimeEnvironmentIdForWorktree|worktree-runtime-owner" src/renderer/src
printf '%s\n' '--- admission implementation and consumers ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
"admitBrowserPageMount|isBrowserPageMountAdmitted|browserPageMount" \
src/renderer/src/components src/renderer/src/store
printf '%s\n' '--- browser page types/building ---'
rg -n -C 6 --glob '*.ts' --glob '*.tsx' \
"browserRuntimeEnvironmentId" \
src/renderer/src/store/slices/browser/browser-slice-contract.ts \
src/renderer/src/store/slices/browser/browser-page-records.ts \
src/renderer/src/store/slices/browserRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -eu
rg -l --glob '*.ts' --glob '*.tsx' 'getBrowserPageRuntimeEnvironmentId' src/renderer/src src/shared || true
rg -l --glob '*.ts' --glob '*.tsx' 'admitBrowserPageMount' src/renderer/src/components src/renderer/src/store
rg -l --glob '*.ts' --glob '*.tsx' 'getRuntimeEnvironmentIdForWorktree' src/renderer/srcRepository: stablyai/orca
Length of output: 7615
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- runtime owner contract ---'
sed -n '1,220p' src/renderer/src/lib/worktree-runtime-owner.ts
printf '%s\n' '--- browser pane ownership and mount admission ---'
sed -n '35,125p' src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsx
sed -n '1,180p' src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts
printf '%s\n' '--- page construction and ownership types ---'
rg -n -C 10 --glob '*.ts' \
'function buildBrowserPage|export function buildBrowserPage|browserRuntimeEnvironmentId' \
src/renderer/src/store/slices/browser/browser-page-records.ts \
src/shared/browser-workspace-types.ts \
src/renderer/src/store/slices/browser/browser-slice-contract.tsRepository: stablyai/orca
Length of output: 21170
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- exact resolver matches ---'
rg -n -m 20 'getBrowserPageRuntimeEnvironmentId' src/renderer/src || true
printf '%s\n' '--- exact admission matches ---'
rg -n -m 20 -C 5 'admitBrowserPageMount' src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts src/renderer/src/store/slices/browser/browser-page-create-actions.ts src/renderer/src/store/slices/browser/browser-tab-actions.ts
printf '%s\n' '--- ownership helper ---'
rg -n -m 20 -C 8 'export function getRuntimeEnvironmentIdForWorktree|function getRuntimeEnvironmentIdForWorktree' src/renderer/src/lib/worktree-runtime-owner.tsRepository: stablyai/orca
Length of output: 7994
🏁 Script executed:
#!/bin/bash
set -eu
rg -n -m 50 'getBrowserPageRuntimeEnvironmentId' src/renderer/srcRepository: stablyai/orca
Length of output: 1517
🏁 Script executed:
#!/bin/bash
set -eu
sed -n '1,75p' src/renderer/src/components/browser-pane/describe-page/browser-page-url-display.ts
sed -n '30,65p' src/renderer/src/components/browser-pane/describe-page/browser-page-url-display.test.tsRepository: stablyai/orca
Length of output: 3685
🏁 Script executed:
#!/bin/bash
set -eu
rg -n -C 6 'useBrowserPageMountAdmission|useAnyBrowserPageMountAdmission|hasAdmittedPage' \
src/renderer/src/components/browser-paneRepository: stablyai/orca
Length of output: 12028
🏁 Script executed:
#!/bin/bash
set -eu
sed -n '100,230p' src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsxRepository: stablyai/orca
Length of output: 5427
🏁 Script executed:
#!/bin/bash
set -eu
sed -n '50,125p' src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.tsxRepository: stablyai/orca
Length of output: 3135
Resolve inherited runtime ownership before admitting a page.
getBrowserPageRuntimeEnvironmentId resolves undefined to the worktree runtime and treats null as local. Both creation actions use a falsy check, so inherited runtime pages enter the admission set. BrowserPaneOverlayLayer checks all page IDs and passes the result to DeferredBrowserContent, so the admitted runtime page can make its overlay paintable and render eagerly. Resolve effective ownership first, then admit only pages without a runtime or with an explicit null owner in both files.
📍 Affects 2 files
src/renderer/src/store/slices/browser/browser-page-create-actions.ts#L40-L42(this comment)src/renderer/src/store/slices/browser/browser-tab-actions.ts#L52-L54
|
Review status: PASS WITH RISK
Residual risk is limited to unmeasured listener fanout at very large tab counts and the missing visible Electron validation. |
There was a problem hiding this comment.
ℹ️ No new issues in this delta. The two substantive concerns from the prior review — per-page mount scoping and the close-path admission leak — are addressed; one part of the leak finding (
convertBrowserPage) remains open and is called out below.
Reviewed changes
- Scoped mount admission to the admitted page —
BrowserPanenow gates sibling mount eligibility withhasAdmittedPage && isBrowserPageMountAdmitted(page.id), so a newly admitted background page mounts while its restored/lazy siblings stay lazy. - Released mount admission on tab close —
closeBrowserTabcollectsclosedPagesForMountReleaseand releases each viareleaseBrowserPageMount;shutdownWorktreeBrowsersis covered through itscloseBrowserTabdelegation. - Extracted
isBrowserPageMountAdmittedand reused it inside bothuseSyncExternalStorehooks.
ℹ️ convertBrowserPage still never releases the old page's admission
The close-path leak is fixed for closeBrowserTab and shutdownWorktreeBrowsers, but convertBrowserPage still swaps plan.oldPage for a fresh id without releasing the old id's admission. A local page admitted at creation and then converted leaves a dead UUID in the module-level admittedPageIds Set for the session — no functional impact, just unbounded growth. This is the remaining part of the prior leak finding, still tracked in the open thread.
Technical details
# convertBrowserPage admission leak
## Affected sites
- `src/renderer/src/store/slices/browser/browser-page-conversion-actions.ts:44` — `convertBrowserPage` replaces `plan.oldPage.id` with `plan.newPage.id` and never calls `releaseBrowserPageMount(plan.oldPage.id)`.
## Required outcome
- `admittedPageIds` must not retain ids for pages no longer in the store. Release `plan.oldPage.id` when the conversion succeeds, mirroring the `releaseDocPreviewGrant(docPageIdToRelease)` release already done at the same site.DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Electron manual validation: newly opened background local-URL tabValidated on dev build from this branch ( Scenario
Result (pass)
Notes / gaps
|
…ound pages Two defects from the same #19326 regression. Each is necessary; neither is sufficient. A 2x2 ablation is in the PR body. Missing publication edge: the offscreen guest policy notified the runtime on every navigation FAILURE path but not on a successful main-frame commit, so a page created blank and then navigated never invalidated the published snapshot. A pull (session.tabs.list) read the live WebContents and looked correct, while the pushed snapshot clients actually apply stayed at about:blank forever. Successful commit now uses the same worktree-scoped notifier the failure paths already use. Missing mount admission: #19326 deferred inactive browser pages behind a paintability gate; #19633 repaired that for local pages by admitting explicitly created ones, but scoped admission to local URL pages. A runtime-backed page opened in the background is never the active tab, has no local guest to retain, and was never admitted, so its pane never mounted. Document previews stay excluded. Guards are vitest, not e2e: e2e is not a required check in this repo.


Problem
The regression was introduced by PR #19326, which added lazy deferral of inactive browser pages. The failure was in the resulting lazy browser guest mount eligibility gate. Newly created background local URL pages were classified like restored inactive pages, so their guest never mounted; the page was created, but its URL title and navigation state never initialized and the E2E flow timed out.
Fix
Add an ephemeral mount-admission registry for pages explicitly created in the renderer. Newly created local URL pages are admitted to guest initialization even when inactive; restored pages remain lazy. Admission is scoped per page and released when a page closes, including bulk tab cleanup.
Validation
pnpm exec oxlinton changed filespnpm run typecheck:webactivate:false; the background guest mounted and its title updated without activation. Full-window screenshot evidence is attached in the PR comments.