← Back to PRs

#16720: fix: fall back to guild_id when guild object is missing in resolveDiscordGuildEntry

by xqliu open 2026-02-15 01:58 View on GitHub →
channel: discord stale size: XS
## 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