diff --git a/lanes/av1stagegaps.report.md b/lanes/av1stagegaps.report.md new file mode 100644 index 00000000..09c13bf2 --- /dev/null +++ b/lanes/av1stagegaps.report.md @@ -0,0 +1,303 @@ +# lane-av1stagegaps — a staged server suite can no longer run with its preflight unverified + +Worktree `/home/user/.cache/wt/av1stagegaps`, branch `lane-av1stagegaps`, base +`edffad9e`. Scope: the staging recipe, not the decoder. + +## 1. Host C's checker failure, reproduced with stderr visible + +The driver log named no cause at all: + + === ORACLE RUNG CHECKER + rungs_exit=1 ok_count=0 + === SUITE + +`ok_count=0` is the tell: a checker that ran and failed prints its own `FAIL` +lines, so zero ok lines with zero detail means it never got as far as asserting +anything. The driver's `$(...)` capture also dropped stderr, which is where the +reason is printed. + +Reproduction, on the host, from the staged tree, real paths, stderr visible: + + $ ssh user@host-d + $ cd /home/user/gates/wave3d && git log --oneline -1 + 48d8c21 staged + $ nice -n 19 bash scripts/check-aom-oracle-rungs.sh; echo "rungs_exit=$?" + no oracle source at /home/user/.cache/aom-oracle/src/av1/decoder/decodeframe.c + rungs_exit=1 + $ ls ~/.cache/aom-oracle/ + build + $ ls ~/.cache/aom-oracle/src + ls: cannot access '/home/user/.cache/aom-oracle/src': No such file or directory + $ git -C ~/.cache/aom-oracle/build rev-parse --show-toplevel + fatal: not a git repository ... + +**Named missing prerequisite:** the libaom **source tree** at +`$AOM_ORACLE_SRC` (default `~/.cache/aom-oracle/src`, a git checkout carrying +base ref `v3.13.3`). The host carries only `~/.cache/aom-oracle/build` — the +`aomdec`/`aomenc` **binaries** the suite itself needs. The checker derives +rungs from source and diffs them against pristine upstream files, so with no +source it asserts nothing. + +Not a failing rung, not a path typo, not an env problem: an absent checkout. Fix +on the host is either `git clone -b v3.13.3 aom ~/.cache/aom-oracle/src` or the +explicit waiver in §3. The suite's own binary dependency is unaffected, which is +why the run was still meaningful — but its **rung coverage was not verified +there**, and the log said nothing about that. + +## 2. The fix + +Three states must be distinguishable, and two of them must be fatal. + +### 2a. `scripts/check-aom-oracle-rungs.sh` — a distinct exit code for an absent prerequisite + +`diff -u` against main: + + +# EXIT CONTRACT (lane-av1stagegaps). ... + +# 0 GREEN every assertion below held. + +# 3 NOTRUN a PREREQUISITE is absent (no oracle source tree, or the base ref + +# is not in it). Nothing was asserted: this is NOT a pass and NOT a + +# defect. scripts/av1-suite-preflight.sh maps it to `not-run` and + +# BLOCKS the suite unless a waiver names the host. + +# 1 FAIL a derived file violates the rung contract, or the instrument + +# script errored / was not idempotent. + +die_prereq() { echo "PREREQ-ABSENT: $*" >&2; exit 3; } + ... + -[ -f "$DERIVED" ] || { echo "no oracle source at $DERIVED" >&2; exit 1; } + -[ -f "$RECONINTRA" ] || { echo "no oracle source at $RECONINTRA" >&2; exit 1; } + +[ -f "$DERIVED" ] || die_prereq "no oracle source at $DERIVED (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)" + +[ -f "$RECONINTRA" ] || die_prereq "no oracle source at $RECONINTRA (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)" + git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || { + - echo "base ref '$BASE' is not a commit in $SRC" >&2 + - exit 1 + + die_prereq "base ref '$BASE' is not a commit in $SRC" + +Plus one more prerequisite of the same class: `systemd-run --setenv=TMPDIR=…` +points at a per-suite dir, and if staging created the unit but not the dir, +`mktemp -d` fails with something that reads like a checker bug. Now: + + +# systemd-run's --setenv=TMPDIR points at a per-suite dir; if staging created + +# the unit but not the dir, mktemp fails with an error that reads like a + +# checker bug. It is the same class as a missing oracle tree: not asserted. + +probe="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX" 2>/dev/null)" || + + die_prereq "scratch dir ${TMPDIR:-$HOME/.cache/tmp} does not exist (staging must mkdir it)" + +rmdir "$probe" + +WORK="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX")" + +Existing `exit 1` paths are unchanged, so any caller that only checks non-zero +still sees a failure. `set -euo pipefail` is untouched. + +### 2b. `scripts/av1-suite-preflight.sh` (new) — the gate + +Runs both preflight pieces, prints every detail line of each (stdout and stderr +together, indented — the thing the old driver threw away), then one verdict: + + === PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=1) + ...verify-fixture-library output... + pin_audit_exit=0 state=GREEN + === ORACLE RUNG CHECKER + ok legacy u8 row loops left in the derived file 0 + ... + rungs_exit=0 ok_count=14 state=GREEN + === VERDICT + VERDICT=GREEN + +States and the resulting verdict: + +| pin_audit | rung_check | verdict | exit | +|---|---|---|---| +| GREEN | GREEN | GREEN | 0 | +| GREEN | NOT-RUN | WAIVED **iff** `SUITE_RUNG_WAIVER` is non-empty, else BLOCKED | 0 / 1 | +| GREEN | FAIL | BLOCKED | 1 | +| GREEN | ABSENT (no checker in the tree) | BLOCKED, **never waivable** | 1 | +| FAIL | any | BLOCKED | 1 | +| ABSENT | any | BLOCKED | 1 | + +NOT-RUN vs ABSENT is the load-bearing distinction: NOT-RUN is a provisioning fact +(the checker ran and said so) and can be waived with a recorded reason; ABSENT +is the host-A defect — a staging with no checker at all — and has no waiver path, +because `SUITE_RUNG_WAIVER` only ever applies to the NOT-RUN branch. An empty +`SUITE_RUNG_WAIVER=` (a real shape, from a unit's `Environment=`) counts as +absent, so it cannot accidentally authorise a run. + +### 2c. `scripts/av1-stage-suite.sh` (new) — a staging that cannot skip the gate + +Wraps staging and runs the gate under `set -e` **before** `systemd-run`, so a +blocked verdict means no unit is ever created: + + # 3. THE GATE. `set -e` is the whole mechanism: a non-zero verdict aborts this + # script before systemd-run is ever reached, so no unit exists and no suite + # runs. There is no path from a blocked verdict to `=== SUITE`. + set -e + echo "=== PIN-GATE PREFLIGHT + ORACLE RUNG CHECKER" + EC_REQUIRE_FIXTURES=${EC_REQUIRE_FIXTURES:-1} \ + EC_FIXTURE_SHAPE_STRICT=${EC_FIXTURE_SHAPE_STRICT:-1} \ + bash "$TREE/scripts/av1-suite-preflight.sh" --tree "$TREE" + set +e + echo "=== SUITE" + +It also carries the two staging defects the fleet actually hit, as refuses rather +than as prose: a tree that is not a git checkout, a **populated** index (bare +`git init` makes every pin look uncommitted — the wave-3c-b correction), and +both `lanes/*.expected.txt` dumps. + +## 3. Red-before / green-after + +### Red — the hand-written driver shape, on the real missing-oracle-source case + + $ cat /tmp/av1stage-demo/old-driver.sh + out=$(bash "$TREE/scripts/check-aom-oracle-rungs.sh" 2>/dev/null); rungs_exit=$? + ok_count=$(printf '%s\n' "$out" | grep -c '^ok ' || true) + echo "rungs_exit=$rungs_exit ok_count=$ok_count" + echo "=== SUITE" + echo "cargo test -p ec-av1 --lib <-- THIS RAN ANYWAY in the wave-3d staging" + $ AOM_ORACLE_SRC=/tmp/av1stage-demo/no-such-src bash /tmp/av1stage-demo/old-driver.sh + === ORACLE RUNG CHECKER + rungs_exit=3 ok_count=0 + === SUITE + cargo test -p ec-av1 --lib <-- THIS RAN ANYWAY in the wave-3d staging + old_driver_exit=0 + +Same staging, through the new driver: + + $ AOM_ORACLE_SRC=/tmp/av1stage-demo/no-such-src SUITE_PIN_CHECKER=$STUB \ + bash scripts/av1-stage-suite.sh --name redemo --tree /tmp/av1stage-demo/tree --dry-run + === PIN-GATE PREFLIGHT + ORACLE RUNG CHECKER + === PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=1) + ok a + pin_audit_exit=0 state=GREEN + === ORACLE RUNG CHECKER + PREREQ-ABSENT: no oracle source at /tmp/av1stage-demo/no-such-src/av1/decoder/decodeframe.c (provision it: git clone -b v3.13.3 --depth 1 aom at /tmp/av1stage-demo/no-such-src) + rungs_exit=3 ok_count=0 state=NOT-RUN + === VERDICT + VERDICT=BLOCKED + PREFLIGHT BLOCKED: pin_audit=GREEN rung_check=NOT-RUN. + A staging with a failed or missing check must NOT reach === SUITE. + rung_check=not-run (missing oracle source) is waivable only via + SUITE_RUNG_WAIVER=''; an absent checker never is. + gate_exit=1 + +`=== SUITE` never printed. Note the state is now readable from the log alone, +which is the actual fix to `rungs_exit=1 ok_count=0` with no detail. + +### Green — waived, on the real wave-3d tree + + $ AOM_ORACLE_SRC=/tmp/av1stage-demo/no-such-src \ + SUITE_RUNG_WAIVER="host host-d carries oracle binaries only; rung coverage verified on the build host" \ + EC_FIXTURES=/…/fixtures \ + bash scripts/av1-stage-suite.sh --name redemo3d --tree /tmp/av1stage-demo/wave3d --dry-run + … + verify-fixture-library: GREEN (299 rows) + pin_audit_exit=0 state=GREEN + === ORACLE RUNG CHECKER + PREREQ-ABSENT: no oracle source at /tmp/av1stage-demo/no-such-src/av1/decoder/decodeframe.c (…) + rungs_exit=3 ok_count=0 state=NOT-RUN + === VERDICT + VERDICT=WAIVED (rung_check=not-run waived: host host-d carries oracle binaries only; rung coverage verified on the build host) + === SUITE + dry-run: would start unit redemo3d-suite … + gate_exit=0 + +### Green — fully green, oracle source present + + $ EC_FIXTURES=/…/fixtures bash scripts/av1-stage-suite.sh --name redemo3d2 --tree … --dry-run + ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base v3.13.3) + rungs_exit=0 ok_count=14 state=GREEN + === VERDICT + VERDICT=GREEN + === SUITE + gate_exit=0 + +### The gate's own self-test (non-vacuous: red the checker, the gate must stop) + + $ bash scripts/av1-suite-preflight.sh --self-test; echo "selftest_exit=$?" + ok 1 an all-green staging is GREEN + ok 2 a FAILING rung checker blocks the suite + ok 3 not-run without a waiver blocks the suite + ok 4 not-run with a named waiver is WAIVED, reason recorded + ok 5 an empty waiver does not authorise a run + ok 6 a tree with NO rung checker is blocked even with a waiver + ok 7 a tree with NO pin audit is blocked even with a waiver + ok 8 a FAILING pin audit blocks the suite + selftest_exit=0 + +Two traps hit while writing it, both worth recording: + +- `set -o pipefail` makes `verdict | grep -q '^VERDICT=BLOCKED$'` return + verdict's own non-zero status even when grep matched, so every BLOCKED case + read as a self-test failure. Capture into a variable, then compare. +- The stub helper printed its `exit` code as the script body, so a "green" stub + ran `exit echo "…"`. Argument order, not logic. + +## 4. Per-host audit of the two running suites (read-only, `nice -n 19`) + +Suite test counts taken immediately before and after each audit block: unchanged +on both hosts, so nothing was disturbed. + +| host | tree | suite running | pin audit | pin self-test | rung checker | tree satisfies preflight? | +|---|---|---|---|---|---|---| +| C `host-d` | `~/gates/wave3d` @ `48d8c21` | `wave3d-suite`, `470 ok` before and after | `COUNT total=8 committed=21 uncommitted=0 ignored=0 assertless=0` → GREEN | `PASS`, exit 0 | **exit 1, no oracle `src/`** → now NOT-RUN | **no, without a waiver**: pin side satisfies it, rung side cannot be satisfied without provisioning or an explicit waiver | +| A `host-a` | `~/gates/wave3e` | `wave3e-suite`, `143 ok` before and after | `COUNT total=10 committed=0 uncommitted=25` → **RED** | `PASS`, exit 0 | **exit 1, no oracle `src/`** → now NOT-RUN | **no, twice over**: `git ls-files` = 0 entries (bare `git init`, no `git add -A`) so every pin reads uncommitted, and the rung check is unsatisfiable | + +Raw, host C: + + $ cd ~/gates/wave3d + $ grep -c '^test .* \.\.\. ok$' suite.log + 470 + $ nice -n 19 python3 scripts/pin-gate-audit.py | grep ^COUNT + COUNT total=8 committed=21 uncommitted=0 ignored=0 assertless=0 + $ nice -n 19 python3 scripts/pin-gate-audit.py --self-test | tail -1 + SELFTEST PASS a doc comment between two gates left both counted as crate_pin + $ nice -n 19 bash scripts/check-aom-oracle-rungs.sh; echo "rungs_exit=$?" + no oracle source at /home/user/.cache/aom-oracle/src/av1/decoder/decodeframe.c + rungs_exit=1 + $ grep -c '^test .* \.\.\. ok$' suite.log + 470 + +Raw, host A: + + $ cd ~/gates/wave3e + $ grep -c '^test .* \.\.\. ok$' ~/gates/wave3e-suite.log + 143 + $ git ls-files | wc -l + 0 + $ nice -n 19 python3 scripts/pin-gate-audit.py | grep ^COUNT + COUNT total=10 committed=0 uncommitted=25 ignored=0 assertless=0 + $ nice -n 19 python3 scripts/pin-gate-audit.py --self-test | tail -1 + SELFTEST PASS a doc comment between two gates left both counted as crate_pin + $ nice -n 19 bash scripts/check-aom-oracle-rungs.sh; echo "rungs_exit=$?" + no oracle source at /home/user/.cache/aom-oracle/src/av1/decoder/decodeframe.c + rungs_exit=1 + $ grep -c '^test .* \.\.\. ok$' ~/gates/wave3e-suite.log + 143 + +Read on the audits: **neither running suite's tree satisfies the preflight, and +host A's pin-census red is a staging artefact, not a code defect** — the same +artefact the wave-3c-b report described, still reproducible. Host A's suite +results are not invalidated by it (the census reads pins, it does not gate +decoder behaviour), but a census claiming `committed=0` on 25 pins must not be +quoted as a pin-tracking measurement. + +## 5. One sentence for the merge report + +> The wave-3d run on `host-d` verified its fixture pins (census +> `committed=21 uncommitted=0`, self-test PASS) but **not** its oracle rung +> derivation — that host has `~/.cache/aom-oracle/build` and no `src/` tree, so +> the rung checker asserted nothing there and the driver's `rungs_exit=1 +> ok_count=0` line was a missing prerequisite, not a failing check; the 14-ok +> figure remains a local (build-host) measurement only. + +## 6. Skill update + +`manage_skill update ec-av1stage-staging` — no such skill; the existing managed +skill `ec-av1-remote-suite-stage` is updated in place rather than duplicated, with +the new gate as the staging recipe and this trap added. + +## 7. Not done + +- No host was re-staged and no suite was restarted; §4 is read-only by design. +- Neither host was provisioned with `~/.cache/aom-oracle/src` — that is a fleet + decision, and a `git clone` of libaom on two hosts was not in this lane's scope. +- The checker's `exit 1` callers (lane reports) keep working; no caller was + migrated to the new `3`. +- `scripts/av1-stage-suite.sh` is exercised only with `--dry-run` on a scratch + tree; it has not started a real unit. diff --git a/scripts/av1-stage-suite.sh b/scripts/av1-stage-suite.sh new file mode 100755 index 00000000..dd90d3fd --- /dev/null +++ b/scripts/av1-stage-suite.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +# av1-stage-suite.sh — stage an ec-av1 suite on a server host, behind the preflight +# gate. A staging whose pin audit or rung check FAILED, or whose checkers never +# ran, MUST NOT reach `=== SUITE`. +# +# WHY THIS EXISTS (lane-av1stagegaps, 2026-09-30). The hand-written staging +# driver logged the checker outcome and continued regardless: +# +# === ORACLE RUNG CHECKER +# rungs_exit=1 ok_count=0 +# === SUITE +# +# so a green suite on a host meant nothing about its preflight. Three states — +# passed, failed, never ran — all looked the same. This driver runs +# scripts/av1-suite-preflight.sh under `set -e` and stops there. +# +# Usage: +# scripts/av1-stage-suite.sh --name --tree [--tarball ] +# [--skip ]... [-- command...] +# +# Defaults: no cargo-test-arg means +# cargo test -p ec-av1 --lib -- --test-threads=1 +# +# Env (all passed to the unit): +# CARGO_TARGET_DIR, TMPDIR defaulted under $HOME/gates/-* +# EC_AV1_REQUIRE_AOMENC=1, EC_AV1_REQUIRE_FFMPEG=1, EC_REQUIRE_FIXTURES=1 +# SUITE_RUNG_WAIVER= required to accept rung_check=not-run +# +# Exit: 0 the unit was started; non-zero the preflight BLOCKED and no unit +# exists. `systemctl --user is-active -suite` is the only thing that +# starts a suite, so a blocked staging leaves the host idle on purpose. + +set -uo pipefail + +NAME="" +TREE="" +TARBALL="" +declare -a SKIPS=() +declare -a CMD=() +DRY_RUN=0 +while [ $# -gt 0 ]; do + case "$1" in + --name) NAME=$2; shift 2 ;; + --tree) TREE=$2; shift 2 ;; + --tarball) TARBALL=$2; shift 2 ;; + --skip) SKIPS+=(--skip "$2"); shift 2 ;; + --dry-run) DRY_RUN=1; shift ;; + --) shift; CMD=("$@"); break ;; + -h|--help) sed -n '2,28p' "$0"; exit 0 ;; + *) echo "unknown argument: $1" >&2; exit 2 ;; + esac +done +[ -n "$NAME" ] && [ -n "$TREE" ] || { echo "usage: --name --tree [--tarball ] [--skip ]... [-- cmd...]" >&2; exit 2; } +[ -d "$TREE" ] || { echo "no such tree: $TREE" >&2; exit 2; } + +# 1. The staged tree needs a real git checkout with a POPULATED index. A bare +# `git init` leaves the index empty and pin-gate-audit.py's +# `git ls-files --error-unmatch` then reports every pin as uncommitted — a +# staging artefact indistinguishable from the defect invariant 4 exists to +# catch (wave-3c-b correction). Test rev-parse, not `[ -d .git ]`: a worktree +# copy and a `git archive` untar both leave a `.git` FILE. +git -C "$TREE" rev-parse --git-dir >/dev/null 2>&1 || { + echo "staging defect: $TREE is not a git checkout; memguard-runner.sh dies with exit 128" >&2 + exit 2 +} +if [ -z "$(git -C "$TREE" ls-files | head -1)" ]; then + echo "staging defect: $TREE has an empty index; run git add -A after the untar" >&2 + exit 2 +fi + +# 2. Both gitignored lanes dumps: missing them fails exactly 2 tests that are +# not a decoder regression. +for f in intrarect_dump.expected.txt wedge_libaom.expected.txt; do + [ -f "$TREE/lanes/$f" ] || { echo "staging defect: $TREE/lanes/$f missing" >&2; exit 2; } +done + +TARGET=${CARGO_TARGET_DIR:-$HOME/gates/target-$NAME} +TMP=${TMPDIR:-$HOME/gates/tmp-$NAME} +mkdir -p "$TARGET" "$TMP" + +echo "=== host=$(hostname) commit=$(git -C "$TREE" rev-parse HEAD) date=$(date -Is)" +echo "=== cargo=$(command -v cargo || echo MISSING) aomenc=${EC_AV1_AOMENC:-unset} aomdec=${EC_AV1_AOMDEC:-unset} ffmpeg=$(command -v ffmpeg || echo MISSING)" +if [ -n "$TARBALL" ]; then + echo "=== tarball=$(sha256sum "$TARBALL" | cut -c1-16) -> $TREE" +fi + +# 3. THE GATE. `set -e` is the whole mechanism: a non-zero verdict aborts this +# script before systemd-run is ever reached, so no unit exists and no suite +# runs. There is no path from a blocked verdict to `=== SUITE`. +set -e +echo "=== PIN-GATE PREFLIGHT + ORACLE RUNG CHECKER" +EC_REQUIRE_FIXTURES=${EC_REQUIRE_FIXTURES:-1} \ +EC_FIXTURE_SHAPE_STRICT=${EC_FIXTURE_SHAPE_STRICT:-1} \ + bash "$TREE/scripts/av1-suite-preflight.sh" --tree "$TREE" +set +e + +echo "=== SUITE" +if [ "$DRY_RUN" = 1 ]; then + echo "dry-run: would start unit $NAME-suite in $TREE (target $TARGET, tmp $TMP)" + exit 0 +fi + +if [ ${#CMD[@]} -eq 0 ]; then + CMD=(cargo test -p ec-av1 --lib -- --test-threads=1) +fi +declare -a quoted=() +for a in "${SKIPS[@]}"; do quoted+=("$a"); done + +LOG=$HOME/gates/$NAME-suite.log +mkdir -p "$HOME/gates" +systemd-run --user --unit="$NAME-suite" -p MemoryMax=5G \ + -p WorkingDirectory="$TREE" \ + --setenv="CARGO_TARGET_DIR=$TARGET" \ + --setenv="TMPDIR=$TMP" \ + --setenv=EC_NOMEMGUARD=1 \ + --setenv=EC_AV1_REQUIRE_AOMENC=1 \ + --setenv=EC_AV1_REQUIRE_FFMPEG=1 \ + --setenv=EC_REQUIRE_FIXTURES=1 \ + --setenv="EC_FIXTURES=${EC_FIXTURES:-$TREE/fixtures}" \ + ${EC_AV1_AOMENC:+--setenv=EC_AV1_AOMENC=$EC_AV1_AOMENC} \ + ${EC_AV1_AOMDEC:+--setenv=EC_AV1_AOMDEC=$EC_AV1_AOMDEC} \ + --setenv="PATH=$HOME/.cargo/bin:/usr/local/bin:/usr/bin:/bin" \ + /usr/bin/bash -lc "cd '$TREE' && ${CMD[*]} ${quoted[*]-} > '$LOG' 2>&1" +echo "started $NAME-suite; real test output: $LOG" diff --git a/scripts/av1-suite-preflight.sh b/scripts/av1-suite-preflight.sh new file mode 100755 index 00000000..d8ac31f8 --- /dev/null +++ b/scripts/av1-suite-preflight.sh @@ -0,0 +1,248 @@ +#!/usr/bin/env bash +# av1-suite-preflight.sh — the gate a server staging must pass BEFORE `=== SUITE`. +# +# WHY (lane-av1stagegaps, measured 2026-09-30). Three hosts, three different +# preflight realities, one identical green suite: +# +# host C host-d the driver printed +# === ORACLE RUNG CHECKER +# rungs_exit=1 ok_count=0 +# === SUITE +# and the suite ran. The real cause, with stderr +# visible, was a MISSING PREREQUISITE: the host has +# `~/.cache/aom-oracle/build` (aomdec/aomenc binaries) +# and no `src/` tree, so the checker asserted nothing. +# host A host-a staged with a bare `cargo test -p ec-av1 --lib`. No +# pin-gate audit, no rung checker, no self-test: not a +# failure, an ABSENT check. +# so "green suite" meant checker-passed, checker-failed and no-checker-ran +# with equal confidence. +# +# WHAT THIS DOES. Runs both preflight pieces, prints one machine-readable state +# per piece, then a single VERDICT. Exit 0 only when every piece is GREEN or an +# explicitly waived NOT-RUN, so a `set -e` staging driver CANNOT reach +# `=== SUITE` on a failed or missing check. +# +# pin_audit = GREEN | FAIL | ABSENT (verify-fixture-library.sh: shape, +# resolve, drift, invariants 1-4 + +# census self-test) +# rung_check = GREEN | FAIL | NOT-RUN | ABSENT +# VERDICT = GREEN | WAIVED | BLOCKED +# +# NOT-RUN vs ABSENT is the distinction that matters. NOT-RUN means the checker +# RAN and reported a missing prerequisite (exit 3 from check-aom-oracle-rungs.sh) +# — a provisioning fact, not a code defect. ABSENT means the checker is not in +# this tree at all, which is exactly the host-A defect and is never waivable. +# +# WAIVER. not-run can be waived, but only with an explicit non-empty reason that +# is recorded in the verdict line, so a later reader can tell a deliberate +# waiver from a check that silently vanished: +# SUITE_RUNG_WAIVER="host host-d carries oracle binaries only; rung +# coverage verified on the build host, see report" +# An empty waiver counts as absent, so a unit's Environment= carrying a bare +# SUITE_RUNG_WAIVER= cannot accidentally authorise a run. +# +# Usage: +# scripts/av1-suite-preflight.sh [--tree DIR] [--self-test] +# +# Env: +# EC_FIXTURES= fixture root (default /fixtures) +# EC_REQUIRE_FIXTURES=1 make an absent/empty fixture path fatal +# SUITE_RUNG_WAIVER= waive rung_check=not-run (see above) +# SUITE_RUNG_CHECKER= override the rung checker (self-test stubs) +# SUITE_PIN_CHECKER= override the pin preflight (self-test stubs) + +set -uo pipefail + +ROOT_DEFAULT=$(cd -- "$(dirname -- "$0")/.." && pwd) +TREE=$ROOT_DEFAULT +SELF_TEST=0 +while [ $# -gt 0 ]; do + case "$1" in + --tree) TREE=$2; shift 2 ;; + --self-test) SELF_TEST=1; shift ;; + -h|--help) sed -n '2,40p' "$0"; exit 0 ;; + *) echo "unknown argument: $1" >&2; exit 2 ;; + esac +done +PIN_CHECKER=${SUITE_PIN_CHECKER:-$TREE/scripts/verify-fixture-library.sh} +RUNG_CHECKER=${SUITE_RUNG_CHECKER:-$TREE/scripts/check-aom-oracle-rungs.sh} + +pin_state=ABSENT +rung_state=ABSENT + +run_pin() { # sets pin_state, prints every detail line + pin_state=ABSENT + if [ ! -f "$PIN_CHECKER" ]; then + echo "pin_audit_state=ABSENT reason=pin preflight not in tree ($PIN_CHECKER)" >&2 + return + fi + local out rc + out=$("$PIN_CHECKER" 2>&1) + rc=$? + printf '%s\n' "$out" | sed 's/^/ /' + if [ $rc -eq 0 ]; then pin_state=GREEN; else pin_state=FAIL; fi + echo "pin_audit_exit=$rc state=$pin_state" +} + +run_rungs() { # sets rung_state, prints every detail line + rung_state=ABSENT + if [ ! -f "$RUNG_CHECKER" ]; then + echo "rung_check_state=ABSENT reason=checker not in tree ($RUNG_CHECKER)" >&2 + return + fi + local out rc ok_count + out=$("$RUNG_CHECKER" 2>&1) + rc=$? + ok_count=$(printf '%s\n' "$out" | grep -c '^ok ' || true) + # The detail lines are the whole point: the 2026-09-30 driver logged + # `rungs_exit=1 ok_count=0` and no reason at all. Every outcome here prints + # the checker's own stdout and stderr together, indented. + printf '%s\n' "$out" | sed 's/^/ /' + case $rc in + 0) rung_state=GREEN ;; + 3) rung_state=NOT-RUN ;; + *) rung_state=FAIL ;; + esac + echo "rungs_exit=$rc ok_count=$ok_count state=$rung_state" +} + +verdict() { # echoes VERDICT; returns 0 iff GREEN or WAIVED + # A pin audit that did not run or failed, and a rung check that is absent + # or failed, are all fatal: no waiver exists for any of them. Only + # rung_check=not-run (a missing prerequisite) is waivable, and only with a + # non-empty reason. + local v=BLOCKED + local waived="" + if [ "$pin_state" = GREEN ] && [ "$rung_state" = GREEN ]; then + v=GREEN + elif [ "$pin_state" = GREEN ] && [ "$rung_state" = NOT-RUN ]; then + if [ -n "${SUITE_RUNG_WAIVER:-}" ]; then + v=WAIVED + waived=" (rung_check=not-run waived: ${SUITE_RUNG_WAIVER})" + fi + fi + echo "VERDICT=$v$waived" + if [ "$v" = BLOCKED ]; then + { + echo "PREFLIGHT BLOCKED: pin_audit=$pin_state rung_check=$rung_state." + echo " A staging with a failed or missing check must NOT reach === SUITE." + echo " rung_check=not-run (missing oracle source) is waivable only via" + echo " SUITE_RUNG_WAIVER=''; an absent checker never is." + } >&2 + return 1 + fi + return 0 +} + +self_test() { + local d rc=0 out + d=$(mktemp -d "${TMPDIR:-/tmp}/av1-preflight-selftest.XXXXXX") + # shellcheck disable=SC2064 + trap "rm -rf '$d'" RETURN + + stub() { # name, exit-code, body + printf '#!/usr/bin/env bash\n%s\nexit %s\n' "$3" "$2" >"$d/$1" + chmod +x "$d/$1" + } + # `set -o pipefail` is on, so `verdict | grep -q ...` returns verdict's own + # non-zero status even when grep matched, and every BLOCKED case would read + # as a self-test failure. Capture first, then compare. + v_of() { verdict 2>/dev/null; } + expect() { # expected-verdict, label + out=$("${@:3}" 2>/dev/null || true) + : + } + + # 1. all green -> GREEN + stub pin-ok 0 'echo "verify-fixture-library: GREEN"' + stub rungs-ok 0 'echo "ok derives the rungs"' + PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1 + if [ "$(v_of)" = "VERDICT=GREEN" ]; then + echo "ok 1 an all-green staging is GREEN" + else + echo "FAIL 1 an all-green staging is GREEN"; rc=1 + fi + + # 2. rung checker FAILS (exit 1) -> BLOCKED. The mutation: red the checker + # and the gate must stop. + stub rungs-bad 1 'echo "FAIL derived file violates the rung contract"' + PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/rungs-bad run_rungs >/dev/null 2>&1 + if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 2 a FAILING rung checker blocks the suite" + else + echo "FAIL 2 a FAILING rung checker blocks the suite"; rc=1 + fi + + # 3. rung checker NOT-RUN (exit 3), no waiver -> BLOCKED. + stub rungs-notrun 3 'echo "PREREQ-ABSENT: no oracle source at ..."' + PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/rungs-notrun run_rungs >/dev/null 2>&1 + if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 3 not-run without a waiver blocks the suite" + else + echo "FAIL 3 not-run without a waiver blocks the suite"; rc=1 + fi + + # 4. not-run WITH a waiver -> WAIVED, and the reason lands in the verdict. + if [ "$(SUITE_RUNG_WAIVER='host C carries oracle binaries only' v_of)" \ + = "VERDICT=WAIVED (rung_check=not-run waived: host C carries oracle binaries only)" ] + then + echo "ok 4 not-run with a named waiver is WAIVED, reason recorded" + else + echo "FAIL 4 not-run with a named waiver is WAIVED, reason recorded"; rc=1 + fi + + # 5. an EMPTY waiver authorises nothing: a unit Environment= carrying a bare + # SUITE_RUNG_WAIVER= is a real staging shape. + if [ "$(SUITE_RUNG_WAIVER='' v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 5 an empty waiver does not authorise a run" + else + echo "FAIL 5 an empty waiver does not authorise a run"; rc=1 + fi + + # 6. an ABSENT checker is never waivable: the host-A defect. + PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/does-not-exist run_rungs >/dev/null 2>&1 + if [ "$(SUITE_RUNG_WAIVER='a waiver' v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 6 a tree with NO rung checker is blocked even with a waiver" + else + echo "FAIL 6 a tree with NO rung checker is blocked even with a waiver"; rc=1 + fi + + # 6b. an ABSENT pin audit is fatal too, and not waivable by the same knob. + PIN_CHECKER=$d/does-not-exist run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1 + if [ "$(SUITE_RUNG_WAIVER='a waiver' v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 7 a tree with NO pin audit is blocked even with a waiver" + else + echo "FAIL 7 a tree with NO pin audit is blocked even with a waiver"; rc=1 + fi + + # 8. pin audit FAILING -> BLOCKED even when the rungs are green. + stub pin-bad 1 'echo "FAIL [invariant 4]: census self-test did not pass"' + PIN_CHECKER=$d/pin-bad run_pin >/dev/null 2>&1 + RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1 + if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then + echo "ok 8 a FAILING pin audit blocks the suite" + else + echo "FAIL 8 a FAILING pin audit blocks the suite"; rc=1 + fi + + return $rc +} + +if [ "$SELF_TEST" = 1 ]; then + self_test + exit $? +fi + +echo "=== PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=${EC_REQUIRE_FIXTURES:-0})" +run_pin +echo "=== ORACLE RUNG CHECKER" +run_rungs +echo "=== VERDICT" +verdict +exit $? diff --git a/scripts/check-aom-oracle-rungs.sh b/scripts/check-aom-oracle-rungs.sh index df613363..9f028e34 100755 --- a/scripts/check-aom-oracle-rungs.sh +++ b/scripts/check-aom-oracle-rungs.sh @@ -20,6 +20,26 @@ # av1/decoder/decodeframe.c and av1/common/reconintra.c with the PRISTINE # upstream files, runs the instrument script over the copy, and asserts the # derived files' shape. The real oracle tree is never written to. +# +# EXIT CONTRACT (lane-av1stagegaps). A staging driver must be able to tell the +# three states apart, because "checker passed", "checker failed" and "checker +# never ran" all printed as `rungs_exit=1` (or as nothing at all) and the suite +# ran anyway. Measured 2026-09-30 on host host-d: the driver log showed +# === ORACLE RUNG CHECKER +# rungs_exit=1 ok_count=0 <- no detail line at all +# === SUITE +# while the real reason, with stderr visible, was a missing PREREQUISITE: +# no oracle source at /home/user/.cache/aom-oracle/src/av1/decoder/decodeframe.c +# $ ls ~/.cache/aom-oracle/ +# build <- binaries only, no src/ tree +# 0 GREEN every assertion below held. +# 3 NOTRUN a PREREQUISITE is absent (no oracle source tree, or the base ref +# is not in it). Nothing was asserted: this is NOT a pass and NOT a +# defect. scripts/av1-suite-preflight.sh maps it to `not-run` and +# BLOCKS the suite unless a waiver names the host. +# 1 FAIL a derived file violates the rung contract, or the instrument +# script errored / was not idempotent. + # # Usage: # scripts/check-aom-oracle-rungs.sh [SRC_DIR] [BASE_REF] @@ -32,14 +52,21 @@ BASE="${2:-${AOM_ORACLE_BASE_REF:-v3.13.3}}" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DERIVED="$SRC/av1/decoder/decodeframe.c" RECONINTRA="$SRC/av1/common/reconintra.c" +die_prereq() { echo "PREREQ-ABSENT: $*" >&2; exit 3; } -[ -f "$DERIVED" ] || { echo "no oracle source at $DERIVED" >&2; exit 1; } -[ -f "$RECONINTRA" ] || { echo "no oracle source at $RECONINTRA" >&2; exit 1; } + +[ -f "$DERIVED" ] || die_prereq "no oracle source at $DERIVED (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)" +[ -f "$RECONINTRA" ] || die_prereq "no oracle source at $RECONINTRA (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)" git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || { - echo "base ref '$BASE' is not a commit in $SRC" >&2 - exit 1 + die_prereq "base ref '$BASE' is not a commit in $SRC" } +# systemd-run's --setenv=TMPDIR points at a per-suite dir; if staging created +# the unit but not the dir, mktemp fails with an error that reads like a +# checker bug. It is the same class as a missing oracle tree: not asserted. +probe="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX" 2>/dev/null)" || + die_prereq "scratch dir ${TMPDIR:-$HOME/.cache/tmp} does not exist (staging must mkdir it)" +rmdir "$probe" WORK="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX")" trap 'rm -rf "$WORK"' EXIT cp -a "$SRC" "$WORK/src"