Skip to content

fix(serve): keep the isolated profile off the login keychain - #25517

Closed
paoValle wants to merge 1 commit into
stablyai:mainfrom
paoValle:fix/isolated-profile-keychain-switches
Closed

paoValle wants to merge 1 commit into
stablyai:mainfrom
paoValle:fix/isolated-profile-keychain-switches

Conversation

@paoValle

@paoValle paoValle commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Author: @paolovalletta_

ELI5

pnpm start:emulator runs Orca with a throwaway HOME so it cannot touch your real profile. On macOS that also means there is no login keychain — and Orca's first startup step on the serve path asks macOS for its encryption key. macOS tries to create the keychain item, finds nothing to authorize it with, and waits for a reply that never comes, so the process stops there and never advertises itself.

Orca already knows how to run an isolated profile without the keychain: its browser sidecar is launched with --use-mock-keychain. The foreground serve process — the one this repro hangs in — was simply never given the same two switches. This shares that decision and applies it there too.

What Changed

Before, on macOS with the pairing runtime's disposable profile:

$ cd mobile && node scripts/start-emulator.mjs
[0] Starting temporary desktop runtime for mobile pairing...
[error] Timeout waiting for temporary desktop pairing URL   # after 120 s

…with the main thread parked in SecItemAdd → AuthorizationCopyRights, and main-thread-hang.json written after 45 s.

After: the foreground serve process is launched with the switches the sidecar already carries, so nothing in an isolated profile reaches the login keychain.

Mechanism. The main-thread caller the report could not name is Orca's own secret-protection probe, and the serve path runs it inline:

  • startup/main-process-ready-foundation.ts:181 — deferUntilFirstWindow: !state.isServeMode, so serve reports inline rather than after a window.
  • host/deferred-secret-protection-report.ts:51 — the non-deferred branch calls reportSecretProtectionGap() directly, on the main thread, before anything is advertised.
  • host/secret-protection-report.ts:49 → getSecretStore().describeProtectionGap() → host/electron-secret-store.ts:10 — first statement is safeStorage.isEncryptionAvailable(). The module's own comment above it records the same class of block on Linux (76 s to first window, STA-5765).

With no login keychain, Chromium's keychain lookup creates the item instead of reading it, and the creation is what waits on the authorization reply.

The switches already existed for this exact profile. orcad/electron-serve-browser-process.ts launches its sidecar with ['--password-store=basic', '--use-mock-keychain'] whenever ORCA_E2E_USER_DATA_DIR || ORCA_E2E_HOME_DIR is set, and electron-serve-browser-process.test.ts pins that. The foreground serve process is spawned by the CLI (cli/runtime/launch.ts, serveOrcaApp) and never received them, so the profile was isolated for one of its two Electron processes only.

This change moves the condition into shared/electron-isolated-profile-switches.ts and uses it at both launch sites.

Why

  • Why not just skip the probe for these profiles. The probe is not the only thing that can reach that keychain item — anything in the process that encrypts, Chromium's own cookie key included, hits the same one. Skipping one caller would leave the next one blocked. --use-mock-keychain removes the keychain from the process, which is why the sidecar uses it.
  • Why not defer the report for serve instead. That timing is deliberate and documented in deferred-secret-protection-report.ts: blocking after the runtime is advertised reads to a paired client as a dead host (stalled pings and PTY pumps), and the maintainers chose blocking before it. Reversing that is their call, not a drive-by change.
  • Why share the condition. Two Electron processes, one profile. The decision existed once in code and once in intent; now it exists once in code.

Linked Issue

Fixes #25453

Visual Proof

N/A — no user-interface change. The observable difference is that the foreground serve process starts advertising.

Testing

Check Result
electron-isolated-profile-switches.test.ts (new) — either env half, neither, and a bare HOME override 4 passed
cli/runtime/launch.test.ts — an isolated profile's serve args carry both switches; a normal profile's carry neither passed, 2 new cases
Mutation check: the same test with only the childArgs.push(...) removed fails with - "--use-mock-keychain", so it cannot pass by construction
main/orcad/electron-serve-browser-process.test.ts (the sidecar's pinned args, after the refactor) passed
pnpm test src/cli/ 1626 passed, 4 skipped (141 files)
pnpm test src/main/orcad/ 241 passed, 12 skipped (34 files)
pnpm tc (node + cli + web) exit 0
oxlint + oxfmt on the five files (pre-commit) clean

Platforms tested: macOS, where the switches are inert for a normal profile. I did not run the packaged reproduction — see Notes for why, and the confirmation I would like from the reporter.

AI Disclosure

Written with an AI coding agent, session model deepseek-v4.1-flash (provider opencode-go). All commands and results above were produced on this machine.

Review

  • Cross-platform: the condition is environment-driven, not platform-driven. A normal profile gets no extra switch on any platform, so macOS, Linux and Windows launches are byte-identical to before. --use-mock-keychain is a macOS switch and --password-store a Linux one; the sidecar already passed both unconditionally for this profile, which is the behaviour this mirrors.
  • SSH / remote / local: the switches are appended to a local process launch and change no wire, host, or provider path.
  • Agent and integration compatibility: no agent surface, hook, or provider frame is touched.
  • Performance risk: none. Two argv entries at launch, and the isolated profile skips a keychain round trip that would otherwise block the main thread.
  • UI quality: not applicable.
  • Security: this makes an isolated profile use Chromium's mock keychain, so anything that profile "encrypts" is not OS-protected. That is the intended trade for a disposable profile handed a temporary HOME, and it is exactly what the sidecar already does for the same profile; a normal profile keeps its real keychain. Stated plainly because it is the one behavioural consequence beyond "it starts".

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Not changed: the inline report on the serve path. It is documented as deliberate and I did not want to reverse a maintainer decision inside a launch-args fix.
  • Not fixed: the general case. A real profile whose login keychain is missing or locked still reaches the same main-thread probe and can still block. This PR removes the keychain for the disposable profile in the report, which is what makes pnpm start:emulator work; making the probe itself non-blocking (or moving it off the main thread) is a separate change and I would want a steer before making it, because it is the timing decision above.
  • I did not run the reproduction myself. The blocking call raises a Keychain authorization UI, and AGENTS.md forbids an agent-launched app from stealing desktop focus, so I could not honestly run it here. What I verified is the missing launch arguments and where they go. @prateek — if you can re-run node scripts/start-emulator.mjs against a build of this branch, that confirms it end to end, and if it still hangs then Chromium is creating the item through a path the mock switch does not cover, which is worth knowing before this goes further.

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) — tc, both affected suites, oxlint and oxfmt pass locally; pnpm lint and build are left to CI

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 77e65f3f-4aef-455e-81c1-63fdc9e165f4

📥 Commits

Reviewing files that changed from the base of the PR and between e2da3a1 and 39b3a220032c0e9988d149ef0500c63772f8ecfb.


📒 Files selected for processing (5)
  • src/cli/runtime/launch.test.ts
  • src/cli/runtime/launch.ts
  • src/main/orcad/electron-serve-browser-process.ts
  • src/shared/electron-isolated-profile-switches.test.ts
  • src/shared/electron-isolated-profile-switches.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.



📝 Walkthrough
📝 Walkthrough

Priority: ⬆️ High

Merge Risk | ⚪ Minimal · up to 39b3a

Merge Risk: ⚪ Minimal · up to 39b3a

The disposable-profile launches appear ready to merge after normal checks. The packaged fresh-HOME reproduction remains untested.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 39b3a

The intended emulator launch uses disposable directories, and ordinary launches retain their existing keychain configuration. However, an incomplete isolation configuration can request mock keychain behavior while still using a persistent profile. This creates a conditional secret-protection risk rather than a demonstrated remote attack path.

Retained concerns

  • Medium · security · inferred: The foreground launch now treats ORCA_E2E_HOME_DIR alone as sufficient to request mock/basic keychain behavior, although startup requires ORCA_E2E_USER_DATA_DIR to redirect application storage and enforce the home boundary. A home-only launch can consequently retain a persistent profile while requesting reduced secret protection. Persistent secret writers do not independently require an OS-protected backend. This is conditional on local configuration and secret operations; the supported pairing launcher supplies both overrides correctly.
Security review details

Security Blast Radius

  • inferred — The demonstrated policy mismatch is confined to the locally configured foreground launch and the home/profile storage it accesses. Plugin vaults inherit the service's userData path, while API-key files use Node's home directory. File access remains necessary for an at-rest disclosure scenario; these changes do not establish cross-tenant, IAM, or network authority expansion.

Security Findings and Attack Paths

  • inferred — A local launcher can inherit ORCA_E2E_HOME_DIR without a user-data override and without changing HOME. The new foreground policy then requests mock/basic keychain behavior while startup keeps ordinary persistent paths. Subsequent secret writes can lose the intended OS-keychain protection depending on backend behavior, exposing them to a reader of the affected files. This is a source-supported conditional concern, not an observed production exploit or demonstrated decryption of existing ciphertext.

Trust Boundaries and Controls

  • observed — The supported mobile caller supplies matching temporary home and user-data overrides. Existing secret-file writes stage files with restrictive permissions and publish them by rename. Plugin host calls retain granted-capability policy resolution. These controls limit the conditional exposure but do not make a home-only override proof of profile isolation.

Resilience and Maintainability Implications

  • observed — Secret readers report decryption failures rather than proving recovery across backend changes. Plugin writes refuse unavailable encryption or unreadable vault files, while API-key writes retain an existing plaintext fallback when encryption is unavailable. These pre-existing behaviors matter because the new foreground switches can change the backend they encounter.

Hardening Proposals

  • proposed — Bind mock/basic backend selection to the same validated profile-isolation contract used at startup, rejecting incomplete override combinations before launch. For any supported persistent-profile use, explicitly define backend-change and recovery behavior rather than relying on encryption availability alone.

🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive Issue #25453 requires orca serve to become ready with a fresh HOME for the disposable pairing profile. The launch code now adds --password-store=basic and --use-mock-keychain when either E2E p… Provide a macOS run with the issue's fresh-HOME environment that confirms orca serve emits readiness or that the pairing runtime obtains its URL.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: keeping isolated profiles off the login keychain during serve startup.
Description check ✅ Passed The description covers the required sections, explains the change and its rationale, links issue #25453, gives a reason for N/A visual proof, and reports tests and platform coverage. It also states th…
Out of Scope Changes check ✅ Passed The shared switch helper, its tests, the foreground serve launch change, and the sidecar refactor all support the #25453 isolated-profile fix. The changes do not show unrelated scope.

Full details: Linked Issues check

Explanation

Issue #25453 requires orca serve to become ready with a fresh HOME for the disposable pairing profile. The launch code now adds --password-store=basic and --use-mock-keychain when either E2E profile variable is set. Tests cover both switches for an isolated profile and their absence for a normal profile. The reported macOS startup scenario was not run, so the evidence does not establish that the process now becomes ready.


  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@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 — the full PR (5 files): moving the isolated-profile keychain switches into one shared helper and applying them to the foreground serve process.

  • Shared helper — src/shared/electron-isolated-profile-switches.ts adds usesIsolatedProfile (either ORCA_E2E_USER_DATA_DIR or ORCA_E2E_HOME_DIR) and electronIsolatedProfileSwitches (the two switches, or []).
  • Foreground serve — serveOrcaApp now pushes those switches right after --serve; a normal profile gets [], so normal launches are unchanged. The update-handoff resume path reuses childArgs, so it is covered too.
  • Sidecar refactor — electron-serve-browser-process.ts calls the helper instead of the inlined condition; behaviour is identical.
  • Tests — new unit test for the helper (both env halves, neither, bare HOME) plus isolated/normal cases in launch.test.ts; the existing sidecar assertion is unchanged.

I confirmed the load-bearing mechanism against Chromium source: --use-mock-keychain is Apple-only and short-circuits Chromium's OSCrypt to a mock keychain, which is the path Electron 43's safeStorage.isEncryptionAvailable() takes (OSCrypt::IsEncryptionAvailable() → GetEncryptionKey() → KeychainPassword::GetPassword()), so the SecItemAdd/AuthorizationCopyRights block is avoided. --password-store=basic is inert on macOS but harmless. The gate stays limited to the disposable ORCA_E2E_* profile, so a normal profile keeps its real keychain.

The author has flagged the one thing this review cannot confirm: the end-to-end repro was not run. That is a verification gap, not a code defect.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@paoValle
paoValle force-pushed the fix/isolated-profile-keychain-switches branch from 39b3a22 to b9aef9e Compare October 8, 2026 13:17
@paoValle

paoValle commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (e3639ef8d6), which moved under the branch while it sat. The only conflict was the import block in src/cli/runtime/launch.ts: upstream refactored the user-data path into ./launch-user-data-path and dropped the old metadata/ephemeral-vm-recipes imports, so the resolution keeps upstream imports plus the new electronIsolatedProfileSwitches one. Net diff against main is unchanged from the original.

pnpm tc clean; focused vitest (launch.test.ts, electron-isolated-profile-switches.test.ts, electron-serve-browser-process.test.ts) 3 files / 39 passed. Upstream still applies the switches only in the sidecar (electron-serve-browser-process.ts), not the foreground serve path, so the fix is still needed for #25453.

The E2E/pairing runtime hands the app a fresh HOME, so there is no login
keychain for OSCrypt to read. On the serve path the secret-protection report
runs inline before readiness and probes safeStorage on the main thread, where
Chromium's keychain lookup creates the item and waits on an authorization
reply that never arrives, so `orca serve` never advertises (stablyai#25453).

The sidecar already launches with --use-mock-keychain for exactly this
profile; share that decision and give the foreground serve process the same
switches.
@paoValle
paoValle force-pushed the fix/isolated-profile-keychain-switches branch from b9aef9e to 53f4459 Compare October 10, 2026 06:52
@paoValle

Copy link
Copy Markdown
Contributor Author

Rebased onto main (f307391637). Force-pushed as 53f44597ff.

Two conflicts, both structural, no change to the fix's intent:

  • src/cli/runtime/launch.ts — upstream folded the per-flag pushes into serveOptionArgs(args, '--serve-'). Kept that call and re-applied the switch push right after it, instead of the old inline if (args.json) … chain.
  • src/main/orcad/electron-serve-browser-process.ts — upstream moved spawnProcess to @orca/process-host. Kept upstream's import and added the electronIsolatedProfileSwitches import; the switch replacement itself applied cleanly. The SpawnedProcess type is no longer imported (it is no longer used).

Net diff against main is the same change as before: the four E2E-profile switches move into electronIsolatedProfileSwitches(env), and the foreground serve process now gets them too.

Verification:

$ node config/scripts/ensure-native-runtime.mjs --runtime=node && \
  node config/scripts/run-vitest.mjs run --config config/vitest.config.ts \
    src/shared/electron-isolated-profile-switches.test.ts \
    src/cli/runtime/launch.test.ts \
    src/main/orcad/electron-serve-browser-process.test.ts
 Test Files  3 passed (3)
      Tests  39 passed (39)
   Duration  4.38s

$ pnpm tc
$ pnpm run typecheck
$ pnpm --filter @orca/process-host build
# exit 0

mergeable is MERGEABLE again; mergeStateStatus is UNSTABLE while checks run.

@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thank you @paoValle, and for the very clear write-up. Your fix landed through #27463 (merged as 5d7f48e), with your commit and authorship kept. It also has two small follow-ups: the two new as string[] test casts were replaced with a small helper, and review found one gap. ORCA_E2E_HOME_DIR alone still selects the user's real profile, so the foreground serve process now requires ORCA_E2E_USER_DATA_DIR before it drops the keychain. The sidecar keeps your either-variable rule.

@OrcaWin OrcaWin closed this Oct 11, 2026
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]: orca serve hangs at startup on macOS when HOME is a fresh directory, so mobile start:emulator cannot pair

2 participants