Skip to content

ci: cancel a pull request's superseded runs - #629

Merged
hogan-yuan merged 1 commit into
mainfrom
ci/cancel-superseded-pr-runs
Nov 19, 2026
Merged

hogan-yuan merged 1 commit into
mainfrom
ci/cancel-superseded-pr-runs

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

No workflow in this repo declares a concurrency group, so every push to a pull request queues another full CI matrix and the run it replaced keeps its place in line.

What that looked like

Observed while iterating on #627 and #628:

全仓库最近 12 次运行:queued=6, completed=6
最近一次真正完成的运行:186 分钟前
最老的排队运行:187 分钟

Six runs queued at once; four were for commits that were no longer any branch's HEAD. Nothing started for roughly three hours. Cancelling the four obsolete runs by hand is what got the queue moving again:

44282677026  b18750b35  superseded → cancelled
44266307848  b846aea07  superseded → cancelled
44265659864  acc1c2549  superseded → cancelled
44259650117  3e99304e9  superseded → cancelled

With nine jobs fanning out across a wide platform matrix, each obsolete run is a lot of runner time spent on a commit nobody is waiting for.

The change

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

github.head_ref is set only for pull_request events, so:

  • a pull request groups by its branch — a new commit cancels the run for the commit it replaced
  • a push to main falls back to github.run_id, which is unique per run, so those get a group of their own: never cancelled, and never made to queue behind each other either

That second half matters. The naive group: ${{ github.workflow }}-${{ github.ref }} would put every main push in one group — either cancelling a main run that a later commit supersedes, or serialising them.

Why only ci.yml

The other five workflows should not cancel, so they are untouched:

workflow trigger why not
release.yml push to release publishes artifacts; aborting halfway is worse than running twice
docs.yml push to release deploys docs; same
check_docs.yml push to main main only, infrequent
close-slate-issues.yml weekly cron nothing to supersede
issue-notify.yml issue opened nothing to supersede

Related, deliberately not bundled

  • longbridge-mcp has no concurrency group in any of its four workflows.
  • longbridge-terminal has one in three of seven, but not in test.yml.

Both are worth the same change, but neither has shown this backlog — their CI is small where this one fans out — so they belong in their own PRs rather than here.

Honest note on how this came up

A good part of the backlog was self-inflicted: I pushed small follow-up commits to #627 and #628 seven times while reviewing them, and in a repo with no concurrency group each of those reset a full matrix. The fix is worth having regardless, but the measurement above is as much a description of my own push cadence as of the CI configuration.

🤖 Generated with Claude Code

Nothing in this repo's workflows declares a concurrency group, so every
push to a PR queued another full CI matrix and the run it replaced kept its
place in line. Observed while iterating on #627 and #628: six runs queued
at once, the oldest for three hours, four of them for commits that were no
longer any branch's HEAD. Nothing started for about three hours; cancelling
the four obsolete runs by hand was what got the queue moving again.

Group CI by the pull request's branch and cancel in progress, so a new
commit supersedes its predecessor's run instead of competing with it.

`github.head_ref` is set only for pull_request events. A push to main falls
back to `github.run_id`, which is unique per run, so those get a group of
their own: they are never cancelled, and never made to queue behind each
other either.

Only ci.yml is changed. The other five workflows should not cancel:
release.yml and docs.yml both run on pushes to `release` and publish
artifacts, where aborting halfway is worse than running twice;
check_docs.yml runs only on main; close-slate-issues.yml is a weekly cron;
issue-notify.yml fires on issue creation.

longbridge-mcp has no concurrency group in any of its four workflows, and
longbridge-terminal has one in three of seven but not in `test.yml`. Both
are worth the same change, but neither has shown the backlog this repo has
-- their CI is small where this one fans out across nine jobs and a wide
platform matrix -- so they are left for separate PRs rather than bundled in.
@hogan-yuan
hogan-yuan merged commit ab241ed into main Nov 19, 2026
6 checks passed
@hogan-yuan
hogan-yuan deleted the ci/cancel-superseded-pr-runs branch November 19, 2026 02:02
hogan-yuan added a commit to longbridge/longbridge-mcp that referenced this pull request Nov 19, 2026
No workflow in this repo declares a `concurrency` group, so every push
to a pull request queues another CI run and **the run it replaced keeps
its place in line**.

## The change

```yaml
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true
```

`github.head_ref` is set **only** for `pull_request` events, so:

- **a pull request** groups by its branch — a new commit cancels the run
for the commit it replaced
- **a push to main** falls back to `github.run_id`, which is unique per
run, so those get a group of their own: never cancelled, and never made
to queue behind each other

The naive `group: ${{ github.workflow }}-${{ github.ref }}` would do one
or the other to main.

## Prevention here, not a fix

Being straight about this: **I did not observe a backlog in this repo.**
Its CI is a single `check` job, so superseded runs cost little.

The same change landed in longbridge/openapi as longbridge/openapi#629,
where it *was* a real problem — nine jobs across a wide platform matrix,
six runs queued at once, nothing starting for about three hours, four of
them for commits that were no longer any branch's HEAD. This repo has
the same configuration gap and none of the symptoms; the fix is cheap
enough to be worth having before it does.

## Why only `ci.yml`

| workflow | trigger | why untouched |
|---|---|---|
| `release.yml` | `v*` tags | publishes container images; aborting
halfway is worse than running twice |
| `preview.yml` | `workflow_dispatch` | a run is something a person
asked for by hand |
| `registry-health-check.yml` | weekly cron | nothing to supersede |

🤖 Generated with [Claude Code](https://claude.com/claude-code)
hogan-yuan added a commit to longbridge/longbridge-terminal that referenced this pull request Nov 19, 2026
`test.yml` is the workflow pull requests actually run, and it is the one
without a `concurrency` group — so every push to a PR queues another run
while **the one it replaced keeps its place in line**.

## The change

```yaml
concurrency:
  group: test-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true
```

Three workflows here already declare groups (`test-update.yml`,
`update-homebrew.yml`, `update-scoop.yml`), so this follows their naming
style — a literal prefix — rather than importing `${{ github.workflow
}}` from elsewhere.

`github.head_ref` is set **only** for `pull_request` events:

- **a pull request** groups by its branch — a new commit cancels the run
for the commit it replaced
- **a push to main, or a tag**, falls back to `github.run_id`, which is
unique per run, so those get a group of their own: never cancelled,
never queued behind each other

That second half matters more here than it would in a PR-only workflow,
because `test.yml` also runs on `tags: ["*"]`, and a tag build is not
something to cancel. `test-update.yml`'s existing `group:
test-update-${{ github.ref }}` would have that problem; this one does
not.

## Why only `test.yml`

| workflow | trigger | why untouched |
|---|---|---|
| `release.yml` | `v*` tags, `build-test` branch | publishes; aborting
halfway is worse than running twice |
| `release-to-oss.yml` | `workflow_dispatch` | a run is something a
person asked for by hand |
| `test-install.yml` | push to main / tags, path-filtered | **no
`pull_request` trigger at all**, so nothing to supersede |

## Prevention here, not a fix

Being straight about it: **no backlog was observed in this repo** — its
CI is a single `build` job.

The same change landed in longbridge/openapi as longbridge/openapi#629,
where it was a real problem: nine jobs across a wide platform matrix,
six runs queued at once, nothing starting for about three hours, four of
them for commits that were no longer any branch's HEAD. This repo has
the same gap in the workflow that matters and none of the symptoms.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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