diff --git a/.crumb b/.crumb index 14551fc..ee6194d 100644 --- a/.crumb +++ b/.crumb @@ -67,8 +67,8 @@ "purpose": "Directory m3. Purpose not yet described by a human." }, { - "digest": "5df4d90d339a694ddd9c6a08bcaa556bcddf1d8e76336ebaf113bbaf71dd010b", - "last_commit": "454a9d3", + "digest": "df3235ec544587726f3dd0aedb376be35259e9450d6faf104e1d4b784ead4aa6", + "last_commit": "2ac7940", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -85,15 +85,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:95b8a876467dd97ba4a5da8e52e0af3c24a57bfabc5ea1ed7287f0d7d59016a5", - "compiled_at": "2026-10-18T04:43:22Z", + "children_root": "sha256:f4b3aa43e2dab0e9664bc72203ec7fab7ea0d14b8ac2a46b893b698f3e2f82d6", + "compiled_at": "2026-10-18T12:52:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:aa2c372b86300a8d3b9c6966e7017b7d31494578e1fb63fcc1e713b895ba8e7d", + "digest": "sha256:0913c2aa05e2a1115edf98e2549a6c1904e65888687040b089f04bcccb517b47", "evidence_files": 81, "evidence_root": "sha256:0a0459a4517679721bb2817540dd06995500a1c1ede079bc4665d9da5c39183d", - "files": 284, - "generated_at_commit": "2043924224b9ecffd79de2c37b2fe7a3a5396e0c", - "source_tree": "sha256:e7e88bad48eb6c9da461c8fbc79440d15b3c331cfdef961e15281bf7d5b3b956" + "files": 287, + "generated_at_commit": "2ac79400f931d23e6f5ed5caea5a383ab4457ca9", + "source_tree": "sha256:7afbdce9240bfbb548a12a604a8a3b00c80b6edde322104022459db1caa82342" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/host-gates.yml b/.github/workflows/host-gates.yml index 914aad9..1518448 100644 --- a/.github/workflows/host-gates.yml +++ b/.github/workflows/host-gates.yml @@ -15,6 +15,8 @@ name: Host gates # receipt reproduced byte for byte; oracle gate compares against omega main # gate34-writer tests/test_forge_gates_receipt.sh Gate 3/4 receipt writer (no GPU), # digests cross-checked with omega tools/json_canon.c +# gb10-lock tests/test_gb10_lock.sh GPU-lock helper: a gate under the judge never +# waits on its own parent (scratch lock file, no GPU) # forge-aegis tests/run_forge_aegis_host_gates.sh AEGIS verifier binds a result to its # request; submit-side refusals before any NVRM call (no GPU) # m2 run_m2_gates.sh M2 PHYSICS_BOOT, 15 gates (QEMU) @@ -51,6 +53,8 @@ jobs: cmd: tests/run_forge_form_gates.sh - gate: gate34-writer cmd: tests/test_forge_gates_receipt.sh "$GITHUB_WORKSPACE/omega" + - gate: gb10-lock + cmd: tests/test_gb10_lock.sh - gate: forge-aegis cmd: tests/run_forge_aegis_host_gates.sh - gate: m2 diff --git a/README.md b/README.md index 8ad5bb9..fd35732 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ tests/test_forge_gates_receipt.sh # Gate 3/4 receipt writer, no GPU (needs jq m3/tests/run_m3_gates.sh # M3 PHYSICS_EFFECTS, 19 gates in QEMU ``` -`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`, `tests/run_submission_visibility_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run. +`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`, `tests/run_submission_visibility_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run. They take the GPU lock (`/tmp/aien-gb10.lock`) through `tests/gb10_lock.sh`, which skips it when a parent process, such as the Spark judge running the gate, already holds it: a gate that locked again would wait on its own parent forever (2026-10-18). `tests/test_gb10_lock.sh` (gate `PHYSICS-GB10-LOCK`, no GPU) checks this. Since 2026-10-16 the DGX Spark is the only test judge for pull requests (aien-architecture ADR 0033). Its gates are the manifests in `tests/gates/`, and the ones that need the real chip run there. [docs/PIPELINE.md](docs/PIPELINE.md) explains how a pull request is tested and how the `ready-to-merge` label leads to a merge. The verdict of record is the commit status "AIEN Verification (Spark)". diff --git a/tests/.crumb b/tests/.crumb index 5f5be13..d2741ec 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -20,14 +20,14 @@ } ], "children_root": "sha256:be29e4df8a1e9e426d7723fccf6e09f23eb6fb07a6b21490cd019c75d6fed6cd", - "compiled_at": "2026-10-14T14:17:04Z", + "compiled_at": "2026-10-18T12:52:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:5df4d90d339a694ddd9c6a08bcaa556bcddf1d8e76336ebaf113bbaf71dd010b", + "digest": "sha256:df3235ec544587726f3dd0aedb376be35259e9450d6faf104e1d4b784ead4aa6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 33, - "generated_at_commit": "ff2c62e820a64a90fd58be0db031a0d2e53fa308", - "source_tree": "sha256:08c3b002086d385ccecce3aa2d9695ec9c136bcdb299b9a4fec6ec7697cb3a11" + "files": 36, + "generated_at_commit": "2ac79400f931d23e6f5ed5caea5a383ab4457ca9", + "source_tree": "sha256:02761b793cd1eaabe8931c94ba24efbb3fe4275d40de4d47df0bc40befcf2b1f" }, "owner_lane": "", "provenance": { diff --git a/tests/gates/physics-gb10-lock.gate b/tests/gates/physics-gb10-lock.gate new file mode 100644 index 0000000..d34e50c --- /dev/null +++ b/tests/gates/physics-gb10-lock.gate @@ -0,0 +1,20 @@ +# tests/gates/physics-gb10-lock.gate +# Mirrors hosted: host-gates.yml matrix gb10-lock 'tests/test_gb10_lock.sh' (scratch lock file, no GPU) +gate: PHYSICS-GB10-LOCK +manifest_version: 2 +owner: physics +requires: + - host +inputs: + - tests/gb10_lock.sh + - tests/test_gb10_lock.sh + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["gb10-lock"] +expects: + exit: 0 + verdict: PASS +timeout: 2m +exactness: EXACT +cache_scope: machine diff --git a/tests/gates/run.sh b/tests/gates/run.sh index cd88661..bc0ce79 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -59,6 +59,7 @@ case "$step" in analog-sim) need_sibling omega; tests/run_forge_analog_sim_gates.sh ;; form0) need_sibling omega; tests/run_forge_form_gates.sh ;; gate34-writer) need_sibling omega; tests/test_forge_gates_receipt.sh "$OMEGA_DIR" ;; + gb10-lock) tests/test_gb10_lock.sh ;; m2) ./run_m2_gates.sh ;; m3) need_sibling aien-architecture diff --git a/tests/gb10_lock.sh b/tests/gb10_lock.sh new file mode 100644 index 0000000..25e0993 --- /dev/null +++ b/tests/gb10_lock.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# tests/gb10_lock.sh -- the GB10 lock for GPU gate scripts (sourced, not run). +# +# gb10_lock_acquire exclusive flock(2) on $GB10_LOCK through fd 9, waiting for any other holder; +# or nothing, when a process above this shell already holds it +# gb10_lock_release closes fd 9 (the kernel drops the lock with the last copy of the descriptor) +# +# Why the parent check: the Spark judge (aien-test worker) takes /tmp/aien-gb10.lock for a whole gb10 +# job and then runs the gate in its sandbox. The gate opening the file again gets a separate open file +# description, and man 2 flock: "An attempt to lock the file using one of these file descriptors may be +# denied by a lock that the calling process has already placed via another file descriptor." The gate +# then waits on its own parent forever (2026-10-18: physics #64, forge-gate34, 83 minutes, every chip +# job on the Spark queued behind it). A holder that is not an ancestor is waited for, as before. +# +# The file is opened read-only when it exists: fs.protected_regular=2 refuses an O_CREAT open of another +# user's file in sticky /tmp, and flock(2) locks whatever the open mode (sc#627). +# The gb10 sandbox profile shares the PID namespace and /proc (aien-run-exec: unshare -m only), so the +# ancestors and /proc/locks are visible from inside. Shell + coreutils + awk. No Python. + +GB10_LOCK=${GB10_LOCK:-/tmp/aien-gb10.lock} + +# gb10_lock_held_by_ancestor FILE: 0 when this shell or one of its ancestors holds a flock on FILE. +gb10_lock_held_by_ancestor() { + local id holders pid p + # /proc/locks names the file as MAJOR:MINOR:INODE (major and minor in hex); waiters are "N: -> FLOCK ...". + id=$(stat -L -c '%Hd %Ld %i' "$1" 2>/dev/null) || return 1 + id=$(printf '%02x:%02x:%s' $id) + holders=$(awk -v id="$id" '$2 == "FLOCK" && $6 == id { print $5 }' /proc/locks 2>/dev/null) + [ -n "$holders" ] || return 1 + p=$$ + while [ -n "$p" ] && [ "$p" -gt 0 ]; do + for pid in $holders; do [ "$p" = "$pid" ] && return 0; done + [ "$p" -eq 1 ] && break + p=$(awk '/^PPid:/ { print $2 }' "/proc/$p/status" 2>/dev/null) + done + return 1 +} + +gb10_lock_acquire() { + if gb10_lock_held_by_ancestor "$GB10_LOCK"; then + echo "[gb10-lock] $GB10_LOCK is held by a parent process (the judge's gb10 job): not taking it again" + return 0 + fi + if [ -e "$GB10_LOCK" ]; then exec 9< "$GB10_LOCK"; else exec 9>> "$GB10_LOCK"; fi \ + || { echo "cannot open $GB10_LOCK" >&2; return 1; } + flock -x 9 || { echo "cannot take $GB10_LOCK" >&2; return 1; } +} + +gb10_lock_release() { exec 9>&-; } diff --git a/tests/run_forge_gates.sh b/tests/run_forge_gates.sh index 371e563..88e51cf 100755 --- a/tests/run_forge_gates.sh +++ b/tests/run_forge_gates.sh @@ -11,7 +11,8 @@ # (created exclusively, mode 0444) plus blobs/.log # # Needs the GB10. The whole build + test section runs under one exclusive -# lock on /tmp/aien-gb10.lock (fd 9); nothing inside takes the lock again. +# lock on /tmp/aien-gb10.lock (fd 9; tests/gb10_lock.sh skips it when a parent such as +# the judge already holds it); nothing inside takes the lock again. # # Receipt mode checks: both candidates are explicit full 40-hex SHAs equal to # HEAD of a clean tree (this physics tree and --omega-dir), before the run @@ -38,6 +39,7 @@ FORGE_ROOT=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) FORGE_LOCK=/tmp/aien-gb10.lock +. "$FORGE_ROOT/tests/gb10_lock.sh" FORGE_ERR= FORGE_SCHEMA=AIEN_M19R_FORGE_GATES_V1 FORGE_GATE=M19R_GATES_3_4_FORGE @@ -289,14 +291,14 @@ forge_main() { echo "Host: $(uname -n) ($(uname -m))" echo "Run: $run_id" - exec 9> "$FORGE_LOCK" || { echo "cannot open $FORGE_LOCK" >&2; exit 1; } - flock -x 9 || { echo "cannot take $FORGE_LOCK" >&2; exit 1; } + # fd 9, or nothing when a parent (the judge's gb10 job) already holds it: tests/gb10_lock.sh + GB10_LOCK=$FORGE_LOCK gb10_lock_acquire || exit 1 ts=$(date -u +%Y-%m-%dT%H:%M:%S.%6NZ) forge_run_section "$rd" 2>&1 | tee "$log" # hash the binaries that ran before another run can rebuild them g3sha=$( [ -f tests/test_forge_seam ] && forge_sha_file tests/test_forge_seam) g4sha=$( [ -f tests/test_forge_hwid ] && forge_sha_file tests/test_forge_hwid) - exec 9>&- + gb10_lock_release g3=$(cat "$rd/gate3.rc"); g4=$(cat "$rd/gate4.rc") echo -e "\n=== M19R FORGE Gates Complete (gate3 exit $g3, gate4 exit $g4) ===" rc=0 diff --git a/tests/run_nvrm_lifecycle_gates.sh b/tests/run_nvrm_lifecycle_gates.sh index 8be08ec..216f107 100755 --- a/tests/run_nvrm_lifecycle_gates.sh +++ b/tests/run_nvrm_lifecycle_gates.sh @@ -4,7 +4,7 @@ set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P) -LOCK_FILE=/tmp/aien-gb10.lock +. "$SCRIPT_DIR/gb10_lock.sh" cd "$REPO_ROOT" @@ -23,7 +23,9 @@ gcc -O2 -Wall -Wextra -Werror \ echo " lifecycle_gates built cleanly." -echo -e "\n[*] Running lifecycle_gates under GPU lock ($LOCK_FILE)..." -flock "$LOCK_FILE" ./nvrm/lifecycle_gates +echo -e "\n[*] Running lifecycle_gates under GPU lock ($GB10_LOCK)..." +gb10_lock_acquire +./nvrm/lifecycle_gates +gb10_lock_release echo -e "\n=== M19R NVRM Lifecycle Gates: done ===" diff --git a/tests/run_submission_visibility_gates.sh b/tests/run_submission_visibility_gates.sh index 6a0b8b4..74a4f9c 100755 --- a/tests/run_submission_visibility_gates.sh +++ b/tests/run_submission_visibility_gates.sh @@ -4,7 +4,7 @@ set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P) -LOCK_FILE=/tmp/aien-gb10.lock +. "$SCRIPT_DIR/gb10_lock.sh" cd "$REPO_ROOT" @@ -28,7 +28,9 @@ if [ ! -e /dev/nvidia0 ]; then exit 0 fi -echo -e "\n[*] Running submission_visibility_gates under GPU lock ($LOCK_FILE)..." -flock "$LOCK_FILE" ./nvrm/submission_visibility_gates +echo -e "\n[*] Running submission_visibility_gates under GPU lock ($GB10_LOCK)..." +gb10_lock_acquire +./nvrm/submission_visibility_gates +gb10_lock_release echo -e "\n=== GB10 Submission Visibility Gates: done ===" diff --git a/tests/test_gb10_lock.sh b/tests/test_gb10_lock.sh new file mode 100755 index 0000000..1bac9f1 --- /dev/null +++ b/tests/test_gb10_lock.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# tests/test_gb10_lock.sh -- host-only tests (no GPU) for tests/gb10_lock.sh, on a scratch lock file. +# +# red a fresh descriptor under a parent that holds the lock is refused (the 2026-10-18 judge deadlock) +# green gb10_lock_acquire under that parent returns at once and says so +# wait a holder that is not an ancestor is waited for, then the lock is ours +# own with no holder the lock is taken through fd 9 and gb10_lock_release drops it +# new a missing lock file is created +# A broken helper would hang, so every case that could block runs bounded in its own process group (scratch file, no +# chip work). Exit 0 only when every case passes. Shell + coreutils + util-linux flock. No Python. +set -u +HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) +LIB=$HERE/gb10_lock.sh +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +L=$work/gb10.lock +: > "$L" +pass=0 fail=0 +check() { if [ "$1" = 0 ]; then pass=$((pass + 1)); echo "[PASS] $2"; else fail=$((fail + 1)); echo "[FAIL] $2"; fi; } +# held_elsewhere FILE: 0 when another process holds FILE (a non-blocking try from a fresh process fails) +held_elsewhere() { ! flock -n "$1" true; } +# run_bounded TENTHS OUT CMD...: CMD in its own process group (setsid), output to OUT; past TENTHS tenths of a +# second the whole group is killed and the status is 124 (a broken helper leaves a child waiting on a lock it +# inherited, so killing only the top process would not end the case) +run_bounded() { + local t=$1 o=$2 p i=0; shift 2 + setsid "$@" > "$o" 2>&1 & + p=$! + while kill -0 "$p" 2>/dev/null; do + if [ "$i" -ge "$t" ]; then kill -- -"$p" 2>/dev/null; wait "$p" 2>/dev/null; return 124; fi + sleep 0.1; i=$((i + 1)) + done + wait "$p" +} + +# red: the old pattern (open the file again, flock it) under a holding parent cannot get the lock +flock -x "$L" bash -c 'exec 9< "$1"; flock -w 2 -x 9' _ "$L" +check $([ $? -ne 0 ] && echo 0 || echo 1) "red: a second descriptor under the holding parent is refused (the deadlock)" + +# green: the helper under the same parent +out=$work/green.out +run_bounded 50 "$out" flock -x "$L" bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire && echo ACQUIRED' _ "$LIB" "$L"; rc=$? +check $([ $rc = 0 ] && grep -q 'held by a parent process' "$out" && grep -q ACQUIRED "$out" && echo 0 || echo 1) "green: under a holding parent gb10_lock_acquire returns at once (rc $rc)" + +# a deeper ancestor counts too (holder -> bash -> bash -> helper) +run_bounded 50 "$out" flock -x "$L" bash -c 'bash -c ". \"\$1\"; GB10_LOCK=\$2; gb10_lock_acquire" _ "$1" "$2"' _ "$LIB" "$L"; rc=$? +check $([ $rc = 0 ] && grep -q 'held by a parent process' "$out" && echo 0 || echo 1) "green: a grandparent holder is found (rc $rc)" + +# wait: a sibling holds the lock for 1.5 s; the helper waits, then holds it itself +setsid flock -x "$L" sleep 1.5 & +h=$! +i=0; while ! held_elsewhere "$L" && [ $i -lt 50 ]; do sleep 0.1; i=$((i + 1)); done +t0=$(date +%s%N) +run_bounded 50 "$out" bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire || exit 1; date +%s%N > "$3"; sleep 0.5' _ "$LIB" "$L" "$work/t1"; rc=$? +kill -- -"$h" 2>/dev/null; wait "$h" 2>/dev/null +t1=$(cat "$work/t1" 2>/dev/null || echo "$t0") +waited_ms=$(( (t1 - t0) / 1000000 )) +check $([ $rc = 0 ] && [ $waited_ms -ge 1000 ] && ! grep -q 'held by a parent' "$out" && echo 0 || echo 1) "wait: a non-ancestor holder is waited for (${waited_ms} ms, rc $rc)" + +# own: no holder; the lock is ours while fd 9 is open, and released after +. "$LIB" +GB10_LOCK=$L +gb10_lock_acquire; rc=$? +held_elsewhere "$L"; h1=$? +gb10_lock_release +held_elsewhere "$L"; h2=$? +check $([ $rc = 0 ] && [ $h1 = 0 ] && [ $h2 != 0 ] && echo 0 || echo 1) "own: taken through fd 9 (held $h1), dropped by gb10_lock_release (held $h2)" + +# new: a missing file is created and locked +GB10_LOCK=$work/new.lock +gb10_lock_acquire; rc=$? +check $([ $rc = 0 ] && [ -e "$work/new.lock" ] && held_elsewhere "$work/new.lock" && echo 0 || echo 1) "new: a missing lock file is created and locked" +gb10_lock_release + +echo "gb10_lock: $pass passed, $fail failed: $([ $fail = 0 ] && echo PASS || echo FAIL)" +[ $fail = 0 ]