Skip to content

fix(browser): end a page's mount admission whenever it leaves the store - #27755

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/browser-admission-removal
Oct 12, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/browser-admission-removal

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 in useTerminalWindowLifecycle calls 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 calls releaseBrowserPageMount(pageId) before destroying the guest. The store sweep moved into destroyWebviewsRemovedFromStore so the app and the regression test run the same code; its behaviour is unchanged. Guest-budget eviction also goes through destroyRemovedBrowserWebview, 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 9d305f3ce4f vs this PR a77bae7408c (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.

pr27755-chart.png

After purging the workspace main this PR
Purged page ids still held by the admission set 20, 20, 20 0, 0, 0
Purged pages left in the store 0 0
Purged ids still held by some Map (both builds) 20 20

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.

Case Rendered assertion Before After
First load the page mounts and renders (#marker visible, 1289x939) empty board page loaded
Close one page the sibling keeps rendering after the other closes two pages open sibling preserved
Whole-workspace removal the tab disappears from the browser UI and the sidebar before removal after removal
Guest-budget eviction + revisit guest destroyed while the tab record stays; revisit rebuilds a new webContents that renders after cycling 6 worktrees rebuilt page on revisit

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 on main); 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.ts 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).

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

  • 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: unaffected (no admission). Mobile: unaffected. Performance: removes a per-page leak; 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)

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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary

The 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 main, only closing a tab or a page took it off. Removing a whole workspace any other way didn't: a listing refresh that finds the worktree gone, project or folder removal, host cleanup. That left the page's id on the list for the rest of the session (STA-7436). Converting a page to a new id leaked the old one the same way. Nobody can see this; it is a small leak that never ends.

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, main still holds all 20 purged ids in the admission set; this PR holds 0 (3 runs each, renderer heap snapshot).

Review loop. Round 1: a correctness reviewer and an architecture challenger. The challenger independently arrived at the same design. The release sits in destroyRemovedBrowserWebview, not destroyPersistentWebview, because the latter is also used to replace a guest, and releasing there would stop a background page from starting. Round 2 narrow check: clean apart from one test nit, fixed. Readiness checklist: pass, no P0/P1.

  • Fixed: the regression test now runs the app's own sweep (extracted into destroyWebviewsRemovedFromStore, unchanged behaviour) and covers eviction. Comment reworded to name eviction.
  • Deferred, stated in the body (intended): a page closed while the workspace view isn't mounted (before it first loads, or while its error card shows) leaves a stale id, the same way it already leaves its webview undestroyed on main. No visible effect, because only pages still in the store are looked up and ids are never reused.

Verified. New and existing cleanup/close tests; typecheck and the repo checks (typecheck:ci fails locally only on this machine's bun). The heap measurement above (laptop, hidden production rigs, count-only per the host rule). CI: see checks; the package (windows) failures were timeouts in Windows process-probe tests this PR doesn't touch (idle-cpu-process-sampling, nsis-process-check), the same flake #27754 passed on re-run.

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.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 12, 2026 05:24
@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: d295c371-7121-4c7a-8cc8-6c6cc574d16e

📥 Commits

Reviewing files that changed from the base of the PR and between 78144e9 and 6cc7793.


📒 Files selected for processing (6)
  • src/renderer/src/components/use-terminal-window-lifecycle.lazy-ref.test.tsx
  • src/renderer/src/components/use-terminal-window-lifecycle.ts
  • src/renderer/src/store/slices/browser-mount-admission-removal.test.ts
  • src/renderer/src/store/slices/browser-webview-cleanup.ts
  • src/renderer/src/store/slices/browser/browser-close-actions.ts
  • src/renderer/src/store/slices/browser/browser-page-create-actions.ts

💤 Files with no reviewable changes (1)
  • src/renderer/src/store/slices/browser/browser-close-actions.ts

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



📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Removed-webview cleanup now releases browser-page mount admission before destroying the persistent webview. The lifecycle hook delegates removed-webview cleanup and stores the current webview IDs returned by the helper. Browser tab and page close actions no longer release mount admission directly. Regression tests cover bulk purge, guest eviction, and tab or page closure.


Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 6cc77

The change appears mergeable after normal checks; no concrete new risk requiring a fix was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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.
Description check Passed The description is complete and directly explains the problem, implementation, scope, testing, visual evidence, known gap, and compatibility considerations. It identifies the related Linear issue, alt…
Title check Passed The title is concise, specific, and accurately summarizes the primary change: ending a browser page's mount admission when the page leaves the store.

  • 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

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 6cc77931843. The earlier fixes put the real cleanup sweep in one function used by the app and its tests, and added eviction coverage. This review needed no further code changes.

  • Verified: four focused test files / 23 tests; fresh web typecheck; all 24 non-typecheck static checks. The full local checker still fails because installed Bun 1.3.14 lacks its required check command.
  • Measurement: all six saved records support the PR's 20-to-0 cleanup count, with zero tracked pages remaining. Other memory containers still hold those IDs in both builds; this does not show that every copy disappears from memory or that CPU use improved.
  • Remote Mac QA: first load, close with a sibling preserved, whole-workspace removal, and eviction followed by a working revisit passed in a hidden Electron build of this head. Eight screenshots are attached in Visual Proof and were inspected. Actions used the real store entry points; DOM and guest-content assertions checked the rendered result. Conversion, the unmounted-view case, and live Windows/Linux/SSH flows were not exercised.
  • Deferred P3: closing while the workspace view has not loaded or shows its error screen can retain an unused page ID until the app's renderer restarts. Guest cleanup already misses those same periods; this PR also allows the background-start ID to remain. That low-impact exception is explicitly accepted, with no demonstrated visible failure.

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.

@brennanb2025
brennanb2025 merged commit 56a12f5 into main Oct 12, 2026
75 of 77 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/browser-admission-removal 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