Repository navigation
fix(browser): end a page's mount admission whenever it leaves the store - #27755
Conversation
A background-opened page's start admission was released only by the two close actions, so a bulk worktree purge (listing refresh, repo or folder removal) dropped the page while its admission stayed in the set. Release it in the one cleanup every page removal already runs through (destroyRemovedBrowserWebview), and drop the per-path copies. STA-7436
Moves the store sweep that destroys removed pages into destroyWebviewsRemovedFromStore so the admission regression test runs the same code the app runs, and adds an eviction case.
Review summaryThe problem. A page opened in the background is put on a small list so its page starts even though nobody is looking (the mount admission). On What changes for you. Nothing visible. The admission now ends in the one cleanup every removed page already goes through, so no removal path can leak it, and the two per-close copies are gone. Measured on the real app: after purging a workspace with 20 background tabs, Review loop. Round 1: a correctness reviewer and an architecture challenger. The challenger independently arrived at the same design. The release sits in
Verified. New and existing cleanup/close tests; Not verified. Real-app runs on Windows or Linux (renderer-only change); the live listing-refresh purge path. The measurement calls the same store purge action that path uses. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change appears mergeable after normal checks; no concrete new risk requiring a fix was identified. Pre-merge checks |
|
|
Removing a whole workspace deleted its browser pages but left their permission to start in the background in memory. Individual close actions released that permission; bulk removal did not. This PR releases it through the existing page cleanup, covering workspace purge, page conversion and guest eviction. Evicted tabs keep their saved state and reload when selected. Correctness, architecture, performance and readiness review found no new blocking issue at
GitHub reports the unchanged branch mergeable with a clean status. Main has no relevant overlapping cleanup changes, so no sync was needed. The review loop is complete and the PR is ready; it remains open and unmerged. |
ELI5
When Orca opens a browser page in the background, it puts the page's id on a small list ("start this page even though nobody is looking"). Closing the tab took the id off the list, but deleting a whole workspace some other way (for example when a refresh finds the worktree gone, or the project is removed) dropped the page without taking its id off. Those ids then stayed in memory for the rest of the session. This PR takes the id off whenever the page leaves Orca's state, no matter which path removed it.
What Changed
Before: only the two close actions (
closeBrowserTab,closeBrowserPage) released a page's mount admission. A bulk worktree purge (purgeWorktreeTerminalState, used when a listing refresh drops a worktree, on repo/folder removal, and on host purges) removed the page records but left their admissions behind.After: the admission is released in
destroyRemovedBrowserWebview, the one cleanup every removed page already goes through: the store sweep inuseTerminalWindowLifecyclecalls it for every page id that disappears from the store, whatever removed it. The two per-close-action release calls are deleted, so there's one owner instead of one copy per removal path. Nothing changes on screen.Mechanism:
destroyRemovedBrowserWebview(pageId)now callsreleaseBrowserPageMount(pageId)before destroying the guest. The store sweep moved intodestroyWebviewsRemovedFromStoreso the app and the regression test run the same code; its behaviour is unchanged. Guest-budget eviction also goes throughdestroyRemovedBrowserWebview, which is the right outcome: an evicted page's guest is gone, so it shouldn't stay admitted to restart in a hidden workspace. Converting a page (which gives it a new id) also leaked the old id's admission on main; the sweep now ends it.Known gap (intended): the sweep runs inside the workspace view. A page closed while that view isn't mounted (before it first loads, or while its error card is showing) leaves its id in the set, as it already leaves its webview undestroyed on main. A stale id there has no visible effect: only pages still in the store are ever looked up, and page ids are never reused.
Why
The bug is a missing release on one removal path, and the next removal path someone adds would miss it the same way. Releasing where the guest itself is destroyed ties the admission's lifetime to the page's and removes that class of leak. Adding a third release call in the purge reducer would fix today's path but keep the per-path bookkeeping.
Independent of #27754 (which ends the admission after the first load). Either can merge first and each is safe alone; land them back to back so an admission lives only from "opened in the background" until "first load finished, or page removed or evicted".
Linked Issue
STA-7436 (Linear). Related: STA-7435 (#27754).
Visual Proof
Real-app measurement on this laptop (memory/count only, per the perf lanes' host rule): hidden production builds, base
9d305f3ce4fvs this PRa77bae7408c(later commits only move the sweep into a shared function and add tests; no behaviour change), 3 interleaved runs each. Scenario: add a local repo, open 1 active and 20 background browser tabs, wait for the pages to load, then bulk-purge the worktree through the store's purge action (the path a listing refresh or repo removal takes). Force garbage collection, take a renderer heap snapshot, and find which containers still hold the 20 purged page ids.Map(both builds)The last row is unrelated to this PR and identical on both builds; most likely it's the remembered toolbar-height cache, which is capped at 512 entries by design (not verified). The leak this PR fixes is small per page (one id string), but it never ended.
Raw data and the recipe are kept outside the repo.
Functional QA: rendered browser behavior at this head (hidden Electron)
Remote hidden Electron QA of head
6cc7793184381788a6880e939752cbe2f7085d49(Apple M4 Air, isolated throwaway profile, CDP-driven, real rendered pages from a loopback fixture). Pages load on first open; closing one page keeps its sibling; removing a workspace drops its browser tab from the UI; guest-budget eviction keeps the saved tab and a revisit reloads a working page.#markervisible, 1289x939)Full report + raw evidence JSON:
remote-qa.md(kept outside the repo, on the QA host).Testing
browser-mount-admission-removal.test.ts(new, real store, runs the app's own sweep function): bulk purge → 0 admissions left (fails onmain); closing a tab or a page still ends its admission and an untouched tab keeps it; evicting a hidden workspace's guests ends their admissions while the pages stay.browser-webview-cleanup.test.ts,browser-cleanup-close.test.tspass;pnpm run typecheckandorca-ci-checkspass (thetypecheck:cistep fails locally only because this machine's bun lacks acheckscript).Cross-platform / SSH / folder workspaces: renderer-only. Runtime-backed (SSH/remote) and workspace-document pages are never admitted. Folder workspaces purge through the same path.
Review
Agent skill upstream boundary
Notes
Security: none. Cross-platform: renderer-only. Remote SSH: unaffected (no admission). Mobile: unaffected. Performance: removes a per-page leak; see measurement.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)