Skip to content

fix(browser): end a background page's mount admission after its first load - #27754

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-admission-first-load
Oct 12, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-admission-first-load

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Orca opens a browser page in the background (a link opened without switching to it, or an agent opening a tab), it gives that page a one-time pass so it starts loading even though you aren't looking at it. That pass was never taken back until the page was closed. So every background-opened tab kept its browser toolbar mounted and laid out, invisibly, for the rest of the session, even after you switched to another workspace. This PR takes the pass back as soon as the page finishes its first load.

What Changed

Before: a tab opened in the background stayed "admitted" until it was closed. In the workspace you're looking at, its overlay stayed laid out at zero opacity; in any other workspace, its toolbar (address bar, buttons) and all its listeners stayed mounted forever instead of unmounting like every other hidden tab.

After: the admission ends when the page's first load finishes (or fails). From then on the page follows the normal rules: it's laid out only while it's the active tab, or while something needs its frames (automation, a phone driving it, a remote viewer), and its toolbar unmounts when you switch workspaces. Nothing changes on screen: background tabs still load in the background, get their title and favicon from that first load, and show the loaded page when you switch to them.

One known limit (pre-existing, now reached by more tabs): a tab that isn't mounted doesn't listen to its page. If a background tab in a workspace you've switched away from navigates on its own after its first load (for example a client-side redirect to a login page), the address bar shows the old URL until the page navigates again; title and back/forward refresh when you open the tab. Every parked tab already behaves this way; this PR makes background-opened tabs in hidden workspaces parked tabs too. The proper fix (reconcile the URL when a parked tab reattaches) applies to all parked tabs and is a separate change.

Mechanism: handleDidStopLoading (the webview's did-stop-loading handler, which fires after both successful and failed loads) now calls releaseBrowserPageMount for its page. Release is idempotent, so later loads are no-ops.

A correction to the ticket's premise: the page content itself (the Chromium guest) was not kept painting. Its viewport has its own paint rule that never counted the admission, so a background page's guest was already parked (display:none). The measurement below confirms it: background guests produce 0 animation frames per second on both builds. What the stuck admission really kept alive was the browser chrome around the page.

Why

The admission exists only to start a guest that was opened in the background (#19633). "Until its first load settles" is the narrowest lifetime that still does that job, and it reuses the existing load-finished signal instead of adding a timer or a second bookkeeping path. Guests aren't destroyed when their chrome unmounts (they're parked), so ending the admission can't drop a loaded page.

Alternatives considered: releasing on first activation (wrong: a background tab may never be activated, which is exactly the leak), or on a timeout (arbitrary, and races slow loads).

Linked Issue

STA-7435 (Linear). Related: STA-7436 is #27755 (ends the admission when a page is removed, including a workspace purge). The two are independent and each lands safely alone; land them back to back so every admission has a way to end. STA-6843 (headless server mode's hidden browser windows) is a separate follow-up.

Visual Proof

Real-app measurement, hidden production builds (VITE_EXPOSE_STORE=true electron-vite build --mode e2e), base 9d305f3ce4f vs this PR 959e7cb54cc, before/after runs interleaved, one fresh disposable profile per run. Scenario: add two local repos, open 1 active browser tab plus 8 tabs opened in the background (each page runs a CSS animation and counts animation frames), wait until every page has loaded, measure; then switch to the other workspace and measure again. Driven by script over the Chrome DevTools Protocol; no UI input.

pr27754-chart.png

M4Air (macOS), 5 runs each, median (min–max):

main this PR
Browser toolbars still mounted after switching to another workspace 9 (9–9) 0 (0–0)
DOM nodes in the window, other workspace shown 2359 (2356–2431) 1734 (1732–1859)
Event listeners, other workspace shown 2500 (2500–2772) 2197 (2190–2237)
Tab overlays laid out (invisible) in the workspace you're looking at 9 (9–9) 1 (1–1)
Animation frames/s produced by the 8 background pages (sum) 0 0
Pages finished loading (of 9) 9 9
Forced full-window relayout, median ms 0.4 (0.2–1.0) 0.8 (0.1–1.0)
200 store updates in a hidden workspace, ms 444 (109–643) 438 (101–558)

The laptop repeated the counts exactly (3 runs each: toolbars 9→0, DOM nodes 2394→1755, listeners 2508→2175, overlays 9→1, background frames 0/0).

What this shows: the leak is mounted browser chrome (about 70 DOM nodes and 35 listeners per background-opened tab, for the whole session), not GPU or painting work: background pages produced zero frames on both builds, because their page area was already hidden by its own paint rule. Timing differences are within noise: on 3 of the 5 M4Air run pairs another workload slowed both builds 4–6×. In the 2 quiet pairs, 200 store updates took 109→101 and 110→104 ms, too few pairs to claim a CPU win. So this PR claims fewer mounted components and listeners, not a measured CPU or GPU gain.

Raw data and the recipe (launcher, measure script, pages, summarizer) are kept outside the repo.

Testing

  • browser-page-mount-admission.test.ts (new): the admission ends after a successful first load and after a failed one.
  • Existing browser host-guest tests pass; pnpm run typecheck and orca-ci-checks pass (the typecheck:ci step fails locally only because this machine's bun lacks a check script; plain typecheck covers the same projects).
  • BrowserPaneOverlayLayer.test.tsx (2 new cases): in a hidden workspace an admitted page's toolbar unmounts once the admission ends; in the visible workspace it stays mounted and only its overlay stops being laid out.
  • Real app on macOS (M4Air and laptop), hidden production rigs driven by script: every background tab still loaded (9/9 in all 16 runs), and the counts above. Not tested on Windows or Linux; the change is renderer-only and has no platform branches.

Cross-platform / SSH / folder workspaces: renderer-only change to local <webview> pages; runtime-backed (SSH/remote server) pages and workspace-document pages are never admitted, so they're unaffected. Folder workspaces behave the same as git worktrees here.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: none. Cross-platform: renderer-only. Remote SSH: runtime-backed pages never take an admission. Mobile: a phone-driven page keeps painting through the existing mobile-driver retention term, not the admission. Performance: see measurement.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… load

A page opened in the background is admitted so its guest starts, but the
admission was only released on close. Its overlay stayed laid out (invisible)
in the visible workspace and its browser chrome never unmounted in hidden
workspaces. Release the admission when the guest's first load settles, so the
normal active-page and paint-retention rules own the page afterwards.

STA-7435
…page

Covers the overlay contract the release relies on: in a hidden worktree the
page's browser chrome unmounts once the admission ends; in the visible worktree
it stays mounted and only its slot stops being laid out. Also corrects the
page-record comment that still said background tabs sit idle until shown.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary

The problem. When Orca opens a browser page in the background (a link opened without switching to it, or an agent opening a tab), the page gets a one-time "start this even though nobody is looking" pass. That pass was only taken back when the page closed. So every background-opened tab kept its browser toolbar mounted for the rest of the session, including after you switched workspaces, and stayed laid out invisibly in the workspace you were looking at. The ticket (STA-7435) also said those pages kept painting. Measurement shows they don't: their page area was already hidden by its own rule, and background pages produced 0 animation frames per second on both builds.

What changes for you. Nothing on screen. Background tabs still load (9/9 pages in all 16 measured runs) and show the loaded page when you open them. Behind the scenes, each background-opened tab stops costing about 70 DOM nodes and 35 listeners once you switch away (M4Air, 8 background tabs: toolbars 9→0, DOM nodes 2359→1734, listeners 2500→2197). No measurable CPU or timing change; the PR doesn't claim one.

Review loop. Round 1: a correctness reviewer and an architecture challenger. The challenger independently arrived at the same design and recommends keeping it; it would also accept folding this with #27755. Round 2 narrow check of the fixes: clean. Readiness checklist: pass, no P0/P1.

  • Fixed: component tests now pin how a released admission parks a background tab (hidden workspace unmounts the toolbar; visible workspace keeps it mounted and stops laying out its overlay). Also fixed a stale comment that said background tabs sit idle until opened.
  • Deferred, stated in the body: a background tab in a hidden workspace doesn't record navigations its page makes on its own after the first load (for example a client-side redirect); the address bar shows the old URL until the next navigation. Every parked tab already behaves this way. The fix (reconcile the URL when a parked tab reattaches) covers all parked tabs and belongs in its own PR.
  • Deferred nit: once fix(browser): end a page's mount admission whenever it leaves the store #27755 also lands, the admission module comment ("or the page closes") should name every way an admission ends. Whichever PR lands second rewords it.

Verified. Unit and component tests; typecheck and the repo checks (typecheck:ci fails locally only because this machine's bun has no check script; CI's typecheck passes). CI green on 51e330a5ca3. The first CI run's package (windows) failure was a 30 s timeout in idle-cpu-process-sampling.test.mjs (Windows process-table test, not touched here); the same job passed on three other recent runs and passed on re-run. Real app on macOS (M4Air, 5 interleaved runs per build; laptop, 3 runs) via hidden production rigs driven by script.

Not verified. Windows and Linux in the real app (renderer-only change, no platform branches); pages behind SSH-routed browser sessions; more than 8 background tabs. Remote-runtime and document pages never take the admission, so this change doesn't reach them.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 12, 2026 05:19
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Review in 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: 1ceb1c9c-7500-4f08-9b26-2fc505498ed1

📥 Commits

Reviewing files that changed from the base of the PR and between 78144e9 and 51e330a.


📒 Files selected for processing (5)
  • src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.test.tsx
  • src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-mount-admission.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview-loading-handlers.ts
  • src/renderer/src/store/slices/browser-page-records.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.



📝 Walkthrough

Walkthrough

The webview loading handler now releases page mount admission on every load stop. Tests verify that admission remains active during loading and ends after a load stops, including for a Chrome error URL. Overlay tests check pane and slot behavior after admission is released in hidden and visible worktrees.


Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 51e33

No actionable merge-blocking issue is established. The change is ready to merge after normal checks.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description thoroughly explains the user impact, mechanism, rationale, testing, measurements, limitations, and checklist status. However, the required linked issue is identified as “STA-7435 (Line… Add a direct link to the tracked issue and complete the required “Fixes #” field, or document the repository-approved format for linking the Linear issue.
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 3 functions across 5 files. 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: ending background page mount admission after the first load.
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 thoroughly explains the user impact, mechanism, rationale, testing, measurements, limitations, and checklist status. However, the required linked issue is identified as “STA-7435 (Linear)” without an actual link, and the “Fixes #” field is empty.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Browser pages opened in the background kept invisible toolbars mounted and laid out because their one-time permission to start loading lasted until close. This PR ends that permission when the first load succeeds or fails. Hidden workspaces can then unmount their toolbars while keeping the page available when you return; automation, mobile control and remote viewers retain their existing rules.

The fresh correctness review, architecture challenge, dedicated performance scan and final readiness checklist found no new blocking issue. No additional source changes were needed. The PR includes success/failure and visible/hidden toolbar regression tests. Deferred: parked pages can retain an old address after navigating on their own, and the companion removal cleanup in #27755 remains separate; the second PR to land should update the combined-lifetime comment.

Verified at 51e330a5ca39: 23 targeted tests, full native typecheck, and the exact-commit CI run, including static analysis and both packaging jobs. Local static checks passed 25/26; the remaining command fails before checking source because installed Bun lacks bun check.

Remote hidden Electron QA on the M4Air verified background pages loading, hidden toolbars unmounting, live content on return, and a genuine connection failure followed by a real Retry click rendering the expected page. I inspected both screenshots below. Windows/Linux runtime, live SSH/mobile flows, and large or hung-load scenarios were not exercised. The original performance measurements remain applicable because runtime code did not change during this loop; they establish fewer mounted toolbars and listeners, without a CPU/GPU speedup claim.

The PR is ready for review and remains unmerged.

Background page after returning to its workspace:

Background page after returning to its workspace

Failed page after clicking Retry:

Failed page after clicking Retry

@brennanb2025
brennanb2025 merged commit b40554b into main Oct 12, 2026
75 of 77 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/browser-admission-first-load branch October 12, 2026 23:55
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