Skip to content

fix(bot): defer-first in play command and guard deferReply against 40060 - #431

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/interaction-reply-race-and-play-timing
Apr 1, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/interaction-reply-race-and-play-timing

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Apr 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Move deferReply() to the top of play command execute, before guildId/voice/collaborative checks. Converts early-exit reply() to editReply(). Fixes LUCKY-1Y (Unknown interaction on early exits).
  • Wrap deferReply() in handleChatInputCommand and handleOtherInteraction in a try-catch — if the interaction is already acknowledged (40060) or expired (10062), we silently return instead of throwing. Fixes LUCKY-23.

Test plan

  • CI passes
  • /play command responds even when user is not in a voice channel
  • No more DiscordAPIError[40060] in Sentry

Summary by CodeRabbit

  • Bug Fixes
    • Fixed play command to properly acknowledge Discord interactions within the required time window by deferring responses at the start of execution, before validation checks.
    • Resolved interaction acknowledgement race conditions that could result in duplicate or failed responses in concurrent command scenarios, improving reliability when handling simultaneous interactions.

@vercel

vercel Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Apr 1, 2026 1:44am

Request Review

@LucasSantana-Dev
LucasSantana-Dev merged commit 25fbcea into main Apr 1, 2026
10 of 12 checks passed
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file bot size/m labels Apr 1, 2026
@coderabbitai

coderabbitai Bot commented Apr 1, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 296c7ea3-a068-400e-988f-3ad684e0a2e7

📥 Commits

Reviewing files that changed from the base of the PR and between 82435d7 and af1fd2c.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • package.json
  • packages/bot/package.json
  • packages/bot/src/functions/music/commands/play/index.spec.ts
  • packages/bot/src/functions/music/commands/play/index.ts
  • packages/bot/src/utils/general/interactionReply.ts

📝 Walkthrough

Walkthrough

This PR addresses Discord interaction acknowledgement race conditions by deferring interaction replies earlier in the command execution lifecycle and wrapping acknowledgement calls with try-catch error handling to gracefully discard duplicate/concurrent acknowledgement errors (40060).

Changes

Cohort / File(s) Summary
Version Updates
CHANGELOG.md, package.json, packages/bot/package.json
Version bumped from 2.6.52/2.6.56 to 2.6.57; changelog entry added documenting fixes for play command reply flow and interaction acknowledgement race conditions.
Play Command
packages/bot/src/functions/music/commands/play/index.ts, packages/bot/src/functions/music/commands/play/index.spec.ts
Play command now calls deferReply() at the start of execute() before validation; early-exit failure paths switch from reply() to editReply(). Test expectations updated to assert deferReply() followed by editReply() for failure scenarios.
Interaction Reply Handler
packages/bot/src/utils/general/interactionReply.ts
deferReply() and subsequent reply calls in handleChatInputCommand and handleOtherInteraction are now wrapped in try-catch blocks; errors from duplicate/concurrent acknowledgements are silently swallowed rather than thrown.

Sequence Diagram(s)

sequenceDiagram
    actor Client as Discord Client
    participant Play as Play Command
    participant IH as Interaction Handler
    
    Client->>Play: Execute play command
    Play->>IH: deferReply() [at start]
    IH->>IH: try: await deferReply()
    IH-->>Play: Acknowledged (or error caught)
    
    alt Validation Failure
        Play->>IH: editReply(embed)
        IH->>IH: try: await editReply()
        IH-->>Play: Reply sent (or error caught)
    else Success/Continue
        Play->>Play: Queue/playback logic
        Play->>IH: editReply(embed)
        IH->>IH: try: await editReply()
        IH-->>Play: Reply sent (or error caught)
    end
    
    Play-->>Client: Command result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bot, size/m

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/interaction-reply-race-and-play-timing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 318 kB

ℹ️ View Unchanged
Filename Size
packages/frontend/dist/assets/ActionPanel-CPPMxhFF.js 401 B
packages/frontend/dist/assets/api-3qPvg92E.js 2.9 kB
packages/frontend/dist/assets/authStore-DBeEdplV.js 557 B
packages/frontend/dist/assets/AutoMessages-B5SGnQRY.js 2.68 kB
packages/frontend/dist/assets/AutoMod-BIev-2yJ.js 4.1 kB
packages/frontend/dist/assets/badge-CtZYPo1h.js 502 B
packages/frontend/dist/assets/Card-CLEr0GPg.js 456 B
packages/frontend/dist/assets/CommandsConfig-BXhrTbl5.js 1.47 kB
packages/frontend/dist/assets/Config-D57d-pFi.js 1.68 kB
packages/frontend/dist/assets/CustomCommands-BxlA9eRj.js 2.16 kB
packages/frontend/dist/assets/DashboardOverview-5PhfZF9m.js 2.54 kB
packages/frontend/dist/assets/dialog-CQehvQgs.js 949 B
packages/frontend/dist/assets/EmbedBuilder-7tHvn4jo.js 3.34 kB
packages/frontend/dist/assets/Features-DzxvVb1H.js 2.85 kB
packages/frontend/dist/assets/GuildAutomation-CeYLVHyE.js 2.92 kB
packages/frontend/dist/assets/guildStore-BuJ9Xfyw.js 794 B
packages/frontend/dist/assets/index-DB-ntyfa.css 14 kB
packages/frontend/dist/assets/index-pfwciEbx.js 27.6 kB
packages/frontend/dist/assets/input-1mJNYRIq.js 466 B
packages/frontend/dist/assets/label-B0w5nWAd.js 488 B
packages/frontend/dist/assets/LastFm-DnWvDY9S.js 1.74 kB
packages/frontend/dist/assets/Levels-D2dn-hXg.js 2.63 kB
packages/frontend/dist/assets/Login-BB_QV5YE.js 2.51 kB
packages/frontend/dist/assets/Lyrics-Dg08GGUZ.js 1.33 kB
packages/frontend/dist/assets/Moderation-D853bYCM.js 3.85 kB
packages/frontend/dist/assets/Music-BMpwnMtJ.js 6.13 kB
packages/frontend/dist/assets/MusicConfig-C8I9qK4Q.js 1.61 kB
packages/frontend/dist/assets/PrivacyPolicy-DUO0quHd.js 1.38 kB
packages/frontend/dist/assets/ReactionRoles-Iu10nhih.js 1.88 kB
packages/frontend/dist/assets/rolldown-runtime-COnpUsM8.js 467 B
packages/frontend/dist/assets/SectionHeader-C3U2Dpr0.js 384 B
packages/frontend/dist/assets/select-BLfozU6F.js 1.23 kB
packages/frontend/dist/assets/ServerLogs-DbDUiuLF.js 2.9 kB
packages/frontend/dist/assets/ServerSettings-CTp3sI-Q.js 4.22 kB
packages/frontend/dist/assets/ServersPage-VL5GlTsG.js 2.92 kB
packages/frontend/dist/assets/Skeleton-Cm2SGg8-.js 235 B
packages/frontend/dist/assets/Starboard-DSgWQM64.js 2.08 kB
packages/frontend/dist/assets/StatTile-ieCmGz9d.js 605 B
packages/frontend/dist/assets/switch-Ubn95ylk.js 542 B
packages/frontend/dist/assets/TermsOfService-B0ThRl8c.js 1.37 kB
packages/frontend/dist/assets/TrackHistory-CwpFViZg.js 1.9 kB
packages/frontend/dist/assets/TwitchNotifications-CVxXBBPA.js 2.29 kB
packages/frontend/dist/assets/usePageMetadata-DNK___tM.js 326 B
packages/frontend/dist/assets/utils-BHIP-_5u.js 148 B
packages/frontend/dist/assets/vendor-forms-KXRApnAU.js 25.4 kB
packages/frontend/dist/assets/vendor-radix-Uy8m4UkR.js 33.5 kB
packages/frontend/dist/assets/vendor-react-DllCF3mE.js 55.6 kB
packages/frontend/dist/assets/vendor-state-BC0s6PNN.js 22 kB
packages/frontend/dist/assets/vendor-ui-DLN5_jR3.js 64.2 kB

compressed-size-action

@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
33.3% Coverage on New Code (required ≥ 80%)
4.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

This branch was successfully deployed

1 active deployment
Preview — af1fd2c2 Deployed Apr 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot dependencies Pull requests that update a dependency file size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant