fix(telegram): honor fallback disable during connect - #82626
Conversation
Riccardo-Vecchi
left a comment
There was a problem hiding this comment.
I reproduced two edge cases that still undermine the fail-open/kill-switch contract:
-
The new discovery timeout is read through the local
_env_float, which accepts non-finite values. WithHERMES_TELEGRAM_FALLBACK_DISCOVERY_TIMEOUT=nanand a discovery coroutine waiting forever,_await_with_thread_deadlinedoes not releaseconnect(); an outer 200 ms deadline fires instead, and the watchdog emits a false "event loop BLOCKED" dump. (infhas the same unsafe shape.) This is the exact startup-hang class the PR is trying to bound. Could this use the existing finite/clamped parser, e.g.self._env_float_clamped(..., min_value=0.0), with a regression case for non-finite input? -
When fallback is disabled but
config.extra.fallback_ipsis populated, those disabled IPs are still included inproxy_targets.resolve_proxy_url()bypasses the proxy whenNO_PROXYmatches any target. Reproduction: fallback IP149.154.167.220,HERMES_TELEGRAM_DISABLE_FALLBACK_IPS=true,TELEGRAM_PROXY=http://127.0.0.1:8080,NO_PROXY=149.154.167.220;connect()succeeds but the constructed polling request hasproxy=None. Since the only actual target is nowapi.telegram.org, this can suppress the required proxy and break bootstrap. Clearing disabled fallback IPs (or excluding them fromproxy_targets) would make the kill switch apply to all downstream decisions.
Both were exercised against head 010175c1 as focused async integration tests in test_telegram_polling_progress.py; result: 2 failed.
010175c to
76f4a93
Compare
Thanks, both edge cases were valid. I updated the patch so the fallback discovery timeout uses the existing finite/clamped parser, which makes NaN/Inf fall back to the default 5s deadline instead of defeating the bound. I also clear configured fallback IPs when HERMES_TELEGRAM_DISABLE_FALLBACK_IPS=true, so disabled fallback hosts no longer participate in proxy target resolution or NO_PROXY matching. With the kill switch set, the only proxy target is api.telegram.org. Added focused regressions for both cases:
Validation: Result: |
|
Merged via #86676 — your commit was cherry-picked onto current main with your authorship preserved in git log, including your non-finite-timeout hardening and the four regression tests. Thank you for the thorough fail-open design and for addressing the review edge cases. Closing this PR as merged-via #86676. |
Addresses #80632
Related to #82558
Telegram cold connect could still enter or be affected by fallback-IP preparation before reaching the plain PTB connect path.
This patch makes fallback preparation bounded and fail-open:
Regression coverage:
Validation:
python3 -m py_compile plugins/platforms/telegram/adapter.py
uv run --extra dev pytest tests/gateway/test_telegram_polling_progress.py tests/gateway/test_telegram_init_deadline.py tests/gateway/test_telegram_network.py -q
git diff --check
Result:
34 passed
git diff --check clean