Skip to content

Keep shared Codex auth read-only during usage refresh - #2970

Merged
steipete merged 20 commits into
mainfrom
fix/2944-codex-auth-readonly
Aug 16, 2026
Merged

Keep shared Codex auth read-only during usage refresh#2970
steipete merged 20 commits into
mainfrom
fix/2944-codex-auth-readonly

Conversation

@steipete

Copy link
Copy Markdown
Owner

Summary

  • Merge @Yuxin-Qiao's read-only Codex OAuth work from Keep shared Codex auth read-only during usage refresh #2944 onto current main, preserving all contributor commits and authorship.
  • Keep native and external shared auth files read-only during usage refresh: CodexBar no longer redeems or publishes their refresh tokens.
  • Delegate stale native credentials to CLI-owned recovery, fail closed for stale legacy/OpenCode credentials, and make recovery errors explicitly recommend codex login.
  • Preserve the winning in-memory OAuth snapshot through reset-credit enrichment so a concurrent CLI login cannot mix accounts.
  • Resolve account scope from direct, namespaced, and organization JWT claims without persisting or logging token material.

Maintainer review findings

The core ownership thesis is sound, but the stale PR still had two blocking routing gaps. Automatic mode could reach an unscoped CLI fallback while a managed workspace was selected, and stale external credentials could also fall through to the CLI instead of failing closed. This repair suppresses both paths and adds regressions for each.

The production usage path has no call to CodexOAuthCredentialsStore.save or CodexTokenRefresher.refresh; only fixture/test code uses those helpers. CODEX_HOME keeps documented precedence, explicit homes never borrow external credentials, and external discovery remains opt-in and off by default. Touched logging paths carry only classifications/metadata, not access, refresh, or ID tokens. The OAuth guide no longer recommends printing auth.json or placing bearer tokens in shell history.

Conflict resolution

  • Resolved the ProviderArchitectureGatekeeperTests conflict against the current SettingsStore.swift anchor (line 1054).
  • Kept every existing 0.50.1 — Unreleased changelog bullet and added the credited Keep shared Codex auth read-only during usage refresh #2944 Codex fix entry.
  • Retained the full 18-commit contributor history through a merge commit.

CI failure investigation

  • The stale Linux arm64 job compiled successfully and then crashed during the full parallel test process with SIGSEGV in libdispatch; it was not a Linux build error or a Codex auth assertion. Touched networking code already uses conditional FoundationNetworking, and macOS-only browser code remains guarded.
  • The stale macOS shard failed an unrelated Kiro timing assertion (idleTimeout vs deadlineExceeded). That group and the complete sharded suite pass on this merged result.
  • The aggregate lint-build-test failure was downstream of the failed macOS shard.

Validation

  • swiftformat Sources Tests (then retained only task-scoped formatter changes; project-pinned lint confirms the whole tree is formatted)
  • swiftlint --strict
  • make check
  • swift test --skip-build --filter 'CodexOAuth|CodexAuth|CodexResetCredit' — 114 macOS tests and 1 Linux compatibility test passed
  • swift test --skip-build --filter 'ProviderArchitectureGatekeeperTests|CodexBaselineCharacterizationTests' — 48 passed
  • make test — 870/870 selections across 73/73 groups; zero failures, retries, or timeouts
  • Structured pre-commit review — no accepted P0/P1 findings

Credit to @Yuxin-Qiao for the original implementation and ownership analysis.

Closes #2944 supersedes the original conflicting pull request.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed August 16, 2026, 3:00 AM ET / 07:00 UTC.

ClawSweeper review

What this changes

The PR stops Codex usage refresh from modifying shared OAuth files, adds source-aware recovery and workspace scoping, and updates related tests and documentation.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this owner-authored PR open: its read-only credential boundary is valuable, but an explicit CLI refresh under a selected managed workspace can still combine CLI usage from one workspace with reset credits requested for another.

Priority: P1
Reviewed head: 04766fd71d7e046be01c4297d217ed2e9354ca38

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The auth-boundary repair is well-developed, but a P1 managed-workspace routing defect blocks merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: This owner-authored PR is exempt from the external-contributor proof gate; the PR body also reports redacted runtime evidence for the core read-only path.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This owner-authored PR is exempt from the external-contributor proof gate; the PR body also reports redacted runtime evidence for the core read-only path.
Evidence reviewed 5 items Explicit CLI remains unscoped: A managed workspace suppresses CLI only in automatic mode; explicit CLI mode still selects the unscoped CLI strategy.
Scoped credits are attached after any winning source: Generic reset-credit enrichment sends the selected workspace ID in preference to the auth-file account ID, without checking that the preceding usage result was workspace-scoped.
Existing regression coverage misses direct CLI mode: The new managed-workspace test covers automatic mode and explicit OAuth recovery, not explicit CLI mode followed by supplemental reset-credit enrichment.
Findings 1 actionable finding [P1] Avoid attaching workspace-B credits to unscoped CLI usage
Security None None.

How this fits together

CodexBar’s Codex provider reads a selected account’s credentials, fetches usage and optional reset-credit inventory, and supplies that snapshot to the menu-bar UI. The fetch plan chooses OAuth, CLI, or web sources while managed-account metadata supplies workspace scope.

flowchart LR
A[Selected Codex account] --> B[Fetch-plan source selection]
C[CLI auth file] --> B
B --> D[OAuth or CLI usage request]
A --> E[Managed workspace scope]
D --> F[Reset-credit enrichment]
E --> F
F --> G[Menu-bar usage snapshot]
Loading

Before merge

  • Avoid attaching workspace-B credits to unscoped CLI usage (P1) - Explicit CLI mode still runs CodexCLIUsageStrategy with the auth-file account, but this line forces the selected managed workspace onto the later reset-credit GET. A selected workspace B can therefore render CLI usage for A with credits for B. This is a late finding: the line is unchanged from the prior reviewed head. Restrict the override to a proven scoped OAuth result, or skip enrichment for explicit CLI, and add a direct-CLI regression.
  • Resolve merge risk (P1) - Merging as-is can display unscoped CLI usage together with reset-credit inventory scoped to the selected managed workspace, misleading users about the account whose limits they are viewing.
  • Complete next step (P2) - The remaining P1 is a narrow, source-proven routing repair with a clear regression boundary.

Findings

  • [P1] Avoid attaching workspace-B credits to unscoped CLI usage — Sources/CodexBar/UsageStore+CodexResetCredits.swift:109
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 30 files; production +568/-98, tests +991/-39 This is a broad provider-auth change with substantial regression coverage, making the remaining untested source combination important.

Root-cause cluster

Relationship: canonical
Canonical: #2970
Summary: This PR is the active integration of the shared-Codex-auth work; the remaining defect is within its managed-workspace routing.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Keep direct CLI enrichment unscoped (recommended)
    Suppress the selected-workspace override for explicit CLI outcomes and add a regression proving CLI usage cannot be combined with another workspace’s credits.
  2. Accept the mixed-account behavior
    Merge with explicit CLI mode documented as potentially showing CLI usage and selected-workspace reset credits from different scopes.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Do not attach managed-workspace reset credits to an unscoped explicit CLI result; add focused direct-CLI coverage and run the Codex OAuth/reset-credit tests plus make check.

Technical review

Best possible solution:

Preserve the read-only OAuth design, but skip supplemental managed-workspace reset credits for unscoped CLI outcomes unless the CLI result can prove it used the same workspace; add a direct-CLI regression test.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: select a managed workspace B, choose explicit CLI while auth.json is scoped to A, and enable credit enrichment; the CLI usage path is unscoped while the supplemental request is forced to B.

Is this the best way to solve the issue?

No: the read-only ownership approach is sound, but generic reset-credit enrichment must not apply managed scope after an unscoped CLI result.

Full review comments:

  • [P1] Avoid attaching workspace-B credits to unscoped CLI usage — Sources/CodexBar/UsageStore+CodexResetCredits.swift:109
    Explicit CLI mode still runs CodexCLIUsageStrategy with the auth-file account, but this line forces the selected managed workspace onto the later reset-credit GET. A selected workspace B can therefore render CLI usage for A with credits for B. This is a late finding: the line is unchanged from the prior reviewed head. Restrict the override to a proven scoped OAuth result, or skip enrichment for explicit CLI, and add a direct-CLI regression.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e0f07f9c65f8.

Labels

Label justifications:

  • P1: The remaining defect can present incorrect Codex account-limit information to users of managed workspaces.
  • merge-risk: 🚨 compatibility: Existing managed-account and explicit CLI selections can produce a changed, internally inconsistent usage snapshot.
  • merge-risk: 🚨 auth-provider: The fault is in how the Codex credential source and managed workspace identity are combined for requests.
  • merge-risk: 🚨 security-boundary: The patch changes cross-process OAuth-file ownership and account-scoping boundaries.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This owner-authored PR is exempt from the external-contributor proof gate; the PR body also reports redacted runtime evidence for the core read-only path.

Evidence

Acceptance criteria:

  • [P1] swift test --filter 'CodexOAuthManagedWorkspaceRecoveryTests|CodexResetCreditOutcomeTests'.
  • [P1] make check.
  • [P1] make test.

What I checked:

Likely related people:

  • Yuxin-Qiao: Introduced the OAuth snapshot and managed-workspace recovery work containing the affected enrichment path. (role: original credential-routing contributor; confidence: high; commits: d58b1beb4588, 91ed021fcbd6; files: Sources/CodexBar/UsageStore+CodexResetCredits.swift, Sources/CodexBarCore/Providers/Codex/CodexProviderDescriptor.swift)
  • steipete: Authored the integration commit and the current branch merge onto main. (role: recent integration contributor; confidence: high; commits: a29973fe9933, 04766fd71d7e; files: Sources/CodexBar/UsageStore+CodexResetCredits.swift, Sources/CodexBarCore/Providers/Codex/CodexProviderDescriptor.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prevent direct CLI usage from receiving managed-workspace reset credits.
  • Add a direct-CLI managed-workspace regression and run the focused OAuth/reset-credit suites plus make check.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-16T06:32:00.866Z sha a29973f :: needs maintainer review before merge. :: none

@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: a29973fe99

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

let priorTokenAccountSnapshot = self.tokenAccountSnapshot(provider: provider, account: tokenAccount)
let descriptor = spec.descriptor
let codexResetCreditsFetcher = self.codexResetCreditsFetcher()
let codexResetCreditsFetcher = self.codexResetCreditsFetcher(workspaceAccountID: fetchContext.codexWorkspaceID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid enriching unscoped CLI usage with managed workspace credits

When a managed account selects workspace B while its now-read-only auth.json remains scoped to workspace A, choosing the explicit CLI source still runs CodexCLIUsageStrategy, which cannot carry the selected workspace header, but this fetcher forces workspace B onto the supplemental reset-credit request. The resulting snapshot can therefore combine workspace A's CLI usage with workspace B's reset credits; either suppress the unscoped CLI route for managed workspaces or only apply this override when the winning usage result was fetched with the same workspace scope.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot removed the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Aug 16, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 16, 2026
@steipete
steipete merged commit d0f35f3 into main Aug 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants