fix(discord): delete stale slash commands before creating new ones - #29134
Closed
kasnol wants to merge 1 commit into
Closed
fix(discord): delete stale slash commands before creating new ones#29134kasnol wants to merge 1 commit into
kasnol wants to merge 1 commit into
Conversation
Discord enforces the 100 global application-command cap server-side at create time. _safe_sync_slash_commands created net-new commands first and deleted stale ones last, so a large command-set delta (e.g. after an update that renames/adds commands) could transiently push the server count past 100. Discord then rejects with HTTP 400 code 30032, the exception aborts the sync, and because the stale deletions ran last they never execute to free space — leaving the app wedged on every reconnect. Prune stale commands before creating new ones so the peak server-side count never exceeds max(len(existing), len(desired)) <= 100. The trailing delete loop is removed (now redundant). Counting/summary semantics are unchanged. Adds a regression test asserting every stale delete precedes the first net-new create (fails on the old ordering, passes with the fix).
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_safe_sync_slash_commands()reconciles the bot's global slash commands on connect. It created net-new commands first and deleted removed ones last.Problem
Discord enforces the 100 global-command cap at create time. When the command set changes substantially (e.g. after pulling an update that renames/adds commands), the old commands are still registered on Discord while the new ones are created one-by-one. The transient total can exceed 100, and Discord rejects the create with
HTTP 400code30032.Because the deletions of now-removed commands ran after the create loop, that rejection aborts the sync before any space is freed. The reconcile then fails identically on every reconnect — the bot is stuck and never recovers on its own.
Fix
Delete commands that are no longer desired before creating new ones. Peak server-side count is bounded by
max(len(existing), len(desired))≤ 100 by construction. The old trailing delete loop is removed (redundant). Counting/summary semantics unchanged.Test
Adds
test_safe_sync_deletes_stale_before_creating_newasserting every stale delete is issued before the first net-new create. Fails on the old ordering, passes with the fix. Fulltest_discord_connect.pysuite (17 tests) green.Reproduction
DISCORD_COMMAND_SYNC_POLICY=safe(the default →_safe_sync_slash_commands).Discord rejects the create:
The exception aborts
_safe_sync_slash_commandsbefore the trailing stale-delete loop runs, so space is never freed and every subsequent reconnect reproduces the same failure (the bot's slash commands stay wedged until manual intervention).The added regression test reproduces the ordering deterministically without a live Discord connection.
Workaround for affected users
Set
DISCORD_COMMAND_SYNC_POLICY=bulk— uses Discord's atomic bulk overwrite (tree.sync()), one request, never transiently exceeds the cap.Runtime verification
Verified on a live bot under the default
safepolicy after applying this patch:No
30032, sync completed in one pass, state recorded successfully. The patched_safe_sync_slash_commands(with delete-stale-first ordering) executed end-to-end against a real Discord application.