fix(discord): resolve numeric guildId/channelId pairs in channel allowlist#12204
fix(discord): resolve numeric guildId/channelId pairs in channel allowlist#12204mcaxtr wants to merge 5 commits intoopenclaw:mainfrom
Conversation
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/discord/resolve-channels.ts
Line: 193:201
Comment:
**Duplicate guild lookup**
`parsed.guildId && guilds.find(...) ? guilds.find(...) : ...` performs the same `find` twice. This isn’t just style: because it’s inside the main resolution loop, it doubles work for `guildOnly` entries and makes behavior harder to reason about if this block ever changes (e.g. if `guilds` becomes non-static). Store the result of the first `find` and reuse it.
How can I resolve this? If you propose a fix, please make it concise. |
|
Re: Duplicate guild lookup — Good catch, fixed in 307c26b. Both instances now store the const guildById = parsed.guildId ? guilds.find((entry) => entry.id === parsed.guildId) : undefined;
const guild = guildById ?? (parsed.guild ? resolveGuildByName(guilds, parsed.guild) : undefined);@greptile-apps could you please re-review? The duplicate lookup is resolved, and I've explained the numeric-name fallback rationale in the inline thread. |
|
@greptile-apps Great catch on the 403-vs-404 distinction — fixed in 1e0f4c5. Could you please re-review? |
|
@greptile-apps Addressed both new comments:
Could you please re-review? |
9fdbc29 to
71a3650
Compare
71a3650 to
ef5c6db
Compare
ef5c6db to
af7d222
Compare
a0ae671 to
1f1e0e1
Compare
bfc1ccb to
f92900f
Compare
c54b6fd to
3ffa93a
Compare
2420696 to
877a62e
Compare
877a62e to
d0999b2
Compare
|
Rebase note: The numeric What this PR still adds on top of current main:
Rebased onto current main — diff is clean against these three changes + corresponding tests. |
…ling Parse numeric channel part as channelId in guildId/channelId input format. Validate guild membership to reject channels belonging to different guilds. Handle 404 and 403 in fetchChannel to prevent batch abort on invalid or inaccessible channel IDs. Preserve guildId context on unresolved lookups so downstream code retains guild association. Fixes openclaw#12185
…up fails When a numeric channel ID cannot be resolved via the Discord API (404), attempt name-based matching within the guild as a graceful degradation. Deduplicate guild lookup logic that was repeated across the numeric and name-based resolution paths.
…ect fallbacks Distinguish 403 (access denied) from 404 (not found) so name-based fallback only triggers on genuine not-found responses. Treat malformed channel payloads (missing id/name) as invalid rather than not-found to avoid incorrect name matching on corrupted API responses.
…ch fetch signature
d0999b2 to
fb6c155
Compare
|
🤖 We're reviewing this PR with Aisle We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛ Progress:
Latest run failed. Keeping previous successful results. Trace ID: Last updated on: 2026-03-03T04:09:56Z |
|
Superseded by #33142 which consolidates the fixes from this PR. Closing this in favor of that PR. |
Fixes #12185
Summary
When users configure Discord channel allowlists with numeric
guildId/channelIdpairs (e.g.111222333/444555666),parseDiscordChannelInputtreated the channel part as a channel name rather than an ID. This caused the resolution to attempt a name-based lookup against guild channels, which always failed for numeric IDs, silently dropping inbound messages from those channels.Changes
guild/channelare all-digits, parse the channel part aschannelIdfor direct API lookupguildIdon unresolved results so downstream onboarding doesn't default to wildcard guildTest plan
"111222333/444555666"resolves via direct channel ID lookup (TDD — test written first)"111222333/444555666"where channel belongs to different guild →resolved: falsewith note"111222333/999000111"where channel ID is 404 → marks unresolved, doesn't abort batch, preservesguildId"111222333/777888999"where channel ID is 403 → marks unresolved, doesn't abort batch"111222333/2024"where "2024" is a channel name → falls back to name matching within guildpnpm build && pnpm checkcleanGreptile Overview
Greptile Summary
This PR updates Discord allowlist parsing/resolution to correctly handle numeric
guildId/channelIdinputs by treating the channel segment as an ID (with optional guild-scoped name fallback on 404), adds a guild-membership consistency check for resolved channels, and improves channel fetch error classification (403 vs 404 vs invalid payload) so a single bad entry doesn’t abort batch resolution.The main logic lives in
src/discord/resolve-channels.ts, whereparseDiscordChannelInputnow returns{guildId, channelId}when both segments are all-digits, andfetchChannelnow returns a discriminatedFetchChannelResultto avoid conflating forbidden/not-found/invalid responses.src/discord/resolve-channels.test.tsadds coverage for the numeric-pair path, guild mismatch rejection, 404/403 behavior, and malformed payload handling.Confidence Score: 5/5
guildId/channelIdpath, and the new error classification avoids previously reported incorrect fallbacks. I did not find any additional deterministic logic issues in the diff beyond previously addressed threads.