Skip to content

feat: skip autoRetry for sendMessageDraft to stop 429 amplification#127

Merged
fitz123 merged 3 commits into
mainfrom
feat/telegram-draft-autoretry-skip
May 27, 2026
Merged

feat: skip autoRetry for sendMessageDraft to stop 429 amplification#127
fitz123 merged 3 commits into
mainfrom
feat/telegram-draft-autoretry-skip

Conversation

@fitz123
Copy link
Copy Markdown
Owner

@fitz123 fitz123 commented May 26, 2026

Summary

Closes #117. Wrap autoRetry in a method-gated transformer that bypasses retries for sendMessageDraft only. 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 full AUTO_RETRY_OPTIONS retry behavior unchanged.

Also fixes the misleading "Drafts are cosmetic — no rate limits" comment in bot/src/stream-relay.ts that originally motivated the 300 ms debounce, and adds a one-line README caveat that bot_telegram_api_calls_total{method="sendMessageDraft"} no longer counts per-attempt (one call = one increment, vs other methods' up-to-5).

Plan and pipeline

  • Plan: docs/plans/2026-05-26-telegram-draft-autoretry-skip.md
  • Ralphex pipeline ran: implementation + 7-agent multi-review (claude) passed clean, then a 2nd-pass claude review picked up two findings — one false positive (rejected), one acted on (README per-attempt caveat). Codex external review: NO ISSUES FOUND.
  • Pipeline terminated on the final "claude evaluating codex findings" step due to a Claude session-window limit; all substantive work was complete by that point.

What's NOT in scope

Test plan

  • cd bot && npx tsc --noEmit — passes
  • cd bot && npm test — 1068 / 1068 pass
  • After merge + restart: trigger a long streaming reply in a DM, confirm Rate limited: method=sendMessageDraft warn lines drop ~5× and sendMessage/sendChatAction still retry on 429
  • After merge + restart: curl -s http://127.0.0.1:9091/metrics | grep bot_telegram_api_calls_total — verify sendMessageDraft rows still increment (one per logical draft, not per retry)

🤖 Generated with Claude Code

fitz123 and others added 3 commits May 26, 2026 12:26
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>
Copilot AI review requested due to automatic review settings May 26, 2026 10:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 autoRetry for sendMessageDraft only.
  • Update inline docs/comments and README to clarify draft rate-limits and the resulting metric semantics.
  • Add unit tests that assert sendMessageDraft is not retried while sendMessage and sendChatAction still 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.

@fitz123 fitz123 merged commit 4834a58 into main May 27, 2026
3 checks passed
@fitz123 fitz123 deleted the feat/telegram-draft-autoretry-skip branch May 27, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sendMessageDraft 429 cascade during long streaming replies in DMs

2 participants