Skip to content

Restrict Codex OAuth CLI fallback#876

Merged
steipete merged 4 commits intosteipete:mainfrom
ViperThanks:codex-oauth-restrict-cli-fallback
May 10, 2026
Merged

Restrict Codex OAuth CLI fallback#876
steipete merged 4 commits intosteipete:mainfrom
ViperThanks:codex-oauth-restrict-cli-fallback

Conversation

@ViperThanks
Copy link
Copy Markdown
Contributor

Summary

  • restrict Codex OAuth auto fallback to missing/invalid auth cases
  • keep transient OAuth API, decode, and no-rate-limit errors from spawning the CLI fallback
  • return partial OAuth data in auto mode when the API response has usable windows or credits
  • document the safer Codex auto fallback rule

Fixes #874.

Validation

  • swift build --target CodexBarCore
  • git diff --check

Note: swift test --filter CodexOAuthTests could not run in this environment because only Command Line Tools are active and the KeyboardShortcuts dependency fails to compile SwiftUI #Preview macros without full Xcode (PreviewsMacros not found).

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9137b6417c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +184 to +185
case .networkError, .invalidResponse, .none:
return false
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve fallback for non-401 refresh denials

When a stale auth.json triggers a token refresh and the OAuth server rejects it with a non-401 status (for example the common HTTP 400 invalid_grant/revoked-token response), CodexTokenRefresher.refresh maps that to RefreshError.invalidResponse at CodexTokenRefresher.swift:69-70. Returning false for .invalidResponse here stops the auto pipeline instead of trying the CLI fallback, even though this is still an invalid-auth state that codex app-server can repair; users in that refresh-failure path will see the OAuth error rather than their CLI usage.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I updated the refresh failure classification instead of broadly allowing all invalidResponse errors to fall back.

Non-401 OAuth refresh failures with invalid_grant now map to .revoked, so auto mode still falls back to CLI for stale/revoked refresh tokens. Other non-auth refresh failures, such as invalid_request, remain .invalidResponse and do not trigger CLI fallback.

@ViperThanks ViperThanks force-pushed the codex-oauth-restrict-cli-fallback branch from 9137b64 to 190f10e Compare May 9, 2026 07:24
@ViperThanks
Copy link
Copy Markdown
Contributor Author

Good catch. I updated the refresh failure classification instead of broadly allowing all invalidResponse errors to fall back.

Non-401 OAuth refresh failures with invalid_grant now map to .revoked, so auto mode still falls back to CLI for stale/revoked refresh tokens. Other non-auth refresh failures, such as invalid_request, remain .invalidResponse and do not trigger CLI fallback.

@steipete steipete force-pushed the codex-oauth-restrict-cli-fallback branch from 48c3fae to d69ac14 Compare May 9, 2026 23:54
@steipete steipete force-pushed the codex-oauth-restrict-cli-fallback branch from d69ac14 to 421f81f Compare May 9, 2026 23:56
@steipete steipete merged commit df47517 into steipete:main May 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex provider falls back to CLI on any OAuth error, causing unexpected token consumption (~3M tokens per invocation)

2 participants