Skip to content

fix(channels): retry ConnectTimeout/PoolTimeout in Telegram API calls… - #652

Closed
andrew1234-arch wants to merge 1 commit into
use-agent-os:mainfrom
andrew1234-arch:fix/telegram-connecttimeout-retry
Closed

fix(channels): retry ConnectTimeout/PoolTimeout in Telegram API calls…#652
andrew1234-arch wants to merge 1 commit into
use-agent-os:mainfrom
andrew1234-arch:fix/telegram-connecttimeout-retry

Conversation

@andrew1234-arch

Copy link
Copy Markdown

Linked issue

Fixes #651

  • This pull request fully resolves the linked issue, or the description
    says what remains.

Summary

TelegramChannel._api() has its own independent retry loop (separate from
the shared retry_request() helper in _util.py that #642/#643/#645
patch — Telegram never calls that function). Its retry-with-backoff branch
only catches httpx.ConnectError, but httpx.ConnectTimeout (DNS/TLS
handshake timeout) and httpx.PoolTimeout (no pooled connection
available) are siblings of ConnectError under TransportError, not
subclasses of it. Both fall through to the generic except httpx.RequestError: branch and raise TelegramApiError on the very
first attempt, with zero retries.

This fix extends the retry branch to (httpx.ConnectError, httpx.ConnectTimeout, httpx.PoolTimeout). WriteTimeout/ReadTimeout
are deliberately left out of the retry set: those can occur after
Telegram has already received the request, so blindly retrying risks
Telegram acting on it twice (e.g. sending the same message twice).

Tests

Added two parametrized regression tests to tests/test_channels/test_telegram_retry.py:

  • test_telegram_api_retries_pre_send_timeouts_like_connect_error
    confirms ConnectTimeout and PoolTimeout now retry and succeed,
    mirroring the existing ConnectError test.
  • test_telegram_api_does_not_retry_post_send_timeouts — confirms
    WriteTimeout/ReadTimeout still raise immediately, guarding against
    a future "just catch everything" regression.

Commands run locally:
uv sync --extra dev
uv run ruff check src/agentos/channels/telegram.py tests/test_channels/test_telegram_retry.py
uv run mypy src/agentos/channels/telegram.py --show-error-codes
uv run pytest tests/test_channels/ -q

Results: ruff — all checks passed. mypy — no issues found. pytest
296 passed, no regressions.

Third-party origin: none.

… like ConnectError

httpx.ConnectTimeout and httpx.PoolTimeout are siblings of ConnectError
(both under TransportError, not one under the other), so _api()'s retry
loop only caught ConnectError and let both fall through to the generic
RequestError branch, raising immediately with no retry. Both occur
before any request bytes reach Telegram, so retrying is safe -- unlike
WriteTimeout/ReadTimeout, which are deliberately left unretried since
the request may have already been sent.

Fixes use-agent-os#651
@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]: Telegram channel does not retry ConnectTimeout/PoolTimeout like ConnectError, causing avoidable API call failures

2 participants