Skip to content

ci: cancel PR workflows on close - #1723

Merged
key4ng merged 1 commit into
mainfrom
codex/cancel-pr-workflow-on-close
Jun 13, 2026
Merged

key4ng merged 1 commit into
mainfrom
codex/cancel-pr-workflow-on-close

Conversation

@key4ng

@key4ng key4ng commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

Long-running PR workflows can keep consuming runners after a PR is merged or manually closed because the existing PR workflows only run on open/update/reopen activity. No final close-event run is created to cancel the active PR concurrency groups.

Solution

Add a lightweight pull_request.closed workflow that starts no-op matrix jobs in the same concurrency groups as the existing PR workflows. With cancel-in-progress: true, GitHub Actions cancels any active run in those groups when the PR closes. This keeps the change scoped to workflows that already define PR concurrency groups and does not modify release workflows.

Changes

  • Add .github/workflows/cancel-pr-workflows.yml.
  • Cover PR Test (SMG), PR Test (MLX), PR Validation, PR Labeler, Claude PR Review, and benchmark PR concurrency groups.
  • Leave release workflows unchanged.

Test Plan

  • actionlint .github/workflows/cancel-pr-workflows.yml
  • pre-commit run --files .github/workflows/cancel-pr-workflows.yml
  • git diff --check
Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated
  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs

Summary by CodeRabbit

  • Chores
    • Added automation to stop in-progress pull request workflows when a PR is closed.
    • Reduced wasted CI time by preventing outdated runs from continuing after closure.

Signed-off-by: key4ng <rukeyang@gmail.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@github-actions github-actions Bot added the ci CI/CD configuration changes label Jun 13, 2026
@coderabbitai

coderabbitai Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1d5b8d73-443a-441f-b407-ad6d6764aa49

📥 Commits

Reviewing files that changed from the base of the PR and between fd330b1 and 08dd08e.

📒 Files selected for processing (1)
  • .github/workflows/cancel-pr-workflows.yml

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that runs when a pull request is closed, computes PR-specific concurrency groups from a matrix of workflow templates, and cancels matching in-progress runs while logging the PR number and resolved group.

Changes

CI workflow cancellation

Layer / File(s) Summary
Closed-PR cancellation workflow
.github/workflows/cancel-pr-workflows.yml
Adds a workflow triggered by closed pull requests that iterates over configured workflow group templates, resolves PR-number-based concurrency groups, cancels matching in-progress runs, and logs the computed group values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • lightseekorg/smg#1530: Both changes add pull request–driven GitHub Actions cancellation logic using PR-number-based concurrency groups.

Suggested labels

ci

Suggested reviewers

  • slin1237
  • XinyueZhang369
  • CatherineSue

Poem

🐇 I saw a PR hop shut its door,
and whisked through workflows gone before.
With tidy groups and gentle might,
I cancelled dangling runs at night.
Carrot cheers for cleaner CI!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: canceling PR workflows when a pull request is closed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/cancel-pr-workflow-on-close

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +17 to +30
include:
# Keep these in sync with the concurrency groups used by PR workflows.
- workflow: PR Test (SMG)
group: gateway-tests-pr-{0}
- workflow: PR Test (MLX)
group: mlx-tests-pr-{0}
- workflow: PR Validation
group: pr-validation-{0}
- workflow: PR Labeler
group: labeler-{0}
- workflow: Claude PR Review
group: claude-review-{0}
- workflow: Benchmark - Tokenizer
group: benchmark-tokenizer-refs/pull/{0}/merge

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit: claude-code-review.yml has a second PR concurrency group — claude-respond-${{ github.event.issue.number || github.event.pull_request.number }} (line 307) — that isn't covered here. Its original cancel-in-progress: false prevents new comment triggers from cancelling an in-flight response, but when the PR is closed there's no audience for the response, so cancelling it would save runner minutes.

If intentionally excluded, a comment in the matrix noting why would help future maintainers keeping this list in sync.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean, well-scoped workflow. All concurrency group strings verified against their source workflows — they match correctly. One minor nit posted about a missing claude-respond group.

Summary: 0 🔴 Important · 1 🟡 Nit · 0 🟣 Pre-existing

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08dd08eb47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +40 to +41
group: ${{ format(matrix.group, github.event.pull_request.number) }}
cancel-in-progress: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid stale close runs canceling reopened PR CI

When a PR is closed and then quickly reopened, the pull_request.closed run can still be queued after the reopened workflows have started; because this job unconditionally enters the same PR concurrency group with cancel-in-progress: true, it can cancel the fresh reopened CI (for example, .github/workflows/pr-test-rust.yml triggers on reopened and uses gateway-tests-pr-{number}). Please avoid touching the target cancellation groups unless the PR is still closed/current, or use an API-based cancellation path that checks current PR state before canceling.

Useful? React with 👍 / 👎.

@key4ng key4ng closed this Jun 13, 2026
@key4ng key4ng reopened this Jun 13, 2026
@key4ng key4ng closed this Jun 13, 2026
@key4ng key4ng reopened this Jun 13, 2026
@key4ng key4ng closed this Jun 13, 2026
@key4ng key4ng reopened this Jun 13, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good. The workflow correctly targets all PR concurrency groups, permissions are minimal, and fail-fast: false is appropriate.

Two existing comments remain relevant:

  • 🟡 Nit (line 30): The claude-respond concurrency group from claude-code-review.yml isn't covered — worth adding to save runner time on closed PRs.
  • 🟡 Nit (line 41, flagged by another reviewer): Close/reopen race — if the closed-event run is delayed past a reopen, it could cancel the freshly-triggered CI. Low probability but worth noting.

No 🔴 Important issues found. 0 important · 2 nits (pre-existing)

@key4ng
key4ng merged commit 43378fe into main Jun 13, 2026
121 of 147 checks passed
@key4ng
key4ng deleted the codex/cancel-pr-workflow-on-close branch June 13, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CI/CD configuration changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant