fix(oauth): resolve GPT-5+ "Failed to extract accountId" with enhanced Codex OAuth scopes (#27055)#27091
Conversation
…penclaw#27055) Allow user-configured api type (e.g. openai-completions) to override the built-in model registry for a provider. This fixes openai-codex OAuth users whose tokens lack api.responses.write scope — they can now set api: openai-completions in their provider config to bypass the openai-codex-responses accountId extraction that fails with newer JWT formats. Also classify 'Failed to extract accountId from token' as an auth failover error so model fallback kicks in automatically.
Greptile SummaryThis PR successfully fixes the OAuth token scope issue (#27055) by allowing provider-level Key improvements:
Implementation quality:
Confidence Score: 5/5
Last reviewed commit: 4630583 |
|
This pull request has been automatically marked as stale due to inactivity. |
|
After updating to 2026.3.7 my codex-5.3 connection broke I am getting now: My baseUrl is set in openclaw.json to: https://api.openai.com/v1 |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Summary
Fixes #27055 — ChatGPT Pro OAuth tokens lack required API scopes, causing all GPT-5+ models to fail with "Failed to extract accountId from token" when using the
openai-codexprovider.Root Cause
pi-ai's built-in Codex OAuth flow requests only
openid profile email offline_accessscopes. Theopenai-codex-responsesstream provider callsextractAccountId(apiKey)on every API request, which decodes the JWT to findchatgpt_account_id. When the JWT doesn't contain this claim (due to insufficient scopes or changed JWT structure), all GPT-5+ models fail immediately.GPT-4o appeared to work because it could use the
openaiprovider (API key based,openai-completionsAPI), which never callsextractAccountId.Changes
Enhanced Codex OAuth provider (
src/agents/openai-codex-enhanced-oauth.ts):model.request(Completions API) +api.responses.write(Responses API)accountIdextraction: falls back to storedaccountIdinstead of throwing when the JWT lacks the claimaccountIdwhen refreshed JWT doesn't contain itregisterOAuthProviderto override pi-ai's built-inopenai-codexproviderLogin command update (
src/commands/openai-codex-oauth.ts):loginOpenAICodexEnhancedinstead of pi-ai'sloginOpenAICodexAuth profile refresh (
src/agents/auth-profiles/oauth.ts):Provider-level API override (
src/agents/pi-embedded-runner/model.ts) — previous commits:applyProviderApiOverride: allows users to forceopenai-completionsAPI for theopenai-codexprovider viaopenclaw.json, completely bypassingextractAccountIdError classification (
src/agents/pi-embedded-helpers/errors.ts) — previous commits:autherror for proper failoverAfter Fix
openai-codex(re-auth with new scopes)openai-codex+api: "openai-completions"overridemodel.requestscopeauth→ triggers failoverUser Action Required
Users must re-authenticate (
openclaw configure→ re-login with openai-codex) to obtain tokens with the expanded scopes.Test Plan
applyProviderApiOverride)auth)pnpm tsgo)pnpm format)openai-codexprovider