[Fix] Recognize managed-role mentions of the Discord bot#438
Merged
Conversation
Discord's mention autocomplete frequently resolves a bot by its managed role (same name as the bot): the message carries mention_roles and <@&role> content with an empty user-mention list, and every such mention was silently classified as not-a-mention. Found live during dogfooding: each @Roomotedev mention arrived at the gateway and was dropped. The session learns the bot's managed role per guild from GUILD_CREATE role tags, with a lazy REST roles lookup for resumed sessions (which never replay GUILD_CREATE). Role mentions are normalized at the gateway into a canonical user mention — content rewritten to <@bot>, a schema-complete user entry injected — so downstream entry gating and mention stripping work unchanged. A contract test asserts the normalized envelope parses with the API's real event schema (the first injection attempt was a bare id and the API quarantined the events as invalid). The mock server's managed role now carries its bot_id tag so this path is exercisable in the harness. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Discord's mention autocomplete frequently resolves a bot by its managed role (same name as the bot). Such messages carry
mention_roles+<@&role>content with an empty user-mention list, and the gateway classified every one as not-a-mention — the bot was silently unreachable for any user whose client picked the role variant. Found live while dogfooding: every@Roomotedevmention arrived and was dropped.Fix
GUILD_CREATErole tags, with a lazyGET /guilds/{id}/rolesfallback for resumed sessions (which never replayGUILD_CREATE)<@bot>, schema-complete user entry injected) so downstream entry gating and mention stripping work unchangeddiscordGatewayEventSchema— the first injection attempt used a bare{id}and the API 400'd the events into the dead-letter stream (which is how [Improve] Harden the Discord gateway delivery and leadership paths #410's DLQ visibility surfaced it)tags.bot_idso the harness can exercise this pathValidation
🤖 Generated with Claude Code