Skip to content

fix(discord): add retry logic for chunked message sends on rate-limit#32899

Closed
kevinWangSheng wants to merge 2 commits intoopenclaw:mainfrom
kevinWangSheng:fix/discord-chunk-retry-on-rate-limit
Closed

fix(discord): add retry logic for chunked message sends on rate-limit#32899
kevinWangSheng wants to merge 2 commits intoopenclaw:mainfrom
kevinWangSheng:fix/discord-chunk-retry-on-rate-limit

Conversation

@kevinWangSheng
Copy link
Copy Markdown
Contributor

Summary

When a long agent response is split into multiple Discord message chunks (>2000 chars), if any chunk hits a 429 rate-limit or 5xx error mid-sequence, the error propagates up and all remaining chunks are silently dropped.

Fix

Add sendWithRetry() wrapper around the bot sender path with:

  • Up to 2 retry attempts for 429 and 5xx errors
  • Backoff with retry-after header support
  • Immediate throw for non-retryable errors (4xx)

Changes

  • src/discord/monitor/reply-delivery.ts: Added sendWithRetry() function and wrapped sendMessageDiscord() call

Testing

  • Format check passed
  • TypeScript compilation verified

Related Issue

Fixes #32887

Kevin Shenghui added 2 commits March 3, 2026 02:36
- Add RTL script detection regex for Hebrew and Arabic
- Prepend RLM (Right-to-Left Mark, \u200F) to draft text when RTL content detected
- Skip RLM when HTML parse mode is used (handles directionality automatically)

Fixes openclaw#32852: Telegram draft preview renders LTR for RTL languages
- Add sendWithRetry() wrapper around bot sender path
- Retry up to 2 times for 429 and 5xx errors
- Support retry-after header for backoff
- Fixes issue openclaw#32887
@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Mar 3, 2026

🤖 We're reviewing this PR with Aisle

We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛
We'll post the results here as soon as they're ready.

Progress:

  • Analysis
  • Triage
  • Finalization

Latest run failed. Keeping previous successful results. Trace ID: 019cb346a71f2396f405ccf8834d303b.

Last updated on: 2026-03-03T10:38:09Z

@openclaw-barnacle openclaw-barnacle bot added channel: discord Channel integration: discord channel: telegram Channel integration: telegram size: S trusted-contributor labels Mar 3, 2026
Copy link
Copy Markdown

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

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: 965cf31bc1

ℹ️ 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".

const draftId = streamDraftId ?? allocateTelegramDraftId();
streamDraftId = draftId;
// Prepend RLM for RTL languages when not using HTML parse mode (which handles directionality automatically)
const rtlText = renderedParseMode ? renderedText : prependRTLMarkIfNeeded(renderedText);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck draft length after prepending RTL mark

The new RTL handling prepends \u200F in draft mode, but the maxChars guard runs earlier against renderedText and does not account for this extra character. For messages already at the configured limit (default 4096) that contain Hebrew/Arabic text, sendMessageDraft is now called with a string length of maxChars + 1, which can trigger Telegram API failures and stop preview streaming unexpectedly for exactly-at-limit RTL content.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR adds retry logic for Discord text chunk sends that encounter 429/5xx rate limits, and prepends RTL marks for Arabic/Hebrew text in Telegram draft-transport previews.

Discord changes: The sendWithRetry() wrapper correctly implements a 3-total-attempt loop with per-attempt exponential backoff and optional retry-after header support, guarded to throw immediately on non-retryable errors. The retry wrapper is properly applied to the bot-sender text path (sendDiscordChunkWithFallback), fixing the core issue of silent message drops on rate-limiting for chunked text sends.

Telegram changes: The RTL fix is well-scoped to draft transport, correctly bypassing HTML parse-mode (which natively handles directionality) and using accurate Unicode ranges for Hebrew and Arabic script detection.

Both changes are focused and non-breaking.

Confidence Score: 4/5

  • Safe to merge. The retry logic is sound, the RTL fix is properly scoped, and no breaking changes are introduced.
  • The core issues described in the PR (chunked text rate-limiting and RTL rendering in Telegram draft mode) are correctly addressed with appropriate fixes. The retry logic is correctly implemented with proper error handling and backoff. The changes are narrowly scoped to their stated purposes and do not introduce side effects. Score is 4 rather than 5 due to some intentional limitations in scope (e.g., media attachment paths are not covered by retry logic, message-transport fallback does not include RTL marking), but these are design choices clearly outside the PR's stated scope.
  • No files require special attention. Both changes are focused, self-contained, and well-implemented within their stated scope.

Last reviewed commit: 965cf31

@thewilloftheshadow
Copy link
Copy Markdown
Member

Superseded by #33226 (combined Discord chunk ordering + retry fixes).

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

Labels

channel: discord Channel integration: discord channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(discord): chunked message sends silently drop on rate-limit mid-sequence

2 participants