Skip to content

fix: device login polling bails on unrecognized error codes - #44

Merged
xjoker merged 1 commit into
xjoker:masterfrom
WhymustIhaveaname:master
Jul 6, 2026
Merged

xjoker merged 1 commit into
xjoker:masterfrom
WhymustIhaveaname:master

Conversation

@WhymustIhaveaname

Copy link
Copy Markdown
Contributor

The device flow polling (login --device) treated unknown/transient error codes as fatal and aborted immediately after a single poll, instead of continuing to poll.

Problem:

  • codex-switch login --device fails with Device token error: ... after one poll
  • This happens when the API returns an error code not in the known list

Fix (2 changes):

  1. Handle OAuth standard error format — {"error": "string_code", "error_description": "..."} in addition to OpenAI's nested {"error": {"code": "...", "message": "..."}}

  2. Make catch-all continue polling — instead of bailing on unrecognized error codes, log at debug level and keep polling until timeout (15 min). Transient API responses shouldn't abort the entire flow.

Tested: Device login on Linux headless server now polls correctly until user completes browser authorization.

The device flow polling treated unknown/transient error codes as fatal
and aborted immediately instead of continuing to poll.

Two fixes:
1. Handle OAuth standard error format {"error": "string_code"}
   in addition to OpenAI's nested {"error": {"code": "..."}}
2. Make the catch-all branch continue polling instead of bailing,
   logging the error at debug level for diagnostics

This prevents the device login from failing with 'Device token error'
after a single poll when the API returns a new or unknown error code.
@xjoker
xjoker merged commit 2ae6c02 into xjoker:master Jul 6, 2026
@xjoker

xjoker commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix. The diagnosis was right: device-code polling can return the OAuth standard error format {"error":"authorization_pending"}, and the old code treated it as fatal instead of continuing to poll.

I merged PR #44 to preserve the contribution, then followed up on dev with a tested version that also covers OpenAI nested error responses, slow_down handling, and retrying unknown transient polling errors. This will be called out in the 0.0.21 release notes.

Thanks again for catching and contributing the fix.

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.

2 participants