Skip to content

Cancel superseded CI runs with a concurrency group - #52

Open
icppWorld wants to merge 1 commit into
mainfrom
ci-concurrency
Open

Cancel superseded CI runs with a concurrency group#52
icppWorld wants to merge 1 commit into
mainfrom
ci-concurrency

Conversation

@icppWorld

@icppWorld icppWorld commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Pushing to a branch does not cancel the previous run, so a superseded matrix keeps going.
That is not just wasted minutes: the macOS runner pool is small, so the stale run holds
runners and the new one sits queued behind it. This happened during #51 — the mac matrix on
the superseded commit had to be cancelled by hand before the new one could start.

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

Added to all three workflows.

Why main is excluded

Not the usual cancel-in-progress: true. The release process pushes a version commit to
main and then waits on its CI before publishing. With unconditional cancellation, a second
push to main — say a pyproject.toml dependency bump landing right after the version
commit, which is exactly what 6.0.0 did — would silently kill the run being waited on.

Superseded branch runs are waste. Superseded main runs are release evidence.

Verified

All three files parse with yaml.safe_load, and each workflow lists its own path in its
trigger filter, so this PR exercises the new config on itself.

Summary by CodeRabbit

  • Chores
    • Improved CI workflow efficiency by automatically canceling superseded runs on non-main branches.
    • Main branch and release-related runs continue to complete without cancellation.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The macOS, Ubuntu, and wheel-test GitHub Actions workflows now cancel superseded runs on non-main branches. Runs on main remain active.

Changes

CI concurrency controls

Layer / File(s) Summary
Add branch-aware workflow concurrency
.github/workflows/cicd-mac.yml, .github/workflows/cicd-ubuntu.yml, .github/workflows/cicd-wheel-test.yml
Each workflow groups runs by workflow and Git reference. Superseded non-main runs are canceled, while main runs are allowed to complete.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 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 superseded CI runs through a concurrency group.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci-concurrency

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/cicd-mac.yml:
- Around line 21-23: Use a unique concurrency group for main runs by updating
the concurrency.group expressions in .github/workflows/cicd-mac.yml lines 21-23,
.github/workflows/cicd-ubuntu.yml lines 19-21, and
.github/workflows/cicd-wheel-test.yml lines 24-26 to incorporate github.run_id
for the main branch, while preserving the existing grouping and cancellation
behavior for non-main runs.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 71a22ccf-ae6d-4ebc-99cd-bc818ac9dc9d

📥 Commits

Reviewing files that changed from the base of the PR and between dd2aa10 and 8a8a5c5.

📒 Files selected for processing (3)
  • .github/workflows/cicd-mac.yml
  • .github/workflows/cicd-ubuntu.yml
  • .github/workflows/cicd-wheel-test.yml

Comment on lines +21 to +23
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow concurrency sections =="
for f in .github/workflows/cicd-mac.yml .github/workflows/cicd-ubuntu.yml .github/workflows/cicd-wheel-test.yml; do
  if [ -f "$f" ]; then
    echo "--- $f"
    nl -ba "$f" | sed -n '1,60p'
  else
    echo "MISSING $f"
  fi
done

echo
echo "== all workflow concurrency usages =="
rg -n "concurrency:|group:|cancel-in-progress:" .github/workflows || true

echo
echo "== expression parser/runtime hints from installed tooling =="
command -v gh || true
command -v python3 || true
python3 - <<'PY'
try:
    from asteval import Interpreter
    print("asteval available")
except Exception as e:
    print("asteval unavailable:", type(e).__name__)
PY

node - <<'JS'
console.log("github.ref != refs/heads/main for main:", 'refs/heads/main' != 'refs/heads/main');
console.log("github.ref != refs/heads/main for pr:", 'refs/pull/123/head' != 'refs/heads/main');
console.log("main run_id branch expression:", ('refs/heads/main' === 'refs/heads/main' ? 'unique:' + 123 : 'refs/heads/main'));
console.log("pr branch expression:", ('refs/pull/123/head' === 'refs/heads/main' ? 'unique:' + 456 : 'refs/pull/123/head'));
JS

Repository: icppWorld/icpp-pro

Length of output: 267


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow concurrency sections =="
for f in .github/workflows/cicd-mac.yml .github/workflows/cicd-ubuntu.yml .github/workflows/cicd-wheel-test.yml; do
  if [ -f "$f" ]; then
    echo "--- $f"
    python3 - "$f" <<'PY'
import sys
path = sys.argv[1]
with open(path, encoding="utf-8") as fh:
    for i, line in enumerate(fh, 1):
        if 1 <= i <= 55:
            print(f"{i}\t{line.rstrip()}")
PY
  else
    echo "MISSING $f"
  fi
done

echo
echo "== all workflow concurrency usages =="
rg -n "concurrency:|group:|cancel-in-progress:" .github/workflows || true

echo
echo "== expression runtime semantics probe =="
node - <<'JS'
const cases = {
  main: 'refs/heads/main',
  pr: 'refs/pull/123/head',
  tag: 'refs/tags/v1.0.0',
};
for (const [name, gref] of Object.entries(cases)) {
  const expressions = {
    defaultGroup: `${{ github.workflow }}-${{ github.ref }}`,
    currentGroupPr: `mac-${gref}`,
    canceled: gref !== 'refs/heads/main',
    uniqueMainGroup: `${${{ gref === 'refs/heads/main' ? 999 : gref }}`,
  };
  console.log(`${name}:`, { currentGroupPr, canceled, uniqueMainGroup });
}
console.log("node", process.version);
JS

Repository: icppWorld/icpp-pro

Length of output: 8268


Use a unique concurrency group for main runs.

A non-zero cancel-in-progress value still cancels pending runs in the same group. These workflows keep main in ${{ github.workflow }}-${{ github.ref }}, so a new main run can cancel an older pending main run in the same concurrency group.

Use github.run_id for the main group instead:

-  group: ${{ github.workflow }}-${{ github.ref }}
+  group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}

Apply this to cicd-mac.yml, cicd-ubuntu.yml, and cicd-wheel-test.yml.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
📍 Affects 3 files
  • .github/workflows/cicd-mac.yml#L21-L23 (this comment)
  • .github/workflows/cicd-ubuntu.yml#L19-L21
  • .github/workflows/cicd-wheel-test.yml#L24-L26
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cicd-mac.yml around lines 21 - 23, Use a unique
concurrency group for main runs by updating the concurrency.group expressions in
.github/workflows/cicd-mac.yml lines 21-23, .github/workflows/cicd-ubuntu.yml
lines 19-21, and .github/workflows/cicd-wheel-test.yml lines 24-26 to
incorporate github.run_id for the main branch, while preserving the existing
grouping and cancellation behavior for non-main runs.

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