fix(integration-discord): handle cloudflare 429#335
Conversation
Parse Retry-After from HTTP header when Discord returns a Cloudflare 429 with non-JSON body. Abort immediately on IP bans (retry-after > 60s).
|
Warning Review limit reached
More reviews will be available in 18 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository YAML (base), Central YAML (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app-modules/integration-discord/src/Sync/Actions/PurgeUnusedInvitesAction.php`:
- Around line 119-120: The RuntimeException thrown when detecting a Cloudflare
IP ban (when retryAfter exceeds 60.0) in the condition at line 119-120 is being
caught by the execute() method at line 74, which allows the purge loop to
continue processing remaining invites instead of stopping the entire operation.
Modify the exception handling in execute() to detect when a RuntimeException
contains "Cloudflare IP ban" in its message and re-throw it without catching it,
so that the IP ban condition propagates up and halts the entire purge operation
rather than continuing with the remaining invites in the loop.
In
`@app-modules/integration-discord/tests/Unit/Sync/PurgeUnusedInvitesActionTest.php`:
- Around line 222-240: The test currently only includes a single invite in the
$invites array, which doesn't exercise the regression where the
PurgeUnusedInvitesAction continues processing subsequent invites after
encountering an IP-ban (429) failure on an earlier one. Add multiple invites to
the $invites array by calling makeInvite() multiple times with different codes
so that the test properly verifies the action's behavior when handling a 429
error in a multi-invite scenario. This will ensure the test catches regressions
where the purge continues attempting to delete invites after receiving
rate-limit failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 4f933417-ffd6-443b-987c-b9f0772ff206
📒 Files selected for processing (2)
app-modules/integration-discord/src/Sync/Actions/PurgeUnusedInvitesAction.phpapp-modules/integration-discord/tests/Unit/Sync/PurgeUnusedInvitesActionTest.php
Fall back to X-RateLimit-Reset-After header when the JSON body has no retry_after field.
Catch CloudflareIpBanException separately to break the loop and count remaining invites as failed.
Summary
Retry-Afterfrom HTTP header when Cloudflare returns a 429 with non-JSON body (error code: 1015), fixingJsonException: Syntax errorRetry-After > 60s) instead of wasting retries against a ~22-hour banArr::getfor safe JSON body parsingTest plan
Retry-Afterheader: retries and succeedsRetry-Afterheader: aborts immediately, no sleep