Skip to content

Avoid stale auth profile write before forced Codex token refresh - #80738

Merged
steipete merged 1 commit into
openclaw:mainfrom
simplyclever914:fix/codex-auth-refresh-no-stale-expiry
May 14, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
simplyclever914:fix/codex-auth-refresh-no-stale-expiry

Conversation

@simplyclever914

@simplyclever914 simplyclever914 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Route Codex app-server forced OAuth refresh through the locked auth-profile refresh path instead of persisting a temporary expires: 0 credential.
  • Treat forceRefresh as a hard refresh contract: after a refresh failure, fallback credentials are reusable only if they changed after the attempted refresh began.
  • Add regression coverage for the child-agent/inherited-main-store fallback so Codex account/chatgptAuthTokens/refresh cannot be satisfied by the same unchanged access token.

Real behavior proof

Behavior addressed: Codex external chatgptAuthTokens refresh requests now perform a real OAuth refresh attempt and do not reuse unchanged inherited auth-profile tokens after refresh failure.

Real environment tested: Local OpenClaw checkout on branch fix/codex-auth-refresh-no-stale-expiry, rebased onto current origin/main, commit 1c1e64109acdb16846a252b54722cd4763ae634b.

Exact steps or command run after this patch: pnpm test src/agents/auth-profiles/oauth.mirror-refresh.test.ts src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts extensions/codex/src/app-server/auth-bridge.test.ts and git diff --check origin/main...HEAD.

Evidence after fix: Copied live terminal output from a local OpenClaw runtime probe on the PR branch after the patch. The probe uses a temporary OPENCLAW_STATE_DIR and OPENCLAW_AGENT_DIR, loads the real createOAuthManager implementation with node --import tsx, seeds a redacted openai-codex OAuth profile, calls resolveOAuthAccess(..., forceRefresh: true), and prints only redacted booleans/results:

$ timeout 15s node --import tsx --input-type=module -e '<runtime probe with redacted credentials>'
auth_store=/tmp/openclaw-oauth-manager-proof-rvuK9T/agents/main/agent/auth-profiles.json
store_loaded_provider=openai-codex
refresh_call_provider=openai-codex
forced_refresh_result=success_rotated
refresh_calls=1
persisted_expires_zero=false

Supplemental exact-head validation output from the same checkout:

$ git grep -n "forceRefresh: params.forceRefresh && Boolean(persistedOAuthCredential)\|expires: 0" -- extensions/codex/src/app-server/auth-bridge.ts
extensions/codex/src/app-server/auth-bridge.ts:494:    forceRefresh: params.forceRefresh && Boolean(persistedOAuthCredential),

$ pnpm test src/agents/auth-profiles/oauth.mirror-refresh.test.ts src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts extensions/codex/src/app-server/auth-bridge.test.ts
src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts: force refresh for unexpired openai-codex credentials through the exported resolver -> refreshProviderOAuthCredentialWithPlugin called once, returned rotated-access-token instead of fresh-access-token
src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts: force refresh does not reuse unchanged inherited main-store access after refresh failure -> rejected OAuth token refresh failed for openai-codex
extensions/codex/src/app-server/auth-bridge.test.ts: refreshCodexAppServerAuthTokens routes persisted OAuth credentials through resolveApiKeyForProfile({ forceRefresh: true })
Test Files  3 passed
Tests       57 passed

Observed result after fix: The runtime probe shows forceRefresh enters the refresh path for an otherwise unexpired openai-codex OAuth profile, returns a rotated access token, and leaves persisted_expires_zero=false. The previous inline expires: 0 persistence path is gone; if refresh fails, unchanged local/main-store fallback access is rejected, while genuinely changed credentials from another completed refresh can still be reused.

What was not tested: A live OpenAI OAuth token rotation with real user credentials was not run to avoid using live auth material in PR proof. Broad pnpm check:changed was attempted, delegated to Testbox, then stopped while still queued after origin/main moved and the PR had to be rebased.

Validation

  • pnpm test src/agents/auth-profiles/oauth.mirror-refresh.test.ts src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts extensions/codex/src/app-server/auth-bridge.test.ts
  • git diff --check origin/main...HEAD

@openclaw-barnacle openclaw-barnacle Bot added extensions: codex triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. size: S labels May 11, 2026
@clawsweeper

clawsweeper Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR removes the Codex app-server temporary expired credential write, threads forceRefresh through auth-profile OAuth resolution, tightens fallback reuse after refresh failure, adds targeted regression tests, and adds a changelog entry.

Reproducibility: yes. Source inspection gives a high-confidence path: a Codex app-server forced refresh with a persisted OAuth credential on current main writes expires: 0 before OAuth resolution, and the resolver has no explicit forceRefresh contract.

Real behavior proof
Needs real behavior proof before merge: The supplied evidence is grep plus targeted test output; before merge, the contributor should add redacted terminal/log/recording proof from a real runtime probe and update the PR body to trigger re-review, or ask a maintainer to comment @clawsweeper re-review.

Next step before merge
The code change looks focused, but external-PR real behavior proof is still mock-only and exact-head validation needs normal maintainer gating.

Security
Cleared: The diff changes auth refresh control flow and tests but does not add dependencies, scripts, workflow permissions, artifact downloads, or secret logging surface.

Review details

Best possible solution:

Land this focused auth-profile fix after the contributor supplies real behavior proof and exact-head targeted validation passes.

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

Yes. Source inspection gives a high-confidence path: a Codex app-server forced refresh with a persisted OAuth credential on current main writes expires: 0 before OAuth resolution, and the resolver has no explicit forceRefresh contract.

Is this the best way to solve the issue?

Yes. Removing the unlocked temporary stale write and routing forced refresh through the existing locked OAuth resolver/manager path is the narrow maintainable fix; the remaining blocker is proof/validation, not a different design.

What I checked:

  • Current main still has the stale write path: resolveOAuthCredentialForCodexAppServer still writes { ...credentialForOwner, expires: 0 } and calls saveAuthProfileStore before resolving a forced refresh. (extensions/codex/src/app-server/auth-bridge.ts:492, 386d321634b3)
  • Current resolver has no force-refresh parameter: ResolveApiKeyForProfileParams on current main has no forceRefresh field, and calls to oauthManager.resolveOAuthAccess do not pass such a contract through. (src/agents/auth-profiles/oauth.ts:131, 386d321634b3)
  • PR removes direct stale persistence: The PR patch removes the saveAuthProfileStore import and the forced expires: 0 write, then passes forceRefresh into resolveApiKeyForProfile for persisted OAuth credentials. (extensions/codex/src/app-server/auth-bridge.ts:477, 1c1e64109acd)
  • PR adds force-refresh semantics to OAuth manager: The patch skips usable-credential early returns when forceRefresh is set, passes the flag into the locked refresh path, and only reuses fallback credentials after refresh failure when they changed after the attempted refresh began. (src/agents/auth-profiles/oauth-manager.ts:141, 1c1e64109acd)
  • Regression coverage targets the bug: The PR adds coverage for no pre-refresh stale persistence in the Codex bridge, forced refresh for unexpired openai-codex credentials through the exported resolver, and rejection of unchanged main-store fallback after forced refresh failure. (src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts:226, 1c1e64109acd)
  • PR state and proof labels: The live PR is open, not draft, mergeable, and labeled proof: supplied; it is not labeled proof: sufficient on the latest head. (1c1e64109acd)

Likely related people:

  • shakkernerd: Recent path history shows fix: reuse provider auth hook lookup context and fix: keep oauth refresh on persisted auth stores in the central OAuth resolver/manager area. (role: recent area contributor; confidence: high; commits: 854323a12481, 34b17c82dace; files: src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/oauth-manager.ts)
  • steipete: Recent history shows repeated auth-profile and Codex app-server changes, and the current PR head commit is authored and committed by this account. (role: recent adjacent contributor and current patch author; confidence: high; commits: 1c1e64109acd, 850d685d4bec, e6cd90e3fd9c; files: extensions/codex/src/app-server/auth-bridge.ts, src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/oauth-manager.ts)
  • vincentkoc: Path history shows several Codex OAuth bridge and OAuth lifecycle manager refactors in the affected auth-profile path. (role: adjacent OAuth lifecycle contributor; confidence: medium; commits: eb1a0aa574b5, 4a4f52b09730, 5f2e77a6e1c4; files: extensions/codex/src/app-server/auth-bridge.ts, src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/oauth-manager.ts)
  • jeffjhunter: Recent path history includes a Codex app-server OAuth harness auth fix touching the bridge/resolver area. (role: recent Codex app-server auth contributor; confidence: medium; commits: 850d685d4bec; files: extensions/codex/src/app-server/auth-bridge.ts, src/agents/auth-profiles/oauth.ts)

Remaining risk / open question:

  • The current after-fix proof is limited to grep and targeted test output, so it does not yet show the changed behavior in a real runtime probe or redacted runtime log.
  • I did not run the targeted tests during this read-only review; exact-head validation should still run before merge.

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

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 11, 2026
@simplyclever914
simplyclever914 requested a review from a team as a code owner May 11, 2026 18:39
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label May 11, 2026
@simplyclever914
simplyclever914 force-pushed the fix/codex-auth-refresh-no-stale-expiry branch 2 times, most recently from 2983612 to 1af02b3 Compare May 12, 2026 06:52
@simplyclever914

simplyclever914 commented May 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated in 1af02b3e19.

Changes since the review:

  • forwarded forceRefresh through the normal exported resolveApiKeyForProfile -> oauthManager.resolveOAuthAccess path;
  • forwarded it through the fallback OAuth helper path as well;
  • added a production resolver regression test that seeds an unexpired persisted openai-codex OAuth credential, calls resolveApiKeyForProfile(..., forceRefresh: true), and verifies provider refresh is called exactly once.

Local targeted validation, without a full workspace install:

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.config.ts extensions/codex/src/app-server/auth-bridge.test.ts src/agents/auth-profiles/oauth-manager.test.ts src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts --reporter=verbose
  • node scripts/run-tsgo.mjs -p extensions/codex/tsconfig.json --incremental false
  • git diff --check

I also updated the PR body with the new behavior proof.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: supplied External PR includes structured after-fix real behavior proof. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@simplyclever914
simplyclever914 force-pushed the fix/codex-auth-refresh-no-stale-expiry branch from 1af02b3 to a149d7d Compare May 13, 2026 12:35
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 13, 2026
@simplyclever914
simplyclever914 force-pushed the fix/codex-auth-refresh-no-stale-expiry branch from a149d7d to 232056f Compare May 13, 2026 12:37
@steipete
steipete force-pushed the fix/codex-auth-refresh-no-stale-expiry branch from 232056f to 1c1e641 Compare May 14, 2026 18:29
@openclaw-barnacle openclaw-barnacle Bot added triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: supplied External PR includes structured after-fix real behavior proof. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 14, 2026
Treat forced OAuth refresh as a hard refresh contract: fallback credentials may be reused only when they changed after the attempted refresh began.

Co-authored-by: Clever <[email protected]>
@steipete
steipete force-pushed the fix/codex-auth-refresh-no-stale-expiry branch from 1c1e641 to 70083f2 Compare May 14, 2026 19:02
@simplyclever914

simplyclever914 commented May 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

I updated the Real behavior proof section with a redacted local OpenClaw runtime probe. It runs the real createOAuthManager path from this PR with a temporary OPENCLAW_STATE_DIR / OPENCLAW_AGENT_DIR, calls resolveOAuthAccess(..., forceRefresh: true), confirms the refresh path is invoked once, returns a rotated access token, and confirms persisted_expires_zero=false.

Re-review progress:

@steipete
steipete merged commit c404711 into openclaw:main May 14, 2026
96 checks passed
@clawsweeper

clawsweeper Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper could not start a re-review for this item.

Reason: re-review requires an open issue or PR.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Treat forced OAuth refresh as a hard refresh contract: fallback credentials may be reused only when they changed after the attempted refresh began.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Clever <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Treat forced OAuth refresh as a hard refresh contract: fallback credentials may be reused only when they changed after the attempted refresh began.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Clever <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Treat forced OAuth refresh as a hard refresh contract: fallback credentials may be reused only when they changed after the attempted refresh began.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Clever <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants