Skip to content

fix: OAuth refresh failures report reauth instead of stale success - #99134

Merged
fuller-stack-dev merged 8 commits into
openclaw:mainfrom
100yenadmin:fix/oauth-managed-refresh-external-fallback-99120
Jul 2, 2026
Merged

fuller-stack-dev merged 8 commits into
openclaw:mainfrom
100yenadmin:fix/oauth-managed-refresh-external-fallback-99120

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #99120

What Problem This Solves

Fixes an issue where users with managed OpenAI OAuth profiles could see auth appear healthy after a refresh failure when an external Codex CLI credential still existed but was stale or invalidated. This made operator status false-green and could require repeated pairing-code relogs.

Why This Change Was Made

The OAuth manager now fails closed on refresh errors instead of falling back to external CLI credentials after refresh failure. External CLI credentials remain available only for the existing unusable-profile bootstrap path.

Provider-wide auth discovery now also enforces that same ownership boundary: bootstrap-only Codex CLI openai:default is not synthesized as an automatic sibling candidate when a canonical local OpenAI OAuth profile already exists, unless that external profile was explicitly selected/configured.

Doctor and failed-turn refresh-failure hints include the affected safe profile id without mutating model defaults.

This touches CODEOWNERS auth files and likely needs auth/secops review.

User Impact

Users and operators get an explicit reauth-required error for the affected profile instead of a misleading successful auth state. Doctor output and failed-turn guidance can point at the exact profile to relog without changing the user's default model.

Review Response

Addressed the P1 review finding from fuller-stack-dev on head 66e088aff75f6727dc2c1754007d963fdceb6ad0:

  • external-cli-sync.ts no longer synthesizes runtime-only Codex CLI openai:default beside a named local OpenAI OAuth profile in provider-wide discovery.
  • resolveApiKeyForProvider preserves the first typed OAuthRefreshFailureError while trying auth candidates and throws it when no earlier env/custom/synthetic fallback succeeds.
  • OAuthRefreshFailureError carries a sanitized provider-prefixed profileId; OAuthManagerRefreshError passes it through with an explicit override.
  • Failed-turn guidance now includes --profile-id for typed refresh failures.
  • docs/concepts/oauth.md no longer documents runtime external CLI fallback after local Codex refresh failure.

The provider-wide regression was first run red before this commit: with expired openai:[email protected], stale future-expiry Codex CLI credential, and no explicit profile lock, resolveApiKeyForProvider({ provider: "openai" }) returned profile:openai:default. It now rejects with the OAuth refresh failure and does not persist the Codex CLI token.

Live customer/setup evidence for the original false-green behavior is in #99120. I did not replay a live customer credential against this branch; the post-fix proof is the deterministic provider-wide regression plus focused type/test validation below.

Evidence

  • node scripts/run-vitest.mjs src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts: 1 Vitest shard, 20 tests passed.
  • node scripts/run-vitest.mjs src/agents/auth-profiles/oauth-refresh-failure.test.ts src/agents/auth-profiles.external-cli-sync.test.ts src/auto-reply/reply/agent-runner-execution.test.ts src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/commands/doctor-auth.hints.test.ts: 4 Vitest shards, 277 tests passed.
  • pnpm tsgo:core: passed.
  • ./node_modules/.bin/oxfmt --check --threads=1 <touched auth/reply files>: passed.
  • git diff --check: passed.
  • .agents/skills/autoreview/scripts/autoreview --mode local --base origin/main --prompt <auth refresh fallback scope>: first Codex-engine run surfaced one P1 (OAuthManagerRefreshError.profileId needed override after adding the base property); fixed in this PR and proven by pnpm tsgo:core. A second Codex-engine rerun stalled with heartbeat-only output and returned only a wrapper KeyboardInterrupt trace when interrupted. Claude-engine fallback failed due local Claude connector/auth precedence, not code.

@100yenadmin
100yenadmin requested a review from a team as a code owner July 2, 2026 15:22
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: M labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 2, 2026, 4:09 PM ET / 20:09 UTC.

Summary
The PR changes managed OpenAI OAuth refresh handling to fail closed instead of using stale external Codex CLI credentials, blocks automatic Codex CLI sibling profile synthesis once managed OAuth exists, and updates targeted reauth guidance, docs, and regression coverage.

PR surface: Source +86, Tests +457, Docs +1. Total +544 across 18 files.

Reproducibility: yes. The source path is clear on current main and v2026.6.11, and the exact-head Crabbox proof reports a base run that falls through to stale external Codex CLI credentials after managed OpenAI refresh failure and a patched run that reports reauth instead.

Review metrics: 2 noteworthy metrics.

  • Runtime fallback surface: 1 post-refresh fallback removed, bootstrap path retained. The PR deliberately removes runtime external CLI recovery while keeping Codex CLI bootstrap, which is the compatibility-sensitive behavior maintainers need to accept.
  • Provider discovery bypass: 1 sibling synthesis path tightened. Provider-wide OpenAI auth discovery no longer adds Codex CLI openai:default beside a managed OAuth profile, closing the bypass found in the earlier review.

Stored data model
Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-auth.hints.test.ts, migration/backfill/repair: src/commands/doctor-auth.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99120
Summary: This PR is the candidate fix for the canonical managed OpenAI OAuth false-green external fallback issue; broader auth issues overlap but do not supersede this repair.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Get explicit auth/secops acceptance for the fail-closed fallback policy before merge.
  • Rerun or otherwise resolve the failing CI shard under normal merge policy.

Risk before merge

  • [P1] Merging intentionally removes shipped post-refresh external CLI recovery for managed OpenAI OAuth, so any setup relying on Codex CLI recovery after a managed refresh failure will now fail closed and require reauth.
  • [P1] The branch changes auth-provider routing and profile-selection behavior; maintainers should explicitly accept the fail-closed policy before landing, even though the patch and live proof look strong.
  • [P1] One CI shard is currently failing on the live PR status, so normal merge gating still needs either a rerun/pass or maintainer-owned interpretation before merge.

Maintainer options:

  1. Accept fail-closed auth policy (recommended)
    Have the auth/secops owner explicitly accept that managed OpenAI refresh failure must report reauth instead of using external Codex CLI fallback, then proceed once normal merge gates are green or intentionally waived.
  2. Add an explicit recovery policy instead
    If maintainers want to preserve upgrade compatibility for fallback users, revise the branch so post-refresh external fallback is provider-verified or explicitly operator-enabled rather than automatic.
  3. Pause if ownership is not settled
    If auth ownership cannot accept the fail-closed behavior now, keep this PR paused rather than merging a compatibility-sensitive provider-policy change by default.

Next step before merge

  • [P1] This should stay with human maintainers because the remaining action is auth/secops acceptance of a compatibility-sensitive fail-closed provider policy plus normal CI gating, not a narrow automated repair.

Security
Cleared: The diff is auth-sensitive, but I found no concrete supply-chain, workflow, dependency, secret-printing, permission, or sensitive-data regression beyond the intended fail-closed auth behavior.

Review details

Best possible solution:

Land this PR or an equivalent provider-owned fix after auth/secops acceptance of the fail-closed fallback policy and normal CI gating; keep the linked issue open until the fix merges.

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

Yes. The source path is clear on current main and v2026.6.11, and the exact-head Crabbox proof reports a base run that falls through to stale external Codex CLI credentials after managed OpenAI refresh failure and a patched run that reports reauth instead.

Is this the best way to solve the issue?

Yes, with policy sign-off. Removing post-refresh external fallback and blocking provider-wide sibling synthesis is the clean owner-boundary fix; the safer alternative would be an explicit or provider-verified fallback if maintainers choose compatibility over fail-closed behavior.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. A maintainer-provided Crabbox proof on exact head fdc83a8 shows the base stale external fallback and the patched auth_permanent reauth path using controlled invalid OAuth credentials against real endpoints, plus a direct OpenAI API-key smoke control.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): A maintainer-provided Crabbox proof on exact head fdc83a8 shows the base stale external fallback and the patched auth_permanent reauth path using controlled invalid OAuth credentials against real endpoints, plus a direct OpenAI API-key smoke control.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The PR addresses a live managed OpenAI OAuth false-green failure that can break real agent turns while status appears healthy.
  • merge-risk: 🚨 compatibility: The branch removes a shipped external CLI fallback path that some existing OpenAI/Codex OAuth setups may have relied on after managed refresh failure.
  • merge-risk: 🚨 auth-provider: The diff directly changes OAuth refresh failure handling, provider-wide auth profile discovery, model auth mode selection, and reauth guidance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): A maintainer-provided Crabbox proof on exact head fdc83a8 shows the base stale external fallback and the patched auth_permanent reauth path using controlled invalid OAuth credentials against real endpoints, plus a direct OpenAI API-key smoke control.
  • proof: sufficient: Contributor real behavior proof is sufficient. A maintainer-provided Crabbox proof on exact head fdc83a8 shows the base stale external fallback and the patched auth_permanent reauth path using controlled invalid OAuth credentials against real endpoints, plus a direct OpenAI API-key smoke control.
Evidence reviewed

PR surface:

Source +86, Tests +457, Docs +1. Total +544 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 9 190 104 +86
Tests 8 485 28 +457
Docs 1 9 8 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 684 140 +544

What I checked:

  • Root and scoped policy read: Read the full 283-line root AGENTS.md plus the scoped agents and docs AGENTS.md files; the auth/provider fallback compatibility rules and Codex dependency-source gate affected this review. (AGENTS.md:1, 4df175baafcf)
  • Current main and latest release still have the fallback: Current main and v2026.6.11 both still call adapter.readFallbackCredential after managed OAuth refresh failure and can return that external credential when it looks usable and identity-compatible. (src/agents/auth-profiles/oauth-manager.ts:809, 4df175baafcf)
  • PR head removes post-refresh external fallback: At fdc83a8, OAuthManagerAdapter no longer exposes readFallbackCredential, OAuthManagerRefreshError carries profileId, and refresh failure throws after main-store recovery fails. (src/agents/auth-profiles/oauth-manager.ts:40, fdc83a8c1325)
  • PR head blocks provider-wide Codex CLI sibling synthesis: Bootstrap-only external CLI state returns no scoped profile ids once the store has managed provider OAuth token material, and focused tests cover named managed OpenAI profiles and empty default slots. (src/agents/auth-profiles/external-cli-sync.ts:177, fdc83a8c1325)
  • Provider-wide regression coverage exists: The PR adds a regression where unpinned provider auth with an expired named managed OpenAI profile and stale same-account Codex CLI credential rejects with OAuthRefreshFailureError carrying the failing profile id. (src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts:672, fdc83a8c1325)
  • Profile-aware guidance and privacy coverage: The PR carries sanitized profile ids through typed OAuth refresh failures, includes them only for direct/private failure replies, and tests omission from group/channel reauth guidance. (src/auto-reply/reply/agent-runner-execution.ts:964, fdc83a8c1325)

Likely related people:

  • steipete: GitHub path history shows steipete authored the earlier Codex OAuth refresh fallback commit and several later OAuth manager, external overlay, and OpenAI provider identity changes in this decision surface. (role: auth fallback and OpenAI provider identity area contributor; confidence: high; commits: b3d9bef38d5d, 4c33aaa86c16, d581d9d733a7; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/auth-profiles/external-cli-sync.ts, src/agents/model-auth.ts)
  • vincentkoc: GitHub path history shows vincentkoc recently centralized OAuth identity matching and contributed earlier canonical OpenAI/Codex OAuth routing helpers used by the external CLI boundary. (role: OAuth identity and canonical routing contributor; confidence: high; commits: 305a44388bcb, 859eb0666282, d97d5c04f03b; files: src/agents/auth-profiles/external-cli-sync.ts, src/agents/auth-profiles/oauth-manager.ts)
  • fuller-stack-dev: Live PR timeline and commits show fuller-stack-dev requested changes for the provider-wide bypass, then updated and approved the contributor branch after adding the provider-owned OAuth fix and live validation. (role: recent reviewer and likely follow-up owner; confidence: high; commits: 3a5b01293eec, 2f31db671db7, fdc83a8c1325; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/auth-profiles/external-cli-sync.ts, src/agents/model-auth.ts)
  • RomneyDa: GitHub path history shows RomneyDa authored recent auth failure dispatch and OAuth refresh no-token handling in the same auth-profile and model-auth behavior family. (role: adjacent auth failure classification contributor; confidence: medium; commits: 50b69e16dc0d, 205c595b134c, 299ed808347c; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/model-auth.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@fuller-stack-dev fuller-stack-dev self-assigned this Jul 2, 2026

@fuller-stack-dev fuller-stack-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes for one blocking gap.

[P1] The fail-closed policy is still bypassed by normal profile failover. Removing readFallbackCredential fixes the refresh manager's direct fallback for a pinned profile, but provider-wide auth discovery still synthesizes a runtime-only Codex CLI openai:default when the canonical store contains only a named managed OpenAI profile (src/agents/auth-profiles/external-cli-sync.ts:255-279). resolveApiKeyForProvider then catches the managed profile's refresh error and continues to the next candidate (src/agents/model-auth.ts:1224-1292).

I reproduced this on head 66e088aff75f6727dc2c1754007d963fdceb6ad0 with a focused regression: an expired openai:[email protected] managed profile, a future-expiry but stale Codex CLI credential, and no explicit profile lock. The managed refresh failed, yet the resolver returned the stale token as profile:openai:default. The probe passed in both agents-core and agents-support shards. This means unpinned model paths can still reach the same invalid external credential after a managed refresh failure.

The best fix is to enforce the bootstrap-only ownership rule at external profile discovery/selection: do not synthesize Codex CLI openai:default as an automatic sibling candidate when a canonical local OpenAI OAuth profile exists, unless that external profile was explicitly selected/configured. Please add a provider-wide regression test covering the named managed profile plus external CLI profile case.

Two follow-ups should be included with the behavior change:

  • docs/concepts/oauth.md:167-173 still documents the fallback this PR removes.
  • The immediate failed-turn guidance still calls buildOAuthRefreshFailureLoginCommand without a profile ID at src/auto-reply/reply/agent-runner-execution.ts:988-992; OAuthRefreshFailureError also does not carry the OAuthManagerRefreshError.profileId, so only doctor gets the new exact-profile hint.

Focused PR tests otherwise passed: 4 Vitest shards, 273 existing tests plus the 2-shard disposable regression probe. git diff --check is clean.

@fuller-stack-dev

Copy link
Copy Markdown
Member

Correction to my review's final verification sentence: the focused run was 273 total tests: 271 existing tests plus the disposable regression probe executed in the agents-core and agents-support shards.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 2, 2026
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Addressed the P1 review on head 66e088aff75f6727dc2c1754007d963fdceb6ad0 in commit eb17a8b219:

  • Blocked provider-wide external CLI sibling synthesis: bootstrap-only Codex CLI openai:default is no longer auto-added beside a canonical local OpenAI OAuth profile unless explicitly selected/configured.
  • Preserved typed OAuthRefreshFailureError through provider-wide candidate iteration so failed managed refreshes report reauth instead of falling through to generic missing-auth.
  • Carried safe profileId through typed refresh failures and failed-turn guidance.
  • Updated docs/concepts/oauth.md to remove the runtime external CLI fallback language.

Validation now on PR body: provider-wide regression passes, focused touched suites pass (4 shards / 277 tests), pnpm tsgo:core passes, formatter and git diff --check pass.

Autoreview note: the first local Codex autoreview surfaced one valid P1 (OAuthManagerRefreshError.profileId needed override), now fixed and typechecked. Rerun stalled in the wrapper with heartbeat-only output; Claude fallback failed due local auth/connectors, not code.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 2, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member

Maintainer update: I replaced the narrow fallback workaround with the provider-owned OAuth fix and updated the contributor branch without rewriting its history.

What changed:

  • Treat Codex CLI credentials as bootstrap-only for OpenAI. Once any managed OpenAI OAuth profile has token material, external Codex CLI state cannot be synthesized into a sibling profile.
  • Enforce that rule in both provider/profile discovery and direct explicit OAuth resolution, including an empty openai:default beside a named managed profile.
  • Fail closed on managed OAuth refresh errors instead of silently selecting stale Codex CLI credentials.
  • Preserve the exact failing profile through refresh/failover wrappers so private replies and doctor output can provide a targeted re-auth command; omit profile IDs in group/channel replies.
  • Keep direct OpenAI API-key model paths from refreshing or selecting managed OAuth.
  • Ensure OAuth-refresh and auth-profile recovery guidance wins over generic HTTP 401 copy.
  • Update OAuth docs and add regression coverage for scoped discovery, explicit profiles, refresh failure propagation, wrapper classification, reply privacy, and doctor hints.
  • Merge the latest upstream/main into the branch without rebasing or force-pushing contributor commits.

Verification on head 3cea24ac1d4b7965b421a46c39c55cfec1f2c471:

  • Focused Vitest proof: 334 tests passed across 4 routed shards.
  • Structured autoreview: clean after resolving two actionable findings found during the first pass.
  • Remote changed gate: AWS Crabbox run run_f588428d1d3d, lease cbx_72769aa34e91, exit 0. Typecheck, lint, import-cycle checks, prompt snapshots, dependency/shrinkwrap guards, and routed repository guards passed.

@fuller-stack-dev fuller-stack-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed exact head fdc83a8c132570c06c776190c4f4631efcd19c19 after refreshing it onto current upstream/main (97ad0b7c211cf6025d16888643b344f373a8b7fe). No actionable findings remain.

This is the canonical fix for #99120:

  • src/agents/auth-profiles/external-cli-sync.ts owns the bootstrap boundary and no longer synthesizes a sibling openai:default Codex CLI profile once OpenClaw already owns managed OpenAI OAuth token material.
  • src/agents/auth-profiles/oauth-manager.ts now fails closed when managed refresh fails instead of switching credential ownership to stale external Codex state.
  • src/agents/model-auth.ts preserves the typed refresh failure for re-auth guidance while retaining explicit configured-profile/API-key failover, and direct OpenAI API-key transports do not select or refresh OAuth profiles.
  • Profile-aware remediation stays available in direct/private replies while group/channel guidance omits profile IDs.

Regression review covered direct API-key models, explicit local profile failover, inherited main-agent OAuth identity, non-OpenAI external providers, profile-id rendering/injection-like values, and group-channel disclosure behavior. Fresh autoreview returned no findings and judged the patch correct (0.83 confidence).

Dependency contract was checked directly against openai/codex@0ccb676dd0904a424a84080d4ec8755677aea22e: codex-rs/login/src/auth/storage.rs:38-61, codex-rs/login/src/auth/manager.rs:1588-1605, 1724-1774, 1790-1806, 2373-2462, and codex-rs/core/src/client.rs:2124-2205. Codex keeps managed refresh and explicitly configured external auth as separate modes; managed refresh persistence/reload errors are terminal rather than a signal to switch credential sources. That supports OpenClaw treating Codex CLI auth as bootstrap-only after ownership is adopted.

Exact-head proof: 398 focused tests passed across four Vitest shards, git diff --check passed, and the upstream refresh merged without overlapping the auth surface. The previous patch head's only flaky CI job passed on retry: https://github.com/openclaw/openclaw/actions/runs/28611321412/job/84846971946. Prior Crabbox proof also exited 0 (run_f588428d1d3d, lease cbx_72769aa34e91).

Remaining proof gap: the patched branch was not replayed with the reporter's live invalidated customer credential; the deterministic regression coverage reproduces the credential-ownership and refresh-failure path without exposing live credentials.

@fuller-stack-dev

Copy link
Copy Markdown
Member

Live validation completed on exact head fdc83a8c132570c06c776190c4f4631efcd19c19.

Crabbox proof:

  • Run: run_5a6a669c51e6 (AWS/Linux proof record), exit 0
  • Environment: AWS c7a.8xlarge, Linux, Node 24.18.0
  • Before: built base 97ad0b7c211cf6025d16888643b344f373a8b7fe
  • After: built PR head fdc83a8c132570c06c776190c4f4631efcd19c19

Behavior proof:

  1. Seeded an isolated agent store with an expired managed OpenAI OAuth credential and a same-account, future-expiry Codex external credential. Both credentials were controlled synthetic invalid tokens.
  2. On the base revision, the managed refresh contacted the real OpenAI auth endpoint and failed, OpenClaw logged using external OAuth credential after refresh failure, and Codex app-server then contacted https://chatgpt.com/backend-api/codex/responses, which rejected the stale external credential with 401 Unauthorized.
  3. On the patched revision with the identical state, the external fallback was absent. OpenClaw surfaced the managed refresh failure as auth_permanent with re-authentication guidance instead of sending the stale external credential to the model endpoint.
  4. As a regression control, the patched revision performed a real API-key-backed agent turn with openai/gpt-5.4-mini and returned exactly API_KEY_SMOKE_OK.

The forwarded API key was allowlisted as a Crabbox secret and was absent from captured stdout/stderr. I deliberately did not consume a real user OAuth refresh token because OpenAI refresh tokens rotate; the OAuth failure case used controlled invalid credentials against the real auth/model endpoints.

Result: the original stale external fallback reproduces on the base, is removed on the exact PR head, and direct OpenAI API-key auth still works live.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member

Land-ready verification for exact head fdc83a8c132570c06c776190c4f4631efcd19c19:

  • Best-fix judgment: yes. Once OpenClaw has managed OpenAI OAuth token material, that canonical profile owns refresh/runtime auth. Codex CLI credentials remain bootstrap-only; a permanent managed refresh failure now fails closed with targeted re-auth guidance instead of silently reviving a separately invalidated external token. This removes the false-green behavior introduced by [codex] Fix Codex OAuth refresh fallback #82117 at the provider/auth ownership boundary rather than special-casing one caller.
  • Sibling/regression review: direct OpenAI platform models remain API-key-only; API-key fallback still works; Anthropic/MiniMax external CLI paths are unchanged; direct/private replies may identify the failing profile while group/channel replies omit it; doctor guidance shell-quotes profile IDs.
  • Codex contract checked directly at upstream b35d4b6b9d: codex-rs/login/src/auth/storage.rs:38-51; codex-rs/login/src/auth/manager.rs:1304-1400, 1588-1774, 2031-2057, 2197-2213, 2373-2462; codex-rs/core/src/client.rs:1357-1451, 2053-2076, 2130-2185. Codex persists refreshed tokens into its authoritative auth record, classifies revoked/reused/expired refresh failures as permanent, scopes that failure to the current auth snapshot, and performs 401 recovery through the auth manager.
  • Fresh review: $autoreview with Codex gpt-5.5 / high reasoning reported no actionable findings (patch is correct, confidence 0.83).
  • CI: rerun attempt 2 passed on the exact head, including checks-node-compact-small-whole-2: https://github.com/openclaw/openclaw/actions/runs/28612984265
  • Live proof: Crabbox run run_5a6a669c51e6 passed on AWS/Linux. The base reproduced the external fallback and real Codex endpoint 401; the patch surfaced permanent managed refresh failure/re-auth instead; a real openai/gpt-5.4-mini API-key positive control returned API_KEY_SMOKE_OK. Controlled invalid OAuth tokens were used, so no real user refresh token was consumed.
  • Focused/remote proof: 398 focused tests across four shards passed; changed-surface Crabbox/Testbox run run_f588428d1d3d exited 0.
  • Current-main safety: fetched upstream/main at c20171ddfc1313aed920d230a54985fe213f19e7; merge-tree is clean (1a7dff5f00d851b2d5389b95c0bd79c9f1bcafbc) with zero changed-file overlap despite branch divergence.

The fail-closed auth policy is accepted for landing under the maintainer request. I am proceeding with an exact-head squash merge.

@fuller-stack-dev
fuller-stack-dev merged commit 46598a1 into openclaw:main Jul 2, 2026
175 of 181 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member

Landed on main as 46598a120fcda9a283c9aef588cbcd4dbdf9bc0a.

Final state: exact-head CI attempt 2 passed, fresh $autoreview had no actionable findings, Crabbox live validation run_5a6a669c51e6 passed, and issue #99120 auto-closed as completed. The squash commit retains Eva as author and includes the contributor co-author trailer.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 3, 2026
…penclaw#99134)

Fail closed when managed OpenAI OAuth refresh fails instead of silently falling back to stale external Codex CLI credentials.

Make managed provider OAuth authoritative after bootstrap, preserve API-key and non-OpenAI external CLI behavior, and surface targeted re-auth guidance without exposing profile IDs in group/channel replies.

Fixes openclaw#99120.

Co-authored-by: Eva <[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 commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI OAuth refresh false-green falls back to invalidated external credential after managed relog

2 participants