Skip to content

fix(discord): add token-based fallback for application ID resolution#29695

Merged
steipete merged 3 commits into
openclaw:mainfrom
dhananjai1729:fix/discord-application-id-precision-loss
Mar 2, 2026
Merged

fix(discord): add token-based fallback for application ID resolution#29695
steipete merged 3 commits into
openclaw:mainfrom
dhananjai1729:fix/discord-application-id-precision-loss

Conversation

@dhananjai1729

@dhananjai1729 dhananjai1729 commented Feb 28, 2026

Copy link
Copy Markdown

Summary

  • Fixes [Bug]: Discord Application ID Precision Loss #29608 — Discord Application ID precision loss causing "Failed to resolve Discord application id" errors
  • Adds parseApplicationIdFromToken() that base64-decodes the first segment of the bot token and keeps the snowflake ID as a string (avoiding Number precision loss for IDs > 2^53 - 1)
  • Uses this as a fallback in fetchDiscordApplicationId() when the API call to /oauth2/applications/@me fails (timeout, network error, etc.)

AI-Assisted PR 🤖

  • This PR was AI-assisted (built with Claude Code)
  • Testing: Lightly tested — pnpm check passes (format, lint, type-check all clean); pnpm test passes 958/959 tests (1 pre-existing failure in server.canvas-auth.test.ts, unrelated to this change)
  • I understand what the code does: adds a fallback to extract the Discord application ID directly from the bot token's base64-encoded first segment (kept as a string to avoid JS number precision loss) when the /oauth2/applications/@me API call fails

Test plan

  • pnpm check — format, lint, type-check all pass
  • pnpm test — 958/959 pass (1 pre-existing failure unrelated to this change)
  • Existing provider.test.ts tests pass (3/3)
  • Manual test: configure a Discord bot with an application ID exceeding Number.MAX_SAFE_INTEGER and verify the bot connects successfully even if the API probe times out

🤖 Generated with Claude Code

When the Discord API call to /oauth2/applications/@me fails (timeout,
network error), the bot fails to start with "Failed to resolve Discord
application id". Add a fallback that extracts the application ID by
base64-decoding the first segment of the bot token, keeping it as a
string to avoid precision loss for snowflake IDs exceeding
Number.MAX_SAFE_INTEGER (2^53 - 1).

Fixes openclaw#29608

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: XS labels Feb 28, 2026
@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a token-based fallback for resolving Discord application IDs when the API call to /oauth2/applications/@me fails. The new parseApplicationIdFromToken() function extracts the ID from the first segment of the bot token (which encodes the application ID as base64) and keeps it as a string to prevent precision loss with large snowflake IDs exceeding Number.MAX_SAFE_INTEGER. This directly addresses issue #29608.

The implementation properly validates the extracted ID (must be all digits) and includes appropriate error handling. The fallback only activates when the primary API call fails, providing better resilience for timeouts or network errors.

Confidence Score: 4/5

  • This PR is safe to merge with low risk - it adds a fallback mechanism without changing existing behavior
  • The implementation correctly addresses the precision loss issue with a sound fallback mechanism. Deducting one point because the new parseApplicationIdFromToken() function lacks visible test coverage, though existing tests reportedly pass. The code is well-structured with proper error handling and validation.
  • No files require special attention

Last reviewed commit: 7a3201a

@dhananjai1729

Copy link
Copy Markdown
Author

Hi @thewilloftheshadow, could you review this when you get a chance? This fixes #29608 (Discord Application ID precision loss) by adding a token-based fallback for application ID resolution. Thanks!

Cover valid tokens, large snowflake IDs exceeding MAX_SAFE_INTEGER,
Bot-prefixed tokens, and various invalid/edge-case inputs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80347b57ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/discord/probe.ts Outdated
Address review feedback: only fall back to token-based ID extraction
on transport/timeout errors (catch block), not on HTTP auth failures
(401/403) which should fail fast to surface credential issues early.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@steipete steipete merged commit 8629b99 into openclaw:main Mar 2, 2026
26 checks passed
@steipete

steipete commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: bunx vitest run src/discord/probe.parse-token.test.ts src/discord/probe.intents.test.ts
  • Land commit: d296181
  • Merge commit: 8629b99

Thanks @dhananjai1729!

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.

[Bug]: Discord Application ID Precision Loss

2 participants