Skip to content

fix(telegram): match grammY HttpError in retry regex - #51589

Closed
Matthew19990919 wants to merge 1 commit into
openclaw:mainfrom
Matthew19990919:fix/telegram-retry-grammy-httperror
Closed

Matthew19990919 wants to merge 1 commit into
openclaw:mainfrom
Matthew19990919:fix/telegram-retry-grammy-httperror

Conversation

@Matthew19990919

Copy link
Copy Markdown
Contributor

Summary

  • Add network request to TELEGRAM_RETRY_RE so grammY HttpError messages trigger the retry path
  • Add test case covering the grammY HttpError message format

Root Cause

grammY wraps underlying network errors in HttpError with the message:

Network request for 'sendMessage' failed!

This string contains none of the existing TELEGRAM_RETRY_RE keywords (429|timeout|connect|reset|closed|unavailable|temporarily), so shouldRetry returns false and retries never fire — even though the underlying cause is a transient network failure (ECONNRESET, UND_ERR_CONNECT_TIMEOUT, etc.).

Fix

Add network request to the regex. This matches grammY's HttpError message format at the top level without needing to traverse .cause, keeping the change minimal and backwards-compatible.

The strictShouldRetry guard for non-idempotent operations (e.g. sendMessage) is unaffected — the regex fallback is only OR'd in for idempotent paths like sendChatAction, setReaction, and deleteMessage.

Test Plan

  • Added test: retries grammY HttpError wrapping network failures via regex
  • All 7 existing + new tests pass
  • Verified strictShouldRetry: true still suppresses the regex fallback

Closes #51525

grammY wraps network errors in HttpError with messages like
"Network request for 'sendMessage' failed!" which contains none of the
existing TELEGRAM_RETRY_RE keywords. Add "network request" to the regex
so these transient failures trigger the retry path.

Closes #51525

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where grammY's HttpError messages ("Network request for 'sendMessage' failed!") were not matched by TELEGRAM_RETRY_RE, causing transient network failures to silently skip the retry path. The fix adds network request to the regex and includes a targeted test.

  • Fix: network request appended to TELEGRAM_RETRY_RE in retry-policy.ts, catching grammY HttpError messages at the top level without needing to traverse .cause.
  • Backwards-compatible: strictShouldRetry callers (non-idempotent ops like sendMessage) remain unaffected — the regex fallback is only OR'd in when strictShouldRetry is not set.
  • Test coverage: New it.each case exercises the regex path with the exact grammY HttpError message format and confirms successful retry on the second attempt.

Confidence Score: 5/5

  • This PR is safe to merge — a minimal, well-tested regex addition with no side-effects on existing retry paths.
  • The change is a single-term addition to an existing regex with a clear, isolated scope (Telegram retry policy). The strictShouldRetry guard for non-idempotent operations is correctly unaffected. The new test case directly validates the intended behaviour using the exact grammY HttpError message format. No existing tests were modified and the overall test suite still passes. False-positive risk from the broad term "network request" is negligible in the context of Telegram API calls, where structured JSON errors from the Bot API would never surface with this string.
  • No files require special attention.

Last reviewed commit: "fix(telegram): match..."

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e3bfbd38a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/retry-policy.ts
Comment on lines +14 to +15
const TELEGRAM_RETRY_RE =
/429|timeout|connect|reset|closed|unavailable|temporarily|network request/i;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Exclude non-idempotent sticker sends from the new regex retry path

Adding network request to the shared fallback regex now retries every Telegram call site that does not set strictShouldRetry. sendStickerTelegram still goes through createTelegramRequestWithDiag rather than createTelegramNonIdempotentRequestWithDiag (extensions/telegram/src/send.ts:1448 vs extensions/telegram/src/send.ts:550), so a grammY HttpError("Network request for 'sendSticker' failed!") will now replay sendSticker. In the common lost-response case where Telegram accepted the first sticker before the socket broke, this turns a single delivery into duplicate stickers for end users.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram retry regex misses grammY HttpError format — retries never fire for network errors

1 participant