open-standards/scripts/check-workflow-concurrency-selftest.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

61 lines
2.3 KiB
Shell
Executable file

#!/usr/bin/env bash
#
# check-workflow-concurrency-selftest.sh
#
# Proves `check-workflow-concurrency.sh` can fail. A check that cannot fail is
# decoration, and this repo has a documented history of gates that passed
# because nothing they guarded was ever read.
#
# Both ways the property can break are exercised against a scratch copy, never
# the working tree:
#
# 1. a workflow with no top-level `concurrency:` block;
# 2. a group that does not vary by `github.ref` — which would serialise every
# branch against every other, worse than having no group at all.
#
# In a script rather than inline in the workflow on purpose. The first version
# embedded a Python heredoc in a `run:` block, and the heredoc body sat at
# column zero, which made the workflow file invalid YAML. An unparseable
# workflow means no CI at all — the exact failure this change exists to
# prevent, reintroduced by the fix for it.
set -euo pipefail
cd "$(dirname "$0")/.."
root=$(pwd)
target=.github/workflows/workflow-hygiene.yml
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
cp -R .github scripts "$tmp/"
# ── 1. remove the block entirely ────────────────────────────────────────────
python3 - "$tmp/$target" <<'PY'
import re, sys
p = sys.argv[1]
s = open(p).read()
out = re.sub(r"^concurrency:\n( .*\n)+", "", s, count=1, flags=re.M)
assert out != s, "fixture unchanged: there was no concurrency block to remove"
open(p, "w").write(out)
PY
if ( cd "$tmp" && ./scripts/check-workflow-concurrency.sh ) >/dev/null 2>&1; then
echo "::error::the check passed a workflow with no concurrency block"
exit 1
fi
# ── 2. a group that does not vary by ref ────────────────────────────────────
cp -f "$root/$target" "$tmp/$target"
python3 - "$tmp/$target" <<'PY'
import re, sys
p = sys.argv[1]
s = open(p).read()
out = re.sub(r"^( group:).*$", r"\1 fixed-for-the-whole-repo", s, count=1, flags=re.M)
assert out != s, "fixture unchanged: there was no group line to rewrite"
open(p, "w").write(out)
PY
if ( cd "$tmp" && ./scripts/check-workflow-concurrency.sh ) >/dev/null 2>&1; then
echo "::error::the check passed a group that does not vary by ref"
exit 1
fi
echo "self-test: the check rejects both a missing block and a fixed group"