fix(channels): retry ConnectTimeout/PoolTimeout in Telegram API calls… - #652
Closed
andrew1234-arch wants to merge 1 commit into
Closed
fix(channels): retry ConnectTimeout/PoolTimeout in Telegram API calls…#652andrew1234-arch wants to merge 1 commit into
andrew1234-arch wants to merge 1 commit into
Conversation
… 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
1 task
3 tasks
Contributor
|
Closing in favor of #782, which landed for #642 and #599 together — the issue thread asked for the three defects in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Fixes #651
says what remains.
Summary
TelegramChannel._api()has its own independent retry loop (separate fromthe shared
retry_request()helper in_util.pythat #642/#643/#645patch — Telegram never calls that function). Its retry-with-backoff branch
only catches
httpx.ConnectError, buthttpx.ConnectTimeout(DNS/TLShandshake timeout) and
httpx.PoolTimeout(no pooled connectionavailable) are siblings of
ConnectErrorunderTransportError, notsubclasses of it. Both fall through to the generic
except httpx.RequestError:branch and raiseTelegramApiErroron the veryfirst attempt, with zero retries.
This fix extends the retry branch to
(httpx.ConnectError, httpx.ConnectTimeout, httpx.PoolTimeout).WriteTimeout/ReadTimeoutare 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
ConnectTimeoutandPoolTimeoutnow retry and succeed,mirroring the existing
ConnectErrortest.test_telegram_api_does_not_retry_post_send_timeouts— confirmsWriteTimeout/ReadTimeoutstill raise immediately, guarding againsta 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.