Repository navigation
fix: OAuth refresh failures report reauth instead of stale success - #99134
fuller-stack-dev merged 8 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Codex review: needs maintainer review before merge. Reviewed July 2, 2026, 4:09 PM ET / 20:09 UTC. Summary 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.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest 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 changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +86, Tests +457, Docs +1. Total +544 across 18 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
fuller-stack-dev
left a comment
There was a problem hiding this comment.
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-173still documents the fallback this PR removes.- The immediate failed-turn guidance still calls
buildOAuthRefreshFailureLoginCommandwithout a profile ID atsrc/auto-reply/reply/agent-runner-execution.ts:988-992;OAuthRefreshFailureErroralso does not carry theOAuthManagerRefreshError.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.
|
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 |
|
Addressed the P1 review on head
Validation now on PR body: provider-wide regression passes, focused touched suites pass (4 shards / 277 tests), Autoreview note: the first local Codex autoreview surfaced one valid P1 ( @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
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:
Verification on head
|
fuller-stack-dev
left a comment
There was a problem hiding this comment.
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.tsowns the bootstrap boundary and no longer synthesizes a siblingopenai:defaultCodex CLI profile once OpenClaw already owns managed OpenAI OAuth token material.src/agents/auth-profiles/oauth-manager.tsnow fails closed when managed refresh fails instead of switching credential ownership to stale external Codex state.src/agents/model-auth.tspreserves 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.
|
Live validation completed on exact head Crabbox proof:
Behavior proof:
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 |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Land-ready verification for exact head
The fail-closed auth policy is accepted for landing under the maintainer request. I am proceeding with an exact-head squash merge. |
|
Landed on Final state: exact-head CI attempt 2 passed, fresh |
…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]>
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:defaultis 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-devon head66e088aff75f6727dc2c1754007d963fdceb6ad0:external-cli-sync.tsno longer synthesizes runtime-only Codex CLIopenai:defaultbeside a named local OpenAI OAuth profile in provider-wide discovery.resolveApiKeyForProviderpreserves the first typedOAuthRefreshFailureErrorwhile trying auth candidates and throws it when no earlier env/custom/synthetic fallback succeeds.OAuthRefreshFailureErrorcarries a sanitized provider-prefixedprofileId;OAuthManagerRefreshErrorpasses it through with an explicitoverride.--profile-idfor typed refresh failures.docs/concepts/oauth.mdno 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" })returnedprofile: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.profileIdneededoverrideafter adding the base property); fixed in this PR and proven bypnpm tsgo:core. A second Codex-engine rerun stalled with heartbeat-only output and returned only a wrapperKeyboardInterrupttrace when interrupted. Claude-engine fallback failed due local Claude connector/auth precedence, not code.