Fix Discord pick announcements arriving out of order and add 429 retry #51

Merged
chrisp merged 1 commit from fix/discord-pick-announcement-ordering into main 2026-05-25 04:34:48 +00:00
Owner

Problem

Two related bugs with Discord pick announcements during drafts:

  1. Out-of-order announces — picks could appear out of order on Discord (e.g. pick #106 before #105 before #104) during autodraft chains. The triggering pick's notifyPickMadeOnDiscord() call was placed after await checkAndTriggerNextAutodraft(), so chained picks announced themselves first, then the triggering pick announced last.

  2. Silently dropped announcements on rate limiting — a burst of consecutive autodraft picks can hit Discord's per-webhook rate limit (HTTP 429). sendDiscordWebhook threw immediately on 429 with no retry, so the announcement was silently swallowed by the .catch at the call site.

Changes

app/models/draft-utils.ts + app/routes/api/draft.make-pick.ts

Moved notifyPickMadeOnDiscord() to fire before checkAndTriggerNextAutodraft() in both the executeAutoPick() function and the manual pick route action. Each pick now announces itself before triggering the next pick in the chain, so Discord receives them in pick-number order.

sendOnTheClockEmail() intentionally stays after the chain — it re-reads the DB to find the true post-chain current pick number.

app/services/discord.ts

Added a single retry with Retry-After delay on HTTP 429:

  • Uses || 1 instead of ?? 1 so non-numeric or NaN header values fall back to a 1-second default rather than firing an instant retry
  • Caps the sleep at 10 seconds so awaited callers (e.g. the draft-order settings page actions) are never hung for a full Discord global-rate-limit window

Known residual limitation

If a pick's Discord webhook itself hits a 429 and has to wait for the retry, chained picks may still post to Discord before the delayed message resolves. Fixing this fully would require awaiting the Discord call before running the chain, which risks blocking the draft if Discord is slow. The 10-second cap limits the worst-case window for this scenario.

## Problem Two related bugs with Discord pick announcements during drafts: 1. **Out-of-order announces** — picks could appear out of order on Discord (e.g. pick #106 before #105 before #104) during autodraft chains. The triggering pick's `notifyPickMadeOnDiscord()` call was placed *after* `await checkAndTriggerNextAutodraft()`, so chained picks announced themselves first, then the triggering pick announced last. 2. **Silently dropped announcements on rate limiting** — a burst of consecutive autodraft picks can hit Discord's per-webhook rate limit (HTTP 429). `sendDiscordWebhook` threw immediately on 429 with no retry, so the announcement was silently swallowed by the `.catch` at the call site. ## Changes ### `app/models/draft-utils.ts` + `app/routes/api/draft.make-pick.ts` Moved `notifyPickMadeOnDiscord()` to fire **before** `checkAndTriggerNextAutodraft()` in both the `executeAutoPick()` function and the manual pick route action. Each pick now announces itself before triggering the next pick in the chain, so Discord receives them in pick-number order. `sendOnTheClockEmail()` intentionally stays *after* the chain — it re-reads the DB to find the true post-chain current pick number. ### `app/services/discord.ts` Added a single retry with `Retry-After` delay on HTTP 429: - Uses `|| 1` instead of `?? 1` so non-numeric or NaN header values fall back to a 1-second default rather than firing an instant retry - Caps the sleep at 10 seconds so awaited callers (e.g. the draft-order settings page actions) are never hung for a full Discord global-rate-limit window ## Known residual limitation If a pick's Discord webhook itself hits a 429 and has to wait for the retry, chained picks may still post to Discord before the delayed message resolves. Fixing this fully would require awaiting the Discord call before running the chain, which risks blocking the draft if Discord is slow. The 10-second cap limits the worst-case window for this scenario.
chrisp added 1 commit 2026-05-25 04:29:25 +00:00
Fix Discord pick announcements arriving out of order and add 429 retry
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 1m30s
🚀 Deploy / ʦ TypeScript (pull_request) Successful in 1m16s
🚀 Deploy / 🔍 Lint (pull_request) Successful in 48s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
77f520823c
- Move notifyPickMadeOnDiscord() before checkAndTriggerNextAutodraft() in
  both executeAutoPick() and the manual pick action. Previously the
  triggering pick's announcement fired after all chained autodraft picks
  had already announced, causing Discord to show e.g. pick #106 before
  #105 before #104. Now each pick announces itself before the next pick
  in the chain is triggered.

- Add a single retry with Retry-After delay in sendDiscordWebhook() on
  HTTP 429. A burst of consecutive autodraft picks could hit Discord's
  per-webhook rate limit and silently drop announcements. Use || 1
  (not ?? 1) to handle non-numeric/NaN headers, and cap at 10 s so
  that awaited callers such as the draft-order settings actions are
  never hung for a full global rate-limit window.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp merged commit 874a2db853 into main 2026-05-25 04:34:48 +00:00
Sign in to join this conversation.
No description provided.