nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Codex login keeps polling for 5 minutes after the token exchange fails

Open addyCooks opened this issue 1 week ago • 1 comments

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

  1. Call pollForCodexAuthorization('dev', 'user', saveFn, fetchFn) with a fetchFn that returns HTTP 200 {authorization_code, code_verifier} for the device token URL and HTTP 400 invalid_grant for the OAuth token URL.
  2. 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 failed saveFn) end the login.
  • Add a test with a failing token exchange.

addyCooks avatar Nov 23 '26 07:11 addyCooks

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.

MaxonT avatar Nov 23 '26 08:11 MaxonT