Fix Discord pick announcements arriving out of order and add 429 retry #51
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/discord-pick-announcement-ordering"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Two related bugs with Discord pick announcements during drafts:
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 afterawait checkAndTriggerNextAutodraft(), so chained picks announced themselves first, then the triggering pick announced last.Silently dropped announcements on rate limiting — a burst of consecutive autodraft picks can hit Discord's per-webhook rate limit (HTTP 429).
sendDiscordWebhookthrew immediately on 429 with no retry, so the announcement was silently swallowed by the.catchat the call site.Changes
app/models/draft-utils.ts+app/routes/api/draft.make-pick.tsMoved
notifyPickMadeOnDiscord()to fire beforecheckAndTriggerNextAutodraft()in both theexecuteAutoPick()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.tsAdded a single retry with
Retry-Afterdelay on HTTP 429:|| 1instead of?? 1so non-numeric or NaN header values fall back to a 1-second default rather than firing an instant retryKnown 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.