Skip to content

fix: robust GraphQL rate limit retry handling #916#917

Open
jaiyankargupta wants to merge 1 commit into
DenverCoder1:mainfrom
jaiyankargupta:fix-rate-limit-retry
Open

fix: robust GraphQL rate limit retry handling #916#917
jaiyankargupta wants to merge 1 commit into
DenverCoder1:mainfrom
jaiyankargupta:fix-rate-limit-retry

Conversation

@jaiyankargupta

Copy link
Copy Markdown

Description

Hey folks
Fixes #916

I noticed an issue where the streak card would occasionally throw the generic "Failed to retrieve contributions. This is likely a GitHub API issue." error instead of correctly displaying the "We are being rate-limited" card when tokens ran out.

After digging into it, I found that when the GraphQL API hits a rate limit and the code does its retry attempt, the logic was accidentally swallowing the rate limit error because it missed an !empty($decoded->errors) check. Since the error slipped through, the exhausted token stayed in the pool and the application eventually crashed with that 500 error.

I've fixed this up by:

  • Swapping out the single retry attempt for a while loop so we can actually cycle through multiple backup tokens if needed.
  • Adding the missing validation check on retries so we properly catch and handle those GraphQL errors.
  • Making sure we exhaust all available tokens in the pool during a rate limit event before we finally throw in the towel.

This should make the token rotation way more bulletproof when rate limits get tight. Let me know if you need anything else to get this merged!

Type of change

  • Bug fix (added a non-breaking change which fixes an issue)
  • New feature (added a non-breaking change which adds functionality)
  • Updated documentation (updated the readme, templates, or other repo files)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Tested locally with a valid username
  • Tested locally with an invalid username
  • Ran tests with composer test
  • Added or updated test cases to test new features

Checklist:

  • I have checked to make sure no other pull requests are open for this issue
  • The code is properly formatted and is consistent with the existing code style
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Screenshots

(N/A - backend logic fix only)

- Upgrade retry logic from a single attempt to a while loop
- Properly check for !empty($decoded->errors) on retries
- Exhaust all available tokens in the pool during rate limits before failing

Copilot AI 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.

Pull request overview

Improves resiliency of GraphQL contribution-graph fetching by retrying failed/invalid responses across multiple tokens, aiming to correctly surface the “rate-limited” error card instead of a generic contributions failure when tokens are exhausted.

Changes:

  • Replace single retry with a loop to allow multiple retry attempts and token rotation.
  • Ensure GraphQL error payloads (including rate-limit errors) are considered “invalid” and retried/handled.
  • Add retry attempt logging and a retry cap to avoid infinite loops.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/stats.php
Comment thread src/stats.php
Comment thread src/stats.php
Comment thread src/stats.php
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.

Streak not showing (API Issue)

3 participants