open-standards/scripts/check-workflow-concurrency.sh
Transaction Science 4ec33b90e6
All checks were successful
standards workspaces build + test / arl-rs (pull_request) Successful in 1m7s
standards workspaces build + test / eoc-rs (pull_request) Successful in 1m58s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m28s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 1m12s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 1m12s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m17s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m13s
standards workspaces build + test / sense-rs (pull_request) Successful in 1m10s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 3m45s
workflow hygiene / every workflow supersedes its own queue (pull_request) Successful in 3s
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 2m29s
standards workspaces build + test / aac-rs (pull_request) Successful in 1m30s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 55s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 37s
standards workspaces build + test / map-rs (pull_request) Successful in 36s
standards workspaces build + test / mesh-rs (pull_request) Successful in 31s
standards workspaces build + test / openpay (pull_request) Successful in 1m46s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 3m52s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 5m44s
ci: guard the concurrency groups, and stop the dev Mac serving 13 of 21 contexts
Two things I argued myself out of doing in #161 and should not have.

## The guard

#161 added a concurrency group to all 15 workflows and nothing stopped the
sixteenth from omitting one — which reintroduces the failure for the whole
repo, invisibly: the workflow still passes, it just queues forever under load.

`scripts/check-workflow-concurrency.sh` requires a top-level `concurrency:`
block whose group varies by `github.ref`. The second condition matters as much
as the first: a fixed group serialises every branch against every other, which
is worse than no group at all.

My reason for skipping it was that a guard "would need its own CI job on the
runner this change exists to unblock". That was wrong on the facts. The guard
runs on `linux` — jetson-hub — not the dev Mac, so it costs nothing I was
trying to protect, and it needs no toolchain.

It also has a self-test, because this repo has a history of gates that passed
while guarding nothing. `check-workflow-concurrency-selftest.sh` breaks the
property both ways against a scratch copy and asserts the check rejects each.

That self-test began as an inline Python heredoc in a `run:` block, and its
body sat at column zero, which made the workflow file **invalid YAML**. An
unparseable workflow means no CI at all — the exact failure the change exists
to prevent, reintroduced by the fix for it. Caught by parsing every workflow
with `yaml.safe_load` before committing; it is a script now.

## The rebalance

#161 named this and left it: the dev Mac hosts **both** the `macos` runner and
the `linux-arm64` colima VM, so it served **13 of 21 contexts** while jetson-hub
sat idle. That is why a PR's `linux` contexts returned in minutes and its macOS
ones could wait indefinitely.

Four workspaces move to `linux` on evidence rather than preference. `arl-rs`,
`sense-rs`, `joulehook-rs` and `joule-ui-rs` each have **zero**
`target_os = "macos"` cfgs, **zero** Apple dependencies, and **zero** Apple
crates in their `Cargo.lock` — so running them on macOS asserted nothing the
repo relies on.

`jouledesk-rs` stays on `macos`, because it does need it: `libwebrtc` and 19
Apple crates in its lockfile. The `linux-arm64` placements stay as well — arm64
is the deployment target, and `jouleclaw-rs` requires `+fp16`.

Labels go from 5 `linux` / 7 `linux-arm64` / 5 `macos` to **9 / 7 / 1**, plus
the dedicated `macOS energy backends` job. The dev Mac drops from 13 contexts
to 9; jetson-hub rises from 5 to 9. macOS is still exercised, by the workspace
that actually depends on it and by the energy job whose whole purpose is the
platform-gated meters.

If one of the four does not build on x86_64, that is a finding rather than a
regression: it would mean a workspace only built on macOS without saying so.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-10-05 12:18:21 -04:00

67 lines
2.4 KiB
Shell
Executable file

#!/usr/bin/env bash
#
# check-workflow-concurrency.sh
#
# Every workflow must declare a concurrency group, so a push supersedes the run
# before it instead of queueing behind it.
#
# Why this is a gate and not a convention. None of the 15 workflows declared
# `concurrency:` until 2026-10-05. A session pushing four versions of a branch
# therefore queued four complete sets of runs, all of which had to drain: one
# PR's 21 contexts settled none in 70 minutes behind a backlog of 25 runs that
# grew faster than it cleared. The repo's CI became unusable for every other
# session, and two PRs were merged on locally-executed equivalents instead of
# on the gate. A gate that cannot run is not a gate.
#
# One omitted `concurrency:` block reintroduces that for the whole repo, and it
# is invisible: the workflow still passes, it just queues forever under load.
# So it is checked rather than remembered.
#
# Runs in seconds with no toolchain, as a step inside an existing job — adding
# a job of its own would spend runner capacity to protect runner capacity.
set -euo pipefail
cd "$(dirname "$0")/.."
fail=0
count=0
for f in .github/workflows/*.yml; do
count=$((count + 1))
name=$(basename "$f")
# A top-level key, so match at column zero: a `concurrency:` nested under a
# job is a different (and legal) thing that does not bound the workflow.
if ! grep -qE '^concurrency:' "$f"; then
echo "::error file=$f::$name declares no top-level \`concurrency:\` block."
echo " Add:"
echo " concurrency:"
echo " group: \${{ github.workflow }}-\${{ github.ref }}"
echo " cancel-in-progress: true"
fail=1
continue
fi
# The group must vary by ref. A fixed group serialises every branch against
# every other, which is worse than no group at all: one busy branch then
# blocks the repo instead of only itself.
if ! grep -A3 -E '^concurrency:' "$f" | grep -qE 'group:.*github\.ref'; then
echo "::error file=$f::$name has a concurrency group that does not vary by \`github.ref\`."
echo " A fixed group serialises unrelated branches against each other."
fail=1
fi
done
if [ "$count" -eq 0 ]; then
echo "::error::no workflows found — this check looked in the wrong place."
exit 1
fi
if [ "$fail" -ne 0 ]; then
echo
echo "checked $count workflow(s): at least one would queue instead of superseding."
exit 1
fi
echo "workflow concurrency: $count workflow(s), each grouped per ref."