#19217: fix(auth): route openai-codex to built-in OAuth in models auth login
commands
size: S
Cluster:
Model Cooldown Management
## Summary
- **Problem**: `openclaw models auth login --provider openai-codex` fails with "Unknown provider" because `modelsAuthLoginCommand` resolves providers exclusively from the plugin registry, but openai-codex uses a built-in OAuth flow (`loginOpenAICodexOAuth`) that bypasses plugins entirely. Found this after `openclaw doctor` told me to re-authenticate and the exact command it suggested was a dead end.
- **Root cause**: The onboarding wizard calls `loginOpenAICodexOAuth` directly, but the `models auth login` command path has no equivalent early-return for built-in OAuth providers. When `openclaw doctor` suggests re-authenticating via `models auth login`, users hit a dead end.
- **Solution**: Add an early-return check in `modelsAuthLoginCommand` that intercepts `--provider openai-codex` before plugin resolution, calling the same `loginOpenAICodexOAuth` + `writeOAuthCredentials` functions already used by the onboarding wizard.
- **Scope boundary**: No changes to existing plugin-based provider paths — other providers work exactly as before.
## Change Type
- [x] Bug fix
## Scope
- [x] Auth / tokens
- [x] UI / DX (CLI)
## Linked Issue
Fixes #19124
## User-visible Changes
- `openclaw models auth login --provider openai-codex` now triggers the OAuth flow (same as onboarding), allowing users to refresh expired codex tokens without re-running `openclaw onboard`.
## Security Impact
- New permissions/capabilities? `No`
- Secrets/tokens handling changed? `No` — reuses existing `loginOpenAICodexOAuth` + `writeOAuthCredentials` functions
- New/changed network calls? `No` — same OAuth flow already used by onboarding
- Command/tool execution surface changed? `No`
- Data access scope changed? `No`
## Repro + Verification
### Environment
- OS: Ubuntu 24.04 (Linux 6.8.0)
- Runtime: Node 22.x + pnpm
- OpenClaw: v2026.2.x
### Steps
1. Set up openai-codex provider via `openclaw onboard`
2. Wait for OAuth token to expire
3. Run `openclaw models auth login --provider openai-codex`
### Expected
OAuth flow triggers and token is refreshed.
### Actual (before fix)
Fails with "Unknown provider" — no way to re-authenticate without re-running onboarding.
## Evidence
- [x] Failing test/log before + passing after
```
✓ src/commands/models.auth.openai-codex.test.ts (4 tests)
✓ successful OAuth login writes credentials and applies auth profile
✓ cancelled OAuth flow exits without writing credentials
✓ --set-default flag sets openai-codex as default model
✓ without --set-default does not modify default model
✓ src/commands/models.auth.provider-resolution.test.ts (4 tests) — no regression
```
## Compatibility
- Backward compatible: `Yes` — early-return only activates for `openai-codex`; all other providers use existing plugin path unchanged
- Config changes: `None`
- Migration: `None`
## Failure Recovery
- Revert: `git revert <sha>` — single commit
- Symptom to watch: `models auth login --provider openai-codex` returning to "Unknown provider" would indicate revert needed
## Risks
- Risk: Future built-in OAuth providers would need similar early-return blocks.
- Mitigation: Pattern is explicit and localized (3 imports + 1 block). If more providers are added, the pattern can be extracted into a registry. Current scope is surgical.
AI-assisted: Yes (Claude Code). Fully tested — all tests pass.
Most Similar PRs
#17531: fix(auth): sync Codex CLI credentials into auth profile store and c...
by sauerdaniel · 2026-02-15
74.5%
#23694: fix: allow OAuth provider models in isolated sessions
by maximalmargin · 2026-02-22
71.1%
#18670: feat: add first-class Claude Code CLI auth path + CLI model UX hard...
by SmithLabsLLC · 2026-02-16
71.0%
#17392: Add testing infrastructure and expand gateway OAuth scopes
by jordanhubbard · 2026-02-15
70.6%
#23117: wizard: add manual endpoint type selection when custom provider det...
by wjonaskr · 2026-02-22
69.5%
#21884: feat(models): auth improvements — status command, heuristics, multi...
by kckylechen1 · 2026-02-20
69.4%
#23256: fix(providers): disable developer role for zhipu provider and bigmo...
by SidQin-cyber · 2026-02-22
68.4%
#22105: feat(auth): add refreshable Anthropic OAuth login flow
by sauerdaniel · 2026-02-20
68.2%
#19267: fix: derive failover reason from timedOut flag to prevent unknown c...
by austenstone · 2026-02-17
67.9%
#20388: fix(failover): don't skip same-provider fallback models when cooldo...
by Limitless2023 · 2026-02-18
67.9%