fix(discord): add token-based fallback for application ID resolution#29695
Conversation
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>
Greptile SummaryAdds a token-based fallback for resolving Discord application IDs when the API call to 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
Last reviewed commit: 7a3201a |
|
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>
There was a problem hiding this comment.
💡 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".
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>
|
Landed via temp rebase onto main.
Thanks @dhananjai1729! |
Summary
parseApplicationIdFromToken()that base64-decodes the first segment of the bot token and keeps the snowflake ID as a string (avoidingNumberprecision loss for IDs > 2^53 - 1)fetchDiscordApplicationId()when the API call to/oauth2/applications/@mefails (timeout, network error, etc.)AI-Assisted PR 🤖
pnpm checkpasses (format, lint, type-check all clean);pnpm testpasses 958/959 tests (1 pre-existing failure inserver.canvas-auth.test.ts, unrelated to this change)/oauth2/applications/@meAPI call failsTest plan
pnpm check— format, lint, type-check all passpnpm test— 958/959 pass (1 pre-existing failure unrelated to this change)provider.test.tstests pass (3/3)Number.MAX_SAFE_INTEGERand verify the bot connects successfully even if the API probe times out🤖 Generated with Claude Code