Skip to content

Conversation

@bafolts
Copy link
Contributor

@bafolts bafolts commented Oct 7, 2025

In cases where the mergeable status is unknown we wait 3 seconds and make another request to determine the pull request status. If 3 seconds isn't enough time it will be the case that we still get a mergeable status of unknown. This change adds exponential backoff and tries a few more times allowing for more time for the status mergeable status to update.

@bafolts bafolts requested a review from zhiyelee October 7, 2025 16:02
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18318656495

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 99.398%

Totals Coverage Status
Change from base Build 15380455883: 0.008%
Covered Lines: 118
Relevant Lines: 118

💛 - Coveralls

Copy link
Collaborator

@zhiyelee zhiyelee left a comment

Choose a reason for hiding this comment

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

LGTM overall. left a comment

// https://docs.github.com/en/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests
// Github recommends to use poll to get a non null/unknown value, we use a compromised version here because of the api rate limit
await wait(3000);
await wait(3000 * Math.pow(2, attempt));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the duration too long?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the duration too long for what? Here I took the existing three seconds that was in place and applied exponential backoff. Since the maximum value of attempt will be 4 this will lead to a value of 48 seconds for the worst case being passed as the argument to the wait function. I think the default timeout for a github workflow is 6 hours. There would have to be thousands of open PRs that all reached the 48 second timeout for this value to be an issue. But in that case we would have waited a long time for every open pull request and for whatever reason github continued to have a value of unknown as the mergeable state. In this case github is most likely having some kinds of outage.

Copy link
Collaborator

@zhiyelee zhiyelee Oct 8, 2025

Choose a reason for hiding this comment

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

makes sense. Have you tested this and confirmed that this wont trigger rate limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No but according to github's documentation we should be at least a thousand requests per hour. I also don't think it is feasible for someone to try to test this. They could see a few passing requests and not hit the rate limit but that doesn't indicate that this change isn't going to ever trigger the rate limit.

Whether this change leads to more rate limit triggers will depend on the number of open PRs that are waiting to merge to master. In cases where the merge status is not known we will end up making 4 more requests. If every PR were to run into this case we will then make those 4 requests again and have more requests per hour.

If you are concerned about reaching the wait limit we could instead change the default 3 seconds to a larger value. This would allow github more time to determine the status and decrease the potential of a rate limit error as we will be making less requests per hour. If we changed it to say 30 seconds we would give github more time to determine the status and have less requests per hour decreasing risk of triggering rate limit errors.

@zhiyelee zhiyelee merged commit a51c014 into master Oct 9, 2025
1 check passed
@zhiyelee zhiyelee deleted the brianfolts/retry-with-backoff branch October 9, 2025 15:25
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.

4 participants