Skip to content

fix(channels): handle Discord API 429 rate-limit responses with retry#4746

Open
bug-ops wants to merge 1 commit into
mainfrom
4728-discord-429-rate-limit
Open

fix(channels): handle Discord API 429 rate-limit responses with retry#4746
bug-ops wants to merge 1 commit into
mainfrom
4728-discord-429-rate-limit

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 30, 2026

Summary

  • Adds send_with_retry helper to crates/zeph-channels/src/discord/rest.rs that intercepts HTTP 429 responses from the Discord API
  • Parses Retry-After header (float/int), falls back to JSON body retry_after field, clamps to 60 s maximum
  • Sleeps and retries up to 3 times; surfaces Err with TOO_MANY_REQUESTS status after all retries exhausted
  • Applies 30-second per-request RequestBuilder::timeout to guard all external awaits including the final exhausted-retry call
  • Migrates all three call sites: send_message, edit_message, trigger_typing

Test plan

  • 218 zeph-channels tests pass (cargo nextest run -p zeph-channels --features discord)
  • 10420 workspace tests pass
  • New test send_with_retry_errors_when_retries_exhausted: mock returns 429 on all calls → assert Err(TOO_MANY_REQUESTS)
  • Existing tests: header-present, body-fallback, non-429 passthrough, clamp math all covered

Closes #4728

Add `send_with_retry` helper in the Discord REST client that intercepts
HTTP 429 responses, reads `Retry-After` from the response header or JSON
body (clamped to 60 s), sleeps, and retries up to 3 times before
surfacing the error. All three call sites — `send_message`,
`edit_message`, and `trigger_typing` — now use this helper. A 30-second
per-request timeout is applied via `RequestBuilder::timeout` to guard
every external await including the final exhausted-retry request.

Closes #4728
@github-actions github-actions Bot added channels zeph-channels crate (Telegram) rust Rust code changes bug Something isn't working size/L Large PR (201-500 lines) labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working channels zeph-channels crate (Telegram) rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(channels): Discord REST client missing 429 rate-limit handling

1 participant