Skip to content

fix(bots): never raise the macOS "Keychain Not Found" prompt - #262

Merged
sambitcreate merged 2 commits into
mainfrom
worktree-fix-keychain-not-found-prompt
Sep 30, 2026
Merged

sambitcreate merged 2 commits into
mainfrom
worktree-fix-keychain-not-found-prompt

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

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 HOME to a mkdtemp root (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 via security 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, createKeychainItem now runs security default-keychain -d user (which exits 1 silently under an isolated HOME). It requires an absolute quoted path whose file exists. Otherwise it throws BotCapabilityUnavailableError before calling add-generic-password. That's the same fail-closed outcome as pressing Cancel, without the modal. Reads were already silent (find-generic-password exits 44). Normal installs with a login keychain behave the same as before.

Tests

  • Existing keychain-anchor mocks answer default-keychain and inject keychainExists.
  • New regression covers exit-1 (isolated HOME), a missing keychain file and unparseable output. It asserts that add-generic-password is never invoked.
  • npm run test:bot-authority (11/11) and main/handlers/bots.contract.test.ts (12/12) pass locally. Local type-check only shows existing errors from the worktree resolving the parent checkout's node_modules; none are in the changed files.

🤖 Generated with Claude Code

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>
@very-hermes-bot

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 5f2eafed2e2344baa4e06e57103cacf3d43a9560
Generated: 2026-09-27T04:46:29+00:00
Reviews: 1

Summary

Automated E2E suites and packaged acceptance runs set HOME to temporary directories where no user keychain search domain exists, prompting securityd to display a blocking "Keychain Not Found — Reset To Defaults" modal dialog upon Bot capability anchor writes. This change introduces a preflight inspection using /usr/bin/security default-keychain -d user and verifies that the resolved path is absolute and points to an existing file before running add-generic-password. If the default keychain is missing, unparseable, or absent from the filesystem, writes fail closed by throwing BotCapabilityUnavailableError, avoiding any UI alert while preserving existing silent reads. Maintainers should double-check that test environments or headless runners where Bot capability persistence is expected have a valid, accessible keychain file configured if tests rely on successful writes.

Confidence Score: 5/5

Full end-to-end trace completed across callers, callees, Apple's security CLI output format, error propagation, and test coverage; behavior and edge cases verified.

📁 Important Files Changed
  • main/services/bot-capability-keychain-anchor.ts: Implements the hasDefaultKeychain preflight check and injectable keychainExists file check before invoking add-generic-password in createKeychainItem.
  • main/services/bot-capability-keychain-anchor.test.ts: Adds regression tests covering missing user domains (exit code 1), missing keychain files, and malformed command output; updates existing test doubles to mock default-keychain responses and pass keychainExists.
  • .memory/keychain-not-found-prompt.md: Records the root cause under isolated temporary HOME fixtures, the fail-closed rationale, and the fix in project memory.

Findings

No findings.

📊 Sequence Diagram
sequenceDiagram
    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
Loading

Machine-Readable Findings

[]

Last reviewed commit: 5f2eafed2e23
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

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

ℹ️ 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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];

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.

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.

@sambitcreate
sambitcreate merged commit 25a0052 into main Sep 30, 2026
22 checks passed
@sambitcreate
sambitcreate deleted the worktree-fix-keychain-not-found-prompt branch September 30, 2026 18:34
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.

2 participants