Skip to content

Cancel a closed PR's CI runs, including for fork contributors - #572

Closed
nirvedhmeshram wants to merge 3 commits into
ROCm:mainfrom
nirvedhmeshram:nmeshram/cancel-ci-on-pr-close
Closed

nirvedhmeshram wants to merge 3 commits into
ROCm:mainfrom
nirvedhmeshram:nmeshram/cancel-ci-on-pr-close

Conversation

@nirvedhmeshram

@nirvedhmeshram nirvedhmeshram commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a PR is merged or closed, its in-flight Iris Tests, performance-regression and external-validation runs keep going and hold the GPU runners. The concurrency group only cancels a run when a newer run of the same PR starts, and merging or closing starts none.

A live example: #570 is merged, but its Iris Tests run (from commit 8f34e8a9) is still queued.

Change

New cancel-closed-pr-ci.yml runs every 10 minutes (and on manual dispatch). It lists in-flight pull_request runs and cancels any whose PR is closed.

  • Finding the PR: each run's PR is found by head branch and commit, because fork runs carry no PR number. A run is cancelled only if every PR whose head is that commit is closed.
  • Security: PR-supplied text like branch names is only ever data: URL-encoded for the API query and compared, never evaluated.

GPU workflows' concurrency is keyed on the PR number instead of github.head_ref, the same pattern IREE uses. Two PRs from different forks with the same branch name (e.g. patch-1) currently share a group and cancel each other's runs.

Why a scheduled sweep

Approach Merged PRs Fork contributors needing approval Security scan
pull_request: closed + concurrency (first commit) ❌ on merge GITHUB_REF is refs/heads/main (docs), so cancel-in-progress is false ❌ the close run waits for approval too ✅
pull_request_target: closed + API (second commit) ✅ ✅ always runs ❌ HIGH dangerous-triggers
Scheduled sweep + API (this) ✅ ✅ ✅

The cost is up to one interval (about 10 minutes) before a closed PR's runs stop, against GPU runs that take 1–2 hours. If instant cancellation is worth a reviewed dangerous-triggers exception in .github/scan_tools_configs/zizmor.yml, the second commit's workflow can come back.

Testing

Scheduled workflows only run from main, so this takes effect after merge; it can also be triggered from the Actions tab.

🤖 Generated with Claude Code

The concurrency group only cancels a PR's in-flight run when a newer run of
the same PR starts. Merging or closing starts none, so the old run kept
holding the GPU runners. Trigger the three GPU workflows on pull_request
closed too: that run joins the PR's group, cancels the in-flight run, and
skips its own jobs.

Also key the group on the PR number rather than the head branch, so two forks'
same-named branches (e.g. patch-1) no longer cancel each other's runs, which
closing a PR would otherwise now do as well.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 19:12
The previous commit's pull_request closed trigger had two gaps. On merge,
GITHUB_REF is refs/heads/main, so cancel-in-progress evaluated to false and
nothing was cancelled in the one case that matters. And a fork contributor's
closed-event run waits for the same maintainer approval as their other runs.

pull_request_target runs from main regardless of approval settings and
GITHUB_REF. The new workflow cancels the PR's queued and in-progress runs by
head commit, branch and repo through the API. It only reads the event payload
and never checks out PR code, so its write token is not exposed to it. The GPU
workflows keep only the PR-number concurrency key.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nirvedhmeshram nirvedhmeshram changed the title Cancel a PR's GPU CI when the PR is merged or closed Cancel a closed PR's CI runs, including for fork contributors Oct 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: None

What changed in this PR

Updates GPU-related GitHub Actions workflows so CI runs don’t keep occupying GPU runners after a PR is closed/merged, by improving concurrency grouping and adding explicit run cancellation on PR close.

Changes:

  • Key concurrency groups by PR number (instead of head_ref) to prevent cross-fork branch-name collisions.
  • Add a pull_request_target: closed workflow that cancels queued/running workflow runs for the PR’s head SHA via the Actions API.
File Description
.github/​workflows/​iris-tests.yml Switch concurrency grouping to PR number to avoid fork branch collisions.
.github/​workflows/​iris-performance-regression-test.yml Switch concurrency grouping to PR number to avoid fork branch collisions.
.github/​workflows/​iris-external-validation-test.yml Switch concurrency grouping to PR number to avoid fork branch collisions.
.github/​workflows/​cancel-closed-pr-ci.yml New workflow to cancel in-flight PR runs when the PR is closed.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

pull_request_target is a HIGH dangerous-triggers finding in the PR security
scan. A scheduled run is equally immune to fork-approval holds and to
GITHUB_REF being main on merge, and needs no scanner exception. Every 10
minutes it lists in-flight pull_request runs, finds each run's PR by head
branch (fork runs carry no PR number) and cancels it only if every PR whose
head is that commit is closed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nirvedhmeshram

Copy link
Copy Markdown
Collaborator Author

This seems too much complexity for a small problem so I will close this PR

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.

2 participants