Skip to content

fix(channels): catch ConnectTimeout/WriteTimeout and handle non-numeric Retry-After (#642) - #645

Closed
Tiktokaiagent wants to merge 3 commits into
use-agent-os:mainfrom
Tiktokaiagent:fix/642-retry-request-timeouts
Closed

fix(channels): catch ConnectTimeout/WriteTimeout and handle non-numeric Retry-After (#642)#645
Tiktokaiagent wants to merge 3 commits into
use-agent-os:mainfrom
Tiktokaiagent:fix/642-retry-request-timeouts

Conversation

@Tiktokaiagent

@Tiktokaiagent Tiktokaiagent commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two bugs in retry_request that cause unnecessary crashes in production:

  1. Missing timeout exception typeshttpx.ConnectTimeout and WriteTimeout inherit from TimeoutException, not ConnectError. Added httpx.TimeoutException to the catch clause so all transient timeouts (DNS, TLS, write, pool) are retried instead of crashing.

  2. Non-numeric Retry-After crash — Per RFC 7231 §7.1.3, Retry-After can be an HTTP-date string (e.g. Wed, 21 Oct 2026 07:28:00 GMT). A bare float() call on such values causes a ValueError crash. Added try/except fallback to the standard exponential backoff delay.

Changes

  • src/agentos/channels/_util.py: Added httpx.TimeoutException to retry catch clause
  • src/agentos/channels/_util.py: Wrapped float(Retry-After) in try/except with fallback to base_delay * (2**attempt)

Tests

6 new regression tests in tests/test_channels/test_channel_retry_util.py:

$ uv run pytest tests/test_channels/test_channel_retry_util.py -v --tb=short
...
tests/test_channels/test_channel_retry_util.py::test_retry_429_with_numeric_retry_after PASSED
tests/test_channels/test_channel_retry_util.py::test_retry_429_with_http_date_retry_after_falls_back PASSED
tests/test_channels/test_channel_retry_util.py::test_retry_429_with_empty_retry_after_falls_back PASSED
tests/test_channels/test_channel_retry_util.py::test_retry_connect_timeout PASSED
tests/test_channels/test_channel_retry_util.py::test_retry_generic_timeout_exception PASSED
tests/test_channels/test_channel_retry_util.py::test_retry_exhausted_raises_last_exception PASSED
============================== 6 passed in 0.90s ===============================

All channel tests still pass:

$ uv run pytest tests/test_channels/ -q
48 passed
  • This pull request fully resolves the linked issue.
  • Bug fix: no breaking changes to existing behavior
  • Both fixes are minimal, targeted changes in a single file

Fixes #642

Tiktokaiagent and others added 2 commits September 1, 2026 17:30
…ic Retry-After

Fixes two bugs in retry_request:
1. httpx.ConnectTimeout and WriteTimeout are not subclasses of
   ConnectError — they inherit from TimeoutException via a separate
   hierarchy. Added TimeoutException to the catch clause.
2. Retry-After header can be an HTTP-date string per RFC 7231 §7.1.3,
   not just delay-seconds. A bare float() call crashes on non-numeric
   values. Added try/except fallback to default backoff delay.

Fixes use-agent-os#642
…y-After (use-agent-os#642)

## Tests (6 new)
- test_retry_429_with_numeric_retry_after
- test_retry_429_with_http_date_retry_after_falls_back
- test_retry_429_with_empty_retry_after_falls_back
- test_retry_connect_timeout
- test_retry_generic_timeout_exception
- test_retry_exhausted_raises_last_exception

## Verification
- uv run pytest tests/test_channels/test_channel_retry_util.py -v — 6 passed
- uv run pytest tests/test_channels/ -q — 48 passed (was 42)
@Tiktokaiagent
Tiktokaiagent force-pushed the fix/642-retry-request-timeouts branch from a80604d to f9b3827 Compare September 1, 2026 17:30
@andreapn

andreapn commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #782, which landed for #642 and #599 together — the issue thread asked for the three defects in retry_request to land as one coherent change rather than as conflicting edits to the same 30-line function, and #782 was the only PR covering all three. Thanks for the fix; the diagnosis in this PR matched, it was the scope that decided it.

@andreapn andreapn closed this Sep 2, 2026
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

2 participants