Repository navigation
Coordinate Keychain secret reads: change-gated, single-flight, circuit-broken - #85
Conversation
…ght, circuit-broken Every in-process secret read now goes through KeychainReadCoordinator: - The item's attribute fingerprint (prompt-free, microseconds) gates the ACL-checked secret read — one real read per credential rotation instead of one per 5-minute refresh cycle. - Concurrent readers of the same service/account share one underlying read; a background caller waits at most 2s on someone else's stuck read before reporting unavailable instead of piling onto a wedged securityd (2026-08-03 incident shape). - A denied/failed read trips a per-item breaker: background reads are answered locally until the item changes or a manual refresh succeeds.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee4b5df6c6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review findings: - An interactive (manual-refresh) read waited unbounded on a wedged background read of the same item — the exact failure it should recover from. It now waits the same bounded interval and then proceeds with its own read; an epoch guard keeps the late, stale background result from clobbering the fresher manual one. - The attribute fingerprint's modification date has one-second resolution, so a secret-only rotation in the same second could serve a stale cache indefinitely. Cached outcomes (including tripped breakers) now revalidate with a real read after 15 minutes, bounding staleness without reintroducing per-cycle reads.
Review finding: the attribute probe ran before the in-flight check, so against a wedged securityd concurrent callers could still stack inside SecItemCopyMatching before single-flight, the bounded wait, or the breaker applied. The probe now runs inside the same per-item flight as the secret read; a late arriver gives up without touching the Keychain at all.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6305a2a550
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…'s flight Review finding: the metadata probes ran SecItemCopyMatching directly, so against a wedged securityd they could still stack per caller — defeating part of the containment the coordinator provides. Public probes now share the item's single flight with the bounded wait (nil = unknown when stuck); the read path's own fingerprint stays raw because it already holds the flight.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5dc26a45c6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…y probe-free Cloud-review findings on the coordinator: - A freshly tripped entry now short-circuits before ANY Keychain traffic — the attribute probe included, since it blocks like any call against a wedged securityd. Change-detection for tripped items moves to the revalidation cadence (or a manual refresh). - A caller that times out behind a stuck flight now serves a fresh recovered value (e.g. from a manual read that succeeded while the wedged call never returned) instead of reporting unavailable — and logs when it has nothing to serve, since the wedged call may never produce its own diagnostic. - An interactive read that proceeds past a stuck flight defers its fingerprint probe until after its own read succeeds, so recovery can never hang on one more Security call; entries may now carry a nil fingerprint, which only the stale-flight fallback serves. - docs: scoped the Keychain-traffic promise to Claude Code's item and described Desktop's separate cached Safe Storage key read.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2f8a7d2c1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Cloud-review findings:
- The coordinated public probe path bypassed the breaker, so a
just-denied item still issued SecItemCopyMatching every refresh — the
metadata query blocks against a wedged securityd like any other call.
A tripped item now answers nil ('unknown') locally until revalidation.
- The interactive path's post-timeout probe was still one more Security
call that could wedge after the read succeeded. It is skipped
entirely when the flight was not acquired; the recovered value is
stored fingerprint-less (served only by the stale-flight fallback),
and the next clean background read re-reads for real.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: febe5f856c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… through the coordinator Review blockers: - withUISuppressed waited on an open approval dialog with no deadline, so an abandoned prompt could strand every concurrent refresh — the contention this gate exists to prevent. Both directions are bounded now; past the deadline the body runs with isSuppressed: false, which by contract yields a local unavailable without touching Security. - Claude's recovery probe was keyed (service, nil) while its read is keyed (service, currentUser), so it neither waited on that flight nor saw its breaker. Added genericPasswordForCurrentUserExists, which probes the exact item. - Claude Desktop and Sakana read Safe Storage keys with direct SecItemCopyMatching calls, outside single-flight and the breaker. Both now go through KeychainReadCoordinator.externalRead; denials throw from inside the flight so the breaker records them. - Corrected the coordinator's own doc comment, which overstated its coverage.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e0a941a14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…curity failure Review findings on externalRead: - It stored unconditionally, so a stuck background Safe Storage read finishing after a successful interactive recovery re-tripped the breaker and locked out callers for 15 minutes. It now carries the same epoch guard nonInteractiveRead uses. - Only the three denial statuses threw from inside the flight, so other failures (errSecNotAvailable, errSecIO) returned normally and CLEARED the breaker before the reader threw. Every non-hit, non-miss status now throws inside the flight.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a63fa6ecfd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review blocker: after an unavailable (service, currentUser) read the non-interactive path continued into the service-wide read — another SecItemCopyMatching behind the same wedge, and with several Claude Code items it could select a different account's login. This is the rule Copilot and Codex already follow; Claude was the inconsistent one. Broadening stays allowed only when this account's item provably does not exist, and the provider already refused lower-priority credentials once the status is permissionRequired, so nothing is lost.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a3cf58842
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review finding: nonInteractiveRead and externalRead drop a stale write, but interactiveRead still stored unconditionally — so when a second interactive read bypassed a pending one and recovered, the older read's later failure re-tripped the breaker and background refreshes reported the credentials unavailable for up to 15 minutes. Every path now goes through the same epoch-checked store.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d228766454
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…item Review finding: ClaudeAuthStore stops at an unreadable exact item, but the observer still ran the service-wide read straight afterwards. That read is keyed (service, nil), so it neither waits on the exact item's flight nor sees its breaker — it just issues another SecItemCopyMatching against the item that was protected. Same containment rule now.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68128d7b70
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…eason Review blocker: distinguishing 'ACL not approved yet' from 'keychain unreadable' by probing after the read is structurally unreliable — the failed read trips that item's breaker, and every later probe is answered nil locally, so the permission branch became unreachable from the second refresh onward. The category now comes from the read's own OSStatus (errSecAuthFailed / errSecInteractionNotAllowed mean the item exists and is merely unapproved), is remembered per item, survives the breaker, and clears on the next success. Also adds the reviewer-requested epoch-guard regression: a stalled interactive read completing after a newer recovery must not re-trip the item.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7dbb4de2f7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…es honest Review findings: - A background read that overlapped another provider's approval dialog got a synthetic errSecInteractionNotAllowed, which was recorded as a denial and tripped a 15-minute breaker on an item that was never attempted — and could tell the user to approve credentials nothing had asked for. Contention is now marked as such: no denial recorded, no breaker tripped. - ClaudeAuthStore classified a protected item by probing after the read had already tripped its breaker, so the probe was answered locally and the user was told to unlock the keychain instead of approving. It uses the read's own remembered verdict now. - externalRead replayed permissionRequired for every cached failure, so an errSecIO outage told Desktop/Sakana users to approve Safe Storage. The original category is replayed instead. - Split the coordinator tests (578 lines) back under the ~500 guideline.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81014f28ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review findings, all in the same theme: a failure has to say WHY, and a read that never happened must not speak for the item at all. - A probe that gives up behind a wedged flight now logs, like the two read paths already did. It was the only silent give-up left. - The contention rule moved into storeIfCurrent, so the interactive and external paths get it too. Previously only background reads honored it, and the Safe Storage readers turned a UI-gate skip into a denial plus a 15-minute lockout for an item that was never attempted. - The Safe Storage readers record the category they already computed, so the breaker's replays keep giving the same advice instead of degrading a real denial into "couldn't be read". - An interactive denial — the strongest ACL evidence there is, since the user just answered the dialog — is now recorded as well.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8463f34643
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The epoch guard dropped a store whose epoch no longer matched, which protected against a wedged read finishing after a newer one recovered the item. But two overlapping reads capture the same epoch, so whichever finished FIRST won: a stuck read that completed just before a manual recovery returned would leave the item tripped for the full window even though the user had just approved it. Reads now take a start ticket and a store is dropped only when an already-stored read started later. Both orderings then resolve in favor of the newer read, which is the one whose evidence is current.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54323773b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… denial Two more places where a fallback answered with something it did not know: - The single-flight timeout served any fresh cache entry. But the stuck read may be fetching a rotation of exactly that secret — its entry was cached against the item's earlier attributes — so a caller could authenticate with a superseded token. Only an interactive recovery's entry, which carries no fingerprint, may answer there now. - withUIAllowed proceeds when a suppressed call is wedged past its deadline, so an interactive read can run with process-wide UI still disabled and come back errSecAuthFailed. That looks exactly like an ACL denial but the prompt was never possible. The gate now tells the body whether UI was actually available, and a failure without it is recorded as contention rather than tripping the item for 15 minutes.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 749e3233ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
withUIAllowed separated interactive operations from suppressed ones but not from each other. Refresh All starts every provider concurrently, so one click could put several macOS approval dialogs on screen at once — the prompt storm this gate exists to prevent. Interactive operations are now exclusive of one another. The wait is unbounded on purpose: the holder is showing the user a dialog, and giving up early would produce exactly the concurrent prompts. The suppressed side keeps its own deadline, so it can still never block on an abandoned dialog.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50accf95bf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Regression from the contention fix: the guard threw on every read that ran while another dialog held the gate, including successful ones. An already-authorized Safe Storage item reads fine with UI disabled, so a manual refresh that had in fact just succeeded was failed and reported as a keychain error. Only a FAILURE without the gate is contention — which is what SecurityKeychainAccessor already did.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 288bfba5e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
External review: Refresh All prompt fan-out — fixedA second reviewer flagged that Verified and fixed: interactive Keychain operations are now exclusive of one another. The wait is unbounded on purpose — the holder is showing the user a dialog, and giving up early would produce exactly the concurrent prompts. The suppressed side keeps its own deadline, so it can never block on an abandoned dialog. Left for you to decide: the reviewer's alternative was to make Refresh All forceful but non-interactive and reserve approval for a per-provider Connect action. That removes the ability to approve from ⌘R and needs new UI, so it is a product call rather than something to land silently here. With this change, a user with N unapproved providers sees the dialogs one at a time instead of all at once. |
Making interactive operations exclusive stopped the concurrent prompts, but the wait was unbounded: an abandoned dialog would hang every later provider's manual refresh behind it, and a provider timeout cannot stop a synchronous straggler. Past the deadline the caller is now told UI is unavailable, which the existing contention path already turns into a logged, friendly busy error — so it neither hangs nor opens a second dialog beside the first.
…gerprint A background read whose fingerprint probe failed also stores its value with a nil fingerprint, so "no fingerprint" never meant "a user just approved this". A caller timing out behind a stuck flight could therefore be served a background value while that stuck read was fetching a rotation of the same secret. Entry now records whether an explicit user action produced the value, and only such an entry may answer there.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 74b2a6b1da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The bounded peer wait reported "UI unavailable" but the bodies still called SecItemCopyMatching — and in that case UI is ENABLED, so a second approval dialog could open beside the first. That recreated the storm the peer gate was added to prevent. The two failure modes need opposite handling, so they are now distinct states rather than one Bool: .suppressionStuck still runs the query (an authorized item reads fine, and only a FAILURE is discounted), while .peerBusy skips Security entirely and reports the friendly busy error.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fafc445eca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
contendedKeys is keyed by item, not by read, and the marker was consumed only AFTER the sequence guard. So a read that recorded contention and then lost the sequence race left its marker behind, and the next read's genuine Security failure absorbed it and skipped tripping the breaker — Runway would keep calling securityd exactly when it should back off, which inverts the guarantee this class exists for. The marker is now consumed before the guard: it belongs to the read that is reporting its outcome, and every path that records one reaches this method. The regression test pins the interleaving that leaks it (the contention is recorded after the newer read has already stored, so nothing else consumes it first) and fails against the old ordering.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
… cookie A keychainFailure from the Safe Storage read — a locked keychain, or another provider holding the UI gate — fell into the generic catch and set sawInvalidCookie, so the card said the cookie was invalid and asked the user to sign in again. The cookie was never examined. It now takes the existing sawUnreadableKey path, which reports credentialsUnreadable.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
… them My previous fix handled only one ordering. The marker was still item-wide, so the inverse case remained: read A records contention, overlapping read B hits a genuine Security failure, B consumes A's marker, and B's failure is excused — the breaker never trips and the next refresh calls securityd again. Same severity as the ordering I already fixed, and my comment claiming the marker belonged to the storing read was simply wrong. Both side channels are now keyed by read sequence rather than by item, and each read receives a ReadTicket it passes back when reporting what it observed. Two reads of the same item overlap routinely, so nothing one read saw can be consumed by another. The failure category rides the same path, so it lands with the outcome it describes or not at all — which also closes the unsequenced-category gap. Tests cover both orderings; the new one fails against the previous code.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
External review: the contention-marker fix was incomplete — now fixed properlyA second reviewer pointed out that moving the marker removal before the sequence guard closed only one ordering. The inverse remained, and I reproduced it:
That is the same severity as the ordering already fixed — the safety guarantee inverted, not a messaging problem — and my code comment claiming the marker belonged to the storing read was simply wrong. Fix: both side channels are keyed by read sequence instead of by item, and every read now receives a
|
…rets in-process (#86) > Stacked on #85 (`keychain-read-coordinator`), which is stacked on #84. **TL;DR**: The ownership rule — only the app that owns a credential may modify it — is now enforced by the type system, and the one secret Runway actually owns moves to in-process Keychain storage with no subprocess and no secret in an argument list. ## What was happening - Every store held the full read/write `KeychainAccessing` protocol, so nothing but discipline stopped a future change from writing another app's credential item — exactly the class of bug PR #84 removed for Claude. - Runway's own secret (the iCloud-sync device id) was written through `/usr/bin/security add-generic-password`, which passes the value through the subprocess argument list (briefly visible to `ps`) and ACL-binds the item to the helper binary instead of Runway. ## What this changes - Splits the Keychain protocol: `KeychainReading` (reads, probes, fingerprints) and `KeychainAccessing: KeychainReading` (writes). Stores that consume another app's credentials — Claude auth store, config-dir discovery, default-account observer, Copilot, Antigravity — now hold only `KeychainReading`, making a foreign-store write a compile error. - Adds `RunwayOwnedKeychainStore` for Runway-owned secrets: in-process `SecItemAdd`/`SecItemCopyMatching`/`SecItemUpdate`, a Runway-specific account, silent reads (the creating process's ACL), no subprocess. - Migrates the iCloud-sync device id to a Runway-owned v2 item with a one-time copy from the v1 item, so existing devices keep their iCloud record instead of minting a duplicate. The v1 item stays behind orphaned (its ACL belongs to the subprocess, so Runway cannot silently delete it) and is never read again once v2 exists. - Docs: a "Credential ownership" section in `docs/architecture.md`. ## Heads-up - **Deviation from the original plan**: the plan said `kSecUseDataProtectionKeychain`. My first rationale for skipping it was wrong and has been corrected: release builds — and dev builds that find an iCloud provisioning profile — *are* signed with `com.apple.application-identifier` and `keychain-access-groups` (`script/render_icloud_entitlements.sh`), so the data-protection keychain would work there. The real constraint is that a plain local build signs with `Runway.local.entitlements.plist`, which carries neither; choosing per build flavor would split this item across two stores and mint a second iCloud sync identity for the same Mac. The login keychain behaves identically everywhere and already delivers what motivated the move (no subprocess, no argv exposure, app-owned ACL). An entitlement-gated migration with a copy-forward is viable follow-up. - Codex and Cursor still write their providers' stores (token rotation) and keep `KeychainAccessing`; extending the read-only ownership model to them is the planned follow-up after this stack, since it changes their refresh behavior the way #84 changed Claude's. ## Tests - Device-id migration: legacy v1 value is copied into the owned v2 item once and never consulted again; a missing id stays `nil`; dev/prod bundle scoping preserved. - `RunwayOwnedKeychainStore` round-trip + in-place update against a real login keychain (skips where unavailable). - The protocol split itself is compile-time enforcement; the existing Claude no-write regression tests from #84 still pass on top. - `swift test`: 1,678 tests, 0 failures. --- ## Review follow-up (later commit on this branch) - **The legacy device-id migration no longer mints a duplicate identity.** The existence gate used `== true`, so an *unknown* probe (locked keychain, suppressed UI) read as "no legacy item" — and with v2 and the saved preference both gone, `resolveDeviceID` minted a fresh UUID and published a **second iCloud device record** for a Mac that already had one. The probe is tri-state now: `false` migrates nothing (fresh install, no subprocess), unknown throws so the store surfaces its existing duplicate warning, `true` proceeds.
…sr/bin/security (#87) > Stacked on #86 (`credential-ownership-model`) → #85 → #84. Closes the gap a post-stack review found: the exact `/usr/bin/security find-generic-password` pattern behind the 2026-08-03 prompt loop was still live for Copilot (and Antigravity), including at launch. **TL;DR**: The read-only providers' Keychain reads (Copilot's `gh:github.com`, Antigravity's `gemini`/`antigravity`) now run in-process through the coordinator: automatic refreshes are prompt-free by construction, and only a manual refresh may raise the approval dialog — once, authorizing Runway itself. ## What was happening - `CopilotAuthStore` and `AntigravityAuthStore` read their foreign Keychain items through the `/usr/bin/security` subprocess — the prompt-capable path whose dialogs authorize the helper binary instead of Runway, so approvals never stick to the app and the prompt can recur every cycle. Launch-time credential detection used the same path. - The PR #85 coordinator only covered in-process reads, so these subprocess reads bypassed the fingerprint gate, single-flight, and circuit breaker entirely. ## What this changes - `KeychainReading` gains account-scoped `readGenericPasswordWithoutUserInteraction(service:account:)` and `readGenericPasswordAllowingUserInteraction(service:account:)`; `SecurityKeychainAccessor` serves both through the existing coordinated in-process path (change-gated, single-flight, circuit-broken). Mock defaults route them through the plain account read, so existing test fakes are untouched. - Copilot: `loadToken` / `loadBillingTokenCandidates` take `allowKeychainInteraction` (default false). Automatic refresh and `hasLocalCredentials` use the prompt-free form; a manual refresh uses the interactive form. A denied interactive read is not retried through the broader service-only lookup — that would just repeat the same prompt. - Antigravity: `loadKeychainToken` gets the same mode split; an unauthorized item on the automatic path surfaces the existing friendly "couldn't read credentials" error locally instead of prompting. - Docs: prompt behavior notes in `docs/providers/copilot.md` and `docs/providers/antigravity.md`. ## Heads-up - **One-time migration friction**: users whose previous "Always Allow" was granted to `/usr/bin/security` will see the Copilot/Antigravity Keychain source report unavailable until one manual refresh re-approves access for Runway itself. After that, reads are silent and survive forever (the grant now sticks to the app). File-based sources (editor config, `hosts.yml`) are unaffected and remain first in line. - Also in this push (amendments from the same review, committed to their own PRs): the fingerprint probe now runs **inside** the coordinator's single flight (#85 — a late arriver no longer touches the Keychain at all, not even the attributes query), and the iCloud device-id migration seeds from the saved UserDefaults copy so the legacy prompt-capable read runs only after a preferences reset, at most once (#86). - After this PR, the only remaining `/usr/bin/security` reads (and writes) belong to Codex and Cursor — the disclosed read-write ownership audit that follows this stack. ## Tests - `ReadModeTrackingKeychain` regression tests: automatic Copilot/Antigravity loads perform only prompt-free reads and never the subprocess-style path; manual loads use the interactive read; an `.unavailable` item throws the friendly error without prompting. - Coordinator: new test proving a late arriver behind a stuck read performs no Keychain call at all (#85); iCloud tests proving the saved-preference seed never touches the legacy path and legacy recovery runs at most once (#86). - `swift test`: 1,689 tests, 0 failures. --- ## Review follow-ups (later commits on this branch) - **Copilot billing keeps the permission state.** `loadBillingTokenCandidates` discarded `keychainPermissionRequired`, so an org-managed seat fell back to an editor token that usually lacks billing scopes and the card said "you need billing access" when an existing credential just needed approval. - **Antigravity gained a permission-specific error.** A protected item mapped to `credentialStoreUnreadable`, whose text says unlock Keychain / sign in again — neither fixes an unapproved ACL. - **Corrected the CLI documentation twice.** `--force` is not equivalent to ⌘R (it never prompts), *and* — the part I got wrong on the first pass — approving an item in the app does **not** authorize the command, because `runway` is a separately signed binary and macOS grants Keychain access per binary. Keychain-only providers reach the CLI through the app's shared snapshot instead. ### Correction An earlier revision of this description said Codex/Cursor writes were the only remaining `/usr/bin/security` use. That omitted the one-shot, existence-gated **legacy iCloud device-id migration read**, which remains after the whole stack. Also in later commits on this branch: Copilot billing keeps its permission state, Antigravity distinguishes a locked keychain from an unapproved ACL (they need opposite advice), and `ProviderRefreshContext` carries `isForced` separately from `isManual` so `runway --force` keeps bypassing negative caches without unlocking credential UI.
…security (#89) > Stacked on #88, the tail of the credential stack. Closes the "High" finding from the latest post-stack review: Codex and Cursor could still recreate the automatic password-prompt loop. **TL;DR**: The last automatic prompt-capable `/usr/bin/security` reads — Codex's keyring lookups (detection, refresh fallback, unattended identity warming) and Cursor's two per-load reads — now run in-process through the coordinator, prompt-free on every automatic path. ## What was happening - `CodexAuthStore.loadKeychainAuth` and `CursorAuthStore`'s keychain reads used the `/usr/bin/security` subprocess: prompt-capable, ACL'd to the helper binary, uncoordinated, and running on launch detection, every automatic refresh, and Codex's background identity-warm task. - A protected item silently collapsed into "not logged in", so keychain-only logins were undetectable and unapprovable. ## What this changes - Codex `loadKeychainCredentials` / Cursor `loadCredentials` (tri-state like Copilot's): automatic paths use the prompt-free in-process reads; only a manual refresh may raise the approval prompt — once, authorizing Runway itself. - A protected item reports **permission-required**: it counts as a credential footprint for seeding, and the card says "…login found in Keychain. Refresh manually and choose Always Allow to connect it." - Cross-login guard mirrors the Copilot fix: a protected exact item (per-home Codex account item) never broadens to the service-only lookup, which could silently select a different login. Other Codex homes are still tried — each read targets its own exact account. - The unattended identity-warm task keeps its collapse-to-nil behavior (a protected home stays hidden with the existing log line) and is prompt-free by construction. - Docs: prompt behavior notes in `docs/providers/codex.md` / `cursor.md`; `docs/architecture.md` now states every provider's automatic Keychain reads are in-process and prompt-free. ## Also in this stack push (fixes from the same review, committed to their PRs) - **#85**: public existence/fingerprint probes now share the coordinator's per-item flight — a probe of an item whose read is wedged returns "unknown" within the bounded wait instead of stacking another `SecItemCopyMatching` onto securityd. - **#86**: the legacy device-id migration is gated on a prompt-free existence probe, so a fresh install never spawns the `/usr/bin/security` subprocess at all. ## Heads-up - Same one-time migration friction as #87: an "Always Allow" previously granted to `/usr/bin/security` doesn't carry over; the card shows the permission-required message until one manual refresh re-approves for Runway. The grant then sticks to the app permanently. - After this PR the only `/usr/bin/security` invocations left are Codex/Cursor **token-rotation writes** and the one-shot legacy device-id migration (now existence-gated). The write side is the remaining ownership audit — it decides whether Codex/Cursor become read-only like Claude, which changes rotation behavior and deserves its own design pass. ## Tests - Codex + Cursor read-mode regression tests (shared `ReadModeTrackingKeychain`): automatic loads perform only prompt-free reads, manual loads only interactive ones, never the subprocess-style path; protected items report permission-required and never broaden; a coordinator test proves probes don't stack behind a wedged read; an iCloud test proves fresh installs never spawn the legacy read. - `swift test`: 1,698 tests, 0 failures. --- ## Review follow-ups (later commits on this branch) - **Reset-credit claims can request approval.** `CodexResetClaimService` loaded keyring credentials non-interactively and collapsed permission-required to `nil`, so clicking **Use** reported a generic "Couldn't reset usage" while the credential that could serve it sat unread. Claiming is an explicit user action, so it may prompt exactly like a manual refresh. - **A denied Codex prompt stops the scan** on this branch too (it was previously only fixed downstream), so this PR is correct standing alone: an interactive denial returns `permissionRequired` immediately instead of opening one dialog per remaining Codex home.
TL;DR: Every in-process read of another app's Keychain item now goes through a small coordinator that only touches the secret when the item actually changed, shares one read between concurrent callers, and stops retrying an item after a denial until it changes or the user acts. (Runway's own item stays outside it — its ACL names Runway, so it never prompts or contends.)
What was happening
What this changes
KeychainReadCoordinator(process-wide, injected intoSecurityKeychainAccessor):.unavailableinstead of adding another blocked call to a wedged securityd.docs/providers/claude.md.Heads-up
nilfingerprint (item absent, or probe failed on a locked keychain) is never cached: it cannot distinguish those two cases, so such reads always go through./usr/bin/security) read path used by other providers is not coordinated here; it is in scope for the ownership follow-up (PR 3).Tests
SecItemUpdateon a real item moves the fingerprint and the next read returns the fresh secret (skips where the keychain is unavailable).swift test: 1,667 tests, 0 failures.Review follow-ups (later commits on this branch)
withUISuppressedwaited on an open approval dialog with no deadline, so an abandoned prompt could strand every concurrent refresh — the contention this gate exists to prevent. Past the deadline the body runs withisSuppressed: false, which by contract yields a local unavailable without touching Security.framework.(service, nil)while its read is keyed(service, currentUser), so it neither waited on that flight nor saw its breaker. AddedgenericPasswordForCurrentUserExists.externalReadentry point (they decode their own payloads, so they don't speakNonInteractiveKeychainRead). Denials throw from inside the flight so the breaker records them.Scope note
At this branch, subprocess (
/usr/bin/security) readers still exist for the providers converted later in the stack — the coordinator covers the in-process path here, and #87/#89/#90 move the remaining providers onto it. Runway's own item (RunwayOwnedKeychainStore) stays outside by design: its ACL names Runway, so it never prompts or contends.Later review follow-ups on this branch
(service, currentUser)item, and a protected item ends the lookup instead of broadening to a service-wide read that could select another account's login.externalRead) with an epoch guard; every failing Security status trips the breaker.