You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(browser): stop agent tabs in background worktrees reloading every ~10 s - #36245
If an agent was using a browser tab in one workspace while you looked at a different one, the agent's page kept reloading about every 10 seconds. Anything it had typed, and any page state like sessionStorage, was wiped, so agents had to keep starting over. The page now stays put while the agent works.
What Changed
Before: with another workspace on screen, an agent's tab in a hidden workspace loaded 5 times in 45 s. Every load came with a new CDP target, an empty sessionStorage, cleared form fields and stale refs.
After: the same tab loads once and stays the same page. That held for 45 s of one command per second, and again for 2.5 minutes of commands sent 15 s apart with idle gaps longer than the lease.
Mechanism: Orca keeps live browser guests for the 4 hidden workspaces you used most recently and destroys the rest (useTerminalBrowserRetention). "Recent" only meant "you clicked into it", so a workspace an agent drives in the background always sorted last. Its only protection was the 10 s automation lease each command takes. When that lease lapsed, the change itself re-ran the retention pass, which destroyed the webview, and the agent's next command loaded a fresh page.
Each retention pass now treats a workspace whose pages are under a paint-retention claim (agent lease, phone driver, paired viewer) as recently used. Once the claim lapses, that workspace sits at the front of the order instead of the back.
selectBrowserGuestEvictionWorktreeIds no longer counts a vetoed workspace against the 4 slots. Workspaces that agents or phones are actively using don't push your own recent workspaces out while their claim is held. On main, vetoed workspaces already sat over budget the same way.
Why
The wrong fact was the recency order, so the change is in the one place that keeps it. It covers every route that holds a guest for something other than the user: agents, phones and paired viewers, git worktrees and folder workspaces alike. Alternatives I ruled out:
A longer lease or a grace timer after it lapses would only push the reload later and only help agents.
Known limit, by design: the budget still caps idle guests. If more than 4 hidden workspaces with live tabs are idle (no claim) at once, the least recently used one is still evicted. That one could be an agent page whose agent went quiet for more than 10 s.
N/A: nothing paints while this happens, because the tab is in a hidden workspace. The proof is the page's own state, read over orca eval in a hidden dev build. One eval per second for 45 s prints performance.timeOrigin|sessionStorage marker:
Automated tests added/updated, or explained why not below
macOS, in a hidden dev build (ORCA_BACKGROUND_LAUNCH=1) driven over CDP and the dev CLI:
Setup: one scratch repo with 6 worktrees. 4 of them have browser tabs and were activated in turn, so they fill the hidden budget. Then a different worktree is activated, and the agent's tab sits in a sixth worktree.
main: 5 loads in 45 s. With browserGuestWorktreeRetentionBudget turned off, the same probe shows 1 load, which confirmed the budget as the cause.
This branch: 1 load across the 45 s probe and the idle/sparse run. The least recently used user worktree was evicted instead, and live hidden guests stayed at 4.
New use-terminal-browser-retention.test.tsx: an agent leases a page in a hidden worktree outside the budget, and the lease lapses. It fails on main (wt-agent evicted) and passes here.
browser-guest-worktree-retention.test.ts: one case updated to the new rule that a vetoed worktree doesn't take a slot.
Focused suites pass, and the changed-file code-quality and React Doctor gates pass.
AI Disclosure
Review
Two review-loop rounds, each with Codex and a Claude reviewer.
Accepted (P2): with the recency change alone, claimed workspaces took budget slots and evicted the user's recent ones. Fixed by keeping vetoed workspaces out of the slot count.
Accepted (P3): the veto now builds on the shared paint-retention check instead of repeating it.
Not changed (P2, by design): more than 4 idle claimed workspaces can still evict an agent page. Noted above as the budget's limit.
Not changed (P3): several workspaces claimed at once get ordered by surface order among themselves. That only matters with more than 4 of them.
Round 2: Codex returned NO FINDINGS.
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
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Renderer-only, with no platform-specific code, IPC or wire change, so mixed client and host versions are unaffected.
Folder workspaces are covered, because the order is built from workspaceSurfaceIds.
Phone-driven and paired-viewer pages get the same protection.
Performance: each retention pass does one more lookup per workspace. Passes run only when a claim, activation or surface changes.
SSH-routed workspaces have a separate, pre-existing reload path that this PR does not touch: SshRoutedBrowserPageGate destroys guests on every remount while its route is re-prepared. It's tracked as a follow-up.
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)
The changes add a check for paint retention across browser tabs and use it to update worktree recency before the retention hook checks active-worktree and budget conditions. The eviction selector now skips non-evictable worktrees before counting retained guests. Tests cover the updated eviction selection and retention after acquiring and releasing an automation visibility lease.
Priority: Normal
Severity of issue fixed: Medium
Merge Risk: Low · up to b7768
The retention test masks an initial mock eviction, leaving a bounded gap in lifecycle coverage. The fixture can be tightened as a follow-up.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Linked Issues check
Issue #36235 requires the agent page to remain the same page while the agent works, including when commands are not flowing. The change gives claimed workspaces recency priority and excludes them from…
Extend the retention behavior so an actively agent-driven page remains protected while the agent is working, independent of the short automation lease and the four-workspace budget. Add an automated test with more than four hidden live-tab …
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the primary change: preventing agent browser tabs in background worktrees from reloading repeatedly.
Description check
The description includes the required sections, explains the user impact and mechanism, links issue #36235, documents testing and limitations, and addresses compatibility and performance. The unchecke…
Out of Scope Changes check
The changed production code updates browser guest recency, eviction-slot accounting, and the shared paint-retention veto. The tests cover those retention rules. These changes directly support issue #3…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Description check
Explanation
The description includes the required sections, explains the user impact and mechanism, links issue #36235, documents testing and limitations, and addresses compatibility and performance. The unchecked full validation checklist does not prevent a pass because focused validation and CI coverage are described.
Full details: Out of Scope Changes check
Explanation
The changed production code updates browser guest recency, eviction-slot accounting, and the shared paint-retention veto. The tests cover those retention rules. These changes directly support issue #36235. The reported SSH reload path is not changed.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 5 files.
Full details: Linked Issues check
Explanation
Issue #36235 requires the agent page to remain the same page while the agent works, including when commands are not flowing. The change gives claimed workspaces recency priority and excludes them from the four-slot count, but the PR states that an idle claimed workspace can still be evicted when more than four hidden workspaces have live tabs. After the short claim expires, the code no longer marks that workspace as vetoed. The implementation therefore does not establish the required duration of retention in that case. The added test covers one claimed workspace outside the budget, not more than four idle claimed workspaces.
Resolution
Extend the retention behavior so an actively agent-driven page remains protected while the agent is working, independent of the short automation lease and the four-workspace budget. Add an automated test with more than four hidden live-tab workspaces and an idle interval after the lease expires.
Finishing Touches
📝 Generate docstrings
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.
… ~10 s
The hidden-worktree guest budget ranked worktrees only by user activation, so a
worktree an agent drove in the background sorted last. Its automation lease was
its only veto, and when the lease lapsed 10 s after each command the retention
pass destroyed its webview; the next command loaded a fresh page.
Paint-retention claims (agent lease, phone driver, paired viewer) now count as
use when ordering the budget, and a worktree under a veto keeps its guests
without taking one of the four slots from the user's recent worktrees.
Avoid the initial eviction without losing mounted-hook coverage.
renderRetention() enables the budget before acquiring the lease, so the initial effect can destroy AGENT. mockReset() clears that recorded call but does not restore the guest. Acquiring before rendering would avoid the eviction, but it would remove coverage for lease notifications delivered to an already-mounted hook.
Mount with the budget disabled, acquire and release the lease after mounting, then enable the budget with a rerender. The final pass should evict wt-a and should not evict AGENT. This preserves acquisition-notification coverage and exposes a regression that fails to update recency.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
If an agent was using a browser tab in one workspace while you looked at a different one, the agent's page kept reloading about every 10 seconds. Anything it had typed, and any page state like sessionStorage, was wiped, so agents had to keep starting over. The page now stays put while the agent works.
What Changed
Before: with another workspace on screen, an agent's tab in a hidden workspace loaded 5 times in 45 s. Every load came with a new CDP target, an empty sessionStorage, cleared form fields and stale refs.
After: the same tab loads once and stays the same page. That held for 45 s of one command per second, and again for 2.5 minutes of commands sent 15 s apart with idle gaps longer than the lease.
Mechanism: Orca keeps live browser guests for the 4 hidden workspaces you used most recently and destroys the rest (
useTerminalBrowserRetention). "Recent" only meant "you clicked into it", so a workspace an agent drives in the background always sorted last. Its only protection was the 10 s automation lease each command takes. When that lease lapsed, the change itself re-ran the retention pass, which destroyed the webview, and the agent's next command loaded a fresh page.selectBrowserGuestEvictionWorktreeIdsno longer counts a vetoed workspace against the 4 slots. Workspaces that agents or phones are actively using don't push your own recent workspaces out while their claim is held. On main, vetoed workspaces already sat over budget the same way.Why
The wrong fact was the recency order, so the change is in the one place that keeps it. It covers every route that holds a guest for something other than the user: agents, phones and paired viewers, git worktrees and folder workspaces alike. Alternatives I ruled out:
Known limit, by design: the budget still caps idle guests. If more than 4 hidden workspaces with live tabs are idle (no claim) at once, the least recently used one is still evicted. That one could be an agent page whose agent went quiet for more than 10 s.
Linked Issue
Fixes #36235
Visual Proof
N/A: nothing paints while this happens, because the tab is in a hidden workspace. The proof is the page's own state, read over
orca evalin a hidden dev build. One eval per second for 45 s printsperformance.timeOrigin|sessionStorage marker:Before (main):
After (this branch), followed by 15 s-spaced evals after a 30 s idle gap, with a form value typed into the page:
Testing
macOS, in a hidden dev build (
ORCA_BACKGROUND_LAUNCH=1) driven over CDP and the dev CLI:browserGuestWorktreeRetentionBudgetturned off, the same probe shows 1 load, which confirmed the budget as the cause.clicktoggled a checkbox andtypefilled an input.Automated:
use-terminal-browser-retention.test.tsx: an agent leases a page in a hidden worktree outside the budget, and the lease lapses. It fails on main (wt-agentevicted) and passes here.browser-guest-worktree-retention.test.ts: one case updated to the new rule that a vetoed worktree doesn't take a slot.AI Disclosure
Review
Two review-loop rounds, each with Codex and a Claude reviewer.
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
workspaceSurfaceIds.SshRoutedBrowserPageGatedestroys guests on every remount while its route is re-prepared. It's tracked as a follow-up.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)