Skip to content

Fix: Telegram send_message should retry on timeout errors - #47238

Closed
kakaco0305 wants to merge 1 commit into
NousResearch:mainfrom
kakaco0305:fix/telegram-timeout-retry
Closed

Fix: Telegram send_message should retry on timeout errors#47238
kakaco0305 wants to merge 1 commit into
NousResearch:mainfrom
kakaco0305:fix/telegram-timeout-retry

Conversation

@kakaco0305

Copy link
Copy Markdown

問題

_telegram_retry_delay 函式對 timeout 錯誤視為不可重試(return None),導致 Telegram 偶發 timeout 時訊息直接丟失。

修復

對齊 502/503/504 邏輯,timeout 也用指數退避重試(2/4/8 秒)。

影響範圍

  • 所有用 send_message 工具發 Telegram 的場景
  • 特別是 cron job 排程的訊息(無人工介入修復)
  • 訊息丟失且無 fallback 機制

修復驗證

KAKACO 已在本機 patch 驗證有效:

  • 修復前:Telegram 偶發 timeout → 訊息丟失
  • 修復後:3 次指數退避(2/4/8 秒)→ 大幅提升送達率

Diff

--- a/tools/send_message_tool.py
+++ b/tools/send_message_tool.py
@@ -97,8 +97,11 @@ def _telegram_retry_delay(exc: Exception, attempt: int) -> float | None:
             return 1.0
 
     text = str(exc).lower()
+    # Telegram timeout errors should also retry (previously returned None as
+    # non-retryable, which caused messages to be lost on transient timeouts).
+    # Aligns with the 502/503/504 retry logic above.
     if "timed out" in text or "timeout" in text:
-        return None
+        return float(2 ** attempt)
     if (
         "bad gateway" in text
         or "502" in text

對應 Issue

Fixes #47229

環境

  • hermes-agent: M3 (含 5 層 fallback 機制)
  • 影響版本:所有 timeout 視為不可重試的版本

Previously, _telegram_retry_delay() returned None for timeout errors,
treating them as non-retryable. This caused messages to be lost when
Telegram API occasionally timed out, particularly affecting cron-scheduled
messages with no human intervention to recover.

This change aligns timeout handling with the 502/503/504 retry logic
(exponential backoff: 2s, 4s, 8s), significantly improving message
delivery rates for transient failures.

Fixes NousResearch#47229
@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels Jun 16, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

What was changed

Telegram send_message tool: retry on timeout errors. Previously, a timeout during Telegram message delivery was not retried, causing message loss. Now the tool retries with exponential backoff on timeout.

Observations

Simple, targeted fix. The retry logic wraps the send operation and handles timeout as a retryable error. This improves Telegram reliability, especially in regions with high latency.

Security

No concerns.


Reviewed by Hermes Agent

@kakaco0305

Copy link
Copy Markdown
Author

Friendly ping — opened this 4 days ago to address the Telegram send_message timeout issue. Happy to make any adjustments or provide additional context if needed. Thanks!

@kakaco0305

Copy link
Copy Markdown
Author

Closing this PR because the Telegram timeout retry functionality has already been merged into main via multiple commits:

Keeping this open would create duplicate work for reviewers. Thanks for the consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram send_message does not retry on timeout errors

3 participants