Skip to content

Read Codex and Cursor credentials in-process, never through /usr/bin/security - #89

Merged
mstallone merged 42 commits into
silence-share-card-test-beepfrom
codex-cursor-reads-in-process
Aug 4, 2026
Merged

mstallone merged 42 commits into
silence-share-card-test-beepfrom
codex-cursor-reads-in-process

Conversation

@mstallone

@mstallone mstallone commented Aug 3, 2026 •

Copy link
Copy Markdown
Owner

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)

Heads-up

  • Same one-time migration friction as Read Copilot and Antigravity credentials in-process, never through /usr/bin/security #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.

…security

Completes the read-side conversion the earlier PRs started: the last
automatic prompt-capable subprocess reads belonged to Codex (keyring
detection, refresh fallback, identity warming) and Cursor (two reads
per credential load).

- Automatic refreshes and launch detection use the prompt-free
  in-process form; only a manual refresh may prompt, once, for Runway
  itself.
- A protected item counts as a login footprint and surfaces a
  permission-required card instead of 'not logged in'; a protected
  exact item never broadens to the service-only lookup (cross-login
  guard, mirroring Copilot).
- The unattended Codex identity-warm task stays prompt-free by
  construction.

The only remaining /usr/bin/security use is Codex/Cursor token-rotation
writes plus the one-shot legacy device-id migration — the write-side
ownership audit stays follow-up work.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e9a03b374

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

…val fix

Review findings:
- probe()'s pre-rotation reload still read the keyring item (and the
  legacy service item) through the subprocess path, so an expiring
  keychain token could raise a prompt from an automatic refresh. Both
  reloads now use the non-interactive in-process read — served from
  the coordinator cache, since the item was just read to get here.
- The unattended identity-warm task now distinguishes a protected
  hidden home and logs the exact fix instead of a generic bind
  failure. An interactive binding flow for hidden keyring homes needs
  a product decision and is tracked as follow-up in the PR.
… free SQLite token

Review finding: with the keychain items protected, the existing
free-membership/different-subject preference could not run, and the
load silently accepted the free SQLite token — possibly the wrong
account, with no path to approval. A free SQLite login now yields the
permission-required state when protected keychain items exist; a paid
SQLite login keeps winning, as it always has.
Review finding: with the access item approved but the refresh item
still protected, the load returned a partial state that works until
the access token expires and then fails as a misleading 'token
expired'. Protected-item detection is now per item, so any confirmed
protected companion surfaces the permission-required state instead of
a partial login.
…for keychain entries that cannot win

Review findings:
- The Codex legacy service-only path treated a nil existence probe
  (locked keychain: cannot check) as absent, silently reporting 'not
  logged in'. Only a confirmed-absent item does now.
- A manual Cursor refresh ran prompt-capable reads before source
  selection, so a paid SQLite login raised approval dialogs for stale
  agent keychain entries it then ignored. Interactive reads now run
  only when the keychain can actually win selection.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a3652c8bd

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0046106984

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f028070117

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af05819dc9

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

… a denial

Review findings:
- 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 ask for
  approval exactly like a manual refresh.
- Backported the denied-prompt guard so this PR is correct standing
  alone: an interactive denial returns permissionRequired immediately
  instead of opening one dialog per remaining Codex home.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d42dc74996

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

…he claim

Review finding: my reset-claim fix asked for approval unconditionally,
so a user whose auth.json already works would see a Keychain dialog for
nothing. The interactive read now runs only when no file candidate
carries a usable access token.
Review finding: the docs said a keyring-only home 'sometimes needs one
additional Runway launch', which is untrue when Runway has never been
approved to read that item — relaunching forever changes nothing. The
entry now names that case and points at the only current remedy, with
the planned in-app flow called out.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46e4a2ddc3

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

…ctually rejected

Review finding: my previous gate keyed off whether a file token was
structurally usable, so a rejected-but-well-formed auth.json suppressed
the prompt and the claim failed with a generic error while the live
keyring item sat unread. claim() now runs a prompt-free pass first —
identical request count on the happy path — and only when that fails
does it ask for approval and retry once with whatever the approval
adds.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8fe308ffc

ℹ️ 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: retrying whenever the first pass returned .failed meant
a timed-out or 5xx credit-list request could open a Keychain approval
dialog even though nothing was rejected. matchCredit and consume now
distinguish 'every candidate refused as unauthenticated' from any other
failure, and only that case asks.
@mstallone mstallone closed this Aug 4, 2026
Both docs/architecture.md and ProviderRefreshContext said a manual
refresh was the ONLY thing that could raise an approval dialog. Since
reset claims escalate to an interactive credential load once every
readable credential was rejected, clicking Use is a second one. The
shared rule is what both now state: a prompt must follow directly from
something the user just clicked.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed14afc92f

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0acd7e1e0

ℹ️ 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 interactive branch returned .permissionRequired for every failure,
so a manual refresh against a locked login keychain told the user to
choose Always Allow — which cannot fix it. It consults the same recorded
verdict the automatic branch already uses.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 874c527537

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14d50ffd47

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

…ey can't help

- A reset claim loaded the keyring before trying any file candidate. The
  read is a synchronous securityd round trip, so a wedged securityd left
  the row on "Resetting…" even though a working auth.json could have
  completed the claim. It now skips the Keychain entirely while a usable
  file credential exists; a keyring-only user still gets the prompt-free
  read, and the interactive escalation is unchanged.
- Cursor's protected-item check used == true, so an indeterminate probe
  read as absent — surfacing a keychain-only login as "Not logged in",
  or letting a free SQLite account win. Only a confirmed absence counts
  as no footprint, matching every other provider.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94bb427b88

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

Last provider with this shape: an indeterminate existence probe and no
recorded category — exactly what UI-gate contention leaves — set
permissionRequired, so the card asked for Always Allow on an item that
was never looked at. Both branches now switch on all three probe states,
matching Copilot, Cursor, and Antigravity.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2cd54aa07

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e05578b6a6

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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@mstallone
mstallone merged commit 7f9c85a into main Aug 4, 2026
2 checks passed
mstallone added a commit that referenced this pull request Aug 4, 2026
…t-broken (#85)

> Stacked on #84 (`claude-credentials-read-only`).

**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

- Every 5-minute refresh (plus the default-account observer) performed a
full ACL-checked secret read of Claude's Keychain item, even though the
item rarely changes.
- During the 2026-08-03 incident, securityd was wedged behind approval
dialogs; Runway's repeated reads stacked onto it, its own refreshes
blocked for 150 s, and there was no backoff — the next cycle piled on
again.
- Two Claude cards (default + extra account) could read concurrently
with no coalescing.

## What this changes

- New `KeychainReadCoordinator` (process-wide, injected into
`SecurityKeychainAccessor`):
- **Change-gated reads** — an attributes-only fingerprint probe
(prompt-free, no ACL evaluation, microseconds) runs first; the secret is
re-read only when the fingerprint moved (e.g. Claude Code rotated its
token). One real read per rotation instead of one per cycle.
- **Single-flight** — concurrent readers of the same service/account
share one underlying read. A background caller waits at most 2 s on
someone else's stuck read, then reports `.unavailable` instead of adding
another blocked call to a wedged securityd.
- **Circuit breaker** — after a denied/failed read (background or an
explicitly denied manual prompt), background reads of that item are
answered locally with no Keychain traffic until the item's fingerprint
changes or a manual-refresh read succeeds.
- Interactive (manual-refresh) reads always go through to securityd —
they are the one place a prompt is legitimate — and seed the cache /
clear the breaker on success.
- Docs: keychain paragraph in `docs/providers/claude.md`.

## Heads-up

- Cached secrets live in process memory only — the same lifetime as the
credential states providers already hold between refreshes.
- A `nil` fingerprint (item absent, or probe failed on a locked
keychain) is never cached: it cannot distinguish those two cases, so
such reads always go through.
- The subprocess (`/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

- Unit tests for the coordinator: cache hit on unchanged fingerprint,
re-read on change, no caching without a fingerprint, breaker trip/reset,
interactive success clearing the breaker, interactive denial tripping
it, and a threaded single-flight/pile-up test.
- A live login-keychain integration test: `SecItemUpdate` on 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)

- **The global UI gate is bounded in both directions.**
`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. Past the deadline the body runs
with `isSuppressed: false`, which by contract yields a local unavailable
without touching Security.framework.
- **Recovery probes hit the exact item.** Claude's 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`.
- **Claude Desktop and Sakana Safe Storage reads joined the
coordinator** via a new `externalRead` entry point (they decode their
own payloads, so they don't speak `NonInteractiveKeychainRead`). Denials
throw from inside the flight so the breaker records them.
- **The breaker covers metadata probes**, and a caller that times out
behind a stuck flight serves a freshly recovered value rather than
reporting unavailable.

### 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

- The suppressed side of the UI gate is bounded, so an abandoned
approval dialog can't strand concurrent refreshes.
- Recovery probes use the exact `(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.
- Claude Desktop and Sakana Safe Storage reads run inside the
coordinator (`externalRead`) with an epoch guard; every failing Security
status trips the breaker.
mstallone added a commit that referenced this pull request Aug 4, 2026
…hain write path (#90)

> Stacked on #89, the tail of the credential stack. Completes the
write-side ownership audit the post-stack reviews kept flagging — the
last automatic prompt-capable paths (token-rotation writes through
`/usr/bin/security`) are gone.

**TL;DR**: Codex and Cursor join Claude as strictly read-only credential
consumers. With no writers left, the Keychain write protocol, the
accessor's write methods, and the `security add-generic-password`
subprocess (secrets in argv) are deleted outright — the only Keychain
write API remaining in the app is `RunwayOwnedKeychainStore`.

## What was happening

- Codex and Cursor automatically refreshed expiring tokens through the
providers' OAuth endpoints and wrote the rotated pairs back into the
providers' own stores (`auth.json` / keyring; Cursor's `state.vscdb` /
keychain items) via prompt-capable subprocess writes. Both providers'
backends have refresh-token reuse detection — Codex even carries a code
comment about tripping `refresh_token_reused` (issue robinebers#516) — so this was
the same incident class the Claude read-only change (#84) closed, still
live for two providers.
- A failed persistence stranded the old refresh token on disk, so the
next cycle could rotate again — the shape of a recurring five-minute
prompt loop.

## What this changes

- **Codex**: never calls `auth.openai.com/oauth/token`, never writes
`auth.json` or the keyring. The pre-fetch reload that adopts the `codex`
CLI's own rotation stays (it is read-only and the reason meters keep
working while the CLI is in use). A hard-expired token or a usage
401/403 shows **"Codex login needs renewal. Run `codex`, then refresh
Runway."** — with source fallback preserved and local spend tiles
unaffected. The refresh-era error cases
(`sessionExpired`/`tokenConflict`/`tokenRevoked`/`tokenExpired`)
collapse into one `loginRenewalRequired`.
- **Cursor**: never calls the token endpoint, never writes the state
database or keychain. Renewal notice: **"Cursor login needs renewal.
Open the Cursor app (or run `agent login`), then refresh Runway."** —
naming both remedies, since the keychain-source credential belongs to
the agent CLI. `SQLiteAccessing.execute` (only used to write Cursor's
DB) is deleted.
- **Write path deleted**: `KeychainAccessing` collapses into
`KeychainReading` everywhere; `SecurityKeychainAccessor` loses its write
methods and the `writePassword` subprocess helper. The one remaining
`/usr/bin/security` invocation in the app is the one-shot,
existence-gated legacy device-id migration read.
- **Prompt bounds** (from the review): a denied Codex prompt stops the
per-home scan (never one dialog per home); a denied Cursor access-item
prompt never chains into the refresh-item prompt; Cursor's unknown
existence probe (`nil` = locked keychain) no longer collapses into "not
logged in", matching Codex.
- **Docs**: `architecture.md`'s ownership section is now unconditional
(resolving the contradiction the review flagged), `privacy.md`,
`codex.md`, `cursor.md` rewritten to the read-only reality, with renewal
troubleshooting entries.

## Heads-up

- Live Codex/Cursor meters now pause when the owning app hasn't run
recently enough to hold a fresh token, showing the renewal notice — the
same deliberate trade Claude made in #84. While the CLI/app is in active
use it rotates its own token and Runway picks it up on the next read
(Codex explicitly re-reads the live store before each fetch).
- Kimi and Grok still refresh their own providers' tokens, but through
file stores only — no Keychain, no prompts, outside this incident class.
Their ownership audit can follow the same recipe later.
- Codex now degrades exactly like Claude — local spend tiles under a
header warning — for both a lapsed login and a pending keyring approval.
(An earlier revision listed this as future cosmetic follow-up; it is
implemented.)

## Tests

- Read-only regressions mirroring #84: an expired Codex/Cursor token
performs zero token-endpoint calls and zero store writes and shows the
renewal notice; a usage 401 does one call (no refresh-and-retry).
- Prompt bounds: denied Codex prompt → exactly one interactive read
across homes; denied Cursor access prompt → exactly one interactive read
total.
- Refresh-era tests (rotation persistence, refresh-endpoint parsing)
removed with the machinery.
- `swift test`: 1,706 tests, 0 failures.

---

## Review follow-ups (later commits on this branch)

- **A rejected token now tries this account's other local credential
once.** Cursor's app and its `agent` CLI keep separate copies, and one
can outlive the other. Previously only an *expired* selection fell back,
so a revoked-but-unexpired token 401'd straight into the renewal notice
while a live same-account token sat unread. The retry makes no OAuth
call, writes nothing, and requires matching JWT subjects so it can never
cross accounts.
- **An expired paid SQLite login can reach its protected keychain
token.** `keychainCanWin` suppressed prompts for every paid SQLite
login, so even a manual refresh returned the dead credential with advice
Runway could not act on.
- **Scoped the no-write claims honestly.**
`privacy.md`/`architecture.md` said Runway never writes another tool's
credential files, but Grok and Kimi are refreshed and saved back to
their CLIs' own files. The guarantee is now scoped to the Keychain
(which the type system enforces), with Grok/Kimi and Antigravity's
Google OAuth refresh named as the exceptions.

### Later review follow-ups on this branch

- A rejected token retries this account's other local credential once
(no OAuth call, subject must match), and reports the alternative's *own*
failure rather than a bogus renewal notice.
- A protected alternative asks for approval instead of collapsing to "no
alternative".
- A live SQLite login beats an expired agent login; an expired paid
login can still reach its protected keychain token.
- The Cursor credential tests moved to `CursorCredentialTests.swift` to
stay within the repository's ~500-line guideline.
@mstallone
mstallone deleted the codex-cursor-reads-in-process branch August 4, 2026 17:18
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.

1 participant