Repository navigation
fix(bots): never raise the macOS "Keychain Not Found" prompt - #262
Conversation
E2E and packaged acceptance launches run Electron with an isolated HOME, so `security add-generic-password` for the Bot capability authority items has no default keychain and securityd shows a modal "Keychain Not Found / Reset To Defaults" alert on every run. Preflight `security default-keychain -d user` before each Keychain write and fail closed with BotCapabilityUnavailableError when no default keychain file exists — the same outcome as pressing Cancel, without the prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hermes Review BotConfidence: 5 Engine: SummaryAutomated E2E suites and packaged acceptance runs set Confidence Score: 5/5Full end-to-end trace completed across callers, callees, Apple's 📁 Important Files Changed
FindingsNo findings. 📊 Sequence DiagramsequenceDiagram
participant Caller as Caller
participant Anchor as KeychainAnchor
participant Security as /usr/bin/security
participant FS as FileSystem
Caller->>Anchor: write(account, value)
Anchor->>Security: default-keychain -d user
alt No default keychain (exit 1 / unparseable)
Security-->>Anchor: exitCode != 0 or unparseable
Anchor-->>Caller: throw BotCapabilityUnavailableError
else Default keychain reported
Security-->>Anchor: "keychain-path" (exit 0)
Anchor->>FS: stat(keychain-path)
alt File missing or not a file
FS-->>Anchor: ENOENT / isFile() == false
Anchor-->>Caller: throw BotCapabilityUnavailableError
else File exists
FS-->>Anchor: isFile() == true
Anchor->>Security: add-generic-password -U -a ... -s ... -w (via stdin)
Security-->>Anchor: exit 0
Anchor-->>Caller: write complete
end
end
Machine-Readable Findings[]
|
There was a problem hiding this comment.
ℹ️ Minor suggestion only; no critical issues.
Reviewed changes This review covers the Keychain preflight, its regression tests, and the recorded incident context.
- Fail-closed Keychain writes Checks the default user keychain path exists before attempting Bot capability or Telegram binding writes.
- Regression coverage Adds cases for missing, absent, and unparseable default keychain results.
GPT Luna | 𝕏
| ): Promise<boolean> { | ||
| const result = await command(["default-keychain", "-d", "user"]); | ||
| if (result.exitCode !== 0) return false; | ||
| const file = DEFAULT_KEYCHAIN_LINE.exec(result.stdout.trim())?.[1]; |
There was a problem hiding this comment.
The parser assumes the quoted path contains no embedded ", but macOS filenames may contain quotes and Apple's formatter does not escape them. A valid custom default keychain at such a path is therefore rejected here and every Bot authority write fails closed; please parse the outer delimiters without rejecting valid path characters.

Problem
Local E2E and packaged acceptance runs kept popping the macOS modal "Keychain Not Found — A keychain cannot be found to store
user-data:<sha256>" with a Reset To Defaults button.These launches set
HOMEto amkdtemproot (tests/e2e/fixtures.ts,pi-session-packaged-restart-acceptance,subagent-run-store-packaged-acceptance,run-packaged-diagnostics-acceptance). At startup the Bot capability checkpoint and Telegram Bot binding store write their rollback/bootstrap items viasecurity add-generic-password. Under the fake HOME there is no user keychain domain, so securityd shows the alert. Every run uses a new temp root, so the hash in the item name changes each time.Fix
Before each Keychain write,
createKeychainItemnow runssecurity default-keychain -d user(which exits 1 silently under an isolated HOME). It requires an absolute quoted path whose file exists. Otherwise it throwsBotCapabilityUnavailableErrorbefore callingadd-generic-password. That's the same fail-closed outcome as pressing Cancel, without the modal. Reads were already silent (find-generic-passwordexits 44). Normal installs with a login keychain behave the same as before.Tests
default-keychainand injectkeychainExists.add-generic-passwordis never invoked.npm run test:bot-authority(11/11) andmain/handlers/bots.contract.test.ts(12/12) pass locally. Localtype-checkonly shows existing errors from the worktree resolving the parent checkout'snode_modules; none are in the changed files.🤖 Generated with Claude Code