Skip to content

Handle OpenAI device auth rate limits#3969

Open
baditaflorin wants to merge 2 commits into
OpenHands:mainfrom
baditaflorin:codex/openai-device-auth-429
Open

Handle OpenAI device auth rate limits#3969
baditaflorin wants to merge 2 commits into
OpenHands:mainfrom
baditaflorin:codex/openai-device-auth-429

Conversation

@baditaflorin

@baditaflorin baditaflorin commented Jul 2, 2026

Copy link
Copy Markdown

HUMAN:

Florin requested this fix after hitting the OpenAI device-auth 500 locally.


AGENT:

Why

OpenAI can rate-limit ChatGPT device-code sign-in. When that happens today, the SDK raises a generic RuntimeError; the agent-server route does not translate it into an HTTP response, so FastAPI reports an unhandled exception and returns 500 Internal Server Error. In local reproduction, POST /api/llm/subscription/openai/device/start returned a 500 with Device code request failed with status 429.

This PR makes the provider failure explicit and returns a retryable 429 Too Many Requests response to callers instead of treating OpenAI rate limiting as an internal server crash.

Summary

  • Add OpenAIDeviceAuthError so OpenAI device-auth failures carry the upstream status code.
  • Map OpenAI device-auth 429s to HTTP 429 responses in the agent-server subscription routes.
  • Keep pending device-login state intact when poll requests hit retryable OpenAI auth failures.

Issue Number

N/A

How to Test

I ran the targeted router tests and formatting/lint checks:

uv run ruff format openhands-agent-server/openhands/agent_server/llm_router.py openhands-sdk/openhands/sdk/llm/auth/openai.py tests/agent_server/test_llm_router.py
uv run ruff check openhands-agent-server/openhands/agent_server/llm_router.py openhands-sdk/openhands/sdk/llm/auth/openai.py tests/agent_server/test_llm_router.py
uv run pytest tests/agent_server/test_llm_router.py

Result:

18 passed in 2.70s

I also reproduced the behavior locally before making the PR: OpenAI returned status 429 from the device-code endpoint, which previously surfaced as a 500. After the same change was applied locally, the agent-server route returned 429 Too Many Requests with a clear retry message.

Video/Screenshots

N/A, API behavior change covered by route tests and local curl reproduction.

Type

Bug fix

@baditaflorin baditaflorin marked this pull request as ready for review July 2, 2026 19:11
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @baditaflorin, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the repository maintainers.

@baditaflorin

Copy link
Copy Markdown
Author

@openhands-agent waiting for youy to merge it

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