Skip to content

The agent that grows with you

fix(gateway): allow Telegram readiness budget

mannnrachman9f8810a69371
diff --git a/gateway/run.py b/gateway/run.py
index 1cfbfdef055..5e0aa1b565d 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -78,6 +78,10 @@ from hermes_cli.fallback_config import get_fallback_chain
_AGENT_CACHE_MAX_SIZE = 128
_AGENT_CACHE_IDLE_TTL_SECS = 3600.0 # evict agents idle for >1h
_PLATFORM_CONNECT_TIMEOUT_SECS_DEFAULT = 30.0
+# Telegram cold polling now proves one real getUpdates round trip before connect
+# returns. Leave enough outer budget for initialize/deleteWebhook/start_polling
+# wall deadlines plus readiness; other platforms retain the 30s isolation bound.
+_TELEGRAM_CONNECT_TIMEOUT_SECS_DEFAULT = 180.0
_ADAPTER_DISCONNECT_TIMEOUT_SECS_DEFAULT = 5.0
_GATEWAY_PROXY_SSE_BUFFER_MAX_CHARS = 16 * 1024 * 1024
_TELEGRAM_COMMAND_MENTION_RE = re.compile(r"(?<![\w:/])/([A-Za-z0-9][A-Za-z0-9_-]*)")
@@ -4026,7 +4030,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
return max(0.0, timeout)
return _ADAPTER_DISCONNECT_TIMEOUT_SECS_DEFAULT
- def _platform_connect_timeout_secs(self) -> float:
+ def _platform_connect_timeout_secs(self, platform=None) -> float:
"""Return the per-platform connect timeout used during startup/retry."""
raw = os.getenv("HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT", "").strip()
if raw:
@@ -4039,6 +4043,8 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
)
else:
return max(0.0, timeout)
+ if platform == Platform.TELEGRAM:
+ return _TELEGRAM_CONNECT_TIMEOUT_SECS_DEFAULT
return _PLATFORM_CONNECT_TIMEOUT_SECS_DEFAULT
async def _connect_adapter_with_timeout(
@@ -4052,7 +4058,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
(preserve the queue so messages sent during the outage are delivered
rather than silently dropped — #46621).
"""
- timeout = self._platform_connect_timeout_secs()
+ timeout = self._platform_connect_timeout_secs(platform)
if timeout <= 0:
return await adapter.connect(is_reconnect=is_reconnect)
# Use the detach-on-timeout pattern instead of plain asyncio.wait_for:
diff --git a/tests/gateway/test_platform_reconnect.py b/tests/gateway/test_platform_reconnect.py
index c57efa407ee..7f526e70bfe 100644
--- a/tests/gateway/test_platform_reconnect.py
+++ b/tests/gateway/test_platform_reconnect.py
@@ -138,6 +138,25 @@ class TestStartupPlatformIsolation:
assert Platform.TELEGRAM not in runner.adapters
assert runner._create_adapter.call_count == 2
+ def test_default_connect_timeout_allows_telegram_polling_readiness(
+ self, monkeypatch
+ ):
+ """Telegram gets a larger default; other platforms stay isolated at 30s."""
+ runner = _make_runner()
+ monkeypatch.delenv("HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT", raising=False)
+
+ assert runner._platform_connect_timeout_secs(Platform.TELEGRAM) == 180
+ assert runner._platform_connect_timeout_secs(Platform.FEISHU) == 30
+
+ def test_explicit_connect_timeout_still_applies_to_every_platform(
+ self, monkeypatch
+ ):
+ runner = _make_runner()
+ monkeypatch.setenv("HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT", "90")
+
+ assert runner._platform_connect_timeout_secs(Platform.TELEGRAM) == 90
+ assert runner._platform_connect_timeout_secs(Platform.FEISHU) == 90
+
@pytest.mark.asyncio
async def test_connect_adapter_timeout_raises_retryable_exception(self, monkeypatch):
"""The timeout helper turns a hanging connect into a caught startup error."""