Stop push/pull_request CI runs from racing to cancel each other - #1246
Merged
Conversation
A push to a branch with an open PR fires both a push and a pull_request:synchronize event for the same commit. Both previously shared one concurrency group (keyed only on branch name), so whichever run happened to start second cancelled the other -- sometimes the pull_request-attached run, whose checks are what a reviewer actually sees on the PR. Keys the concurrency group on event name too, so push and pull_request runs for the same branch can never cancel each other; each event type still dedupes/cancels its own superseded runs as before. Adds a check-duplicate-push job that queries the GitHub API for an open PR on the pushed branch and, if one exists, skips every other job in the push-triggered run entirely -- restoring single-run-per-commit behavior without relying on a cancellation race to get there. Every job's `if:` explicitly ANDs in success() alongside the new skip check, since a custom `if:` replaces GitHub's default implicit success-of-needs check rather than being combined with it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Also a live trigger for validating this PR's own fix: pushing this to a branch that already has an open PR should skip the resulting push-triggered run's downstream jobs while this PR's own pull_request-triggered run proceeds unaffected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
A push to a branch with an open PR fires both a
pushevent and apull_request:synchronizeevent for the same commit. Both previously shared one concurrency group (keyed only on branch name), so whichever run happened to start second cancelled the other — sometimes the pull_request-attached run, whose checks are what a reviewer actually sees on the PR.concurrencygroup on event name too, sopushandpull_requestruns for the same branch can never cancel each other; each event type still dedupes/cancels its own superseded runs as before.check-duplicate-pushjob that queries the GitHub API for an open PR on the pushed branch and, if one exists, skips every other job in the push-triggered run entirely — restoring single-run-per-commit behavior without relying on a cancellation race to get there.if:explicitly ANDs insuccess()alongside the new skip check, since a customif:replaces GitHub's default implicit success-of-needs check rather than being combined with it.Test plan
ruby -ryaml -e 'YAML.load_file(...)')needs:/if:wiring to confirm the original "only run if dependencies succeeded" behavior is preserved alongside the new skip guardpushand apull_request:synchronizeevent for the same commit — the exact scenario this fix targets. Expected: thepull_request-triggered run (this PR's checks) runs to completion, unaffected; the redundantpush-triggered run'scheck-duplicate-pushjob detects this open PR and skips its remaining jobs. Results will be added to this PR's checks/comments once observed.🤖 Generated with Claude Code