Skip to content

fix(serve): report secrets unavailable instead of hanging on an unreachable macOS keychain - #27441

Merged
OrcaWin merged 2 commits into
mainfrom
np/d1-keychain-probe
Oct 11, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/d1-keychain-probe

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​183 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​173

ELI5

On a Mac, orca serve can be started where no one is logged into the desktop: over SSH, or by a LaunchAgent after a reboot. In that case, asking the macOS keychain for Orca's encryption key can wait forever on a password prompt that nobody can see. Orca asked inline before it reported ready, so the server never came up. Now Orca first asks the keychain from a separate, short-lived process that is killed after 5 seconds. If the keychain cannot answer, Orca says secrets are unavailable for this run and starts anyway.

What Changed

  • Before: headless orca serve on macOS called safeStorage on the main thread before readiness. With no default keychain (a fresh HOME, [Bug]: orca serve hangs at startup on macOS when HOME is a fresh directory, so mobile start:emulator cannot pair #25453) or a keychain that needs a prompt, that call blocked forever, and the server never printed its ready line. The same call could also freeze a running server the first time any feature read a stored credential.
  • After, in serve mode on macOS: before the profile loads (loading can decrypt secrets), Orca runs /usr/bin/security show-keychain-info in a child process with a 5 s kill.
    • Answers normally: nothing changes.
    • No default keychain, prompt not allowed, or no answer within 5 s: Orca withholds the keychain for the rest of the run.
      • Every in-process safeStorage call goes through guardedSafeStorage and reports "unavailable" instead of blocking.
      • The serve log says why and what to do (start from a logged-in desktop session, or unlock the login keychain).
      • The protection report explains the same.
    • Probe cannot tell: for example security is missing or prints something unexpected. Today's behavior is kept.
  • Unchanged:
    • The desktop app, which has a GUI session that can show the prompt.
    • Linux, which already probes its secret service out of process before choosing a backend.
    • Existing sealed secrets are never migrated or re-encrypted. They are just not read during a run where the keychain is unavailable.
  • orcad message: "This host has no OS keyring" was false on macOS and Windows desktops. It now names the keychain orcad does not use (macOS Keychain, Windows credential protection, or OS keyring), and drops the advice to install a keyring orcad would not use anyway.

Mechanism: the six modules that imported electron.safeStorage (the secret store, cloud session, zcode, minimax, plugin secrets and API-key file stores) now import guardedSafeStorage from src/main/host/safe-storage-availability.ts. It is a pass-through until something withholds the keychain.

Why

Owner decision D1 Q10: the Electron fallback for orca serve is chosen automatically for every profile with SSH targets, so a headless Mac without a GUI session is a normal case.

  • Why a child process: safeStorage is synchronous, and a timer in the same process cannot interrupt it. The probe runs in a child that can be killed.
  • Why a guard on every caller: the critique of the earlier design showed that moving the report after readiness only moves the freeze behind a ready line. Once the probe has shown the keychain cannot answer, the guard keeps first use from freezing the host.
  • Rejected alternative: switching to the mock or basic password store automatically. That would make every already-sealed secret unreadable.
  • Why show-keychain-info: it reads keychain settings, never a secret, so it cannot raise the prompt it is checking for. It is the same pattern as the existing Linux secret-service probe.

Linked Issue

Fixes #25453 (a fresh HOME has no default keychain, so serve now starts and reports secrets unavailable). #25517 still applies its isolated-profile switches for E2E profiles.

Visual Proof

N/A: headless startup only. The visible change is that orca serve reaches its ready line within about 5 s, with a [secrets] Secrets are unavailable for this run: … log line, where before it hung.

Testing

  • Automated tests added/updated
  • macos-keychain-reachability.test.ts: covers each security outcome.
    • Exit 0 is reachable.
    • "A default keychain could not be found" (verified locally with a fresh HOME: exit 37) is unavailable.
    • "User interaction is not allowed" is unavailable.
    • A timeout is unavailable.
    • Anything else, or a spawn failure, is unknown.
  • safe-storage-availability.test.ts: covers the following.
    • Pass-through until withheld.
    • Once withheld, no native keychain call happens and encrypt/decrypt throw secrets_unavailable.
    • The secret store reports the reason without probing.
  • serve-keychain-guard.test.ts: covers the following.
    • On macOS, an unavailable keychain is withheld with a warning.
    • A reachable or undecided keychain is left alone.
    • No probe runs off macOS.
  • orcad-secret-protection-gap.test.ts: the per-platform wording.
  • All suites for the migrated stores, startup, orcad and host pass. pnpm tc, pnpm lint and pnpm run check:code-quality:changed pass.

Review

Agent skill upstream boundary

  • Not applicable

Notes

  • Known gaps (none is a regression; each keeps today's behavior):
    • A per-item access prompt can still block safeStorage after the probe says the keychain is reachable. Examples: a login keychain whose settings security can read without a prompt, or an "Orca Safe Storage" item whose access list no longer matches the app's signature. The probe never reads the item, because reading it is exactly what could prompt. The 5 s timeout catches a security that itself waits.
    • A probe it cannot interpret (for example security missing) keeps today's inline behavior.
  • Exit codes: they are classified as well as messages. security(1) exits with the OSStatus low byte, so a localized message still classifies: 37 means no default keychain, 36 means interaction not allowed.
  • Mock keychain: the probe is skipped when the process already runs with --use-mock-keychain (E2E and isolated sidecars), because a mock keychain never prompts.
  • Ratchet test: a new test fails if any module other than the guard and the secret store's availability probe imports electron.safeStorage directly.
  • Wire: no change. A withheld keychain is local to the serve process.
  • SSH: the target case. A Mac served over SSH without a GUI session now starts.
  • Windows and Linux: unchanged.
  • Security: nothing is downgraded silently. While withheld, stores behave exactly as they do on a host without a keyring today, and the log and protection report say so.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck, and focused tests pass locally; CI covers the rest

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

Serve startup now probes macOS Keychain reachability before profile loading. If the probe reports an unavailable Keychain, the process withholds safe storage and warns. Secret stores use a guarded safe-storage interface that reports unavailable status and rejects encryption and decryption while withholding is active. Orca’s headless server also reports platform-specific credential-protection details.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to d2968

Serve’s keychain timeout path is correctly guarded. The remaining test gap does not show a current secrets failure, but the ratchet should cover permitted import forms to protect future changes.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: serve mode reports unavailable secrets instead of hanging on an unreachable macOS keychain.
Description check Passed The description follows the required template and provides a clear user-facing explanation, scope, rationale, linked issue, visual proof, testing details, known gaps, compatibility notes, and checklis…
Linked Issues check Passed For [#25453], serve startup calls withholdUnreachableKeychainForServe before profile loading. On macOS, the child-process probe has a 5-second bound. An unavailable keychain records a run-wide withh…
Out of Scope Changes check Passed The changed production files support the linked objective. The guarded safe-storage callers prevent later keychain hangs after startup. The serve warning and protection report describe the unavailable…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

❤️ Share

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

…eychain, ratchet direct safeStorage imports

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

🧹 Nitpick comments (1)
src/main/host/safe-storage-import-ratchet.test.ts (1)

24-26: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Make the ratchet cover permitted Electron access forms.

The test claims that only two files may access electron.safeStorage, but its regex matches only one named-import spelling. require('electron') is already used in src/main, so a require-based safeStorage access can bypass the ratchet. Namespace imports can bypass it as well. The quote-only fix handles only double-quoted named imports. Extend the check to all permitted access forms, preferably with an AST-based check.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4fe6d1ec-1024-4ceb-b4ab-2ca15a50d165
📥 Commits

Reviewing files that changed from the base of the PR and between 27970fd and d2968d1.

📒 Files selected for processing (6)
  • src/main/host/macos-keychain-reachability.test.ts
  • src/main/host/macos-keychain-reachability.ts
  • src/main/host/safe-storage-import-ratchet.test.ts
  • src/main/host/serve-keychain-guard.test.ts
  • src/main/host/serve-keychain-guard.ts
  • src/main/startup/main-process-ready-foundation.ts

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

@OrcaWin
OrcaWin merged commit 398cb84 into main Oct 11, 2026
51 checks passed
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

1 participant