feat: skip autoRetry for sendMessageDraft to stop 429 amplification#127
Merged
Conversation
Wrap autoRetry in a method-gated transformer that bypasses retries for sendMessageDraft only. Drafts are cosmetic fire-and-forget calls — a 3-10s late retry lands on a stream that has already moved on, and 5x amplification turns one rate-limited draft into five log lines and five Prometheus error-counter increments. Every other method retains the full AUTO_RETRY_OPTIONS behavior unchanged. Fixes issue #117. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…tempt counters After e0adc07 the per-attempt counter description applied to every method except sendMessageDraft, whose counters now reflect one increment per logical call. Operators comparing pre/post-deploy 429 volume for that method need the caveat to understand the ~5x drop. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR reduces Telegram 429 log/metric amplification during long DM streaming replies by disabling @grammyjs/auto-retry specifically for the cosmetic sendMessageDraft API method, while keeping existing retry behavior unchanged for all other Telegram API methods.
Changes:
- Add a method-gated API transformer that bypasses
autoRetryforsendMessageDraftonly. - Update inline docs/comments and README to clarify draft rate-limits and the resulting metric semantics.
- Add unit tests that assert
sendMessageDraftis not retried whilesendMessageandsendChatActionstill retry on 429.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the sendMessageDraft exception to per-attempt counter behavior due to retry bypass. |
| docs/plans/2026-05-26-telegram-draft-autoretry-skip.md | Adds an implementation plan and rationale for skipping autoRetry on drafts. |
| bot/src/telegram-bot.ts | Introduces createDraftSkipAutoRetryTransformer and wires it into the API transformer chain. |
| bot/src/stream-relay.ts | Corrects the draft debounce comment to acknowledge per-chat rate limits and the retry bypass behavior. |
| bot/src/tests/telegram-bot.test.ts | Adds tests verifying draft bypass and continued retries for other methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #117. Wrap
autoRetryin a method-gated transformer that bypasses retries forsendMessageDraftonly. Drafts are cosmetic fire-and-forget calls — a 3-10 s late retry lands on a stream that has already moved on, and the 5× amplification turns one rate-limited draft into five log lines and five Prometheus error-counter increments. Every other Telegram API method retains the fullAUTO_RETRY_OPTIONSretry behavior unchanged.Also fixes the misleading "Drafts are cosmetic — no rate limits" comment in
bot/src/stream-relay.tsthat originally motivated the 300 ms debounce, and adds a one-line README caveat thatbot_telegram_api_calls_total{method="sendMessageDraft"}no longer counts per-attempt (one call = one increment, vs other methods' up-to-5).Plan and pipeline
docs/plans/2026-05-26-telegram-draft-autoretry-skip.mdNO ISSUES FOUND.What's NOT in scope
DRAFT_DEBOUNCE_MS(Option A from sendMessageDraft 429 cascade during long streaming replies in DMs #117). Deferred until residualsendMessageDraft429 ratio is measured against the newbot_telegram_api_calls_totalcounter (deployed in feat: chat_id in API error logs + bot_telegram_api_calls_total counter #118).Test plan
cd bot && npx tsc --noEmit— passescd bot && npm test— 1068 / 1068 passRate limited: method=sendMessageDraftwarn lines drop ~5× andsendMessage/sendChatActionstill retry on 429curl -s http://127.0.0.1:9091/metrics | grep bot_telegram_api_calls_total— verifysendMessageDraftrows still increment (one per logical draft, not per retry)🤖 Generated with Claude Code