Skip to content

ci: key workflow concurrency groups on pull request number - #7829

Queued
adityavaish wants to merge 4 commits into
apache:mainfrom
adityavaish:adityavaish-fix-ci-concurrency-group
Queued

adityavaish wants to merge 4 commits into
apache:mainfrom
adityavaish:adityavaish-fix-ci-concurrency-group

Conversation

@adityavaish

@adityavaish adityavaish commented Dec 2, 2026 •

Copy link
Copy Markdown

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 5c7929e3a447b9db68d3866bf96c4e89cf32a94c

Dimension Assessment Rationale
Change confidence 9.5/10 ↑ Updates codeql.yml, pr_title_check.yml, and (for consistency) miri.yml, simplifies check_concurrency_groups() to a focused github.head_ref scan with zero edits to shared helpers, and passes all 19 check-ci-config.py checks, test-docs-permissions.py, and actionlint --shellcheck=off.
↓ Live GitHub Actions runs on Linux and check_local_ci_config() under native Linux bash are pending CI approval.
Diagnosis confidence 9.5/10 ↑ Workflow inspection confirmed codeql.yml and pr_title_check.yml still keyed PR concurrency.group on github.head_ref (and miri.yml carried the same template on non-PR triggers), while ci.yml was already updated in #7311.
Evidence fit 9.5/10 ↑ Directly resolves the remaining PR workflows in #7315 and guards against reintroducing github.head_ref in dev/ci/check-ci-config.py.

Which issue does this PR close?

Closes #7315.

Rationale for this change

codeql.yml and pr_title_check.yml still keyed concurrency.group on github.head_ref || github.sha. Because github.head_ref is only the branch name without the fork repository or PR number, two open pull requests from different forks sharing a branch name (such as main or patch-1) collide in the same concurrency group and cancel each other's runs. (ci.yml was already switched to github.event.pull_request.number in #7311; miri.yml only triggers on schedule/workflow_dispatch so its matching edit is for consistency rather than a runtime fix.)

What changes are included in this PR?

  • Updated concurrency.group in .github/workflows/codeql.yml and .github/workflows/pr_title_check.yml from github.head_ref || github.sha to github.event.pull_request.number || github.sha (and updated .github/workflows/miri.yml to match for consistency).
  • Added a concise check_concurrency_groups() scan in dev/ci/check-ci-config.py that checks .github/workflows/*.y*ml and fails if any workflow- or job-level concurrency: block references github.head_ref.

How are these changes tested?

  • Confirmed check_concurrency_groups() fails on the pre-fix codeql.yml, miri.yml, and pr_title_check.yml from main (3 failures) and passes on the updated files.
  • Verified edge cases for check_concurrency_groups() (inline scalar/flow concurrency:, multiline group: >-, job-level concurrency:, ignoring comments and run: blocks).
  • Verified all 19 Python checks in dev/ci/check-ci-config.py pass (bash -n dev/local-ci.sh passed separately; check_local_ci_config() has a pre-existing Windows backslash quirk).
  • python dev/ci/test-docs-permissions.py — passed.
  • actionlint --shellcheck=off (v1.7.12) across all workflows — passed (exit code 0).

Switch concurrency.group in codeql.yml, miri.yml, and pr_title_check.yml from github.head_ref to github.event.pull_request.number (preserving the github.sha fallback for non-PR events), matching ci.yml so pull requests from different forks sharing a branch name cannot cancel each other's runs.

Add check_concurrency_groups() to dev/ci/check-ci-config.py to pin this invariant across all workflows, including same-branch cross-fork PRs, case-only branch variants, same-PR superseding, ci_label.yml -> ci.yml label runs, workflow_run fork isolation, and non-PR commit fallbacks.

Resolves apache#7315

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

The three workflow edits are correct. For codeql.yml's push and schedule and for pr_title_check.yml's pull_request events the fallback to github.sha behaves as before, because github.head_ref is also empty on push and schedule. The 330 line checker is far larger than the bug needs, and it carries drive-by refactors of shared helpers. A grep-level rule would guard the same regression.


concurrency:
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
group: ${{ github.repository }}-${{ github.event.pull_request.number || github.sha }}-${{ github.workflow }}

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.

miri.yml triggers only on schedule and workflow_dispatch (see its on: block), and nothing calls it through workflow_call. github.event.pull_request.number is never set there, and github.head_ref was already empty, so this edit changes no group at runtime. Keeping it for consistency is fine, but the PR description and the issue should not count it as a fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch—kept the miri.yml change for consistency and updated the PR description to note that miri.yml only triggers on schedule/workflow_dispatch and is a consistency edit rather than a runtime fix.

Auto-replied by the GitHub Copilot app

Comment thread dev/ci/check-ci-config.py
}


def check_concurrency_groups():

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.

The bug is that a concurrency group names github.head_ref. A check that scans .github/workflows/*.y*ml for a group: line containing github.head_ref is about 15 lines and fails on exactly the three files this PR fixes. check_concurrency_groups instead adds a hand-rolled YAML block parser (concurrency_blocks, about 60 lines), simulates pull request, workflow_run, push, merge_group, schedule and workflow_dispatch contexts, and re-derives the case-only and cross-fork properties by evaluating expressions. The script already holds a concurrency: regex check in check_fork_runs (line 1767) that could host the simple rule. I would replace the new function with the short scan and drop the helpers it needs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Simplified in 5c7929e3a—replaced the parser and context simulation with a concise check_concurrency_groups() scan (~35 lines) that flags any workflow- or job-level concurrency: block referencing github.head_ref (handling inline scalar/flow and multiline group: values while ignoring comments). Confirmed it catches the three pre-fix files and passes on the updated workflows.

Auto-replied by the GitHub Copilot app

Comment thread dev/ci/check-ci-config.py Outdated
Comment on lines +2211 to +2213
# ci_label.yml calls ci.yml on `labeled`; ci.yml owns the concurrency group
# and shares the caller's pull_request context.
if LABEL_WORKFLOW.exists():

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.

This block re-tests ci.yml's group against ci_label.yml runs and asserts that ci_label.yml has no concurrency. ci.yml is not touched by this PR (its group was fixed in #7311), so this is new coverage for a different property and belongs in its own change if it is wanted.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed in 5c7929e3a so this PR stays focused strictly on preventing github.head_ref in concurrency groups.

Auto-replied by the GitHub Copilot app

Comment thread dev/ci/check-ci-config.py Outdated
"""Return {event: its `types:` list, or None} from ci.yml's top-level `on:`."""
lines = (WORKFLOWS / "ci.yml").read_text(encoding="utf-8").splitlines()
event_key = re.compile(r"^ ([a-z_]+):\s*$")
def workflow_triggers(path):

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.

workflow_triggers (generalizing ci_triggers), the _unquote_yaml_scalar change to workflow_name, and the evaluate_condition to evaluate_expression split exist only to serve the new checker. If the checker shrinks to the short scan from my other comment, these edits to shared helpers are not needed, and the PR then does what its title says with no change to existing checks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Reverted all shared-helper edits in 5c7929e3a (ci_triggers, workflow_name, and evaluate_condition are now unchanged from main).

Auto-replied by the GitHub Copilot app

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

thanks @adityavaish, the PR goes into right direction, please check some nits!

@sunchao sunchao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new keys separate same-named branches across forks and keep successive runs on one PR together. The CI configuration checks passed locally. I found one case the new regression check misses.

Automated review by Codex.

Comment thread dev/ci/check-ci-config.py Outdated
"github.head_ref": head_ref,
"github.ref": f"refs/pull/{number}/merge",
"github.ref_name": f"{number}/merge",
"github.sha": sha,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I appended -${{ github.event.pull_request.head.sha }} to the CodeQL group and python3 dev/ci/check-ci-config.py still passed. pr_context varies github.sha but leaves the PR head SHA unset, so the evaluator substitutes an empty string on both pushes. In Actions the suffix changes and the previous run keeps running. If we keep this simulation, can we give successive pushes distinct head SHAs and check that this mutation fails?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching that—per @comphead's feedback, 5c7929e3a replaced the context simulation with a direct github.head_ref concurrency-group scan, so pr_context has been removed.

Auto-replied by the GitHub Copilot app

adityavaish and others added 2 commits December 2, 2026 17:18
Replace the expression-evaluating concurrency checker and shared-helper refactors in dev/ci/check-ci-config.py with a concise scan that rejects github.head_ref in any workflow concurrency group.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@adityavaish

Copy link
Copy Markdown
Author

Thanks @comphead and @sunchao for the review! Addressed all comments in 5c7929e (simplified \check_concurrency_groups()\ to a concise \github.head_ref\ scan, reverted unrelated helper edits, removed the \ci_label.yml\ check, and clarified \miri.yml\ in the PR description).

@comphead could you please approve the workflow runs on this updated commit (and queue for merge once CI is green)?

@github-actions github-actions Bot added build Build environment enhancement New feature or request area:ci CI/CD, GitHub Actions, build tooling labels Dec 3, 2026
@sunchao
sunchao added this pull request to the merge queue Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI/CD, GitHub Actions, build tooling build Build environment enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: concurrency group is keyed on the branch name, so same-named fork branches can cancel each other's CI

4 participants