Repository navigation
fix(browser): end a background page's mount admission after its first load - #27754
Conversation
… 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.
Review summaryThe 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.
Verified. Unit and component tests; 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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established. The change is ready to merge after normal checks. Pre-merge checks |
|
|
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 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: Failed page after clicking Retry: |


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'sdid-stop-loadinghandler, which fires after both successful and failed loads) now callsreleaseBrowserPageMountfor 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), base9d305f3ce4fvs this PR959e7cb54cc, 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.M4Air (macOS), 5 runs each, median (min–max):
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.pnpm run typecheckandorca-ci-checkspass (thetypecheck:cistep fails locally only because this machine's bun lacks acheckscript; plaintypecheckcovers 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.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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)