Skip to content

GitHubPusher: add commits instead of resetting branch#133

Merged
sorah merged 1 commit intomasterfrom
generate_sponsors_yaml_file_job_reuse2
Mar 2, 2026
Merged

GitHubPusher: add commits instead of resetting branch#133
sorah merged 1 commit intomasterfrom
generate_sponsors_yaml_file_job_reuse2

Conversation

@sorah
Copy link
Copy Markdown
Member

@sorah sorah commented Mar 2, 2026

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

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>
@sorah sorah enabled auto-merge March 2, 2026 07:17
@sorah sorah added this pull request to the merge queue Mar 2, 2026
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Merged via the queue into master with commit 5bdbe41 Mar 2, 2026
2 checks passed
@sorah sorah deleted the generate_sponsors_yaml_file_job_reuse2 branch March 2, 2026 07:21
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.

1 participant