Repository navigation
fix(browser): switch client-hosted profiles by staging the replacement guest - #30452
Conversation
…ment Squashed from #30351 by @oliver-mee onto the current main. Fixes #30350
…ry host profile metadata - A fence during automation retirement now revokes and stops the staged guest. - A failed or late-settling switch releases its execution-host grant so the page can be recreated. - Staging cleanup failures before handover stay visible to executor close. - createPage/restorePage carry host-owned profile metadata to profile-switch-v1 desktops, so recovery and restore can rebuild a switched page.
…get path when switching profiles
…en a switch commits
… while its switch is pending
…rs after a switch
…ule, no re-export
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to
|
4e746f6 to
7bbb24d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6f8ae0eb-6123-4fe9-9280-d7ea3098a686
📒 Files selected for processing: 20
src/main/browser/browser-client-network-route-registry.tssrc/main/browser/browser-client-route-cookie-import-partition-parity.test.tssrc/main/browser/browser-execution-host-storage-identity.tssrc/main/browser/browser-network-execution-route.tssrc/main/browser/browser-route-partition-stability.test.tssrc/main/browser/paired-runtime-browser-network-route.test.tssrc/main/browser/paired-runtime-browser-network-route.tssrc/main/browser/paired-runtime-browser-network-transport.tssrc/main/runtime/browser-host/browser-host-client-profile-switch.test.tssrc/main/runtime/browser-host/browser-host-client-profile-switch.tssrc/main/runtime/browser-host/browser-host-lease-registry.tssrc/main/runtime/browser-host/browser-host-profile-switch-recovery.test.tssrc/main/runtime/browser/browser-command-contracts.tssrc/main/runtime/browser/browser-profiles-client-placement.test.tssrc/main/runtime/browser/browser-profiles.tssrc/main/runtime/runtime-browser-client-page-creation.tssrc/main/runtime/runtime-browser-network-execution-host.tssrc/main/runtime/terminal/driver/terminal-driver-resources.tssrc/main/runtime/terminal/launch/terminal-workspace-scope.tssrc/shared/browser-client-host-protocol.ts
💤 Files with no reviewable changes: 1
- src/shared/browser-client-host-protocol.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| const retirePlacement = () => { | ||
| if (input.placements.getPlacement(authority.browserPageId) === expected) { | ||
| input.placements.completePageRetirement( | ||
| input.placements.beginPageRetirement(authority.browserPageId, expected) | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
rg -nP -C12 'export function completeBrowserHostPageRetirement' src/main/runtime/browser-hostRepository: stablyai/orca
Length of output: 2658
🏁 Script executed:
set -eu
printf '%s\n' '--- switch implementation ---'
nl -ba src/main/runtime/browser-host/browser-host-client-profile-switch.ts | sed -n '1,180p'
printf '%s\n' '--- retirement completion wrapper ---'
nl -ba src/main/runtime/browser-host/browser-host-page-retirement-completion.ts | sed -n '1,120p'
printf '%s\n' '--- lease registry retirement bindings ---'
rg -n -F --glob '*.ts' -e 'completePageRetirement(' -e 'beginPageRetirement(' -e 'onClientPageReleased' src/main/runtime/browser-host
printf '%s\n' '--- lease registry declaration and relevant implementation ---'
rg -n -F --glob '*.ts' 'class BrowserHostLeaseRegistry' src/main/runtime/browser-hostRepository: stablyai/orca
Length of output: 23006
🏁 Script executed:
set -eu
printf '%s\n' '--- lease registry retirement and switch wiring ---'
nl -ba src/main/runtime/browser-host/browser-host-lease-registry.ts | sed -n '200,350p'
nl -ba src/main/runtime/browser-host/browser-host-lease-registry-instance.ts | sed -n '1,100p'
rg -n -F --glob '*.ts' -e 'switchBrowserHostClientProfile(' -e 'onLateCommit' -e 'onCommitted' src/main/runtime/browser-host src/main/runtime
printf '%s\n' '--- grant and transfer cleanup definitions ---'
rg -n -F --glob '*.ts' -e 'interface BrowserClientPageExecutionHostGrant' -e 'type BrowserClientPageExecutionHostGrant' -e 'class BrowserClientPageExecutionHostGrant' -e 'release()' src/main/runtime/browser-host
nl -ba src/main/runtime/browser-host/browser-host-client-page-creation.ts | sed -n '1,240p'
nl -ba src/main/runtime/browser-host/browser-host-lease-download-transfer-cleanup.test.ts | sed -n '1,130p'Repository: stablyai/orca
Length of output: 27230
Route switched-page retirement through BrowserHostLeaseRegistry.
retirePlacement bypasses command-ledger retirement and onClientPageReleased, which releases staged download transfers. Its local releaseGrant only handles the grant, so pass a retirement callback from BrowserHostLeaseRegistry and remove the duplicate grant cleanup.
🐛 Suggested fix
diff --git a/src/main/runtime/browser-host/browser-host-client-profile-switch.ts b/src/main/runtime/browser-host/browser-host-client-profile-switch.ts
@@
registry: Pick<BrowserHostLeaseRegistry, 'requireClientPage' | 'select'>
+ retirePage: (
+ browserPageId: string,
+ expected: RuntimeBrowserClientPlacement
+ ) => void
@@
const retirePlacement = () => {
if (input.placements.getPlacement(authority.browserPageId) === expected) {
- input.placements.completePageRetirement(
- input.placements.beginPageRetirement(authority.browserPageId, expected)
- )
+ input.retirePage(authority.browserPageId, expected)
}
}
- // Why: a held grant blocks recreating the page once its placement is retired.
- const releaseGrant = () => {
- if (input.grants.get(authority.browserPageId) === grant) {
- input.grants.delete(authority.browserPageId)
- grant.release()
- }
- }
@@
retirePlacement()
closeSettledReplacement()
- releaseGrant()
@@
input.placements.cancelClientPageReservation(reservation)
retirePlacement()
- releaseGrant()
}diff --git a/src/main/runtime/browser-host/browser-host-lease-registry.ts b/src/main/runtime/browser-host/browser-host-lease-registry.ts
@@
placements: this.pagePlacements,
grants: this.clientPageExecutionHostGrants,
+ retirePage: (browserPageId, expected) =>
+ this.completePageRetirement(this.beginPageRetirement(browserPageId, expected)),
onCommitted: this.options.onClientPageReleased
ELI5
In a paired remote workspace whose browser runs on this computer, asking to move a browser tab into another session profile (its own cookie jar) could not be done safely. This lets the tab switch profiles by building the new page first and only throwing the old one away once the new one is working.
What Changed
Before:
browser.tabSetProfileon a page hosted by the desktop for a paired remote workspace sent the request to the server's own window, which does not hold that page. It either did nothing while reporting success (an isolated page asked to go back to the default profile was answered "already default" from the wrong registry) or failed against a renderer that is not there. There was no safe way to replace the live guest: closing it first would lose the logged-in page if the replacement then failed.After: the switch reaches the desktop that actually hosts the page, and the page keeps its identity (same page id, same workspace, same URL) while moving to the new profile's cookie jar. If anything goes wrong, the original page stays open and usable.
How it works:
profile-switch-v1. The server checks it, plus the page's lease generation, before touching any state. Older desktops get a clean "unsupported" error and nothing is mutated.switchProfilecommand. The desktop builds the replacement guest in its own partition (derived on the desktop from the profile id; only id, label and scope cross the wire, never a partition name), binds it, reloads the current URL, and only then publishes it and retires the old guest. Failure at any step tears down only the staged guest and rebinds the original.createPageandrestorePagenow carry the same optional profile metadata to desktops that advertise the capability, so a page that was switched can still be restored after a guest crash or a reconnect.This is the runtime operation only. It does not add a toolbar profile picker.
src/shared/browser-network-execution-host.ts(to keep the protocol file under the line limit); every importer imports it from there directly.Why
Keeping the old guest until the new one is bound is the only order that never leaves the user with a dead page or two live ones. The alternatives were "close then create" (loses the page and its session if creation fails, which is what the issue describes) or switching the existing guest's session in place (Electron cannot change a live webview's partition). Carrying profile metadata on the existing page commands, behind the same capability, reuses the creation and restore paths rather than adding a second profile catalog on the desktop.
Mixed versions: new server with an old desktop never sends
switchProfileor the optionalprofilefield (both gated onprofile-switch-v1). A new desktop with an old server receives neither and keeps its existing local-profile validation. The new command type only travels inside the existing command event after negotiation.This builds on #30351 by @oliver-mee, which proposed the staged-replacement design and the first version of this code; that commit keeps its original author. The follow-up commits address review findings on fencing, recovery, timeouts and downloads.
Linked Issue
Fixes #30350
Visual Proof
N/A: this changes a runtime command and the browser guest lifecycle, not any UI.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reproduced on main:
browser-profiles-client-placement.test.tsfails 7/7 against main'sbrowser-profiles.ts(main answers from the server's own window or reports a false "already in that profile").New and updated unit tests cover negotiation and rejection of old desktops, staged replacement in both directions, rollback on preparation, binding, navigation and abort failures, fencing during the switch, a dead replacement, a lost original guest, timeouts with late success and late failure, grant release, generation-scoped download release, staged download admission, metadata on create/restore, and folder-workspace targets. Each fix's test was confirmed failing without its fix.
Paired Electron end-to-end (
tests/e2e/paired-client-hosted-profile-cookies.spec.ts, hidden windows viaORCA_BACKGROUND_LAUNCH=1) passed locally on macOS: it switches default → isolated → default → isolated on a live client-hosted page and checks each native cookie jar keeps its own value.Unit folders around the change (
src/main/browser,src/main/runtime/browser-host,src/main/runtime/browser,src/main/runtime/rpc/methods,src/shared, browser-pane renderer tests) pass single-worker; typecheck and the full static-analysis job pass locally.Not verified: Windows or Linux live runs, an SSH-hosted remote server, or an installed build.
Review
Please look closest at
browser-client-page-profile-switch.ts(desktop staging and rollback order),browser-host-client-profile-switch.ts(server reservation, timeout and late-result handling), and the file-channel admission of a pending switch inbrowser-host-client-page-connection.ts.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Security: the desktop never accepts a partition name from the server; it derives the partition from the authority, execution host and profile id, so a server cannot point a page at the desktop's own cookie jars. File transfers under a reserved generation are admitted only for the same page, lease and connection while that page's switch is pending.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)