Skip to content

fix(browser): load newly opened background tabs - #19633

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-background-tab-admission
Sep 8, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-background-tab-admission

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​75

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 oxlint on changed files
  • pnpm run typecheck:web
  • Manual Electron validation: created a foreground local URL tab, then a background local URL tab with activate:false; the background guest mounted and its title updated without activation. Full-window screenshot evidence is attached in the PR comments.

@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

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-global admittedPageIds Set with admit / release / useAnyBrowserPageMountAdmission (and an unused singular useBrowserPageMountAdmission).
  • browser-page-create-actions.ts / browser-tab-actions.ts — admit a page on createBrowserPage / createBrowserTab when it is a local URL page (!browserRuntimeEnvironmentId && !docLocation); release on closeBrowserPage.
  • BrowserPaneOverlayLayer.tsx — isPaintable gains || isMountAdmitted so the whole pane chrome mounts for a background tab.
  • browser-workspace-pane.tsx — per-page isBrowserPagePanePaintable gains || hasAdmittedPage so 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 useSyncExternalStore return value and recompute the snapshot (return admittedPageIds.has(pageId) / pageIds.some(…)); the void version is a no-op. return useSyncExternalStore(subscribe, () => admittedPageIds.has(pageId), () => false) is simpler and returns the store's tearing-safe snapshot directly.

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

},

closeBrowserPage: (pageId) => {
releaseBrowserPageMount(pageId)

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.

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.

@coderabbitai

coderabbitai Bot commented Sep 8, 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: e5641299-4838-460b-beb1-241b85b1a1d2

📥 Commits

Reviewing files that changed from the base of the PR and between 3f315da and 7c1728c.

📒 Files selected for processing (3)
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsx
  • src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts
  • src/renderer/src/store/slices/browser/browser-close-actions.ts

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


📝 Walkthrough

Walkthrough

The 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 7c172

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)

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 10 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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… Add the missing template sections and required information. Provide a real Fixes #<issue> reference, include or explicitly describe the required visual proof, document manual and automated testing with platforms, complete the AI Disclosur…
✅ 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: loading newly opened background browser tabs.
Full details: Description check

Explanation

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 Fixes #&lt;issue&gt; reference, include or explicitly describe the required visual proof, document manual and automated testing with platforms, complete the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, and explain any skipped checks.

  • 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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e94d8de4-3193-4539-b793-257b36d7430e

📥 Commits

Reviewing files that changed from the base of the PR and between 12f2c6b and 3f315da.

📒 Files selected for processing (5)
  • src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsx
  • 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

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

Comment on lines +32 to +43
useSyncExternalStore(
(listener) => {
listeners.add(listener)
return () => listeners.delete(listener)
},
() => {
void version
return admittedPageIds.has(pageId)
},
() => false
)
return admittedPageIds.has(pageId)

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

🔎 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/src

Repository: 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/src

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

Comment on lines +40 to +42
if (!options?.browserRuntimeEnvironmentId && !options?.docLocation) {
admitBrowserPageMount(page.id)
}

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 | 🟠 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/src

Repository: 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/browser

Repository: 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/src

Repository: 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.ts

Repository: 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.ts

Repository: stablyai/orca

Length of output: 7994


🏁 Script executed:

#!/bin/bash
set -eu
rg -n -m 50 'getBrowserPageRuntimeEnvironmentId' src/renderer/src

Repository: 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.ts

Repository: stablyai/orca

Length of output: 3685


🏁 Script executed:

#!/bin/bash
set -eu
rg -n -C 6 'useBrowserPageMountAdmission|useAnyBrowserPageMountAdmission|hasAdmittedPage' \
  src/renderer/src/components/browser-pane

Repository: 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.tsx

Repository: 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.tsx

Repository: 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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: PASS WITH RISK

  • Same-model review found and fixed a real lifecycle/performance regression: mount admission is now scoped per page, and bulk tab closure releases admitted page IDs. Changes were pushed in 7c1728c58b.
  • pnpm tc:web passed; changed-file oxlint and React checks passed via commit hooks.
  • Readiness checklist completed at start and end with no proven P0/P1/P2 issues.
  • Reference comparison supports the creation-time admission and disposal lifecycle; the bulk-close release was added to close the identified lifecycle gap.
  • Electron/Grok orchestration validation and screenshots were blocked by consumer_fenced because no coordinator Task Run terminal was available. No UI evidence is claimed.

Residual risk is limited to unmeasured listener fanout at very large tab counts and the missing visible Electron validation.

@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 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 — BrowserPane now gates sibling mount eligibility with hasAdmittedPage && isBrowserPageMountAdmitted(page.id), so a newly admitted background page mounts while its restored/lazy siblings stay lazy.
  • Released mount admission on tab close — closeBrowserTab collects closedPagesForMountRelease and releases each via releaseBrowserPageMount; shutdownWorktreeBrowsers is covered through its closeBrowserTab delegation.
  • Extracted isBrowserPageMountAdmitted and reused it inside both useSyncExternalStore hooks.

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

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron manual validation: newly opened background local-URL tab

Validated on dev build from this branch (mermaid @ brennanb2025/browser-background-tab-admission, CDP attach identity confirmed via window.api.app.getIdentity).

Scenario

  1. Created foreground tab (active) and navigated it to file:///tmp/fg-admission-test.html (title Foreground Tab 19633).
  2. Created background tab with createBrowserTab(worktreeId, 'file:///tmp/bg-admission-test.html', { activate: false }) — never activated (global + per-worktree activeBrowserTabId stayed on the foreground tab throughout).

Result (pass)

  • Background page title updated in store to Background Admitted Title 19633 (the guest document title), not the creation-time New Background Tab placeholder — i.e. the background guest mounted and reported its title while inactive.
  • Foreground page title updated to Foreground Tab 19633; address bar + rendered content match.
  • Full-window screenshot shows the tab bar with Foreground… (active), New Tab, Backgroun… and the foreground file content rendered:

mermaid-bg-tab-validation.png

Notes / gaps

  • data: URLs were unusable for this check (store normalizes them to bare data:text/html,), so file:// URLs were used as the local-URL vehicle.
  • No code modified. Test tabs were left in the dev profile only; nothing persisted to the repo.
  • Not verified: restored-session pages remaining lazy after reload (covered by existing hydration behavior, out of scope for this run).

@brennanb2025
brennanb2025 merged commit 94a64cf into main Sep 8, 2026
34 checks passed
brennanb2025 pushed a commit that referenced this pull request Sep 12, 2026
…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.
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