Skip to content

fix(channels): catch all TimeoutException subclasses and safely parse Retry-After in retry_request - #643

Open
tejajakarulloh wants to merge 1 commit into
use-agent-os:mainfrom
tejajakarulloh:fix/channels-retry-request-timeouts-and-retry-after
Open

fix(channels): catch all TimeoutException subclasses and safely parse Retry-After in retry_request#643
tejajakarulloh wants to merge 1 commit into
use-agent-os:mainfrom
tejajakarulloh:fix/channels-retry-request-timeouts-and-retry-after

Conversation

@tejajakarulloh

Copy link
Copy Markdown
Contributor

Fixes #642

Problem

retry_request (src/agentos/channels/_util.py) has two bugs:

  1. Incomplete timeout handling — catches (httpx.ConnectError, httpx.ReadTimeout) but misses ConnectTimeout, WriteTimeout, and PoolTimeout. These are all httpx.TimeoutException subclasses, not ConnectError subclasses (separate inheritance branches under TransportError). A DNS/TLS handshake timeout crashes through without retry.

  2. Unsafe Retry-After parsingfloat(resp.headers.get("Retry-After", ...)) raises ValueError if the header contains an HTTP-date string (RFC 7231 §7.1.3 permits both formats).

Fix

  • Widen the exception clause from (httpx.ConnectError, httpx.ReadTimeout) to (httpx.ConnectError, httpx.TimeoutException).
  • Wrap Retry-After parsing in try/except (ValueError, TypeError) with fallback to exponential backoff; clamp with max(0.0, ...).

Testing

New test file tests/test_channels/test_channel_retry_util.py covers:

  • All four TimeoutException subclasses are retried (ConnectTimeout, ReadTimeout, WriteTimeout, PoolTimeout)
  • ConnectError still retried (unchanged behavior)
  • Exhaustion after max retries raises
  • Numeric Retry-After header honored
  • Non-numeric / HTTP-date / missing Retry-After falls back to backoff

All existing channel tests pass (306 passed).

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.

[Bug]: retry_request misses ConnectTimeout/WriteTimeout and crashes on non-numeric Retry-After

1 participant