omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / train / train_receipt.sh
| 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # train_receipt.sh -- receipt for the M22 optimizer substrate + E5 provenance |
| 18 | # tests (mk/train.mk). |
| 19 | # |
| 20 | # tests/train/train_receipt.sh [out-dir] (default: evidence/M22/receipts) |
| 21 | # |
| 22 | # Refuses a dirty tree. Runs `make test-train` twice from a clean build dir; |
| 23 | # both runs (plain + ASan/UBSan builds each) must print the same replay digest. |
| 24 | # Writes a NEW file named by the SHA-256 of its own bytes; never rewrites one. |
| 25 | # Verdict vocabulary: the SUBSTRATE tests PASS or FAIL; M22 itself is always |
| 26 | # NOT QUALIFIED here (no tensor/autodiff integration; waits M20/M21). |
| 27 | # Host-only, single core. Shell + coreutils only. |
| 28 | set -u |
| 29 | HERE=$(cd "$(dirname "$0")/../.." && pwd) |
| 30 | cd "$HERE" || exit 2 |
| 31 | OUTDIR=${1:-evidence/M22/receipts} |
| 32 | |
| 33 | if [ -n "$(git status --porcelain)" ]; then |
| 34 | echo "train_receipt: refusing: working tree is dirty (commit first)" >&2 |
| 35 | exit 3 |
| 36 | fi |
| 37 | head0=$(git rev-parse HEAD) |
| 38 | tree0=$(git rev-parse 'HEAD^{tree}') |
| 39 | run_id=$(date -u +%Y%m%dT%H%M%SZ) |
| 40 | W=$(mktemp -d) |
| 41 | trap 'rm -rf "$W"' EXIT |
| 42 | |
| 43 | run() { # $1 = label |
| 44 | rm -rf build/train |
| 45 | make --no-print-directory test-train > "$W/$1.log" 2>&1 |
| 46 | local rc=$? |
| 47 | cp build/train/plain.log "$W/$1.plain.log" 2>/dev/null |
| 48 | echo $rc |
| 49 | } |
| 50 | rc1=$(run run1) |
| 51 | rc2=$(run run2) |
| 52 | dig() { awk -v k="$2" '$1 == k {print $2}' "$W/$1" | tail -n 1; } |
| 53 | d1=$(dig run1.log replay_digest); d2=$(dig run2.log replay_digest) |
| 54 | h1=$(dig run1.log replay_dispatch_head) |
| 55 | pass1=$(grep -c '^M22_SUBSTRATE_TESTS_PASS$' "$W/run1.log"); pass2=$(grep -c '^M22_SUBSTRATE_TESTS_PASS$' "$W/run2.log") |
| 56 | both=$(grep -c '^test-train: plain and ASan/UBSan PASS, replay digest equal across builds$' "$W/run1.log") |
| 57 | checks=$(awk '$1 == "checks" {print $2; exit}' "$W/run1.log") |
| 58 | reverified=$(dig run1.log replay_steps_reverified) |
| 59 | race=$(grep '^reader_race ' "$W/run1.plain.log" | head -n 1) |
| 60 | crash_old=$(grep -c '^crash .*recovered=OLD' "$W/run1.plain.log") |
| 61 | crash_new=$(grep -c '^crash .*recovered=NEW' "$W/run1.plain.log") |
| 62 | cost=$(grep '^cost ' "$W/run1.plain.log" | sed 's/"//g' | tr '\n' ';') |
| 63 | head1=$(git rev-parse HEAD) |
| 64 | dirty1=$(git status --porcelain | grep -v '^?? build/' || true) |
| 65 | |
| 66 | reasons="" |
| 67 | [ "$rc1" = 0 ] && [ "$rc2" = 0 ] || reasons="$reasons make-failed($rc1,$rc2)" |
| 68 | [ "$pass1" = 2 ] && [ "$pass2" = 2 ] || reasons="$reasons verdict-line-missing" |
| 69 | [ "$both" = 1 ] || reasons="$reasons cross-build-replay-missing" |
| 70 | [ -n "$d1" ] && [ "$d1" = "$d2" ] || reasons="$reasons replay-digest-differs" |
| 71 | [ "$crash_old" = 9 ] && [ "$crash_new" = 2 ] || reasons="$reasons crash-matrix($crash_old,$crash_new)" |
| 72 | [ "$head0" = "$head1" ] || reasons="$reasons head-moved" |
| 73 | [ -z "$dirty1" ] || reasons="$reasons tree-dirty-after" |
| 74 | verdict=PASS; [ -z "$reasons" ] || verdict=FAIL |
| 75 | |
| 76 | log_sha=$(cat "$W/run1.log" "$W/run2.log" | sha256sum | awk '{print $1}') |
| 77 | src_sha=$(cat src/train/*.om tests/train/test_train.om mk/train.mk | sha256sum | awk '{print $1}') |
| 78 | mkdir -p "$OUTDIR" |
| 79 | cat > "$W/receipt.json" <<JSON |
| 80 | { |
| 81 | "schema": "omega.m22.train-substrate.receipt.v1", |
| 82 | "gate": "M22_SUBSTRATE", |
| 83 | "m22_status": "M22 NOT QUALIFIED: optimizer substrate + SGD path only; no tensor/autodiff integration (waits M20/M21)", |
| 84 | "substrate_tests_verdict": "$verdict", |
| 85 | "reasons": "$(echo $reasons)", |
| 86 | "scope": "host-only, single core; process-crash fault injection (fork + _exit at 8 points, plus torn-file simulation of not-yet-current files); NOT a power-loss test, NOT a GPU or hardware qualification; SGD with caller-supplied gradients (hand-written quadratic), Adam/AdamW deferred", |
| 87 | "commit": "$head0", |
| 88 | "tree": "$tree0", |
| 89 | "tree_clean": true, |
| 90 | "run_id": "$run_id", |
| 91 | "command": "make test-train (twice, clean build/train each time; each run = plain -O2 build + ASan/UBSan -O1 build)", |
| 92 | "checks_per_binary_run": "${checks:-null}", |
| 93 | "replay_digest_run1": "${d1:-null}", |
| 94 | "replay_digest_run2": "${d2:-null}", |
| 95 | "replay_dispatch_head": "${h1:-null}", |
| 96 | "replay_steps_reverified": "${reverified:-null}", |
| 97 | "crash_matrix": {"recovered_old": $crash_old, "recovered_new": $crash_new}, |
| 98 | "reader_race": "$race", |
| 99 | "provenance_cost": "$cost", |
| 100 | "train_sources_sha256": "$src_sha", |
| 101 | "logs_sha256": "$log_sha", |
| 102 | "host": "$(uname -srm)" |
| 103 | } |
| 104 | JSON |
| 105 | name=$(sha256sum "$W/receipt.json" | awk '{print $1}') |
| 106 | if [ -e "$OUTDIR/$name.json" ]; then |
| 107 | echo "train_receipt: $OUTDIR/$name.json already exists; not rewritten" >&2 |
| 108 | exit 0 |
| 109 | fi |
| 110 | cp "$W/receipt.json" "$OUTDIR/$name.json" |
| 111 | echo "train_receipt: $verdict -> $OUTDIR/$name.json" |
| 112 | [ "$verdict" = PASS ] |