Add retry to latestPullRequest for commit-to-PR index race condition#333
Merged
Merged
Conversation
GitHub's ListPullRequestsWithCommit API depends on an internal index that associates commits with PRs. This index update is asynchronous, so the endpoint may return an empty list when called immediately after a merge. When this happens, tagpr fails to detect its own release PR merge and falls through to create a duplicate release PR. Add retry logic (3 attempts, 2s interval) to latestPullRequest() so that transient empty responses are retried before giving up.
Owner
|
Thank you! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for building tagpr! I use it both at work and in personal projects and it's been great.
Summary
Add retry logic to
latestPullRequest()so that tagpr can tolerate the GitHub API's eventual consistency when resolving commits to pull requests.Problem
latestPullRequest()callsListPullRequestsWithCommitonce with no retry. The GitHub API endpointGET /repos/{owner}/{repo}/commits/{sha}/pullsdepends on an internal index that associates commits with PRs. This index update is asynchronous — when tagpr queries the API within seconds of a merge, the endpoint may return an empty list.When this happens,
latestPullRequestreturns(nil, nil),isTagPR(nil)returnsfalse, and tagpr falls through to create a duplicate release PR instead of tagging the release.Real-world example
In babarot/gh-infra, the following sequence occurred:
08:58:5808:59:39506696d)ListPullRequestsWithCommitfor506696d— the API returned an empty list (index not yet updated, only 13 seconds after merge)v0.7.0tag was never createdThis was a regular merge commit (not squash), confirming that the race condition is not limited to squash merges as initially reported in #330.