The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(telegram): parse max_concurrent_updates with coerce_port
kshitijk4poorc03cca2763b6
diff --git a/gateway/platforms/_shared.py b/gateway/platforms/_shared.pyindex 6c20976aa3b..cf220e0c414 100644--- a/gateway/platforms/_shared.py+++ b/gateway/platforms/_shared.py@@ -243,8 +243,8 @@ def env_is_connected(*names: str) -> Callable[[Any], bool]:def coerce_port(value: Any, default: int) -> int:- """``int(value)`` or ``default`` when unparseable."""+ """``int(value)`` or ``default`` when unparseable (incl. non-finite YAML like ``.inf``)."""try:return int(value)- except (TypeError, ValueError):+ except (TypeError, ValueError, OverflowError):return defaultdiff --git a/plugins/platforms/telegram/update_admission.py b/plugins/platforms/telegram/update_admission.pyindex 4557902afe3..d973bb36741 100644--- a/plugins/platforms/telegram/update_admission.py+++ b/plugins/platforms/telegram/update_admission.py@@ -19,6 +19,7 @@ from functools import wrapsfrom telegram import Updatefrom telegram.ext import Application, ApplicationHandlerStop, ConversationHandler, SimpleUpdateProcessor+from gateway.platforms._shared import coerce_portfrom gateway.platforms.helpers import bounded_putfrom utils import atomic_json_write@@ -169,10 +170,7 @@ class PerChatUpdateProcessor(SimpleUpdateProcessor):def build_update_processor(extra, name: str) -> PerChatUpdateProcessor:"""``platforms.telegram.extra.max_concurrent_updates`` (default 32); bad values warn and fall back."""raw = extra.get("max_concurrent_updates", DEFAULT_MAX_CONCURRENT_UPDATES)- try:- limit = int(raw)- except (TypeError, ValueError):- limit = 0+ limit = coerce_port(raw, 0)if limit < 1:logger.warning("[%s] Invalid max_concurrent_updates=%r; using %d",name, raw, DEFAULT_MAX_CONCURRENT_UPDATES)diff --git a/tests/plugins/test_telegram_update_admission.py b/tests/plugins/test_telegram_update_admission.pyindex 0f74738512c..d34851b5b96 100644--- a/tests/plugins/test_telegram_update_admission.py+++ b/tests/plugins/test_telegram_update_admission.py@@ -807,8 +807,9 @@ async def test_connect_builds_concurrent_update_processor(monkeypatch):async with connected(monkeypatch, extra={"max_concurrent_updates": 7}) as (adapter, app, delivered):assert app.concurrent_updates == 7- async with connected(monkeypatch, extra={"max_concurrent_updates": "lots"}) as (adapter, app, delivered):- assert app.concurrent_updates == DEFAULT_MAX_CONCURRENT_UPDATES+ for bad in ("lots", float("inf")): # .inf in YAML: int() raises OverflowError+ async with connected(monkeypatch, extra={"max_concurrent_updates": bad}) as (adapter, app, delivered):+ assert app.concurrent_updates == DEFAULT_MAX_CONCURRENT_UPDATES# Cancelling a waiting same-chat update must neither fail its running predecessor nor# let the next update of that chat overtake it.