interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / native / collective / admit / run.sh

233 lines · 12883 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: AGPL-3.0-only
3# DRA-15 / aien-train#26 P0 admission refusal contract: native replay of
4# native/collective/admit_p0.om against an oracle it does not carry.
5#
6# OMC=/path/to/seed/out/omc sh native/collective/admit/run.sh OUTDIR
7#
8# Runs from the repository root. OMC must hash to the aien-train aarch64 pin
9# (omega-mv e5b32567, omc sha256 2c824805...); any other compiler exits 77
10# (NOT_RUN). Linux AArch64 only (omc writes a static AArch64 ELF).
11#
12# What it checks:
13# 1. the unit's self-test compiles and exits 0, three times, with identical
14# binaries;
15# 2. observation build A1 (every line of admit_p0.om before "fn main to int",
16# byte-identical, plus admit/a1emit-main.om) runs all 46 cases of
17# fixtures/admission_v0.json in one process; its stdout must equal
18# admit/expected-a1.out, the string Wolfram returned for
19# evidence/COLLECTIVE-P0-ADMIT/oracle-query.wl (sha256 pinned below).
20# Status, response and counters after every case are in that string, so a
21# refused case that writes a response or moves a counter is caught;
22# 3. process build CLI (same prefix plus admit/cli-main.om) runs each case in
23# its own process; exit status and stdout must equal admit/expected-cli.out
24# (Wolfram): an admitted case exits 0 and prints one line, a refused case
25# exits with minus its status and prints nothing;
26# 4. the comparators refuse one-byte-corrupted expectations, and the CLI tail
27# refuses bad arguments with a nonzero exit and no output;
28# 5. one compiled guard-removal mutant per guard (17), plus a mutant that
29# computes before the admission verdict (state change on refusal), a
30# selection-order mutant and a coordinated mutant that also rewrites the
31# self-test's own expectations: each must be killed by the A1 oracle;
32# 6. four score/permission swap mutants must be refused by the compiler
33# (omc error 7): the abstract types make the swap unrepresentable.
34# Output: OUTDIR/receipt.tsv, raw stdout/stderr/status per build and run, and a
35# final line "ADMITP0 PASS ..." or "ADMITP0 FAIL ..." (exit 0 / 1).
36set -u
37PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
38A1_SHA=a41baa404a15e90d2dabcc25ee4f6830754a67930be65015b5496fb3799fc66a
39CLI_SHA=90c11b093b9d0038fcb1db2911f38268cead7df78ca5332a1bb4dfce3d356ab8
40NCASE=46
41SRC=native/collective/admit_p0.om
42EMIT=native/collective/admit/a1emit-main.om
43CLIT=native/collective/admit/cli-main.om
44EXPA=native/collective/admit/expected-a1.out
45EXPC=native/collective/admit/expected-cli.out
46OUT=${1:?usage: OMC=... sh run.sh OUTDIR}
47OMC=${OMC:?set OMC}
48[ "$(uname -m)" = aarch64 ] || { echo "ADMITP0 NOT_RUN host $(uname -m) is not aarch64"; exit 77; }
49got=$(sha256sum "$OMC" | cut -d' ' -f1)
50[ "$got" = "$PIN" ] || { echo "ADMITP0 NOT_RUN omc $got is not the pin $PIN"; exit 77; }
51[ "$(sha256sum "$EXPA" | cut -d' ' -f1)" = "$A1_SHA" ] || { echo "ADMITP0 FAIL $EXPA is not the Wolfram result"; exit 1; }
52[ "$(sha256sum "$EXPC" | cut -d' ' -f1)" = "$CLI_SHA" ] || { echo "ADMITP0 FAIL $EXPC is not the Wolfram result"; exit 1; }
53[ "$(grep -c '^fn main to int$' "$SRC")" = 1 ] || { echo "ADMITP0 FAIL $SRC must have exactly one fn main"; exit 1; }
54mkdir -p "$OUT"
55R="$OUT/receipt.tsv"
56printf 'case\tbuild\tsource_sha256\tcompile_rc\tbinary_sha256\trun_exit\tstdout_sha256\tverdict\n' > "$R"
57fails=0
58note() { printf '%s\n' "$*"; }
59
60# build NAME SOURCE: compile; never run a refused compile's output.
61build() {
62 "$OMC" < "$2" > "$OUT/$1.bin" 2> "$OUT/$1.compile.stderr"
63 crc=$?
64 echo "$crc" > "$OUT/$1.compile.status"
65 bsha=-
66 if [ "$crc" = 0 ]; then chmod 755 "$OUT/$1.bin"; bsha=$(sha256sum "$OUT/$1.bin" | cut -d' ' -f1); fi
67}
68# run NAME [ARG]: execute a built binary with a 10 s ceiling.
69run() {
70 rexit=-; osha=-
71 if [ "$crc" = 0 ]; then
72 timeout 10 "$OUT/$1.bin" ${2+"$2"} > "$OUT/$1.stdout" 2> "$OUT/$1.stderr"
73 rexit=$?
74 echo "$rexit" > "$OUT/$1.status"
75 osha=$(sha256sum "$OUT/$1.stdout" | cut -d' ' -f1)
76 fi
77}
78row() { # case build source verdict
79 printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$1" "$2" "$(sha256sum "$3" | cut -d' ' -f1)" "$crc" "$bsha" "$rexit" "$osha" "$4" >> "$R"
80}
81# prefix SRCFILE TAIL DEST: every line before "fn main to int" + tail.
82prefix() { sed '/^fn main to int$/,$d' "$1" > "$3"; cat "$2" >> "$3"; }
83# clirun NAME: run the built CLI binary NAME once per case; write NAME.cli.out
84# in the expected-cli.out format: "case exit stdout-line" or "case exit -".
85clirun() {
86 : > "$OUT/$1.cli.out"
87 n=0
88 while [ "$n" -lt "$NCASE" ]; do
89 timeout 10 "$OUT/$1.bin" "$n" > "$OUT/$1.c$n.stdout" 2> "$OUT/$1.c$n.stderr"
90 ex=$?
91 f="$OUT/$1.c$n.stdout"
92 if [ ! -s "$f" ]; then body=-
93 elif [ "$(wc -l < "$f")" = 1 ] && [ "$(tail -c 1 "$f" | od -An -tx1 | tr -d ' ')" = 0a ]; then body=$(cat "$f")
94 else body=BADFORM
95 fi
96 printf '%s %s %s\n' "$n" "$ex" "$body" >> "$OUT/$1.cli.out"
97 n=$((n+1))
98 done
99}
100
101# 1+2. Self-test and A1 observation, three repeats each.
102prefix "$SRC" "$EMIT" "$OUT/a1.om"
103prefix "$SRC" "$CLIT" "$OUT/cli.om"
104for k in 1 2 3; do
105 build "selftest-$k" "$SRC"; run "selftest-$k"
106 v=FAIL; [ "$crc" = 0 ] && [ "$rexit" = 0 ] && v=PASS
107 [ "$v" = PASS ] || fails=$((fails+1))
108 row original selftest "$SRC" "$v"
109 build "a1-$k" "$OUT/a1.om"; run "a1-$k"
110 v=FAIL; [ "$crc" = 0 ] && [ "$rexit" = 0 ] && cmp -s "$OUT/a1-$k.stdout" "$EXPA" && v=PASS
111 [ "$v" = PASS ] || fails=$((fails+1))
112 row original oracle-a1 "$OUT/a1.om" "$v"
113done
114[ "$(sha256sum "$OUT/selftest-1.bin" | cut -d' ' -f1)" = "$(sha256sum "$OUT/selftest-3.bin" | cut -d' ' -f1)" ] || { note "nondeterministic compile"; fails=$((fails+1)); }
115
116# 3. One case per process.
117build cli "$OUT/cli.om"
118v=FAIL
119if [ "$crc" = 0 ]; then clirun cli; cmp -s "$OUT/cli.cli.out" "$EXPC" && v=PASS; fi
120[ "$v" = PASS ] || fails=$((fails+1))
121rexit=-; osha=-; [ -f "$OUT/cli.cli.out" ] && osha=$(sha256sum "$OUT/cli.cli.out" | cut -d' ' -f1)
122row original oracle-cli "$OUT/cli.om" "$v"
123nref=$(grep -c ' -$' "$EXPC"); nadm=$(grep -c ' Y ' "$EXPC")
124
125# 4. Negative controls of the judges themselves.
126sed '2s/ -4 / -5 /' "$EXPA" > "$OUT/expected-a1-corrupt.out"
127if cmp -s "$OUT/a1-1.stdout" "$OUT/expected-a1-corrupt.out"; then v=FAIL; fails=$((fails+1)); else v=PASS; fi
128crc=0; bsha=-; rexit=-; osha=$(sha256sum "$OUT/expected-a1-corrupt.out" | cut -d' ' -f1)
129row comparator-corrupt-a1 oracle-a1 "$OUT/expected-a1-corrupt.out" "$v"
130sed '2s/^1 4 -$/1 0 -/' "$EXPC" > "$OUT/expected-cli-corrupt.out"
131if cmp -s "$OUT/cli.cli.out" "$OUT/expected-cli-corrupt.out"; then v=FAIL; fails=$((fails+1)); else v=PASS; fi
132osha=$(sha256sum "$OUT/expected-cli-corrupt.out" | cut -d' ' -f1)
133row comparator-corrupt-cli oracle-cli "$OUT/expected-cli-corrupt.out" "$v"
134crc=$(cat "$OUT/cli.compile.status"); bsha=$(sha256sum "$OUT/cli.bin" | cut -d' ' -f1)
135for a in none:99 46:96 x:97 12345:98; do
136 arg=${a%%:*}; want=${a#*:}
137 if [ "$arg" = none ]; then run cli; else run cli "$arg"; fi
138 cp "$OUT/cli.stdout" "$OUT/cli-arg-$arg.stdout"
139 v=FAIL; [ "$rexit" = "$want" ] && [ ! -s "$OUT/cli.stdout" ] && v=PASS
140 [ "$v" = PASS ] || fails=$((fails+1))
141 row "cli-arg-$arg" usage "$OUT/cli.om" "$v"
142done
143
144# 5+6. Mutants. mutate NAME LINE 'OLD' 'NEW' [LINE 'OLD' 'NEW' ...] on top of
145# SRC, applied in the order given (an insert shifts later lines).
146# NEW of "+STATEMENT" inserts that statement after LINE instead.
147OFF='if eq ulong 1 ulong 0'
148mutate() {
149 m=$1; shift
150 cp "$SRC" "$OUT/$m.om"
151 while [ $# -ge 3 ]; do
152 ln=$1; old=$2; new=$3; shift 3
153 cur=$(sed -n "${ln}p" "$OUT/$m.om")
154 [ "$cur" = "$old" ] || { note "mutant $m: line $ln is '$cur', wanted '$old'"; fails=$((fails+1)); return 1; }
155 case $new in
156 +*) sed "${ln}a\\
157${new#+}" "$OUT/$m.om" > "$OUT/$m.tmp" ;;
158 *) sed "${ln}s/.*/$new/" "$OUT/$m.om" > "$OUT/$m.tmp" ;;
159 esac
160 mv "$OUT/$m.tmp" "$OUT/$m.om"
161 done
162}
163killed=0; mutants=0
164mutcase() { # NAME: self-test, A1 oracle and CLI oracle for $OUT/NAME.om
165 m=$1
166 mutants=$((mutants+1))
167 build "$m-selftest" "$OUT/$m.om"; run "$m-selftest"
168 if [ "$crc" = 0 ] && [ "$rexit" = 0 ]; then st=SELFTEST_MISSED; else st=SELFTEST_CAUGHT; fi
169 [ "$crc" = 0 ] || { st="MUTANT_INVALID_compile$crc"; fails=$((fails+1)); }
170 row "$m" selftest "$OUT/$m.om" "$st"
171 prefix "$OUT/$m.om" "$EMIT" "$OUT/$m-a1.om"
172 build "$m-a1" "$OUT/$m-a1.om"; run "$m-a1"
173 if [ "$crc" = 0 ] && [ "$rexit" = 0 ] && cmp -s "$OUT/$m-a1.stdout" "$EXPA"; then va=ORACLE_MISSED; fails=$((fails+1)); else va=ORACLE_KILLED; killed=$((killed+1)); fi
174 [ "$crc" = 0 ] || { va="MUTANT_INVALID_compile$crc"; fails=$((fails+1)); }
175 row "$m" oracle-a1 "$OUT/$m-a1.om" "$va"
176 prefix "$OUT/$m.om" "$CLIT" "$OUT/$m-cli.om"
177 build "$m-cli" "$OUT/$m-cli.om"
178 vc="MUTANT_INVALID_compile$crc"
179 if [ "$crc" = 0 ]; then
180 clirun "$m-cli"
181 if cmp -s "$OUT/$m-cli.cli.out" "$EXPC"; then vc=CLI_MISSED; else vc=CLI_KILLED; fi
182 else fails=$((fails+1)); fi
183 rexit=-; osha=-; [ -f "$OUT/$m-cli.cli.out" ] && osha=$(sha256sum "$OUT/$m-cli.cli.out" | cut -d' ' -f1)
184 row "$m" oracle-cli "$OUT/$m-cli.om" "$vc"
185 printf '%s %s %s %s\n' "$m" "$st" "$va" "$vc"
186}
187compref() { # NAME: must be refused by omc with error 7
188 m=$1
189 build "$m" "$OUT/$m.om"
190 rexit=-; osha=-
191 if [ "$crc" = 7 ]; then v=COMPILE_REFUSED_7; else v="NOT_REFUSED_rc$crc"; fails=$((fails+1)); fi
192 row "$m" compile "$OUT/$m.om" "$v"
193 printf '%s %s %s\n' "$m" "$v" "$(cat "$OUT/$m.compile.stderr")"
194}
195mutate g01-rank 221 'if or ne get Dsc 0 1 ne get Req 0 get Dsc 0' "$OFF" && mutcase g01-rank
196mutate g02-shape 224 'if shapebad' "$OFF" && mutcase g02-shape
197mutate g03-missing-base 227 'if or eq get Dsc 3 0 eq get Req 3 0' "$OFF" && mutcase g03-missing-base
198mutate g04-wrong-base-req 230 'if ne get Req 3 get Dsc 3' "$OFF" && mutcase g04-wrong-base-req
199mutate g05-wrong-base-content 233 'if ne bdigest get Dsc 3' "$OFF" && mutcase g05-wrong-base-content
200mutate g06-generation 236 'if ne get Req 4 get Dsc 4' "$OFF" && mutcase g06-generation
201mutate g07-perm-valid 240 'if permbad permat i' "$OFF" && mutcase g07-perm-valid
202mutate g08-mode 245 'if gt md 1' "$OFF" && mutcase g08-mode
203mutate g09-budget-zero 249 'if eq k 0' "$OFF" && mutcase g09-budget-zero
204mutate g10-budget-ceiling 252 'if gt k KMAX' "$OFF" && mutcase g10-budget-ceiling
205mutate g11-all-denied 260 'if ge id NCAND' "$OFF" && mutcase g11-all-denied
206mutate g12-index 270 'if ge id NCAND' "$OFF" && mutcase g12-index
207mutate g13-denied 273 'if denied permat id' "$OFF" && mutcase g13-denied
208mutate g14-stale 276 'if ne get Cgen id get Dsc 4' "$OFF" && mutcase g14-stale
209mutate g15-phase 280 'if and ne ph 1 ne ph -1' "$OFF" && mutcase g15-phase
210mutate g16-duplicate 283 'if dupat j id' "$OFF" && mutcase g16-duplicate
211mutate g17-range 287 'if rangebad k' "$OFF" && mutcase g17-range
212mutate m18-compute-before-verdict 335 'compute get Req 5' 'note compute moved before the verdict' 331 'st = admit' '+compute get Req 5' && mutcase m18-compute-before-verdict
213mutate m19-select-order 194 'if above s bsc' 'if above bsc s' && mutcase m19-select-order
214mutate m20-coordinated 276 'if ne get Cgen id get Dsc 4' "$OFF" 538 'put Exp 13 -9' 'put Exp 13 0' 539 'put Exp 14 -9' 'put Exp 14 0' 570 'put Exp 45 -9' 'put Exp 45 0' 591 'if ne get Counts 0 14' 'if ne get Counts 0 17' 594 'if ne get Counts 1 28' 'if ne get Counts 1 34' && mutcase m20-coordinated
215[ "$mutants" = 20 ] || { note "expected 20 mutants, ran $mutants"; fails=$((fails+1)); }
216# Overflow backstop: with the range guard removed, case 41 (x2 = 2^62) must
217# trap 1 (exit 101) in its own process, not print a wrapped response.
218ovf=$(sed -n '42p' "$OUT/g17-range-cli.cli.out" 2>/dev/null)
219if [ "$ovf" = "41 101 -" ]; then v=TRAP1; else v="NOT_TRAP1:$ovf"; fails=$((fails+1)); fi
220crc=0; bsha=-; rexit=101; osha=-
221row g17-range-case41 overflow-backstop "$OUT/g17-range-cli.om" "$v"
222mutate x1-swap-denied 273 'if denied permat id' 'if denied scoreat id' && compref x1-swap-denied
223mutate x2-swap-pick 188 's = scoreat id' 's = permat id' && compref x2-swap-pick
224mutate x3-raw-perm 273 'if denied permat id' 'if denied get PermA id' && compref x3-raw-perm
225mutate x4-swap-valid 240 'if permbad permat i' 'if permbad scoreat i' && compref x4-swap-valid
226nx=$(grep -c " compile .* COMPILE_REFUSED_7$" "$R")
227
228note "omc $got"
229note "selftest binary $(sha256sum "$OUT/selftest-1.bin" | cut -d' ' -f1) exit $(cat "$OUT/selftest-1.status")"
230note "a1 binary $(sha256sum "$OUT/a1-1.bin" | cut -d' ' -f1) exit $(cat "$OUT/a1-1.status")"
231note "cli binary $(sha256sum "$OUT/cli.bin" | cut -d' ' -f1) cases admitted=$nadm refused=$nref"
232if [ "$fails" = 0 ]; then note "ADMITP0 PASS selftest+a1 x3 cli=$NCASE/$NCASE comparators=refuse usage=4/4 mutants_killed=$killed/$mutants overflow=trap1 swap_compile_refused=$nx/4"; exit 0; fi
233note "ADMITP0 FAIL failures=$fails mutants_killed=$killed/$mutants swap_compile_refused=$nx/4"; exit 1