feat: add codex oauth plan override#2808
feat: add codex oauth plan override#2808WeilongHan wants to merge 1 commit intorouter-for-me:devfrom
Conversation
|
This pull request targeted The base branch has been automatically changed to |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to override the Codex plan type via the CODEX_OAUTH_PLAN_OVERRIDE environment variable for non-API key authentication methods. It includes a new helper function for validation and a corresponding unit test. The review feedback suggests optimizing the helper function by using sync.Once to prevent log spam from invalid environment values and ensuring the returned plan type is consistently lowercased.
| func codexOAuthPlanOverride() string { | ||
| raw := strings.TrimSpace(os.Getenv("CODEX_OAUTH_PLAN_OVERRIDE")) | ||
| if raw == "" { | ||
| return "" | ||
| } | ||
| switch strings.ToLower(raw) { | ||
| case "free", "plus", "pro", "team", "business", "go": | ||
| return raw | ||
| default: | ||
| log.Warnf("ignoring invalid CODEX_OAUTH_PLAN_OVERRIDE value: %q", raw) | ||
| return "" | ||
| } | ||
| } |
There was a problem hiding this comment.
The codexOAuthPlanOverride function is called during model registration, which can occur frequently (e.g., on every auth update or periodic refresh). Since it reads from the environment and performs validation with a potential warning log, it's better to avoid repeated log spam if an invalid value is provided. Additionally, normalizing the return value to lowercase simplifies the logic for callers and ensures consistency.
var codexOverrideWarnOnce sync.Once
func codexOAuthPlanOverride() string {
raw := strings.TrimSpace(os.Getenv("CODEX_OAUTH_PLAN_OVERRIDE"))
if raw == "" {
return ""
}
val := strings.ToLower(raw)
switch val {
case "free", "plus", "pro", "team", "business", "go":
return val
default:
codexOverrideWarnOnce.Do(func() {
log.Warnf("ignoring invalid CODEX_OAUTH_PLAN_OVERRIDE value: %q", raw)
})
return ""
}
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb8c60ece1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if authKind != "apikey" { | ||
| if override := codexOAuthPlanOverride(); override != "" { | ||
| codexPlanType = override | ||
| } |
There was a problem hiding this comment.
Restrict plan override to OAuth auth_kind
The new override gate uses if authKind != "apikey", which treats auth_kind: "api_key" as non-API-key and applies CODEX_OAUTH_PLAN_OVERRIDE to that credential. In this codebase, api_key is a recognized account type (AccountInfo() returns "api_key"), so Codex API-key auths using that spelling can now be forced onto OAuth plan model sets whenever the env var is set. This is a regression from the “OAuth-only override” intent and can expose or hide models unexpectedly for API-key clients.
Useful? React with 👍 / 👎.
No description provided.