Skip to content

[AI-assisted] Discord: fix bare guild ID misrouted as channel ID#12326

Merged
thewilloftheshadow merged 2 commits intoopenclaw:mainfrom
headswim:fix/discord-guild-id-misroute
Feb 13, 2026
Merged

[AI-assisted] Discord: fix bare guild ID misrouted as channel ID#12326
thewilloftheshadow merged 2 commits intoopenclaw:mainfrom
headswim:fix/discord-guild-id-misroute

Conversation

@headswim
Copy link
Contributor

@headswim headswim commented Feb 9, 2026

Summary

Due to regex ordering in parseDiscordChannelInput, bare numeric guild IDs were matched as channel IDs. This caused the resolver to call Discord's /channels/<guildId> endpoint, which 404s, and the entire channel resolution would fall back to raw config entries.

Prefixing guild-only entries with guild: ensures the parser skips the channel regex and routes them correctly.

Repro Steps

  1. Configure channels.discord.guilds with a numeric guild ID and no specific channel keys
  2. Start the Discord monitor
  3. Observe: discord channel resolve failed; using config entries. Discord API /channels/<guildId> failed (404): Unknown Channel

Root Cause

In resolve-channels.ts, two regexes both match bare numeric strings:

  • ^(?:channel:|discord:)?(\d+)$ (channel — fires first)
  • ^(?:guild:|server:)?(\d+)$ (guild — never reached for bare numbers)

Because of the ordering of the regex parsing on the Discord config, bare guild IDs hit the channel path. Prefixing with guild: makes it skip the channel regex (which doesn't recognize guild: as a valid prefix) and land on the correct guild regex.

Behavior Changes

  • Guild-only entries now prefixed with guild: at both call sites (monitor provider + onboarding wizard)
  • No change to the parser itself — the guild: prefix was already supported

Tests

  • Lightly tested — new regression tests added, all existing tests pass
  • pnpm build && pnpm check && pnpm test — all green

AI-Assisted

  • Built with Cursor (Claude)
  • Bug initially identified via gateway logs (discord channel resolve failed; using config entries. Discord API /channels/<guildId> failed (404): Unknown Channel)
  • Root-caused by tracing the guild ID through provider.ts into parseDiscordChannelInput and seeing the regex ordering issue
  • Second instance found in onboarding wizard (onboarding/discord.ts) with the same pattern
  • Confirmed understanding of the parser, fix, and both call sites
  • 🦞

Sign-Off

  • Models used: Claude Opus4.6 (Cursor+ Claude Code)
  • Submitter effort: identified bug from logs, guided fix and testing
  • Agent notes: one-line fix at two call sites, regression tests confirm the parser ambiguity, submitter's first pull request on oss

Greptile Overview

Greptile Summary

This change prefixes guild-only Discord allowlist entries with guild: at the two call sites that generate inputs for resolveDiscordChannelAllowlist() (the Discord monitor provider and the onboarding wizard). This avoids an ambiguity in parseDiscordChannelInput() where bare numeric strings match the channel-id regex before the guild-id regex, causing numeric guild IDs to be treated as channel IDs.

A couple regression tests were added in src/discord/resolve-channels.test.ts to cover guild:-prefixed resolution and to document the bare-numeric ambiguity.

Confidence Score: 4/5

  • This PR is likely safe to merge, but one new regression test does not accurately model the reported failure mode.
  • The runtime behavior change is minimal and localized (string prefixing at two call sites) and aligns with the existing parser behavior. The main remaining concern is test coverage: the added bare-numeric regression test currently makes the misrouting path succeed by returning a 200 for /channels/<id>, so it doesn’t protect against the real 404-driven fallback described in the PR.
  • src/discord/resolve-channels.test.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle bot added the channel: discord Channel integration: discord label Feb 9, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@headswim headswim force-pushed the fix/discord-guild-id-misroute branch from 4333f7b to 927d054 Compare February 9, 2026 04:30
@headswim
Copy link
Contributor Author

headswim commented Feb 9, 2026

Updated regression test per Greptile review feedback; bare numeric case now returns a realistic 404 from /channels/ and asserts the resolver throws, matching the actual failure mode from production logs.

headswim and others added 2 commits February 13, 2026 11:00
The channel allowlist parser matches bare numeric strings as channel IDs
before checking for guild IDs, causing guild snowflakes to hit Discord's
/channels/ endpoint (404). Prefix guild-only entries with 'guild:' so the
parser routes them to the correct guild resolution path.

Fixes both the monitor provider and onboarding wizard call sites.
Adds regression tests.
@thewilloftheshadow thewilloftheshadow force-pushed the fix/discord-guild-id-misroute branch from 927d054 to 288875a Compare February 13, 2026 17:03
@thewilloftheshadow thewilloftheshadow merged commit 1f4943a into openclaw:main Feb 13, 2026
10 checks passed
@thewilloftheshadow
Copy link
Member

Landed via temp rebase onto main.

  • Gate: skipped (already run by requester)
  • Land commit: 288875a
  • Merge commit: 1f4943a

Thanks @headswim!

skyhawk14 pushed a commit to skyhawk14/openclaw that referenced this pull request Feb 13, 2026
zhangyang-crazy-one pushed a commit to zhangyang-crazy-one/openclaw that referenced this pull request Feb 13, 2026
steipete pushed a commit to azade-c/openclaw that referenced this pull request Feb 14, 2026
GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
cloud-neutral pushed a commit to cloud-neutral-toolkit/openclawbot.svc.plus that referenced this pull request Feb 15, 2026
jiulingyun added a commit to jiulingyun/openclaw-cn that referenced this pull request Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments