GitHubPusher: add commits instead of resetting branch#133
Merged
Conversation
Deleting and recreating the branch causes GitHub to close the associated PR. Force-updating has the same effect on PR history. Instead, only create the branch when it doesn't exist and commit on top, so the PR stays open and accumulates commits naturally. follow-up: #132 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines
+179
to
+183
| def ensure_branch | ||
| octokit.branch(@repo.name, @branch_name) | ||
| rescue Octokit::NotFound | ||
| head_sha = octokit.branch(@repo.name, base_branch)[:commit][:sha] | ||
| octokit.create_ref(@repo.name, "refs/heads/#{@branch_name}", head_sha) |
There was a problem hiding this comment.
Bug: The ensure_branch method has a race condition where concurrent jobs can both attempt to create the same branch, causing the second job to crash with an unhandled exception.
Severity: HIGH
Suggested Fix
Modify the ensure_branch method to rescue the Octokit::UnprocessableEntity exception. If this error occurs, it means another job has already created the branch, which is the desired state, so the exception can be safely ignored.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: app/jobs/generate_sponsors_yaml_file_job.rb#L179-L183
Potential issue: The `ensure_branch` method is not atomic. When multiple
`GenerateSponsorsYamlFileJob` instances run concurrently for the same conference, they
can both check if a branch exists and find it missing. The first job will create the
branch successfully. When the second job attempts to create the same branch using
`octokit.create_ref`, the GitHub API will raise an `Octokit::UnprocessableEntity`
exception. Because this exception is not handled within the `ensure_branch` method, the
second job will crash, leading to a failed background job.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
Deleting and recreating the branch causes GitHub to close the associated PR. Force-updating has the same effect on PR history. Instead, only create the branch when it doesn't exist and commit on top, so the PR stays open and accumulates commits naturally.
follow-up: #132