carlos / platform Public

ci: shard edge, activator, grouproll; 15m go test timeout; cpu report

The gate had crept from 112 s (2026-10-25) to 430-500 s. edge (380 s),
activator (318 s) and grouproll (180 s) ran as single processes inside
the "rest" job, so the gate could not finish before edge did.

- TEST_SPLIT now also deals edge 4, activator 4 and grouproll 2 ways,
  heaviest packages first so their shards start earliest.
- go test -timeout 15m (was 30m, equal to CI's step limit). main
  6c2c167a timed out at 30m with an empty log; now a hang fails its own
  job with the goroutine dump. TestCutoverWitnessControlsAreTagged reads
  the cutover-witness line and follows it.
- Each job prints its start offset, and the gate ends with the CPU its
  jobs used against wall clock, so a slow run says whether it was short
  of cores or waiting.
- GATE_WEIGHTS=1 runs the shards with -json and prints a fresh
  test-weights.tsv measured on the machine that ran it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 519c947a3cf839c1e0e99df1a211935b836291c5 parent 6c2c167
4 files changed, +83 −10
  • .amadan/test-gate.sh +73 −6
  • .amadan/test-weights.sh +3 −1
  • AGENTS.md +6 −2
  • internal/console/apirunsbox_test.go +1 −1
diff --git a/.amadan/test-gate.sh b/.amadan/test-gate.sh
index 2906f7e11..32c40df28 100755
--- a/.amadan/test-gate.sh
+++ b/.amadan/test-gate.sh
@@ -31,10 +31,36 @@
# Shards are separate processes, so tests that leaned on running in the
# same process as some other test (package state one test leaves for the
# next) can surface here. That is a bug in the test, not in the split.
+#
+# THE TIMEOUT. Every go test here runs with -timeout 15m, half CI's
+# 30-minute step limit. A hung test then fails its own job with Go's
+# goroutine dump (go test kills the binary a minute after that if it
+# still will not stop) and the gate prints it. At -timeout 30m the step
+# limit fired first and the log was empty (main 6c2c167a, 2026-11-10).
+#
+# WEIGHTS. GATE_WEIGHTS=1 runs the split packages' shards with -json
+# and, instead of their logs, prints a fresh test-weights.tsv measured on
+# whatever machine ran it. Set it in .amadan/ci.d/10-gate for one push to
+# measure on CI itself, copy the printed file in, and unset it again. The
+# shards' own logs are not printed in that mode, so it is a measurement
+# run, not a gate.
+#
+# The last thing the gate prints is how much CPU its jobs used against
+# how long it took, so a slow run says whether it was short of cores.
set -eu
-: "${TEST_SPLIT=./internal/console=8 ./internal/host=4 .=5}"
+# Heaviest first: discovery compiles each package's tests in turn, so the
+# packages that dominate the wall clock get their shards started earliest.
+: "${TEST_SPLIT=./internal/console=8 ./internal/edge=4 ./internal/activator=4 ./internal/host=4 .=5 ./internal/grouproll=2}"
weights=$(pwd)/.amadan/test-weights.tsv
+gate_t0=$(date +%s)
+# Busy and total jiffies for the whole machine, from /proc/stat's cpu
+# line (user nice system idle iowait irq softirq steal), or nothing where
+# there is no /proc/stat (a maintainer's Mac).
+machine_cpu() {
+ awk '$1 == "cpu" { print $2 + $3 + $4 + $7 + $8 + $9, $2 + $3 + $4 + $5 + $6 + $7 + $8 + $9; exit }' /proc/stat 2>/dev/null || true
+}
+machine_t0=$(machine_cpu)
# A shard count that is not a whole number of at least 1 would take a
# package out of the ordinary run and then launch none of its shards: a
@@ -117,6 +143,7 @@ start() {
(
set +e
t0=$(date +%s)
+ echo $((t0 - gate_t0)) >"$out/$start_name.at"
"$@" >"$out/$start_name.log" 2>&1
echo $? >"$out/$start_name.rc"
echo $(($(date +%s) - t0)) >"$out/$start_name.secs"
@@ -166,13 +193,19 @@ done
# With no packages left, go test would test the current directory instead.
if [ -n "$rest" ]; then
# shellcheck disable=SC2086 # one word per package, on purpose
- start rest go test -count=1 -timeout 30m $rest
+ start rest go test -count=1 -timeout 15m $rest
fi
# The fleet-run cutover witnesses (rootfs apps Plan 6 Task 16): the real CLI
# against a fleet run queued across a lifetimes cutover. They and the console
# controls they need are built only with this tag, which no other job and no
# production build sets.
-start cutover-witness go test -count=1 -timeout 30m -tags carlos_cutover_witness -run '^TestQueuedFleetRunAtACutoverExpires' .
+start cutover-witness go test -count=1 -timeout 15m -tags carlos_cutover_witness -run '^TestQueuedFleetRunAtACutoverExpires' .
+
+# The split shards' -json, in weights mode only (see WEIGHTS above).
+shard_json=""
+if [ "${GATE_WEIGHTS:-}" = 1 ]; then
+ shard_json=-json
+fi
for spec in $TEST_SPLIT; do
dir=${spec%=*}
@@ -222,7 +255,7 @@ for spec in $TEST_SPLIT; do
while [ "$i" -lt "$shards" ]; do
pattern=$(awk -v i="$i" -F '\t' '$1 == i { printf "%s%s", sep, $2; sep = "|" }' "$out/deal-$tag")
if [ -n "$pattern" ]; then
- start "$tag@$i" go test -count=1 -timeout 30m -run "^($pattern)\$" "$dir"
+ start "$tag@$i" go test $shard_json -count=1 -timeout 15m -run "^($pattern)\$" "$dir"
launched=$((launched + $(awk -v i="$i" -F '\t' '$1 == i' "$out/deal-$tag" | wc -l)))
fi
i=$((i + 1))
@@ -239,8 +272,11 @@ failed=""
for name in $names; do
# A job with no status file was killed before it could write one.
rc=$(cat "$out/$name.rc" 2>/dev/null || echo 1)
- echo "=== $name ($(cat "$out/$name.secs" 2>/dev/null || echo '?') s)"
- cat "$out/$name.log" 2>/dev/null || true
+ echo "=== $name ($(cat "$out/$name.secs" 2>/dev/null || echo '?') s, from +$(cat "$out/$name.at" 2>/dev/null || echo '?') s)"
+ case $shard_json:$name in
+ -json:*@*) grep '"Action":"fail"' "$out/$name.log" 2>/dev/null | head -20 || true ;;
+ *) cat "$out/$name.log" 2>/dev/null || true ;;
+ esac
case $name in
*@*)
if grep -q 'no tests to run' "$out/$name.log"; then
@@ -252,6 +288,37 @@ for name in $names; do
[ "$rc" -eq 0 ] || failed="$failed $name"
done
+# CPU used against wall clock. The shell's `times` covers every job it
+# has waited for, and each job waited for its go test and the test
+# binaries under it, so this is the whole gate's CPU. Busy cores well
+# under the machine's count mean the run was waiting, not computing; the
+# machine's own figure includes whatever else was running on it.
+wall=$(($(date +%s) - gate_t0))
+cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo '?')
+# `times` writes to a file, not a pipe: in a pipeline it would run in a
+# subshell, which has waited for nothing.
+times >"$out/times"
+awk -v wall="$wall" -v cores="$cores" -v m0="$machine_t0" -v m1="$(machine_cpu)" '
+ NR == 2 {
+ gsub(/[ms]/, " ")
+ cpu = $1 * 60 + $2 + $3 * 60 + $4
+ line = sprintf("=== cpu: the gate used %d cpu-seconds in %d s, about %.1f of %s cores", cpu, wall, (wall > 0 ? cpu / wall : 0), cores)
+ split(m0, a, " "); split(m1, b, " ")
+ if (b[2] > a[2]) line = line sprintf("; the machine as a whole was %d%% busy", 100 * (b[1] - a[1]) / (b[2] - a[2]))
+ print line
+ }
+' "$out/times"
+
+if [ -n "$shard_json" ]; then
+ # shellcheck disable=SC2046 # one file per split shard, on purpose
+ .amadan/test-weights.sh $(for name in $names; do
+ case $name in *@*) echo "$out/$name.log" ;; esac
+ done)
+ echo "=== test-weights.tsv measured on this run"
+ cat .amadan/test-weights.tsv
+ echo "=== end test-weights.tsv"
+fi
+
if [ -n "$failed" ]; then
# The logs above can run to megabytes, and CI keeps only the tail, so
# a failing test's name used to scroll out of sight (main bcae2a72,
diff --git a/.amadan/test-weights.sh b/.amadan/test-weights.sh
index 6efc4c14a..3b1fd5c2b 100755
--- a/.amadan/test-weights.sh
+++ b/.amadan/test-weights.sh
@@ -7,7 +7,9 @@
# .amadan/test-weights.sh console.json root.json
#
# Measure on a quiet machine with the temp root on tmpfs, as CI has it, or
-# the fsync-heavy tests weigh several times what they do there.
+# the fsync-heavy tests weigh several times what they do there. Simpler
+# still, measure on CI: GATE_WEIGHTS=1 makes .amadan/test-gate.sh run this
+# over its shards and print the result.
#
# Only the packages in the given files are rewritten; rows for other
# packages are kept. A top-level test of a quarter-second or more gets a
diff --git a/AGENTS.md b/AGENTS.md
index a34bccdde..8e13668c8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -260,8 +260,12 @@ anything.
(`.amadan/test-gate.sh`, `TEST_SPLIT`). Each shard is its own process,
so a test must not depend on another top-level test having run first
in the same process. Shards are dealt by `.amadan/test-weights.tsv`;
- refresh it when the gate's shard times in the CI log drift far apart
- (its header says how). A test missing from it still runs.
+ refresh it when the gate's shard times in the CI log drift far apart.
+ The easy way is one push with `GATE_WEIGHTS=1` set in
+ `.amadan/ci.d/10-gate`: the gate then prints a new file measured on CI
+ itself (`.amadan/test-gate.sh` header). A test missing from it still
+ runs. The gate's last line says how many cores it kept busy, which
+ tells you whether more shards would help.
- **CI is triggered by a push to amadan, not by GitHub.** Nothing on
GitHub runs a build. A branch that exists only on GitHub has been gated
by exactly nothing. Read a branch's verdict with
diff --git a/internal/console/apirunsbox_test.go b/internal/console/apirunsbox_test.go
index e85d8763d..52674eef5 100644
--- a/internal/console/apirunsbox_test.go
+++ b/internal/console/apirunsbox_test.go
@@ -830,7 +830,7 @@ func TestCutoverWitnessControlsAreTagged(t *testing.T) {
t.Fatal(err)
}
gate, err := os.ReadFile(filepath.Join(root, ".amadan", "test-gate.sh"))
- if err != nil || !bytes.Contains(gate, []byte("start cutover-witness go test -count=1 -timeout 30m -tags "+tag+" -run '^TestQueuedFleetRunAtACutoverExpires' .")) {
+ if err != nil || !bytes.Contains(gate, []byte("start cutover-witness go test -count=1 -timeout 15m -tags "+tag+" -run '^TestQueuedFleetRunAtACutoverExpires' .")) {
t.Fatalf("the gate has no cutover-witness job: %v", err)
}
}