Skip to content

[Fix] Recognize managed-role mentions of the Discord bot#438

Merged
daniel-lxs merged 1 commit into
developfrom
fix/discord-role-mentions
Jul 16, 2026
Merged

[Fix] Recognize managed-role mentions of the Discord bot#438
daniel-lxs merged 1 commit into
developfrom
fix/discord-role-mentions

Conversation

@daniel-lxs

Copy link
Copy Markdown
Member

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 @Roomotedev mention arrived and was dropped.

Fix

  • The session learns the bot's managed role per guild from GUILD_CREATE role tags, with a lazy GET /guilds/{id}/roles fallback for resumed sessions (which never replay GUILD_CREATE)
  • Role mentions are normalized at the gateway into a canonical user mention (content rewritten to <@bot>, schema-complete user entry injected) so downstream entry gating and mention stripping work unchanged
  • New contract test: the normalized envelope must parse with the API's real discordGatewayEventSchema — 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)
  • The mock's managed role now carries its tags.bot_id so the harness can exercise this path

Validation

  • 78/78 discord-gateway tests (3 new: normalization + schema contract, foreign-role ignored, unknown-role fallback)
  • check-types 26/26, oxlint, format, knip green
  • Verified live against real Discord end-to-end during dogfooding

🤖 Generated with Claude Code

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>
@daniel-lxs
daniel-lxs merged commit bf7baa7 into develop Jul 16, 2026
17 checks passed
@daniel-lxs
daniel-lxs deleted the fix/discord-role-mentions branch July 16, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant