Skip to content

fix(browser): switch client-hosted profiles with staged guest replacement - #30351

Closed
oliver-mee wants to merge 6 commits into
stablyai:mainfrom
oliver-mee:fix/client-hosted-profile-runtime
Closed

oliver-mee wants to merge 6 commits into
stablyai:mainfrom
oliver-mee:fix/client-hosted-profile-runtime

Conversation

@oliver-mee

Copy link
Copy Markdown
Contributor

ELI5

Switch a paired browser page to another session profile without destroying the working page before its replacement is ready.

What Changed

Adds a capability-negotiated profile-switch command, validates remote profile metadata, derives the desktop route partition, and stages guest replacement with rollback. Older desktops reject before mutation. Local behavior and same-profile no-ops remain unchanged.

Why

Closing the old guest first loses the working page when replacement fails. Staging keeps its guest and cookie jar intact until the replacement has bound successfully.

Linked Issue

Fixes #30350

Visual Proof

N/A: this PR changes the runtime command and guest lifecycle, not toolbar UI. Toolbar profile selection remains separate unfinished work.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • macOS: 728 tests passed across 82 files using the Node runner and an isolated HOME. Node and renderer typechecks, changed-file oxlint and diff checks passed.

  • Linux: an actual paired Electron E2E passed against a combined integration checkout. It switches default to isolated, back to default, then isolated again, checking native cookie jars retain their own values without leakage.

  • Combined integration: both typechecks and 49 focused profile/import tests passed.

The Electron result is from an integration checkout containing the separate annotation and controls changes, not a standalone packaged build. No Windows or installed-app manual validation is claimed. Creation/restoration retain existing desktop-profile validation; the remote metadata extension covers switching only. Full repository suites were not run.

AI Disclosure

OpenAI GPT-6.1 Sol implemented and tested this change under human direction.

Review

Please review staged replacement, rollback, stale-generation fencing and old-peer rejection. This does not add a toolbar profile selector or change cookie-import policy.

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

Runtime switching is implemented and tested. Toolbar integration is explicitly outside this scoped PR; this is not a claim of complete UI parity.

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)

🤖 Generated with GPT-6.1 Sol
🧑‍💻 Ideated, directed and reviewed by a human, @oliver-mee

Negotiate profile-switch support before mutation and derive desktop route partitions from validated authority-owned metadata. Keep the old guest available until its replacement is bound, then advance placement and command generations together. Preserve rollback bindings and cached switch replies.
@coderabbitai

coderabbitai Bot commented Oct 18, 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: c3a14ca8-0c24-416c-ae45-1320c8f3b8b3
📥 Commits

Reviewing files that changed from the base of the PR and between 9cc9b62 and 6ade997.

📒 Files selected for processing: 3
  • src/main/runtime/browser-host/browser-host-client-profile-switch.test.ts
  • src/main/runtime/browser-host/browser-host-client-profile-switch.ts
  • src/main/runtime/browser-host/browser-host-profile-switch-recovery.test.ts
🚧 Files skipped from review as they are similar to previous changes: 3
  • src/main/runtime/browser-host/browser-host-profile-switch-recovery.test.ts
  • src/main/runtime/browser-host/browser-host-client-profile-switch.test.ts
  • src/main/runtime/browser-host/browser-host-client-profile-switch.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.

📝 Walkthrough

The change adds client-hosted browser profile switching through a generation-scoped command. The host validates support and placement state, then coordinates replacement placement. The client prepares and binds a page in the requested profile while retaining the existing guest until commit. Runtime profile selection routes registered client pages through this flow and updates their profile and placement. Tests cover switching, failure recovery, and profile-specific cookies.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 6ade9

The change adds ordered cleanup after late profile switches, along with recovery tests. No outstanding merge-blocking issue was found in the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 2.70% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 37 functions across 50 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description follows the required template and clearly covers the change, rationale, linked issue, visual proof, testing results, scope, review notes, and checklist. It also discloses that manual v…
Title check Passed The title is concise, specific, and accurately summarizes the main change: staged guest replacement for switching client-hosted browser profiles.
Linked Issues check Passed Issue #30350 is open and directly linked. The PR negotiates profile-switch-v1 before mutation, validates authority-owned profile metadata and page generation, derives the isolated route partition, a…
Out of Scope Changes check Passed The changes stay within issue #30350. Production changes support client-hosted profile switching, staged guest replacement, rollback, generation fencing, cleanup ordering, and placement updates. Suppo…
Full details: Description check

Explanation

The description follows the required template and clearly covers the change, rationale, linked issue, visual proof, testing results, scope, review notes, and checklist. It also discloses that manual validation, full repository suites, Windows testing, and some local commands were not completed.

Full details: Linked Issues check

Explanation

Issue #30350 is open and directly linked. The PR negotiates profile-switch-v1 before mutation, validates authority-owned profile metadata and page generation, derives the isolated route partition, and stages a replacement guest. The old guest remains bound until replacement binding and navigation succeed. Failure paths retain or restore the old page. Older clients reject the command before mutation. Added unit, integration, and paired Electron tests cover success, rollback, stale generations, capability rejection, metadata validation, and cookie isolation.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #30350. Production changes support client-hosted profile switching, staged guest replacement, rollback, generation fencing, cleanup ordering, and placement updates. Supporting tests cover these behaviors. The PR does not add toolbar profile selection or implement cookie import or annotation controls.

  • Fix all pre-merge checks with AI
  • 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.

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26c2047e-20f1-40b2-87a0-035e7b1f2439
📥 Commits

Reviewing files that changed from the base of the PR and between 506aa03 and 908294f.

📒 Files selected for processing: 40
  • src/main/browser/browser-client-host-command-page.ts
  • src/main/browser/browser-client-host-command-state.ts
  • src/main/browser/browser-client-page-automation-runtime.test.ts
  • src/main/browser/browser-client-page-automation-runtime.ts
  • src/main/browser/browser-client-page-availability.ts
  • src/main/browser/browser-client-page-command-executor-dependencies.ts
  • src/main/browser/browser-client-page-command-executor-test-harness.ts
  • src/main/browser/browser-client-page-command-executor.ts
  • src/main/browser/browser-client-page-creation.ts
  • src/main/browser/browser-client-page-executor-close.ts
  • src/main/browser/browser-client-page-guest-binding.ts
  • src/main/browser/browser-client-page-profile-binding.test.ts
  • src/main/browser/browser-client-page-profile-switch.test.ts
  • src/main/browser/browser-client-page-profile-switch.ts
  • src/main/browser/browser-client-page-reconciliation.ts
  • src/main/browser/browser-client-page-retained-state.ts
  • src/main/browser/browser-manager-registration.ts
  • src/main/browser/browser-route-session-policy.ts
  • src/main/browser/browser-route-session-registry-contract.ts
  • src/main/browser/browser-route-session-registry.test.ts
  • src/main/browser/browser-route-session-registry.ts
  • src/main/browser/browser-route-session-runtime.ts
  • src/main/browser/browser-route-session-state.ts
  • src/main/browser/paired-runtime-browser-client-host-runtime.ts
  • src/main/runtime/browser-host-client-page-creation.ts
  • src/main/runtime/browser-host-client-profile-switch.test.ts
  • src/main/runtime/browser-host-client-profile-switch.ts
  • src/main/runtime/browser-host-command-ledger.ts
  • src/main/runtime/browser-host-command-result-replay.ts
  • src/main/runtime/browser-host-command-state.ts
  • src/main/runtime/browser-host-lease-registry.ts
  • src/main/runtime/browser-host-page-command-admission.ts
  • src/main/runtime/browser-host-page-placement.ts
  • src/main/runtime/browser/browser-profiles-client-placement.test.ts
  • src/main/runtime/browser/browser-profiles.ts
  • src/main/runtime/runtime-browser-page-registry.ts
  • src/renderer/src/components/browser-pane/browser-client-page-profile-staging.test.ts
  • src/shared/browser-client-host-protocol.ts
  • src/shared/browser-client-profile-switch-protocol.ts
  • tests/e2e/paired-client-hosted-profile-cookies.spec.ts

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

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a3e57872-7379-4a00-93a2-ecfd4aa48da9
📥 Commits

Reviewing files that changed from the base of the PR and between 908294f and 9cc9b62.

📒 Files selected for processing: 11
  • src/main/runtime/browser-host/browser-host-client-page-creation.ts
  • src/main/runtime/browser-host/browser-host-client-profile-switch.test.ts
  • src/main/runtime/browser-host/browser-host-client-profile-switch.ts
  • src/main/runtime/browser-host/browser-host-command-ledger.ts
  • src/main/runtime/browser-host/browser-host-command-result-replay.ts
  • src/main/runtime/browser-host/browser-host-command-state.ts
  • src/main/runtime/browser-host/browser-host-lease-registry.ts
  • src/main/runtime/browser-host/browser-host-page-command-admission.ts
  • src/main/runtime/browser-host/browser-host-page-placement.ts
  • src/main/runtime/browser-host/browser-host-profile-switch-recovery.test.ts
  • src/main/runtime/browser/browser-profiles-client-placement.test.ts

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

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @oliver-mee. Your staged-replacement design is the basis of #30452, which carries your commit (you remain its author) rebased onto current main, plus follow-ups from review: fencing the staged guest during the switch, keeping the original placement until a timed-out switch settles, releasing the execution-host grant and only the replaced generation's download transfers, carrying host-owned profile metadata on createPage/restorePage so switched pages can be recovered, and resolving folder-workspace targets through the client-page catalog. Closing this in favour of #30452.

@nwparker nwparker closed this Oct 18, 2026
nwparker pushed a commit that referenced this pull request Oct 19, 2026
nwparker added a commit that referenced this pull request Oct 19, 2026
…t guest (#30452)

* fix(browser): switch client-hosted profiles with staged guest replacement

Squashed from #30351 by @oliver-mee onto the current main.

Fixes #30350

* fix(browser): fence staged profile guests, release switch grants, carry 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.

* fix(browser): roll back a switch whose replacement died, and report a lost old guest

* fix(browser): resolve client-hosted pages before the server-local target path when switching profiles

* fix(browser): a staged profile-switch guest owns downloads it starts while loading

* fix(browser): keep the original placement until a timed-out switch settles

* fix(browser): rebind the original guest before releasing a rolled-back staged guest

* test(browser): type the harness guest release mock

* fix(browser): release the replaced generation's download transfers when a switch commits

* fix(browser): admit file transfers from a staged profile-switch guest while its switch is pending

* fix(browser): release only the replaced generation's download transfers after a switch

* refactor(shared): import BrowserNetworkExecutionHost from its own module, no re-export

* fix(browser): adopt a profile switch the client finished after the caller timed out

---------

Co-authored-by: Oliver Mee <102673257+oliver-mee@users.noreply.github.com>
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.

[Bug]: Client-hosted browser profile switching cannot safely replace a live guest

2 participants