Skip to content

Defer inactive browser pages across worktree switches - #19326

Merged
AmethystLiang merged 6 commits into
mainfrom
no-restore-of-all-browser-tabs
Sep 7, 2026
Merged

AmethystLiang merged 6 commits into
mainfrom
no-restore-of-all-browser-tabs

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​743 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​730
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119 $\color{#cf222e}{\Huge{\mathbf{−}}}$​102 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

Browser tabs in inactive worktrees no longer wake up all at once. Orca creates a page only when it is needed, then releases inactive browser UI while retaining the state required to restore it when the user returns.

What Changed

  • Defer browser-pane and page mounting until the tab is active or is required by automation, a mobile driver, or a remote viewer.
  • Release inactive worktree browser content while keeping stable overlay viewport slots so already-live URL guests are not reparented during tab moves.
  • Recreate a guest when the hidden-worktree retention budget evicts it and the page becomes active again.
  • Create background browser pages cold (loading: false) until a guest exists.
  • Keep document-preview guests across browser-profile switches because they use the fixed document-preview partition.
  • Register document-preview guests before they become hittable, preserving drag passthrough when a preview remounts mid-drag.

Why

Opening or switching to a worktree with many browser tabs should not restore every hidden browser guest. This reduces unnecessary guest initialization and memory use while preserving active streaming and the state of pages that remain retained.

Linked Issue

N/A — standalone browser lifecycle improvement.

Visual Proof

Hidden Electron validation confirmed that the active tab rendered one webview while a second, inactive cold tab rendered none. The inactive tab remained visible in the tab strip without initializing a browser guest.

Testing

  • ORCA_BACKGROUND_LAUNCH=1 pnpm tc:web
  • ORCA_BACKGROUND_LAUNCH=1 pnpm test src/renderer/src/components/assemble-chrome/browser-deferred-lifecycle.test.tsx src/renderer/src/components/assemble-chrome/BrowserPaneOverlayLayer.test.tsx src/renderer/src/components/assemble-chrome/browser-workspace-pane.retention-props.test.tsx src/renderer/src/components/browser-pane src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.profile-switch.test.ts src/renderer/src/store/slices/browser.test.ts — 107 files / 861 tests passed
  • ORCA_BACKGROUND_LAUNCH=1 pnpm run check:code-quality:changed
  • Hidden Electron/CDP check: verified the target worktree, one active guest, zero inactive cold-tab guests, and no renderer console errors.

The rendered activation/remount, worktree-return, and document-preview transitions were covered by automated tests; the bounded CDP run exercised the cold-tab behavior.

Review

  • No persisted schema, protocol, RPC, mobile-facing, SSH-routing, or platform-specific contract changes.
  • Readiness review found no proven P0, P1, or important P2 issues.
  • New lifecycle code and tests are colocated under the browser-pane assembly and host-guest areas.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Visual behavior was checked in a hidden Electron renderer
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and backward-compatibility impact considered
  • Focused typecheck, tests, and changed-code quality checks pass

Restore worktrees and tabs on demand instead of mounting the full tree.
Only render active pages and those required by automation, mobile drivers,
or remote viewers. Inactive panes stay deferred with persistent viewport
slots so their webview guests survive chrome unmounts, reducing memory
overhead when opening workspaces with many tabs.
Pages defer rendering until active, then retain state when inactive.
Add recovery logic to restore guests evicted by workspace memory
pressure when pages are reactivated.
- Browser panes and pages now unmount when their worktree transitions to inactive, except for pages claimed by automation/mobile/viewer consumers
- Prevents unwanted restoration of all hidden browser tabs when switching between worktrees
- Tests verify proper cleanup at scale and correct page lifecycle across worktree switches
Document previews use a fixed partition and should not be recreated when
the profile changes. Only URL-based pages need their webviews destroyed
and rebuilt with the new profile. Includes test coverage.
Pages created in the background now start with loading: false, since they
don't own a guest until first shown. Only live guests can report loading
status, so background tabs sit idle until activation triggers navigation.
Move webview registration to attachDocPreviewWebview before append,
ensuring it's enrolled in drag passthrough before becoming hittable.
When a document preview tab remounts mid-drag, the previous hook-based
enrollment landed too late. Also refactor mountEligible into
isBrowserPagePanePaintable for clarity.
@AmethystLiang AmethystLiang changed the title No restore of all browser tabs Defer inactive browser pages across worktree switches Sep 7, 2026

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

Reviewed changes

This PR stops Orca from restoring every browser tab on worktree activation or relaunch by deferring <webview> guest creation until a tab/page is first shown, then retaining it while its worktree stays active.

  • Deferred inactive-tab mounting — BrowserOverlaySlot now wraps BrowserPane in a new DeferredBrowserContent gate keyed on isPaintable with retainMounted={isWorktreeActive}, so only the active tab (or a paint-retained one) mounts a guest while its viewport slot stays pinned.
  • Cold page creation — buildBrowserPage now sets loading: false unconditionally, so background tabs no longer show a phantom spinner and navigate on first activation instead of eagerly.
  • Shared deferral gate — DeferredBrowserContent centralizes the "latch once mounted, retain while active" logic that was previously duplicated in RetainedBrowserPaneOverlayLayer.
  • Eviction-aware guest recovery — validateRegistration treats a disconnected webview as evicted and rebuilds instead of retrying into a failure card.
  • Document previews join the registry — doc-preview webviews now register via registerPersistentWebview (drag passthrough + eviction accounting), restore on reactivation, and survive profile switches since they use a fixed partition.

I traced the retention/deferral seam end to end (overlay slot → BrowserPane → per-page gate), the SSH routing gate's page-id change, the eviction-recovery path, and the doc-preview registry/remint flow. The deferral semantics (retain once mounted, drop on worktree deactivate) are coherent, the two non-overlay BrowserPane callers keep their old behavior via the isWorktreeActive default, and the new tests pin real behavior rather than tautologies.

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

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: a41eb574-7d79-4b44-abe1-d4730134c6f9

📥 Commits

Reviewing files that changed from the base of the PR and between 9fed61e and 15c3953.

📒 Files selected for processing (19)
  • src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/DeferredBrowserContent.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.retention-props.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-workspace-pane.tsx
  • src/renderer/src/components/browser-pane/host-guest/browser-page-evicted-guest-recovery.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview-guest-session.ts
  • src/renderer/src/components/browser-pane/host-guest/use-guest-drag-passthrough.ts
  • src/renderer/src/components/browser-pane/workspace-doc/HtmlDocPreview.failure-message.test.tsx
  • src/renderer/src/components/browser-pane/workspace-doc/HtmlDocPreview.toolbar.test.tsx
  • src/renderer/src/components/browser-pane/workspace-doc/HtmlDocPreview.tsx
  • src/renderer/src/components/browser-pane/workspace-doc/doc-preview-webview-attach.test.ts
  • src/renderer/src/components/browser-pane/workspace-doc/doc-preview-webview-attach.ts
  • src/renderer/src/components/browser-pane/workspace-doc/workspace-doc-page-pane.tsx
  • src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.profile-switch.test.ts
  • src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.ts
  • src/renderer/src/store/slices/browser-page-records.ts
  • src/renderer/src/store/slices/browser.test.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/browser-pane/host-guest/use-guest-drag-passthrough.ts

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


📝 Walkthrough

Walkthrough

Browser panes now use deferred mounting and retention based on paintability and worktree activity. Overlay slots remain retained while inactive panes are parked. Guest recovery handles disconnected webviews and restores selected evicted pages. Document previews register persistent guests, remint guests after eviction, and remain during profile changes. New tests cover lifecycle transitions, large workspaces, guest recovery, profile switching, and loading state initialization.

Merge Risk: ⚪ Minimal · up to 15c39

No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 18 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.
Title check ✅ Passed The title clearly and concisely describes the primary change: deferring inactive browser pages during worktree switches.
Description check ✅ Passed The description is detailed and covers the change, rationale, testing, review, and checklist. However, it does not provide the required linked issue, and the visual proof section does not include befo…
  • 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.

@AmethystLiang
AmethystLiang merged commit 1d1b73c into main Sep 7, 2026
35 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