interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / docs / campaigns / smollm2-qualification / run-windows.sh

199 lines · 12059 bytes Raw Blame History
1#!/usr/bin/env 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# SMOLLM2-Q qualification (copied from cand4-qualification): harness-side tests for coverage cases 2 and 5 (ACCEPTANCE-SMOLLM2-Q.md
18# section 6.1). Shell + jq only. No candidate code, no hook: the frozen cpu_fault binary is
19# started, killed with SIGKILL at a measured moment and restarted. Never touches the GPU.
20# run-windows.sh FIX_ROOT RUN_ROOT
21# FIX_ROOT the Q2 fixture F0 (fixture.json with s3_committed true)
22# RUN_ROOT output; results.jsonl gets one line per run:
23# {row, rep, verdict, outcome, env:"CPU fault injection", checks, run_root}
24# AIEN_BIN = the cpu_fault binary. Rows (windows.decl.json):
25# W-ctl-nokill control: propose to the end, no kill; measures the propose time TP
26# W-ctl-wrong-expect control: the restart evaluator given a wrong prefix digest must say FAIL
27# W-ctl-damaged-mark control: a damaged record mark after a clean authorize must be seen
28# W2 x3 case 2: SIGKILL the daemon at 0.3 / 0.5 / 0.7 x TP into `compose propose`
29# W5 x1 case 5: 40 trials, authorize + SIGKILL at a random 0-50 ms offset
30# Verdicts: PASS, FAIL, NOT_RUN (the injection did not happen: nothing is claimed).
31set -u
32BIN=${AIEN_BIN:?AIEN_BIN}
33FIX=${1:?FIX_ROOT} ROOT=${2:?RUN_ROOT}
34TRIALS=${W5_TRIALS:-40}
35mkdir -p "$ROOT"; ROOT=$(cd "$ROOT" && pwd); FIX=$(cd "$FIX" && pwd)
36jq -e '.s3_committed == true' "$FIX/fixture.json" >/dev/null || { echo "fixture F0 has no committed proposal: NOT_RUN"; exit 3; }
37PPATH=$(jq -r .proposal_path "$FIX/fixture.json")
38GOAL='Create the file NOTES.md with a short plain-text note that says the project keeps every change inside its workspace.'
39
40now_ms() { echo $(( $(date +%s%N) / 1000000 )); }
41sha() { sha256sum "$1" 2>/dev/null | cut -d' ' -f1; }
42tree_list() { (cd "$1" && find . -type f -print0 | sort -z | xargs -0 -r sha256sum); }
43# the socket path must be shorter than SUN_LEN (108): sockets live in a short temp dir
44SOCKD=$(mktemp -d /tmp/c4w.XXXXXX); SOCK=$SOCKD/s
45DPID=
46trap 'rm -rf "$SOCKD"; [ -n "$DPID" ] && kill -0 "$DPID" 2>/dev/null && kill -9 "$DPID" 2>/dev/null' EXIT
47start_daemon() {
48 local log=$R/$1.log i=0
49 rm -f "$SOCK"
50 (cd "$R" && exec setsid "$BIN" daemon >"$log" 2>&1 </dev/null) &
51 DPID=$!
52 while kill -0 "$DPID" 2>/dev/null && [ $i -lt 1200 ]; do
53 if [ -S "$SOCK" ] && grep -q '^Reconcile:' "$log"; then break; fi
54 sleep 0.1; i=$((i + 1))
55 done
56 kill -0 "$DPID" 2>/dev/null || { wait "$DPID" 2>/dev/null; return 1; }
57 if ! grep -q 'Backend:.*CPU-reference' "$log"; then
58 echo "harness: daemon $1 is not the CPU build; stopping (no GPU use allowed here)" >&2
59 kill -9 "$DPID"; exit 9
60 fi
61 [ -S "$SOCK" ] && grep -q '^Reconcile:' "$log"
62}
63stop_daemon() {
64 "$BIN" compose shutdown >/dev/null 2>&1
65 local i=0; while kill -0 "$DPID" 2>/dev/null && [ $i -lt 300 ]; do sleep 0.1; i=$((i + 1)); done
66 wait "$DPID" 2>/dev/null; rm -f "$SOCK"
67}
68kill_daemon() { kill -9 "$DPID" 2>/dev/null; wait "$DPID" 2>/dev/null; rm -f "$SOCK"; }
69cx() { local id=$1; shift; "$BIN" compose "$@" >"$R/steps/$id.json" 2>"$R/steps/$id.err"; local rc=$?; echo "$rc" >"$R/steps/$id.rc"; return $rc; }
70j() { jq -r "$2" "$R/steps/$1.json" 2>/dev/null; }
71eq() { [ "$1" = "$2" ] && echo true || echo false; }
72q() { jq -Rn --arg s "$1" '$s'; }
73CHECKS='[]'; NOTRUN=
74chk() { CHECKS=$(jq -c --arg n "$1" --argjson ok "$2" --argjson v "${3:-null}" '. + [{check:$n, ok:$ok, value:$v}]' <<<"$CHECKS"); }
75
76new_run() { # NAME
77 R=$ROOT/$1; rm -rf "$R"; mkdir -p "$R"/prov "$R"/state "$R"/steps
78 cp -a "$FIX/compose" "$FIX/compose.machine-root" "$FIX/ws" "$FIX/outside" "$FIX/s3-report.json" "$R/"
79 [ -f "$FIX/compose.cortex-mark" ] && cp -a "$FIX/compose.cortex-mark" "$R/"
80 WS=$R/ws; CHECKS='[]'; NOTRUN=
81 export AIEN_COMPOSE_DIR=$R/compose AIEN_PROVENANCE_DIR=$R/prov AIEN_RUNTIME_SOCK=$SOCK \
82 AIEN_RUNTIME_STATE_DIR=$R/state AIEN_REQUIRE_CHECKPOINT=0
83 unset AIEN_MODEL_PATH AIEN_TOKENIZER_PATH AIEN_REQUIRE_BLACKWELL AIEN_GPU_BACKEND AIEN_FAULT_HOLD AIEN_FAULT_HOLD_FILE
84 # sc#328: the daemon requires the approval desk key (the fixture may carry one).
85 [ -f "$R/compose/approval-desk.key" ] || "$BIN" compose desk-key --create 1 >/dev/null
86 WS0=$(tree_list "$WS")
87}
88pre_state() { # sets N0, MID0, PD0 (daemon up)
89 cx pre recall >/dev/null; N0=$(j pre .recall.records_total); MID0=$(j pre .machine_id)
90 cx pre-prefix recall --prefix "$N0" >/dev/null; PD0=$(j pre-prefix .recall.prefix_digest)
91}
92# eval_restart TAG WANT_PD: the restart evaluator. Daemon TAG is up (or not). Returns 0 iff
93# every consistency check holds: up, recall ok, no E_MARK, machine id and the prefix digest
94# over the first N0 records equal the pre-fault values, workspace unchanged.
95EVAL_NOTES=
96eval_restart() {
97 local tag=$1 wantpd=$2 ok=0 em
98 cx "$tag-recall" recall --prefix "$N0" >/dev/null
99 em=$(cd "$R" && grep -l 'E_MARK' daemon-*.log steps/*.json 2>/dev/null | paste -sd, -)
100 chk "${tag}_recall_ok" "$(eq "$(j "$tag-recall" .ok)" true)" "$(q "$(j "$tag-recall" '.error // "ok"' | cut -c1-160)")"
101 chk "${tag}_no_E_MARK" "$( [ -z "$em" ] && echo true || echo false)" "$(q "$em")"
102 chk "${tag}_machine_id" "$(eq "$(j "$tag-recall" .machine_id)" "$MID0")"
103 chk "${tag}_prefix_digest" "$(eq "$(j "$tag-recall" .recall.prefix_digest)" "$wantpd")"
104 chk "${tag}_workspace_unchanged" "$(eq "$(tree_list "$WS")" "$WS0")"
105 jq -e 'all(.ok)' <<<"$CHECKS" >/dev/null
106}
107emit() { # ROW REP VERDICT OUTCOME
108 jq -nc --arg row "$1" --argjson rep "$2" --arg v "$3" --arg o "$4" --argjson c "$CHECKS" --arg root "$R" \
109 '{row:$row, rep:$rep, verdict:$v, outcome:$o, env:"CPU fault injection", checks:$c, run_root:$root}' >>"$ROOT/results.jsonl"
110 echo "$1 rep $2: $3 $4"
111}
112verdict_of() { if [ -n "$NOTRUN" ]; then echo NOT_RUN; else jq -r 'if length > 0 and all(.ok) then "PASS" else "FAIL" end' <<<"$CHECKS"; fi; }
113fsleep() { sleep "$(awk "BEGIN{printf \"%.3f\", $1/1000}")"; }
114
115TP_MS=; SETTLE=
116# ---- W-ctl-nokill: baseline, also measures the propose time and whether propose settles
117new_run W-ctl-nokill
118start_daemon d1 || { chk daemon_up false; emit W-ctl-nokill 1 FAIL "daemon did not start"; exit 0; }
119pre_state
120t0=$(now_ms); cx P1 propose --goal "$GOAL" --workspace "$WS"; TP_MS=$(( $(now_ms) - t0 ))
121cx post recall >/dev/null; N1=$(j post .recall.records_total)
122SETTLE=$(( N1 > N0 ? 1 : 0 ))
123chk propose_answered "$(eq "$(j P1 'has("report") or has("error")')" true)" "$(q "$(j P1 '.report.committed // .error // "none"' | cut -c1-120)")"
124chk propose_ms_measured "$( [ "$TP_MS" -gt 0 ] && echo true || echo false)" "$TP_MS"
125chk propose_wrote_records "$(eq "$SETTLE" 1)" "[$N0,$N1]"
126N0=$N1; cx pre-prefix recall --prefix "$N0" >/dev/null; PD0=$(j pre-prefix .recall.prefix_digest)
127stop_daemon; start_daemon d2 || chk daemon_2_up false
128eval_restart restart "$PD0"
129emit W-ctl-nokill 1 "$(verdict_of)" "propose took ${TP_MS} ms, records $N0 after, records written by propose: $SETTLE"
130stop_daemon
131echo "$TP_MS $SETTLE" >"$ROOT/tp"
132
133# ---- W-ctl-wrong-expect: the evaluator must reject a wrong expected prefix digest
134new_run W-ctl-wrong-expect
135start_daemon d1; pre_state; stop_daemon; start_daemon d2
136if eval_restart restart "$(printf '0%.0s' $(seq 64))"; then v=FAIL o="the evaluator accepted a wrong prefix digest"; else v=PASS o="the evaluator rejected a wrong prefix digest (a control: PASS means it can see the difference)"; fi
137emit W-ctl-wrong-expect 1 $v "$o"; stop_daemon
138
139# ---- W-ctl-damaged-mark: a damaged record mark after a clean authorize must be seen
140new_run W-ctl-damaged-mark
141start_daemon d1; pre_state
142cx A1 authorize --report "$R/s3-report.json" --workspace "$WS" --approver drake --desk 1
143stop_daemon
144if [ -f "$R/compose.cortex-mark" ]; then
145 printf 'X' | dd of="$R/compose.cortex-mark" bs=1 seek=70 conv=notrunc 2>/dev/null
146 start_daemon d2; cx pre2 recall >/dev/null
147 em=$(cd "$R" && grep -l 'E_MARK' daemon-*.log steps/*.json 2>/dev/null | paste -sd, -)
148 if [ -n "$em" ]; then v=PASS o="a damaged mark shows E_MARK in: $em"; else v=FAIL o="a damaged mark was not reported"; fi
149 stop_daemon
150else v=FAIL o="no record mark to damage"; fi
151emit W-ctl-damaged-mark 1 $v "$o"
152
153# ---- W2: SIGKILL the daemon inside `compose propose`, then restart
154if [ "$SETTLE" != 1 ] || [ "$TP_MS" -lt 20 ]; then why="control propose took ${TP_MS} ms and wrote records=$SETTLE: no window to hit on this build"; else why=; fi
155rep=0
156for f in 300 500 700; do
157 rep=$((rep + 1)); new_run "W2-$rep"
158 if [ -n "$why" ]; then NOTRUN=$why; emit W2 $rep NOT_RUN "$why"; continue; fi
159 start_daemon d1 || { chk daemon_1_up false; emit W2 $rep FAIL "daemon did not start"; continue; }
160 pre_state
161 "$BIN" compose propose --goal "$GOAL" --workspace "$WS" >"$R/steps/P1.json" 2>"$R/steps/P1.err" & CPID=$!
162 fsleep $(( TP_MS * f / 1000 ))
163 alive=no; kill -0 "$CPID" 2>/dev/null && alive=yes
164 kill_daemon; wait "$CPID" 2>/dev/null; crc=$?
165 chk kill_in_flight "$(eq "$alive" yes)" "$(jq -nc --argjson tp "$TP_MS" --argjson f "$f" --argjson crc "$crc" '{tp_ms:$tp, at_permille:$f, client_rc:$crc}')"
166 [ "$alive" = yes ] || NOTRUN="the propose client had already finished when the kill was sent"
167 if start_daemon d2; then chk daemon_2_up true; else
168 chk daemon_2_up false "$(q "$(grep -m1 -E 'Fatal|E_[A-Z_]+' "$R/d2.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-160)")"
169 cx REC recover >/dev/null 2>&1; chk recover_ran "$(eq "$(cat "$R/steps/REC.rc")" 0)"
170 start_daemon d3 && chk daemon_3_up true || chk daemon_3_up false
171 fi
172 eval_restart restart "$PD0"
173 NA=$(j restart-recall .recall.records_total)
174 emit W2 $rep "$(verdict_of)" "kill at $((f / 10))% of ${TP_MS} ms; client alive $alive; records before $N0, after restart $NA; $(grep -m1 'Reconcile:' "$R/d2.log" 2>/dev/null | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-80)"
175 stop_daemon
176done
177
178# ---- W5: authorize + SIGKILL at a random 0-50 ms, restart, TRIALS times
179new_run W5; W5R=$R; ALLCHECKS='[]'; adv=0; landed=0; bad=0; offs=
180for t in $(seq 1 "$TRIALS"); do
181 new_run "W5/t$t"
182 off=$(( RANDOM % 51 )); offs="$offs $off"
183 if ! start_daemon d1; then bad=$((bad + 1)); ALLCHECKS=$(jq -c --argjson t "$t" '. + [{check:"trial_\($t)_daemon_1_up", ok:false}]' <<<"$ALLCHECKS"); continue; fi
184 pre_state
185 "$BIN" compose authorize --report "$R/s3-report.json" --workspace "$WS" --approver drake --desk 1 >"$R/steps/A1.json" 2>"$R/steps/A1.err" & CPID=$!
186 fsleep "$off"
187 kill_daemon; wait "$CPID" 2>/dev/null
188 start_daemon d2 || { chk daemon_2_up false; cx REC recover >/dev/null 2>&1; start_daemon d3; }
189 eval_restart restart "$PD0" || bad=$((bad + 1))
190 grep -q 'record mark advanced' "$R/d2.log" 2>/dev/null && adv=$((adv + 1))
191 ALLCHECKS=$(jq -c --argjson t "$t" --argjson off "$off" --argjson ad "$(grep -q 'record mark advanced' "$R/d2.log" 2>/dev/null && echo true || echo false)" \
192 --argjson ok "$(jq 'all(.ok)' <<<"$CHECKS")" '. + [{check:"trial_\($t)_restart_consistent", ok:$ok, value:{offset_ms:$off, record_mark_advanced:$ad}}]' <<<"$ALLCHECKS")
193 stop_daemon
194done
195R=$W5R; CHECKS=$ALLCHECKS
196chk all_trials_consistent "$(eq "$bad" 0)" "$bad"
197chk window_hit_at_least_once "$( [ "$adv" -ge 1 ] && echo true || echo false)" "$(q "$adv of $TRIALS restarts logged record mark advanced")"
198[ "$adv" -ge 1 ] || NOTRUN="no trial hit the window (no restart logged: record mark advanced)"
199emit W5 1 "$(verdict_of)" "$TRIALS trials, offsets (ms)${offs}; restarts that advanced the mark: $adv; inconsistent: $bad"