Skip to content

fix(browser): isolate embedded profiles per session - #1526

Merged
Astro-Han merged 2 commits into
devfrom
fix/browser-session-isolation
Jul 20, 2026
Merged

fix(browser): isolate embedded profiles per session#1526
Astro-Han merged 2 commits into
devfrom
fix/browser-session-isolation

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Give every conversation-owned embedded browser its own persistent Electron profile partition.
  • Persist the conversation-to-profile mapping and carry a Home draft's immutable profile through adoption.
  • Clear all registered profiles plus the legacy shared partition from the existing Clear Data action.

Why

The browser controllers, pages, and CDP connections were conversation-owned, but every WebContentsView still used the same persist:pawwork-browser partition. Electron reuses one Session for pages with the same partition, so cookies, local storage, IndexedDB, service workers, cache, and permission handlers remained shared. Two conversations operating the same site concurrently could therefore mutate each other's browser state.

The profile partition is now part of the conversation ownership boundary instead of an app-wide singleton.

Related Issue

Related to #1333. This concurrency bug was reported directly and does not have a dedicated issue.

Human Review Status

Pending

Review Focus

  • Profile identity and persistence in profile-registry.ts, especially duplicate-map repair.
  • Home draft adoption: the live page must retain its existing profile while the mapping moves to the newly created session.
  • Clear Data coverage for live draft profiles, stored conversation profiles, and the legacy shared partition.

Risk Notes

  • Existing data in the legacy shared browser partition is deliberately not copied into isolated profiles. Copying mixed state would reintroduce the leak; users may need to sign in once in each conversation after upgrading.
  • The profile index is local Electron state and contains opaque profile IDs keyed by session ID; it contains no cookies or credentials.
  • No visible UI or copy changed, so the visual-check checklist item is not applicable.

How To Verify

Regression RED: options test confirmed both profiles resolved to persist:pawwork-browser before the fix.
Focused browser tests: 70 passed, 0 failed.
Desktop typecheck: passed.
Desktop production build: passed.
Native Electron isolation smoke: same partition exposed localStorage ("a"); distinct profile partitions returned null.
Real desktop startup: bun run dev:desktop reached sidecar ready and rendered the desktop shell without startup errors.
Diff check and targeted ESLint: passed with no errors.

Screenshots or Recordings

Not applicable; this changes Electron storage ownership without changing visible UI.

Checklist

How to use this checklist:

  • Tick a box by replacing [ ] with [x]. Do not edit, add, or remove items.
  • The bot-applied label items can only be honestly ticked AFTER the PR is opened and the labeler / priority-triage bots have run — return to the PR description and tick them then.
  • Most items are required. The few that are conditional are explicitly marked (conditional); for those, leave unticked if they truly do not apply and explain why in Risk Notes. All other items must be ticked before requesting human review.
  • Type label — this PR carries exactly one of bug, enhancement, task, documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

Summary by CodeRabbit

  • New Features

    • Added separate persistent browser profiles for each conversation.
    • Preserved cookies, storage, and browsing settings independently across conversations.
    • Improved profile handling when browser sessions are reopened or reassigned.
  • Bug Fixes

    • Signing out now clears cookies, storage, and cache across all browser profiles.
    • Maintained embedded browser security protections for every profile.

@github-actions github-actions Bot added app Application behavior and product flows ui Design system and user interface platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions labels Jul 20, 2026
@Astro-Han Astro-Han added bug Something isn't working P1 High priority desktop labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Astro-Han, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 01098d8f-0746-4cd2-b75b-66954794f62c

📥 Commits

Reviewing files that changed from the base of the PR and between 7260061 and 5fa477b.

📒 Files selected for processing (10)
  • packages/desktop-electron/src/main/browser/controller-automation.ts
  • packages/desktop-electron/src/main/browser/controller.ts
  • packages/desktop-electron/src/main/browser/options.test.ts
  • packages/desktop-electron/src/main/browser/options.ts
  • packages/desktop-electron/src/main/browser/profile-registry.test.ts
  • packages/desktop-electron/src/main/browser/profile-registry.ts
  • packages/desktop-electron/src/main/browser/profile-sessions.test.ts
  • packages/desktop-electron/src/main/browser/profile-sessions.ts
  • packages/desktop-electron/src/main/ipc/browser.ts
  • packages/desktop-electron/src/main/runtime-namespace.ts
📝 Walkthrough

Walkthrough

The embedded browser now assigns persistent profiles per conversation, maps profiles through persisted main-process state, creates profile-specific Electron partitions, and clears data across legacy and active profile partitions.

Changes

Browser profile isolation

Layer / File(s) Summary
Persisted browser profile registry
packages/desktop-electron/src/main/runtime-namespace.ts, packages/desktop-electron/src/main/browser/profile-registry.ts, packages/desktop-electron/src/main/browser/profile-registry.test.ts, packages/desktop-electron/src/main/browser/controller-automation.ts
A persisted registry assigns, restores, validates, deduplicates, and adopts profile IDs for browser sessions, with coverage for stable mappings, drafts, and duplicate repair.
Profile-specific browser controllers
packages/desktop-electron/src/main/browser/options.ts, packages/desktop-electron/src/main/browser/options.test.ts, packages/desktop-electron/src/main/browser/controller.ts
Browser preferences and views use profile-specific persistent partitions; user-agent setup is tracked per partition, and controllers expose profile IDs and adoption callbacks.
Cross-profile data clearing and documentation
packages/desktop-electron/src/main/ipc/browser.ts, packages/app/src/context/platform.tsx
Clear-data handling clears legacy and discovered profile partitions, while browser bridge comments describe profile-scoped persistence and sign-out behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Conversation
  participant browserControllers
  participant BrowserProfileRegistry
  participant BrowserViewController
  participant ElectronPartitions
  Conversation->>browserControllers: request browser controller
  browserControllers->>BrowserProfileRegistry: profileFor(conversation)
  browserControllers->>BrowserViewController: create with profileID
  BrowserViewController->>ElectronPartitions: create profile-specific WebContentsView
  BrowserViewController->>BrowserProfileRegistry: adopt(sessionID, profileID) on retarget
  Conversation->>browserControllers: clear browser data
  browserControllers->>BrowserProfileRegistry: profileIDs()
  browserControllers->>ElectronPartitions: clear legacy and profile partitions
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. 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 summarizes the main change: isolating embedded browser profiles per session.
Description check ✅ Passed The PR description matches the template and includes all required sections, risks, verification, and checklist items.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/browser-session-isolation

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested priority: P2 (includes user-path files (packages/app/src/context/platform.tsx, packages/desktop-electron/src/main/browser/controller-automation.ts, packages/desktop-electron/src/main/browser/controller.ts, packages/desktop-electron/src/main/browser/options.test.ts, packages/desktop-electron/src/main/browser/options.ts, packages/desktop-electron/src/main/browser/profile-registry.test.ts, packages/desktop-electron/src/main/browser/profile-registry.ts, packages/desktop-electron/src/main/ipc/browser.ts, packages/desktop-electron/src/main/runtime-namespace.ts)).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/desktop-electron/src/main/browser/profile-registry.ts`:
- Around line 42-61: Update profileFor to persist newly created draft profiles
under a unique unadopted:${created} key instead of leaving them untracked.
Update adopt to locate and remove that temporary key when adopting the profile,
then persist the profile under sessionID; preserve existing handling for invalid
or already non-draft sessions. Adjust the unadopted draft assertion in
profile-registry.test.ts to expect the temporary storage key.

In `@packages/desktop-electron/src/main/ipc/browser.ts`:
- Around line 83-98: Update the browser:clear-data handler to avoid
session.fromPartition for inactive profiles: clear storage and cache through
Electron only for partitions belonging to active browserControllers, while
removing inactive partition directories directly with fs.promises.rm using the
userData/Partitions path and recursive, force options. Process cleanup
sequentially rather than with Promise.all, preserve cleanup of the legacy
partition, and continue reloading loaded controllers afterward.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 07555b75-9259-4cef-80a3-ec1312f5a631

📥 Commits

Reviewing files that changed from the base of the PR and between 257966e and 7260061.

📒 Files selected for processing (9)
  • packages/app/src/context/platform.tsx
  • packages/desktop-electron/src/main/browser/controller-automation.ts
  • packages/desktop-electron/src/main/browser/controller.ts
  • packages/desktop-electron/src/main/browser/options.test.ts
  • packages/desktop-electron/src/main/browser/options.ts
  • packages/desktop-electron/src/main/browser/profile-registry.test.ts
  • packages/desktop-electron/src/main/browser/profile-registry.ts
  • packages/desktop-electron/src/main/ipc/browser.ts
  • packages/desktop-electron/src/main/runtime-namespace.ts

Comment thread packages/desktop-electron/src/main/browser/profile-registry.ts
Comment thread packages/desktop-electron/src/main/ipc/browser.ts
@Astro-Han
Astro-Han merged commit 4a59656 into dev Jul 20, 2026
43 checks passed
@Astro-Han
Astro-Han deleted the fix/browser-session-isolation branch July 20, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Application behavior and product flows bug Something isn't working desktop P1 High priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions ui Design system and user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant