Skip to content

fix(discord): harden rate limit retries - #75338

Merged
clawsweeper[bot] merged 3 commits into
mainfrom
fix/discord-rest-rate-limit-retries
May 1, 2026
Merged

clawsweeper[bot] merged 3 commits into
mainfrom
fix/discord-rest-rate-limit-retries

Conversation

@steipete

@steipete steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retry queued Discord REST 429s using learned route bucket/global cooldown state before rejecting callers
  • parse Retry-After seconds and HTTP-date headers consistently across REST, webhook, and voice upload paths
  • make webhook/voice upload failures throw typed Discord errors so delivery retry can see status and retryAfter
  • reacquire a fresh Discord voice upload URL when the CDN upload itself is rate limited

Verification

  • pnpm test extensions/discord/src/internal/rest.test.ts extensions/discord/src/send.webhook.proxy.test.ts extensions/discord/src/api.test.ts extensions/discord/src/internal/gateway.test.ts extensions/discord/src/proxy-request-client.test.ts extensions/discord/src/client.proxy.test.ts extensions/discord/src/send.creates-thread.test.ts extensions/discord/src/outbound-adapter.test.ts extensions/discord/src/actions/runtime.test.ts extensions/discord/src/voice-message.test.ts -- --run
  • Testbox OPENCLAW_TESTBOX=1 pnpm check:changed (tbx_01kqgj672yetap933mr5gsk8wb)

@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: L maintainer Maintainer-authored PR labels May 1, 2026
@steipete
steipete force-pushed the fix/discord-rest-rate-limit-retries branch from 3363f63 to 01d0833 Compare May 1, 2026 01:27
@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🦞🦞
ClawSweeper automerge is enabled for this PR.

I added clawsweeper:automerge and asked ClawSweeper to review this head. If ClawSweeper emits a repair marker or requests changes, I will repair/rebase the branch and ask for another review, up to the configured round limit.

Draft PRs stay fix-only until GitHub marks them ready for review. A maintainer can pause this with /clawsweeper stop.

@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed for ClawSweeper automerge.

What this changes:

The PR adds Discord REST queued 429 retry scheduling with retry limits and generation guards, shared Retry-After parsing, typed webhook and voice-upload errors, guarded voice-upload URL reacquisition, regression tests, and a changelog entry.

Automerge follow-up:

No repair job is needed: the latest PR head already addresses the prior narrow review blocker, so the remaining action is normal exact-head automerge gating rather than a ClawSweeper fix PR.

Security review:

Security review cleared: No concrete security or supply-chain regression found: the diff touches Discord TypeScript code, tests, and changelog only, and the moved raw voice-upload network calls use fetchWithSsrFGuard.

Review details

Best possible solution:

Let the automerge path continue on the exact current head once required checks and merge gates pass; keep this Discord-owned retry hardening in the Discord plugin with the added scheduler, webhook, and voice-upload tests.

Do we have a high-confidence way to reproduce the issue?

Yes. The added focused unit test covers the previously identified clearQueue/active-429 race, and adjacent tests cover queued 429 retry timing, max retry behavior, HTTP-date Retry-After parsing, and fresh voice upload URL reacquisition.

Is this the best way to solve the issue?

Yes. The latest generation guard is a narrow scheduler fix for the stale requeue race, and routing the voice upload raw HTTP calls through the plugin SDK SSRF guard is the safer boundary-preserving direction.

What I checked:

Likely related people:

  • steipete: Current-main blame and -S history for the Discord REST scheduler, REST client, webhook sender, and voice-message code point to Peter Steinberger, and the same area was recently carried through the current PR repair commits. (role: recent maintainer and feature-history owner; confidence: high; commits: 65c94df872b9, a448042c2edd, 727710d20c9d; files: extensions/discord/src/internal/rest-scheduler.ts, extensions/discord/src/internal/rest.ts, extensions/discord/src/send.webhook.ts)

Remaining risk / open question:

  • Several broader exact-head check-runs were still in progress at review time, so automerge should continue to wait for required checks and mergeability on head 727710d.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3c4851037b6c.

@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🦞🦞
Thanks, ClawSweeper. ClawSweeper picked up the repair feedback.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper marker: fix-required (finding=security-review sha=01d083318f045e6d3324b1321a9e08e02ac0712f)
Action: dispatched repair-cluster-worker.yml for jobs/openclaw/inbox/automerge-openclaw-openclaw-75338.md in autonomous mode.
Model: gpt-5.5

I will update this PR branch, or open a safe credited replacement, if the repair worker finds a narrow fix.

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

Copy link
Copy Markdown
Contributor

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: 3363f63300

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +350 to +352
if (error instanceof RateLimitError && this.requeueRateLimitedRequest(queued)) {
requeued = true;
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Skip rate-limit requeue after queue is cleared

When clearQueue() is called, callers expect all queued work to be rejected and no further retries to be scheduled, but runQueuedRequest will still requeue an in-flight request on RateLimitError (requeueRateLimitedRequest) and return early. In a shutdown or teardown path where clearQueue() races with an active request that receives HTTP 429, that request can survive the clear and run again later, leaving queueSize non-zero and the original promise unresolved longer than expected.

Useful? React with 👍 / 👎.

@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🦞🦞
ClawSweeper automerge is enabled for this PR.

I added clawsweeper:automerge and asked ClawSweeper to review this head. If ClawSweeper emits a repair marker or requests changes, I will repair/rebase the branch and ask for another review, up to the configured round limit.

Draft PRs stay fix-only until GitHub marks them ready for review. A maintainer can pause this with /clawsweeper stop.

@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper automerge

@clawsweeper
clawsweeper Bot merged commit bd20f8e into main May 1, 2026
93 checks passed
@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🦞🦞
Thanks, ClawSweeper. ClawSweeper merged this PR after the passing review.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper verdict: pass (sha=727710d20c9df2e01596a8b8fb2bfb333cbcdd54)
Merge status: merged by ClawSweeper automerge
Merged at: 2026-05-01T01:49:03Z

The automerge loop is complete.

@clawsweeper
clawsweeper Bot deleted the fix/discord-rest-rate-limit-retries branch May 1, 2026 01:49
@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🦞
ClawSweeper could not enable automerge for this PR.

Reason: automerge requires an open PR.

Draft PRs stay fix-only until GitHub marks them ready for review. A maintainer can pause this with /clawsweeper stop.

lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
* fix(discord): harden rate limit retries

* fix(discord): guard voice upload fetches

* fix(discord): avoid stale rate limit requeues
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(discord): harden rate limit retries

* fix(discord): guard voice upload fetches

* fix(discord): avoid stale rate limit requeues
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix(discord): harden rate limit retries

* fix(discord): guard voice upload fetches

* fix(discord): avoid stale rate limit requeues
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix(discord): harden rate limit retries

* fix(discord): guard voice upload fetches

* fix(discord): avoid stale rate limit requeues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant