Skip to content

fix(auth): improve network error messages and add retry resilience during token polling#579

Draft
raymyers wants to merge 1 commit intomainfrom
fix/token-polling-network-error-resilience
Draft

fix(auth): improve network error messages and add retry resilience during token polling#579
raymyers wants to merge 1 commit intomainfrom
fix/token-polling-network-error-resilience

Conversation

@raymyers
Copy link
Contributor

@raymyers raymyers commented Mar 8, 2026

What changed

Two bugs fixed in the OAuth 2.0 device flow login path, surfaced by a real login failure:

Error: Network error during token polling: Network error: 
Authentication failed: Network error during token polling: Network error: 

Bug 1 — Confusing empty error message (http_client.py)

httpx.RequestError subclasses (e.g. ConnectError) can produce an empty str(e). The previous code did:

raise AuthHttpError(f"Network error: {str(e)}")   # → "Network error: "

Fix: fall back to the exception class name when the string is empty:

error_msg = str(e) or type(e).__name__
raise AuthHttpError(f"Network error: {error_msg}")  # → "Network error: ConnectError"

Bug 2 — Single network blip kills the entire login (device_flow.py)

The polling loop raised immediately on the first AuthHttpError, even though the error could be transient (brief connectivity hiccup, DNS blip, etc.). A 10-minute polling window that fails on the very first attempt is not resilient.

Fix: track consecutive network errors and only raise after max_network_errors (default: 3) consecutive failures. Each failed attempt sleeps for interval seconds before retrying, consistent with the rest of the polling loop.

Commands run

make lint    # all checks passed
uv run pytest -m "not integration" --ignore=tests/snapshots -q
# 1274 passed

Before / After

Before:

Waiting for authentication to complete...
Error: Network error during token polling: Network error: 
Authentication failed: Network error during token polling: Network error: 

After (persistent failure):

Waiting for authentication to complete...
Error: Network error during token polling: Network error: ConnectError
Authentication failed: Network error during token polling: Network error: ConnectError

After (transient failure — now recovers silently):

Waiting for authentication to complete...
✓ Authentication successful!

🚀 Try this PR

uvx --python 3.12 git+https://github.com/OpenHands/OpenHands-CLI.git@fix/token-polling-network-error-resilience

…ring token polling

- http_client.py: fall back to exception class name when str(httpx.RequestError)
  is empty, preventing the confusing trailing 'Network error: ' with no detail
- device_flow.py: retry transient network errors up to max_network_errors (3)
  consecutive times before failing, so a brief connectivity blip no longer kills
  the entire login flow
- tests: add test for empty-message fallback; update network-error test to assert
  3 retries are made; add new transient-recovery test

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands_cli/auth
   device_flow.py101298%124–125
   http_client.py470100% 
TOTAL664793385% 

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