#17513: fix(discord): respect groupPolicy in channel config fallback (#4555)
channel: discord
stale
size: S
Cluster:
Signal and Discord Fixes
## Problem
Discord guild messages are silently dropped when:
1. A guild entry has a `channels` block with at least one entry
2. The incoming message is from a channel NOT listed in that block
3. `groupPolicy` is `"open"`
`resolveDiscordChannelConfigWithFallback()` returns `{ allowed: false }` as a default when no channel entry matches. A second check in the preflight handler (`channelConfig?.allowed === false`) then drops the message — **even though `isDiscordGroupAllowedByPolicy()` already returned `true`** for open policy.
## Why most users are NOT affected
Most users fall into one of these categories that avoid the bug:
- **No `channels` block in guild config** → `resolveDiscordChannelConfigWithFallback` returns `null` (not `{ allowed: false }`), and `null?.allowed === false` evaluates to `false`, so messages pass through
- **Wildcard `"*"` channel entry** → matches everything, returns `{ allowed: true }`
- **Explicit channel entries covering all active channels** → always matches
- **No guild config at all** → `channelConfig` is `null`
The bug only triggers when a user has a **partial** channels config (e.g., configuring `requireMention` for one channel) combined with `groupPolicy: "open"` — the unconfigured channels get silently dropped.
## Fix
Skip the redundant `channelConfig?.allowed === false` check when `groupPolicy === "open"`, since `isDiscordGroupAllowedByPolicy` already approved the message.
**1 line changed** in `message-handler.preflight.ts` + **80 lines of tests** covering the groupPolicy × channel-config matrix.
Fixes #4555
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a bug where Discord guild messages from unlisted channels were silently dropped even when `groupPolicy` is `"open"`. The root cause was a redundant `channelConfig?.allowed === false` check in `preflightDiscordMessage` (line 372) that ran **after** `isDiscordGroupAllowedByPolicy()` had already approved the message for open policy. The fix adds `&& params.groupPolicy !== "open"` to skip this redundant check when the policy is open.
- **1-line fix** in `message-handler.preflight.ts`: skips the `channelConfig.allowed === false` guard when `groupPolicy === "open"`, deferring to the already-evaluated `isDiscordGroupAllowedByPolicy()` result
- **80 lines of tests** in `monitor.test.ts`: covers the `groupPolicy × channelConfig` interaction matrix, documenting the expected behavior for open, allowlist, and disabled policies with matched/unmatched/unconfigured channels
- Non-open policies (`allowlist`, `disabled`) are unaffected — for `allowlist`, unmatched channels are already blocked at the `isDiscordGroupAllowedByPolicy` checkpoint; the redundant check still applies as a belt-and-suspenders guard for non-open policies
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — a minimal, well-targeted 1-line fix with comprehensive test coverage.
- The change is a single additional condition (`&& params.groupPolicy !== "open"`) on an existing guard clause. The fix aligns the redundant check with the already-evaluated `isDiscordGroupAllowedByPolicy()` result. Non-open policies (allowlist, disabled) are unaffected because unmatched channels are already blocked at the earlier checkpoint. The 6 new unit tests cover the key interaction matrix. The logic is straightforward and the risk of regression is minimal.
- No files require special attention
<sub>Last reviewed commit: 9386b3d</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12204: fix(discord): resolve numeric guildId/channelId pairs in channel al...
by mcaxtr · 2026-02-09
82.4%
#17865: Refactor: centralize dm/group policy resolution
by iyoda · 2026-02-16
80.9%
#23158: discord: harden preflight/reply path against slow lookup latency
by danielstarman · 2026-02-22
80.8%
#16720: fix: fall back to guild_id when guild object is missing in resolveD...
by xqliu · 2026-02-15
80.7%
#17648: fix: Discord guild channel detection using rawMessage.guild_id
by MisterGuy420 · 2026-02-16
80.0%
#18664: fix(imessage): honor groupConfig regardless of allowlistEnabled
by brandonwise · 2026-02-16
79.9%
#17254: fix(discord): intercept text-based slash commands instead of forwar...
by robbyczgw-cla · 2026-02-15
79.6%
#14318: feat(discord): enforce outbound allowlist on send functions
by builtbyrobben · 2026-02-11
79.1%
#21463: fix(discord): prevent WebSocket death spiral + fix numeric channel ID…
by akropp · 2026-02-20
79.1%
#11611: feat: separate group-level allowlist from sender-level command auth...
by thisnick · 2026-02-08
77.9%