Skip to content

[codex] Fix Codex OAuth refresh fallback - #82117

Merged
steipete merged 2 commits into
mainfrom
codex/codex-oauth-refresh-fallback
May 15, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/codex-oauth-refresh-fallback

Conversation

@steipete

@steipete steipete commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #82069 by adding a narrow runtime recovery path for OpenAI Codex OAuth refresh failures:

  • keep OpenClaw's local openai-codex auth profile canonical during normal bootstrap/refresh
  • after a local Codex refresh fails, read usable Codex CLI OAuth credentials as a runtime-only fallback
  • require same provider, usable access token, matching account/email identity, and changed token material for forced refresh recovery
  • support both openai-codex:default and named profiles such as openai-codex:[email protected]
  • never write Codex CLI access/refresh tokens back to auth-profiles.json

Verification

  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles.external-cli-sync.test.ts src/agents/auth-profiles/external-oauth.test.ts src/agents/auth-profiles/oauth-manager.test.ts extensions/codex/src/app-server/auth-bridge.test.ts - 9 files, 150 tests passed
  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles.external-cli-sync.test.ts - 4 files, 74 tests passed after named-profile fix
  • pnpm check:changed - Blacksmith Testbox tbx_01krnp642m5neh6rhw1g9hjnnp, GitHub Actions run https://github.com/openclaw/openclaw/actions/runs/25915319488, exit 0
  • /Users/steipete/Projects/agent-scripts/skills/codex-review/scripts/codex-review --mode branch --base origin/main --full-access - found named-profile fallback gap, fixed
  • /Users/steipete/Projects/agent-scripts/skills/codex-review/scripts/codex-review --mode local --full-access - clean after fix, no accepted/actionable findings

Real behavior proof

Behavior addressed: OpenClaw can recover a stale local OpenAI Codex OAuth refresh token by using same-account Codex CLI OAuth tokens at runtime only.

Real environment tested: Local OpenClaw auth-profile unit/integration tests plus Blacksmith Testbox changed gate.

Exact steps or command run after this patch: pnpm check:changed on Blacksmith Testbox lease tbx_01krnp642m5neh6rhw1g9hjnnp.

Evidence after fix: Regression tests cover default and named Codex profiles, mismatched-account rejection, identity-less rejection, unchanged-token forced-refresh rejection, and no persistence of Codex CLI token material.

Observed result after fix: Focused tests and Testbox changed gate passed; PR checks for SHA 3f0a0614226e2202516eb3bdd73d484c289a315c are clean/skipped as expected.

What was not tested: Reporter's exact machine state and keychain-only Codex CLI credentials; the fallback intentionally uses allowKeychainPrompt: false, so unavailable keychain-only tokens still fail closed.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels May 15, 2026
@clawsweeper

clawsweeper Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds a runtime-only same-account Codex CLI OAuth fallback after OpenAI Codex refresh failures, plus focused auth tests, OAuth docs, and a changelog entry.

Reproducibility: no. high-confidence live reproduction here: the linked issue has strong reporter logs, and source inspection confirms current main lacks a post-refresh-failure Codex CLI fallback, but I did not run a real OpenAI Codex OAuth account through the failing runtime path.

Real behavior proof
Not applicable: The PR is labeled maintainer, so the external-contributor proof gate does not apply; the cited Testbox run still should be reconciled during maintainer review.

Next step before merge
Human maintainer review is needed because the PR is draft, protected by maintainer, dirty/unmergeable, and its linked proof run needs reconciliation.

Security
Cleared: The diff does not add dependencies, workflows, script execution, or broader secret persistence; it narrows fallback use with provider, usability, identity, non-prompting, and non-persistence gates.

Review details

Best possible solution:

Keep this PR open for maintainer review, reconcile the proof/run status, and land the fallback only after confirming it preserves OpenClaw as the canonical token sink while recovering the Codex app-server refresh-failure path.

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

No high-confidence live reproduction here: the linked issue has strong reporter logs, and source inspection confirms current main lacks a post-refresh-failure Codex CLI fallback, but I did not run a real OpenAI Codex OAuth account through the failing runtime path.

Is this the best way to solve the issue?

Unclear but plausible: a tightly gated runtime-only fallback at the OAuth manager refresh-failure boundary matches the reported failure better than changing the Codex harness flag. The PI-route follow-up and proof-link mismatch mean maintainer verification is still needed before landing.

Acceptance criteria:

  • node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles.external-cli-sync.test.ts src/agents/auth-profiles/external-oauth.test.ts src/agents/auth-profiles/oauth-manager.test.ts
  • node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.adopt-identity.test.ts src/agents/auth-profiles/oauth.mirror-refresh.test.ts src/agents/auth-profiles/oauth.concurrent-agents.test.ts src/agents/auth-profiles/oauth-refresh-queue.test.ts
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/auth-bridge.test.ts
  • node scripts/crabbox-wrapper.mjs run ... --shell -- "pnpm check:changed"
  • Redacted live OpenAI Codex OAuth runtime proof for app-server refresh failure recovery, if feasible

What I checked:

Likely related people:

  • steipete: Recent GitHub history shows repeated auth-profile and Codex OAuth work in this area, and this PR branch proposes the fallback fix. (role: recent area contributor and current fix author; confidence: high; commits: f6f0d07019b0, aca10acd73a5, 2fc429dfbf0e; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/external-cli-sync.ts)
  • simplyclever914: Commit c404711 changed the forced Codex OAuth refresh contract in the central OAuth manager/auth bridge path this PR builds on. (role: recent forced-refresh contributor; confidence: high; commits: c4047117030c; files: extensions/codex/src/app-server/auth-bridge.ts, src/agents/auth-profiles/oauth-manager.ts)
  • Gforce10-design: Commit 5a202f6 introduced the bootstrap-only Codex CLI credential behavior that this PR extends without replacing. (role: Codex CLI bootstrap introducer; confidence: medium; commits: 5a202f6f909d; files: src/agents/auth-profiles/external-cli-sync.ts)
  • pashpashpash: Recent Codex app-server/auth commits touch adjacent runtime and auth-profile rotation paths relevant to validating this behavior. (role: recent Codex app-server contributor; confidence: medium; commits: cc95d4dd28eb, 74860e93fd6e; files: extensions/codex/src/app-server/auth-bridge.ts)

Remaining risk / open question:

  • The PR is draft, dirty/unmergeable, and protected by the maintainer label, so cleanup automation should not close or replace it.
  • The linked Testbox run named in the PR body is visible but reports cancelled from the public Actions API; maintainers should verify the intended green run before merge.
  • The linked issue includes a PI embedded-route access-token rejection as well as refresh failure, so this fallback may be only part of the user-visible auth recovery path.

Codex review notes: model gpt-5.5, reasoning high; reviewed against cd9b2c0af4f5.

@steipete
steipete force-pushed the codex/codex-oauth-refresh-fallback branch from f6f0d07 to 3f0a061 Compare May 15, 2026 11:29
@steipete

Copy link
Copy Markdown
Contributor Author

Verification before merge:

  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles.external-cli-sync.test.ts src/agents/auth-profiles/external-oauth.test.ts src/agents/auth-profiles/oauth-manager.test.ts extensions/codex/src/app-server/auth-bridge.test.ts - 9 files, 150 tests passed
  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles.external-cli-sync.test.ts - 4 files, 74 tests passed after the named-profile CodexReview fix
  • pnpm check:changed - Blacksmith Testbox tbx_01krnp642m5neh6rhw1g9hjnnp, Actions run https://github.com/openclaw/openclaw/actions/runs/25915319488, exit 0
  • CodexReview branch pass found one actionable named-profile fallback gap; fixed in 3f0a061422
  • Final CodexReview local pass clean: no accepted/actionable findings

Known proof gap: exact reporter machine/keychain state not available; keychain-only Codex CLI tokens still fail closed because runtime fallback is non-prompting.

@steipete
steipete marked this pull request as ready for review May 15, 2026 11:31
@steipete
steipete requested a review from a team as a code owner May 15, 2026 11:31
@steipete
steipete merged commit b3d9bef into main May 15, 2026
63 of 64 checks passed
@steipete
steipete deleted the codex/codex-oauth-refresh-fallback branch May 15, 2026 11:32
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix: fall back to Codex CLI OAuth after refresh failure

* fix: support Codex CLI fallback for named profiles
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: fall back to Codex CLI OAuth after refresh failure

* fix: support Codex CLI fallback for named profiles
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: fall back to Codex CLI OAuth after refresh failure

* fix: support Codex CLI fallback for named profiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: openai-codex OAuth refresh still 401 token_expired on v2026.5.14-beta.1 (post-#80738)

1 participant