Skip to content

Fix Discord snowflake validation, add 503 retry, and Slack rate limit backoff#2253

Open
Divide-By-0 wants to merge 1 commit into42wim:masterfrom
Divide-By-0:fix/discord-snowflake-503-retry-ratelimit-backoff
Open

Fix Discord snowflake validation, add 503 retry, and Slack rate limit backoff#2253
Divide-By-0 wants to merge 1 commit into42wim:masterfrom
Divide-By-0:fix/discord-snowflake-503-retry-ratelimit-backoff

Conversation

@Divide-By-0
Copy link
Copy Markdown

Summary

  • Discord snowflake validation: When bridging Slack thread replies to Discord, the gateway can pass a Slack message timestamp (e.g., "slack 1772220754.010239") as the message_reference.message_id when the message cache misses. Discord rejects this with NUMBER_TYPE_COERCE / "not snowflake", silently dropping the message. This adds:

    1. Upfront validation that ParentID is a valid numeric snowflake
    2. Numeric-only extraction as a fallback (strip non-digit chars)
    3. Retry without threading if Discord still rejects the reference — so the message is delivered flat instead of dropped
  • 503 retry at gateway level: Adds retry with exponential backoff (1s, 2s, 4s, up to 3 attempts) for transient 503 Service Unavailable responses, preventing silent message loss during Discord outages.

  • Slack rate limit exponential backoff: Upgrades handleRateLimit to track consecutive rate limit hits per operation, applying RetryAfter × 2^consecutiveHits backoff. Capped at 5 minutes max wait and 10 consecutive hits before giving up. Prevents tight retry loops during reconnection bursts when matterbridge re-fetches channel/user info for many channels at once.

Test plan

  • Compiled and deployed to production Slack↔Discord bridge (13 channels)
  • Verified clean startup with all gateways connected
  • Monitor logs for correct warn-level messages when snowflake fallback triggers
  • Verify thread replies from Slack still appear on Discord (as flat messages when cache misses, as threaded replies when cache hits)
  • Confirm 503 retry logging appears during Discord outages instead of immediate failure

🤖 Generated with Claude Code

… backoff

When bridging Slack threads to Discord, the gateway can pass a Slack
message timestamp (e.g., "slack 1772220754.010239") as the ParentID
when the message cache misses. Discord rejects this as "not snowflake",
silently dropping the message. This adds upfront validation of the
ParentID, attempts numeric extraction as a fallback, and retries
without threading if Discord still rejects the reference.

Also adds retry with exponential backoff (1s, 2s, 4s) at the gateway
level for transient 503 Service Unavailable errors from Discord.

Finally, upgrades the Slack rate limit handler to use exponential
backoff (RetryAfter * 2^consecutiveHits), capped at 5 minutes and
10 consecutive hits, to prevent tight retry loops during reconnection
bursts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant