#16720: fix: fall back to guild_id when guild object is missing in resolveDiscordGuildEntry
channel: discord
stale
size: XS
Cluster:
Signal and Discord Fixes
## Summary
- `resolveDiscordGuildEntry` requires `params.guild` (full guild object) to resolve guild config, but the guild object depends on gateway cache from `GUILD_CREATE` events
- When cache is cold (reconnection, cold start, or Discord-compatible servers like Spacebar), `data.guild` is undefined even though `data.guild_id` is always present
- Guild resolution fails → message silently dropped
Fix: add optional `guildId` and `guildName` fallback parameters. When `guild` is absent, use `guild_id` from the event data to look up guild config by ID. Updated all 4 call sites:
- `message-handler.preflight.ts` — MESSAGE_CREATE preflight
- `listeners.ts` — reaction handler
- `agent-components.ts` — button + select menu handlers (2 sites, already had `rawGuildId` available)
Fixes #16715
## Test plan
- [ ] Bot resolves guild config when `data.guild` is present (no regression)
- [ ] Bot resolves guild config when `data.guild` is absent but `data.guild_id` exists
- [ ] Bot still blocks messages from unconfigured guilds when `guildEntries` is non-empty
- [ ] Component interactions (buttons, select menus) resolve guild from `rawGuildId` fallback
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a cold-cache bug where `resolveDiscordGuildEntry` would fail when the Discord gateway cache doesn't have the full guild object (e.g., after reconnection or cold start). The fix adds optional `guildId` and `guildName` fallback parameters so guild config can be resolved using `guild_id` from the raw event data when the hydrated `guild` object is unavailable.
- Core logic in `allow-list.ts` is clean: falls back to `guildId` param when `guild.id` is missing, guards against empty slug lookups, and preserves existing behavior when `guild` is present.
- All 4 call sites mentioned in the PR description are correctly updated.
- **One call site missed**: `native-command.ts:558` has the same cold-cache vulnerability but was not updated in this PR. Slash commands going through `handleNativeCommand` will still silently fail guild resolution when the cache is cold.
<h3>Confidence Score: 3/5</h3>
- The changes are correct for the 4 updated call sites but miss a 5th call site with the same bug.
- The core logic change in `resolveDiscordGuildEntry` is well-implemented with proper fallback handling and edge case guards. However, the fix is incomplete — `native-command.ts` has an identical call site that was not updated, meaning slash commands will still break under the same cold-cache conditions this PR aims to fix.
- `src/discord/monitor/native-command.ts` — missed call site at line 558 needs the same `guildId`/`guildName` fallback parameters.
<sub>Last reviewed commit: 911d865</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17648: fix: Discord guild channel detection using rawMessage.guild_id
by MisterGuy420 · 2026-02-16
83.8%
#12204: fix(discord): resolve numeric guildId/channelId pairs in channel al...
by mcaxtr · 2026-02-09
82.9%
#17513: fix(discord): respect groupPolicy in channel config fallback (#4555)
by aronchick · 2026-02-15
80.7%
#23158: discord: harden preflight/reply path against slow lookup latency
by danielstarman · 2026-02-22
78.6%
#21463: fix(discord): prevent WebSocket death spiral + fix numeric channel ID…
by akropp · 2026-02-20
77.1%
#22557: fix(discord): coerce exec approval approver IDs to string to preven...
by zwffff · 2026-02-21
75.6%
#16801: fix: Register Discord listeners before gateway connects
by MisterGuy420 · 2026-02-15
74.9%
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
74.6%
#17254: fix(discord): intercept text-based slash commands instead of forwar...
by robbyczgw-cla · 2026-02-15
74.4%
#20009: fix(discord): immediately defer interactions to prevent timeouts
by Gitjay11 · 2026-02-18
74.4%