Repository navigation
Description
Summary
When main moves or an entry ahead leaves the queue, the queue builds new merge groups on new temporary branches and deletes the old ones. The runs of a group that no longer exists are not reliably cancelled: some end cancelled on their own, others stay queued for runners beside the live group's jobs, on a plan with about 20 concurrent jobs. A plain cancel does not clear the stuck ones, because the if: always() aggregate jobs of each workflow stay queued. The repository documents a tool that retires one run at a time. This issue collects the evidence and the options. It proposes no fix.
What the repository says
.github/CI.md:62-67(## Retiring a deleted merge-group revision): "Rebuilding the merge queue gives its temporary branches new names. Workflow concurrency is keyed by the complete ref, so an old revision can keep running after GitHub deletes its branch."tools/cli/scripts/ci-retire-merge-group.tsretires one run per invocation (--run <id>): read-only by default, then an ordinary cancellation with a receipt, only for a run of one of the seven validation workflows whose ref returns 404 and whose head is absent from the queue. "It does not escalate to force cancellation"; "Ordinary cancellation may leave analways()aggregate queued; the explicit finishing mode below is a separate decision" (CI.md:91-92).- Each workflow's concurrency group is the full ref, on purpose: "a merge-group ref … is unique, so queued runs never cancel each other or a PR run" (
CI.md:991). - Budget: "the public repository's free plan runs about 20 jobs at once across every PR and queue run, a full merge-group run needs dozens … a queued run can wait hours for a runner" (
CI.md:968).
What was observed
On 2026-10-12, while #4849 and #4853 waited in the queue (see #4873 for why the groups were rebuilt):
- At about 14:35 UTC the repository had 64 queued and 4 in-progress workflow runs. 28 of the queued or running
merge_groupruns belonged to 8 groups that no longer existed (their heads were not entries of the queue): three groups of fix(platform): harden chat tools and light sandboxes after review #4849, three of fix(platform): hold up under a load burst and a database restart #4853 and two of test(cli): exempt the smoke fixture suite from the target guard #4856. The oldest, a Build run, had been queued since 13:51. - A job as small as
Lint commits(the Commitlint workflow's only job that does work; it took 36 s on a pull request run) had been queued for 13 minutes when the live group of fix(platform): harden chat tools and light sandboxes after review #4849 was checked at 14:34. - A plain
gh run canceldid not finish the runs. After it, run 38265555277 (Checks) showed its other jobs finished orcancelled, butUnit, thealways()aggregate, was stillqueued, and so was the run.gh run cancel --forcefinished it (completed/cancelled). - Queued runs repository-wide went from 64 to 55 at 14:37, after a first sweep of plain cancellations (27 runs), and to 29 at about 15:00, after later sweeps with
--force. Not all of that is attributable to the cancellations. - Each rebuild left more. Later sweeps kept finding runs of dissolved groups, between 2 and 12 per sweep, some of them runs whose earlier plain cancel had not finished.
- Some runs are cancelled without manual action. Of the 330 merge-group runs that had settled by 14:35 UTC, before any manual cancellation, 247 succeeded, 18 failed and 65 (20%) ended
cancelled. I did not establish what cancelled them. The 400 most recent runs (2026-10-11 23:22Z to 2026-10-12 14:54Z) cover 57 groups for 21 PRs.
Why it matters
A rebuild is supposed to replace a group, but the replaced group's runs keep competing for the same ~20 runner slots. The live group can wait behind work whose result nobody will read, and every direct merge to main (#4873) creates another batch of such runs. At 14:34 the live group's Commitlint run, the lightest of its seven workflows, had not started 13 minutes after it was created.
Options (not exhaustive, no preference stated)
- Retire in bulk. Run the existing retire command, or the sketch below, over every eligible run on a schedule (a workflow with
actions: write), keeping the documented safety checks: ref returns 404, head absent from the queue. - Cancel from inside the new group. When a merge-group workflow starts for a PR, cancel older runs for the same PR whose heads are no longer queue entries.
- Key merge-group concurrency by PR number so a PR's groups cancel each other. Trade-offs: a group can contain several PRs and its ref names only the last one; and "queued runs never cancel each other" (
CI.md:991) is a deliberate property. - Reduce the work per group, so a rebuild costs fewer jobs.
- Add runner capacity, so dissolved runs drain harmlessly.
Questions
- Is force cancellation acceptable for a group that no longer exists?
CI.mdcalls the finishing mode "a separate decision". - Who retires obsolete runs today, and how often?
- Should retirement be part of the queue's own tooling, or stay a manual maintenance step?
Reproduce
A sketch of the check used above (needs an authenticated gh; it is a dry run unless --apply is given):
retire-dissolved-groups.py
#!/usr/bin/env python3
"""List, and with --apply force-cancel, the merge-group runs whose group no longer exists.
usage: python3 retire-dissolved-groups.py # dry run: prints what would be cancelled
python3 retire-dissolved-groups.py --apply
A run is eligible only when both hold:
1. its head commit is not the head of any entry in the merge queue right now, and
2. its temporary branch (gh-readonly-queue/main/pr-<number>-<sha>) no longer exists.
If the queue or a branch cannot be read, nothing is cancelled. --force is used because a plain cancel leaves the
`if: always()` aggregate jobs ("Unit", "CI ready (...)") queued, so the run would stay in the backlog.
"""
import json
import subprocess
import sys
REPO = 'tale-project/tale'
APPLY = '--apply' in sys.argv
def gh(*args, check=True):
return subprocess.run(['gh', *args], capture_output=True, text=True, check=check)
def queue_heads():
query = ('query { repository(owner:"tale-project", name:"tale") { mergeQueue(branch:"main") '
'{ entries(first:100) { nodes { headCommit { oid } } } } } }')
nodes = json.loads(gh('api', 'graphql', '-f', f'query={query}').stdout)['data']['repository']['mergeQueue']['entries']['nodes']
return {node['headCommit']['oid'] for node in nodes if node['headCommit']}
def branch_is_gone(branch):
result = gh('api', f'repos/{REPO}/git/ref/heads/{branch}', check=False)
if result.returncode == 0:
return False
if '404' in result.stderr or 'Not Found' in result.stderr:
return True
raise RuntimeError(f'cannot tell whether {branch} exists: {result.stderr.strip()}')
heads = queue_heads()
runs = []
for status in ('queued', 'in_progress', 'waiting', 'pending'):
out = gh('run', 'list', '--repo', REPO, '--event', 'merge_group', '--status', status, '--limit', '100',
'--json', 'databaseId,headSha,headBranch,workflowName,createdAt').stdout
runs += json.loads(out or '[]')
gone = {}
eligible = []
for run in runs:
if run['headSha'] in heads:
continue
branch = run['headBranch']
if branch not in gone:
gone[branch] = branch_is_gone(branch)
if gone[branch]:
eligible.append(run)
print(f'{len(runs)} merge_group runs are queued or running; {len(eligible)} belong to groups that no longer exist')
for run in sorted(eligible, key=lambda r: r['createdAt']):
print(f" {run['createdAt'][5:16]}Z {run['workflowName']:<10} {run['headBranch'].rsplit('/', 1)[-1][:28]}")
if APPLY:
gh('run', 'cancel', '--force', str(run['databaseId']), '--repo', REPO, check=False)
if eligible and not APPLY:
print('dry run: pass --apply to cancel them')The group statistics come from merge-group-stats.py in #4873.
Related
#4873 (how changes reach main, and what a direct merge does to the groups in the queue), #3951 (an earlier case of newer main builds starving a pinned validation).
Observed at main a83e645e27.
Activity
yannickmonney commentedon Oct 13, 2026
Evidence from 2026-10-13 (UTC), the same mechanics with a different harm: the live first group lost its jobs.
failed_checksat 18:38:53Z and again at 19:47:29Z, each one to two minutes later, and was merged directly at 19:51:24Z, 3 h 40 min after its first entry.merge_groupruns that endedcancelled: 36 between 18:38:16Z and 18:39:40Z (groups of fix(platform): repair review access retargeting #4396, fix(platform): preserve custom API-key expiry dates #4582, fix(platform): back off harness rate limits #4952 and fix(release): enforce daily cohort admission #4956 on several bases) and 13 between 19:44:41Z and 19:48:07Z. The second set includes theE2Erun of the group of fix(platform): repair review access retargeting #4396 built on76a11ec8, cancelled at 19:47:16Z.mainhad been at76a11ec8since 18:46:03Z and fix(platform): repair review access retargeting #4396 stayed queued until 19:47:29Z, so that was the live group, not a dissolved one.pull_requestChecks run of feat(platform): connect a coding agent on the MCP settings page #4968 (Lint, Type check, Unit (platform 1/2), Unit (workspaces); run 38454476804) endedcancelledbetween 19:47:36Z and 19:48:16Z, which turnedUnitandCI ready (Checks)red untilgh run rerun --failed. The Security and SAST runs of that PR answered "cannot be retried".CLIrun of the live group of feat(platform): create an automation with a coding agent #4966 (pr-4966-5197d946…) endedcancelled; it is the only run that endedcancelledwithin two minutes of that time. The queue removed feat(platform): create an automation with a coding agent #4966 withfailed_checksnine seconds later, 1 h 31 min after it had entered.merge_group) and 4 in progress (3 of themmerge_group). The live group of feat(platform): create an automation with a coding agent #4966, created at 19:51:56Z, still had Build, CLI, E2E and Checks queued at 20:50Z. After 15 runs of dissolved groups of feat(platform): create an automation with a coding agent #4966 and feat(platform): connect a coding agent in the setup wizard #4967 were cancelled at 20:50Z (each only when its head was no queue entry's head and its temporary branch returned 404, the entry heads re-read before every cancellation), seconds later theE2Eruns of the live groups of fix(cli): let tale deploy cross the automation protocol cutover #4954 and feat(platform): connect a coding agent in the setup wizard #4967 and theCLIrun of the group of feat(platform): connect a coding agent in the setup wizard #4967 were in progress.workflows.cancelled_workflow_runwith the actor. One coincidence was checked and does not explain it: feat(platform): create an automation with a coding agent #4966's last required pull request check completed at 19:46:29Z and it entered the queue at 19:46:36Z, but the second cluster began at 19:44:41Z.yannickmonney commentedon Nov 14, 2026
Decision
Rule: main has no merge queue, so no dissolved merge groups exist and none need retiring. Close this issue as resolved by removing the queue. Add a guard so the queue cannot return without a plan for its dissolved groups.
What changed since the report
ci-retire-merge-group.tsandci-merge-group-finish.ts.merge_grouptrigger from every workflow. GitHub now reports no merge queue formain, and the required-CI ruleset only requires status checks.main, which deliberately keeps running. The one leftover case, analways()tail left queued after a cancel, is covered byci-retire-tail.ts. It force-cancels a single run only after re-checking that it is obsolete, and it writes a receipt.Answers
ci-retire-tail.tsdoes. A blind sweep is not acceptable.mainruns automatically. An operator or agent usesci-retire-tail.tson demand for a stuck tail. Nothing runs on a schedule.Rationale: Removing the queue removed the cause, so every option listed here would be code for an event that never fires. A scheduled force-cancel job with
actions: writewould be a privileged component with nothing to do. A guard test is cheap. Without it, turning the queue back on would quietly bring back the runner starvation and the cancelled live groups recorded here.Implementation units
merge_grouptrigger. Its failure message points to a new CI.md paragraph stating the rule above.