nanocoder
nanocoder copied to clipboard
[Bug] Codex login keeps polling for 5 minutes after the token exchange fails
Description
During the ChatGPT/Codex device login, pollForCodexAuthorization exchanges the authorization code for tokens. If that exchange fails (HTTP 400), the error is swallowed by the "network errors, keep trying" catch, and the loop polls again with the same one-time code until the 5-minute timeout. The user never sees the real error.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at eb7dee57)
- Provider: ChatGPT/Codex (fake backend)
- Model: Not model-specific
Steps to Reproduce
- Call
pollForCodexAuthorization('dev', 'user', saveFn, fetchFn)with afetchFnthat returns HTTP 200{authorization_code, code_verifier}for the device token URL and HTTP 400invalid_grantfor the OAuth token URL. - Wait 12 seconds.
Expected Behavior
The promise rejects at once with Token exchange failed: 400 ....
Actual Behavior
Still polling after 12 seconds. The two requests repeat every 5 seconds (5 requests in the test).
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/auth/chatgpt-codex.ts:98(exchangeCodeForTokens) and the catch at:107-122: only keep polling for network errors from the poll request itself. Let the "Token exchange failed" error (and a failedsaveFn) end the login.- Add a test with a failing token exchange.
I'll take this one. The fix is to keep only the poll request inside the network-error retry, so a failed token exchange or save ends the login.