Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/docs/campaigns/next-phase-2/run-faults.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / docs / campaigns / next-phase-2 / run-faults.sh` 738 lines ยท 45671 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 # NEXT-PHASE-2 fault harness (ACCEPTANCE-v2.md, amended by ACCEPTANCE-v3.md and ACCEPTANCE-v4.md). 18 # Shell + jq only, no Python. 19 # 20 # run-faults.sh fixture FIX_ROOT 21 # F0: one real S0..S3 on the gpu build (AIEN_BIN), then Shutdown. 22 # Needs AIEN_MODEL_PATH, AIEN_TOKENIZER_PATH, AIEN_REQUIRE_BLACKWELL=1, 23 # and a GPU window: run it under `quietlock hold` (<= 20 min) with the 24 # announce and release whispers, as NEXT-PHASE-1 did. 25 # run-faults.sh cases FIX_ROOT RUN_ROOT [CASE ...] 26 # Every case of ACCEPTANCE-v2 section 5 on the cpu-fault build 27 # (AIEN_BIN built with the compose archive, no GPU archive, feature 28 # fault-hold). Never touches the GPU: a daemon whose Backend line is not 29 # CPU-reference stops the harness. CASE = control C1a C1b C2a C2b C2c C2d 30 # C3a C3b C4 C5a C5b C5c C6a..C6h C6c-ctl C6i C7a C7b C7c C8a C8b (default: 31 # all). REPS (default 3); C6i always runs once (ACCEPTANCE-v3 DECIDED 4). 32 # C8a needs FIX_OLD = the v2 fixture F0v2 (no record mark), else NOT_RUN. 33 # 34 # Each run starts from a byte copy of F0 in RUN_ROOT/-/ with its own 35 # provenance and state dirs, and writes result.json there; RUN_ROOT/results.jsonl 36 # collects them. make-receipt.sh turns RUN_ROOT into the content-addressed receipt. 37 set -u 38 BIN=${AIEN_BIN:?AIEN_BIN} 39 MODE=${1:?fixture|cases} 40 FIX=${2:?FIX_ROOT} 41 REPS=${REPS:-3} 42 GOAL='Create the file NOTES.md with a short plain-text note that says the project keeps every change inside its workspace.' 43 CONSTRAINT='Project constraints: every change stays inside the authorized workspace; one file per change; plain text only; no network.' 44 45 now_ms() { echo $(( $(date +%s%N) / `1000000` )); } 46 sha() { sha256sum "$1" 2>/dev/null | cut -d' ' -f1; } 47 tstat() { stat -c '%i %s %.9Y %.9Z' "$1" 2>/dev/null || echo absent; } 48 tree_list() { (cd "$1" && find . -type f -print0 | sort -z | xargs -0 -r sha256sum); } 49 tree_digest() { tree_list "$1" | sha256sum | cut -d' ' -f1; } 50 # The home's files: compose dir, machine root, record mark (ACCEPTANCE-v3 2.1). 51 home_digest() { (tree_list "$1/compose"; sha256sum "$1/compose.machine-root"; [ -f "$1/compose.cortex-mark" ] && sha256sum "$1/compose.cortex-mark") | sha256sum | cut -d' ' -f1; } 52 mark_records() { od -An -tu8 -j56 -N8 "$1" 2>/dev/null | tr -d ' '; } 53 54 DPID=; NOTRUN= 55 # Never leave a daemon of ours behind, whatever stops the harness. 56 trap '[ -n "$DPID" ] && kill -0 "$DPID" 2>/dev/null && kill -9 "$DPID" 2>/dev/null' EXIT 57 # start_daemon NAME: wait for the socket and the Reconcile: line (rc 0), or 58 # for the process to exit (rc 1). 59 start_daemon() { 60 local log=$R/$1.log i=0 61 [ -n "${KEEP_SOCK:-}" ] || rm -f "$R/aien.sock" # C7c keeps a left socket file 62 (cd "$R" && exec setsid "$BIN" daemon >"$log" 2>&1 /dev/null && [ $i -lt 1200 ]; do 65 if [ -S "$R/aien.sock" ] && grep -q '^Reconcile:' "$log"; then break; fi 66 sleep 0.1; i=$((i + 1)) 67 done 68 if ! kill -0 "$DPID" 2>/dev/null; then wait "$DPID" 2>/dev/null; DRC=$?; return 1; fi 69 if [ "$MODE" = cases ] && ! grep -q 'Backend:.*CPU-reference' "$log"; then 70 echo "harness: daemon $1 is not the CPU build; stopping (no GPU use allowed here)" >&2 71 kill -9 "$DPID"; exit 9 72 fi 73 [ -S "$R/aien.sock" ] && grep -q '^Reconcile:' "$log" 74 } 75 stop_daemon() { 76 "$BIN" compose shutdown >/dev/null 2>&1 77 local i=0; while kill -0 "$DPID" 2>/dev/null && [ $i -lt 300 ]; do sleep 0.1; i=$((i + 1)); done 78 wait "$DPID" 2>/dev/null; rm -f "$R/aien.sock" 79 } 80 kill_daemon() { kill -9 "$DPID" 2>/dev/null; wait "$DPID" 2>/dev/null; rm -f "$R/aien.sock"; } 81 reconcile_line() { grep -m1 '^Reconcile:' "$R/$1.log"; } 82 83 # cx ID ARGS...: one `aien compose` call; stdout kept as steps/ID.json. 84 cx() { 85 local id=$1; shift 86 "$BIN" compose "$@" >"$R/steps/$id.json" 2>"$R/steps/$id.err" 87 local rc=$?; echo "$rc" >"$R/steps/$id.rc"; return $rc 88 } 89 j() { jq -r "$2" "$R/steps/$1.json" 2>/dev/null; } 90 refusal() { j "$1" '.error // ""' | sed -n 's/^EFFECT_REFUSED \([A-Za-z]*\):.*/\1/p'; } 91 authorize() { cx "$1" authorize --report "$R/s3-report.json" --workspace "$WS" --approver drake --desk 1; j "$1" '.authorization.id // empty'; } 92 execute() { cx "$1" execute --report "$R/s3-report.json" --workspace "$WS" --authorization "$2"; } 93 94 # exec_hold POINT ID AUTH: execute in the background, stopped at POINT. 95 EPID=; ERC= 96 exec_hold() { 97 rm -f "$R/hold" 98 AIEN_FAULT_HOLD=$1 AIEN_FAULT_HOLD_FILE=$R/hold "$BIN" compose execute --report "$R/s3-report.json" \ 99 --workspace "$WS" --authorization "$3" >"$R/steps/$2.json" 2>"$R/steps/$2.err" & 100 EPID=$! 101 local i=0 102 while [ ! -s "$R/hold" ] && kill -0 "$EPID" 2>/dev/null && [ $i -lt 600 ]; do sleep 0.05; i=$((i + 1)); done 103 [ -s "$R/hold" ] 104 } 105 release() { rm -f "$R/hold"; wait "$EPID"; ERC=$?; echo "$ERC" >"$R/steps/$1.rc"; } 106 kill_executor() { kill -9 "$EPID" 2>/dev/null; wait "$EPID"; ERC=$?; echo "$ERC" >"$R/steps/$1.rc"; rm -f "$R/hold"; } 107 108 CHECKS='[]' 109 chk() { CHECKS=$(jq -c --arg n "$1" --argjson ok "$2" --argjson v "${3:-null}" '. + [{check:$n, ok:$ok, value:$v}]' <<<"$CHECKS"); } 110 eq() { [ "$1" = "$2" ] && echo true || echo false; } 111 q() { jq -Rn --arg s "$1" '$s'; } 112 113 ledger() { cx "$1" effects >/dev/null; } 114 # phases ID PHASE INTENT_OR_AUTH_KEY VALUE: count effect notes of PHASE whose KEY == VALUE. 115 phases() { j "$1" "[.effects[].text | fromjson? | select(.phase == \"$2\" and .$3 == $4)] | length"; } 116 intent_state() { j "$1" "[.ledger.intents[] | select(.authorization == $2)] | .[0].state // \"none\""; } 117 118 # ---------------------------------------------------------------- fixture 119 if [ "$MODE" = fixture ]; then 120 : "${AIEN_MODEL_PATH:?}" "${AIEN_TOKENIZER_PATH:?}" 121 R=$FIX; rm -rf "$R"; mkdir -p "$R"/ws/docs "$R"/outside "$R"/compose "$R"/prov "$R"/state "$R"/steps 122 R=$(cd "$R" && pwd); WS=$R/ws 123 export AIEN_COMPOSE_DIR=$R/compose AIEN_PROVENANCE_DIR=$R/prov AIEN_RUNTIME_SOCK=$R/aien.sock \ 124 AIEN_RUNTIME_STATE_DIR=$R/state AIEN_REQUIRE_CHECKPOINT=1 125 printf '# Demo project\n\nA small local project used by the NEXT-PHASE-2 campaign.\n' >"$WS/README.md" 126 printf 'Plan: keep notes short and local.\n' >"$WS/docs/plan.txt" 127 printf 'sentinel outside the authorized workspace\n' >"$R/outside/sentinel.txt" 128 # sc#328: the daemon requires the approval desk key (copied into every run with the fixture). 129 "$BIN" compose desk-key --create 1 >/dev/null || { echo "desk key create failed"; exit 2; } 130 t0=$(now_ms) 131 start_daemon daemon-fixture || { echo "fixture daemon failed"; tail -5 "$R/daemon-fixture.log"; exit 2; } 132 t1=$(now_ms) 133 cx S0 recall 134 cx S1 remember --text "$CONSTRAINT" 135 cx S2 inspect --workspace "$WS" 136 cx S3 propose --goal "$GOAL" --workspace "$WS" 137 jq '.report' "$R/steps/S3.json" >"$R/s3-report.json" 138 stop_daemon 139 jq -n --arg backend "$(grep -m1 'Backend:' "$R/daemon-fixture.log" | sed 's/\x1b\[[0-9;]*m//g; s/^ *Backend: //')" \ 140 --arg reconcile "$(reconcile_line daemon-fixture)" --argjson start_ms $((t1 - t0)) \ 141 --slurpfile s3 "$R/steps/S3.json" --arg files "$( (tree_list "$R/compose"; sha256sum "$R/compose.machine-root"; [ -f "$R/compose.cortex-mark" ] && sha256sum "$R/compose.cortex-mark"; tree_list "$WS") | sha256sum | cut -d' ' -f1)" \ 142 '{backend:$backend, reconcile:$reconcile, daemon_start_ms:$start_ms, s3_ok:($s3[0].ok // false), 143 s3_committed:($s3[0].report.committed // false), proposal_path:($s3[0].report.proposal_path // null), 144 machine_id:($s3[0].report.machine_id // null), files_sha256:$files}' >"$R/fixture.json" 145 cat "$R/fixture.json" 146 exit 0 147 fi 148 149 # ---------------------------------------------------------------- cases 150 ROOT=${3:?RUN_ROOT}; shift 3 151 mkdir -p "$ROOT"; ROOT=$(cd "$ROOT" && pwd); FIX=$(cd "$FIX" && pwd) 152 jq -e '.s3_committed == true' "$FIX/fixture.json" >/dev/null || { echo "fixture F0 has no committed proposal: cases NOT_RUN"; exit 3; } 153 PPATH=$(jq -r .proposal_path "$FIX/fixture.json") 154 CASES=${*:-control C1a C1b C2a C2b C2c C2d C3a C3b C4 C5a C5b C5c C6a C6b C6c C6c-ctl C6d C6e C6f C6g C6h C6i C7a C7b C7c C8a C8b} 155 156 new_run() { # NAME [FIXTURE] 157 local from=${2:-$FIX} 158 R=$ROOT/$1; rm -rf "$R"; mkdir -p "$R"/prov "$R"/state "$R"/steps 159 cp -a "$from/compose" "$from/compose.machine-root" "$from/ws" "$from/outside" "$from/s3-report.json" "$R/" 160 [ -f "$from/compose.cortex-mark" ] && cp -a "$from/compose.cortex-mark" "$R/" 161 WS=$R/ws; T=$WS/$PPATH; CHECKS='[]'; INJ=; OUTCOME=; NOTRUN=; NOTAPPL=; NO_R6= 162 export AIEN_COMPOSE_DIR=$R/compose AIEN_PROVENANCE_DIR=$R/prov AIEN_RUNTIME_SOCK=$R/aien.sock \ 163 AIEN_RUNTIME_STATE_DIR=$R/state AIEN_REQUIRE_CHECKPOINT=0 164 unset AIEN_MODEL_PATH AIEN_TOKENIZER_PATH AIEN_REQUIRE_BLACKWELL AIEN_GPU_BACKEND AIEN_FAULT_HOLD AIEN_FAULT_HOLD_FILE KEEP_SOCK 165 T0=$(tstat "$T"); WS0=$(tree_list "$WS"); OUT0=$(tree_digest "$R/outside") 166 } 167 168 # pre_state ID: machine id, record count and prefix digest before the fault. 169 pre_state() { 170 cx "$1" recall >/dev/null 171 N0=$(j "$1" .recall.records_total); MID0=$(j "$1" .machine_id); MIDF0=$(sha "$R/compose/machine.id") 172 cx "$1-prefix" recall --prefix "$N0" >/dev/null; PD0=$(j "$1-prefix" .recall.prefix_digest) 173 } 174 175 # rules ID: R1..R4 of ACCEPTANCE-v2 section 3, on the final state (daemon up). 176 rules() { 177 cx "$1-recall" recall --prefix "$N0" >/dev/null 178 chk R4_machine_id "$(eq "$(j "$1-recall" .machine_id)" "$MID0")" "$(jq -nc --arg a "$MID0" --arg b "$(j "$1-recall" .machine_id)" '[$a,$b]')" 179 chk R4_machine_id_file "$(eq "$(sha "$R/compose/machine.id")" "$MIDF0")" 180 chk R4_prefix_digest "$(eq "$(j "$1-recall" .recall.prefix_digest)" "$PD0")" "$(jq -nc --arg a "$PD0" --arg b "$(j "$1-recall" .recall.prefix_digest)" '[$a,$b]')" 181 ledger "$1-ledger" 182 local auths intents ok_true receipts_true done_n changed 183 auths=$(j "$1-recall" '[.authorizations[] | select(.verified) | {id, g: (.text | fromjson? // {})}]') 184 intents=$(j "$1-ledger" '.ledger.intents') 185 chk R1_intents_cite_earlier_matching_grants "$(jq -n --argjson a "$auths" --argjson i "$intents" \ 186 '[$i[] | . as $r | ($a | map(select(.id == $r.authorization)) | .[0].g) as $g 187 | select($g == null or $r.authorization >= $r.intent or $g.path != $r.path 188 or $g.content_sha256 != $r.content_sha256 or $g.target != $r.target)] | length == 0')" "$(jq -nc --argjson i "$intents" '[$i[].intent]')" 189 changed=$(diff <(echo "$WS0") <(tree_list "$WS") | sed -n 's/^[<>] [0-9a-f]* \.\///p' | sort -u | jq -R . | jq -sc .) 190 chk R1_workspace_only_proposal_path "$(jq -n --argjson c "$changed" --arg p "$PPATH" '$c - [$p] | length == 0')" "$changed" 191 chk R1_outside_unchanged "$(eq "$(tree_digest "$R/outside")" "$OUT0")" 192 chk R2_one_intent_per_authorization "$(jq -n --argjson i "$intents" '[$i[].authorization] | length == (unique | length)')" 193 done_n=$(jq -n --argjson i "$intents" '[$i[] | select(.state == "DONE")] | length') 194 receipts_true=0 195 for p in "$R"/prov/*.json; do 196 [ -f "$p" ] || continue 197 [ "$(jq -r '.tool + ":" + (.success|tostring)' "$p")" = "write_file:true" ] && receipts_true=$((receipts_true + 1)) 198 done 199 chk R2_success_receipts_le_done_intents "$( [ "$receipts_true" -le "$done_n" ] && echo true || echo false)" "[$receipts_true,$done_n]" 200 ok_true=$(for f in "$R"/steps/*.json; do jq -c 'select(.step == "S5" and .ok == true) | .state' "$f" 2>/dev/null; done | sort -u | paste -sd, -) 201 chk R3_execute_ok_only_when_done "$( [ -z "$ok_true" ] || [ "$ok_true" = '"DONE"' ] && echo true || echo false)" "$(q "$ok_true")" 202 chk R3_done_means_content_on_disk "$(jq -n --argjson i "$intents" --arg t "$(sha "$T")" \ 203 '[$i[] | select(.state == "DONE") | .content_sha256] | unique | (length == 0) or (. == [$t])')" 204 } 205 206 finish() { # NAME REP 207 local verdict 208 # R6 (ACCEPTANCE-v3 section 3): no E_MARK in any start line, recall or execute 209 # answer of a control, C1..C5, C6c-ctl, C7a, C7c (ACCEPTANCE-v4) or C8 run. 210 case $1 in control-*|C1*|C2*|C3*|C4*|C5*|C6c-ctl|C7a|C7c|C8*) 211 local em; em=$(cd "$R" && grep -l 'E_MARK' daemon-*.log steps/*.json 2>/dev/null | paste -sd, -) 212 chk R6_no_E_MARK "$( [ -z "$em" ] && echo true || echo false)" "$(q "$em")";; 213 esac 214 verdict=$(jq -r 'if length > 0 and all(.ok) then "PASS" else "FAIL" end' <<<"$CHECKS") 215 # C6d guard (DECIDED 3): an uninjected run whose checks all hold is 216 # NOT_APPLICABLE, never PASS; a failed check stays FAIL. 217 [ -n "$NOTAPPL" ] && [ "$verdict" = PASS ] && verdict=NOT_APPLICABLE 218 [ -n "$NOTRUN" ] && verdict=NOT_RUN 219 local ev 220 ev=$(cd "$R" && find steps -maxdepth 1 -type f -name '*.json' -o -maxdepth 1 -name 'daemon-*.log' | sort | while read -r f; do 221 jq -nc --arg f "$f" --arg s "$(sha "$R/$f")" '{file:$f, sha256:$s}'; done | jq -sc .) 222 ev=$(jq -c --argjson more "$(cd "$R" && for f in daemon-*.log; do [ -f "$f" ] && jq -nc --arg f "$f" --arg s "$(sha "$R/$f")" '{file:$f, sha256:$s}'; done | jq -sc .)" '. + $more' <<<"$ev") 223 jq -n --arg row "$1" --argjson rep "$2" --arg inj "$INJ" --arg out "$OUTCOME" --argjson checks "$CHECKS" \ 224 --arg verdict "$verdict" --argjson ev "$ev" --arg root "$R" \ 225 '{row:$row, rep:$rep, injected_at:$inj, outcome:$out, verdict:$verdict, checks:$checks, evidence_digests:$ev, run_root:$root}' \ 226 >"$R/result.json" 227 jq -c . "$R/result.json" >>"$ROOT/results.jsonl" 228 echo "$1 rep $2: $verdict $OUTCOME" 229 jq -r '.checks[] | select(.ok | not) | " FAILED \(.check) \(.value)"' "$R/result.json" 230 } 231 232 up() { start_daemon "$1" || { chk "daemon_$1_up" false "$(q "$(tail -3 "$R/$1.log" | tr '\n' ' ')")"; return 1; }; chk "daemon_$1_up" true; } 233 234 run_control() { 235 INJ="none (uninjected control)" 236 up daemon-1 || return 237 chk reconcile_at_start_nothing_open "$(reconcile_line daemon-1 | grep -q 'checked 0' && echo true || echo false)" "$(q "$(reconcile_line daemon-1)")" 238 pre_state pre 239 A1=$(authorize A1) 240 execute X1 "$A1"; chk execute_done "$(eq "$(j X1 .state)" DONE)" "$(q "$(j X1 .state)")" 241 T1=$(tstat "$T") 242 chk written "$( [ "$T1" != "$T0" ] && echo true || echo false)" 243 execute X2 "$A1"; chk retry_refused_AlreadySpent "$(eq "$(refusal X2)" AlreadySpent)" "$(q "$(refusal X2)")" 244 chk retry_no_write "$(eq "$(tstat "$T")" "$T1")" 245 stop_daemon; up daemon-2 || return 246 chk restart_reconcile_nothing_open "$(reconcile_line daemon-2 | grep -q 'checked 0' && echo true || echo false)" "$(q "$(reconcile_line daemon-2)")" 247 rules final; stop_daemon 248 OUTCOME="DONE once; retry AlreadySpent; restart clean" 249 } 250 251 run_C1() { # $1 = a|b 252 INJ="hold after_write; SIGKILL daemon; release (ack lost)$([ "$1" = b ] && echo '; harness overwrites target before restart')" 253 up daemon-1 || return; pre_state pre 254 A1=$(authorize A1) 255 exec_hold after_write X1 "$A1" || { chk hold_reached false; return; } 256 T1=$(tstat "$T"); chk written_before_ack "$( [ "$T1" != "$T0" ] && echo true || echo false)" 257 kill_daemon; release X1 258 chk executor_exit_3 "$(eq "$ERC" 3)" "$ERC" 259 chk executor_state_UNRESOLVED "$(eq "$(j X1 .state)" UNRESOLVED)" "$(q "$(j X1 .state)")" 260 chk executor_ok_false "$(eq "$(j X1 .ok)" false)" 261 chk receipt_success_false "$(eq "$(j X1 .receipt.success)" false)" 262 chk written_once_so_far "$(eq "$(tstat "$T")" "$T1")" 263 if [ "$1" = b ]; then 264 printf 'harness bytes, not the proposal\n' >"$T"; T1=$(tstat "$T"); TH=$(sha "$T") 265 fi 266 up daemon-2 || return 267 local rl; rl=$(reconcile_line daemon-2) 268 ledger L1; local st; st=$(intent_state L1 "$A1") 269 cx RC1 recall >/dev/null 270 local I; I=$(j L1 "[.ledger.intents[] | select(.authorization == $A1)] | .[0].intent") 271 chk intent_has_no_ack "$(eq "$(phases RC1 ack intent "$I")" 0)" 272 if [ "$1" = a ]; then 273 chk restart_reconcile_DONE "$(echo "$rl" | grep -q 'DONE 1,' && echo true || echo false)" "$(q "$rl")" 274 chk ledger_DONE "$(eq "$st" DONE)" "$(q "$st")" 275 execute X2 "$A1"; chk retry_refused_AlreadySpent "$(eq "$(refusal X2)" AlreadySpent)" "$(q "$(refusal X2)")" 276 OUTCOME="ack lost -> UNRESOLVED (exit $ERC) -> restart reconcile $st; retry $(refusal X2)" 277 else 278 chk restart_reconcile_UNRESOLVED "$(echo "$rl" | grep -q 'UNRESOLVED 1 recorded' && echo true || echo false)" "$(q "$rl")" 279 chk ledger_UNRESOLVED "$(eq "$st" UNRESOLVED)" "$(q "$st")" 280 execute X2 "$A1"; chk retry_refused_ReconciliationRequired "$(eq "$(refusal X2)" ReconciliationRequired)" "$(q "$(refusal X2)")" 281 ledger L2; chk R5_effects_lists_UNRESOLVED "$(eq "$(intent_state L2 "$A1")" UNRESOLVED)" 282 cx D1 reconcile --intent "$I" --declare not_done --approver drake 283 chk declare_NOT_DONE "$(eq "$(j D1 '.reconcile.outcomes[0].state')" NOT_DONE)" "$(q "$(j D1 '.reconcile.outcomes[0].state')")" 284 execute X3 "$A1"; chk retry_after_declare_AlreadySpent "$(eq "$(refusal X3)" AlreadySpent)" "$(q "$(refusal X3)")" 285 chk harness_bytes_kept "$(eq "$(sha "$T")" "$TH")" 286 OUTCOME="ack lost + world changed -> restart UNRESOLVED; retry $(refusal X2); operator NOT_DONE; retry $(refusal X3)" 287 fi 288 chk no_second_write "$(eq "$(tstat "$T")" "$T1")" 289 rules final; stop_daemon 290 } 291 292 run_C2a() { 293 INJ="hold before_intent; SIGKILL daemon; release" 294 up daemon-1 || return; pre_state pre 295 A1=$(authorize A1) 296 cx count1 recall >/dev/null; local n1; n1=$(j count1 .recall.records_total) 297 exec_hold before_intent X1 "$A1" || { chk hold_reached false; return; } 298 kill_daemon; release X1 299 chk executor_refused "$(eq "$(j X1 .ok)" false)" "$(q "$(j X1 .error)")" 300 chk no_write "$(eq "$(tstat "$T")" "$T0")" 301 up daemon-2 || return 302 # ACCEPTANCE-v3 C2a (rule frozen, G1): a daemon open appends exactly the 5 303 # start-up records (class 1, kind 65538, subjects 1..5), nothing else. 304 local n2 h1 h2 ids; n1=${n1:-0}; ids=$(seq -s, $((n1 + 1)) $((n1 + 5))) 305 cx count2 recall --ids "$ids" >/dev/null 306 n2=$(j count2 .recall.records_total); h1=$(j count1 '.recall.host | length'); h2=$(j count2 '.recall.host | length') 307 chk host_record_count_unchanged "$(eq "$h2" "$h1")" "[$h1,$h2]" 308 chk records_total_is_before_plus_5 "$(eq "$n2" $((n1 + 5)))" "{\"before_kill\":$n1,\"after_restart\":$n2}" 309 local seen; seen=$(j count2 '[.recall.cited[] | {id, cls, kind, subject}]') 310 chk startup_records_are_5_entity_creates "$(jq -n --argjson s "$seen" --argjson lo $((n1 + 1)) \ 311 '($s | length == 5) and ([$s[] | select(.cls == 1 and .kind == 65538)] | length == 5) 312 and ([$s[].subject] | sort == [1,2,3,4,5]) and ([$s[].id] | sort == [range($lo; $lo + 5)])')" "$(jq -nc --argjson s "$seen" '$s')" 313 ledger L1; chk no_intent "$(eq "$(intent_state L1 "$A1")" none)" 314 execute X2 "$A1"; chk same_grant_executes_after_restart "$(eq "$(j X2 .state)" DONE)" "$(q "$(j X2 .state)")" 315 T1=$(tstat "$T"); execute X3 "$A1" 316 chk no_second_write "$(eq "$(tstat "$T")" "$T1")" 317 OUTCOME="refused while daemon dead (no intent, no write); after restart DONE once" 318 rules final; stop_daemon 319 } 320 321 run_C2bcd() { # b|c|d 322 local point=after_intent; [ "$1" = d ] && point=after_write 323 case $1 in 324 b) INJ="hold after_intent; SIGKILL executor (daemon up)";; 325 c) INJ="hold after_intent; SIGKILL daemon then executor; restart";; 326 d) INJ="hold after_write; SIGKILL executor (daemon up)";; 327 esac 328 up daemon-1 || return; pre_state pre 329 A1=$(authorize A1) 330 exec_hold "$point" X1 "$A1" || { chk hold_reached false; return; } 331 [ "$1" = c ] && kill_daemon 332 kill_executor X1 333 T1=$(tstat "$T") 334 if [ "$1" = d ]; then chk written "$( [ "$T1" != "$T0" ] && echo true || echo false)"; else chk no_write "$(eq "$T1" "$T0")"; fi 335 local want=NOT_DONE; [ "$1" = d ] && want=DONE 336 if [ "$1" = c ]; then 337 up daemon-2 || return 338 chk restart_reconcile_NOT_DONE "$(reconcile_line daemon-2 | grep -q 'NOT_DONE 1,' && echo true || echo false)" "$(q "$(reconcile_line daemon-2)")" 339 cx RC2 recall >/dev/null 340 chk recall_shows_intent "$(eq "$(phases RC2 intent authorization "$A1")" 1)" 341 chk recall_shows_reconcile_record "$(eq "$(phases RC2 reconcile authorization "$A1")" 1)" 342 else 343 execute X2 "$A1"; chk retry_refused_ReconciliationRequired "$(eq "$(refusal X2)" ReconciliationRequired)" "$(q "$(refusal X2)")" 344 cx RC reconcile 345 chk reconcile_records_$want "$(eq "$(j RC '.reconcile.outcomes[0].state')" $want)" "$(q "$(j RC '.reconcile.outcomes[0].state')")" 346 fi 347 ledger L1; chk ledger_$want "$(eq "$(intent_state L1 "$A1")" $want)" 348 execute X3 "$A1"; chk retry_refused_AlreadySpent "$(eq "$(refusal X3)" AlreadySpent)" "$(q "$(refusal X3)")" 349 chk no_write_by_retry "$(eq "$(tstat "$T")" "$T1")" 350 OUTCOME="executor killed at $point -> $(intent_state L1 "$A1"); retry $(refusal X3)" 351 if [ "$1" = b ]; then 352 A2=$(authorize A2); execute X4 "$A2" 353 chk new_grant_DONE "$(eq "$(j X4 .state)" DONE)" "$(q "$(j X4 .state)")" 354 cx RC3 recall >/dev/null 355 local na; na=$(( $(j RC3 '.authorizations | length') - $(j pre '.authorizations | length') )) 356 chk approvals_2_both_counted "$(eq "$na" 2)" "$na" 357 OUTCOME="$OUTCOME; new grant A2 DONE (approvals $na)" 358 fi 359 rules final; stop_daemon 360 } 361 362 run_C3a() { 363 INJ="cpu-fault daemon started with AIEN_REQUIRE_BLACKWELL=1" 364 local before; before=$(home_digest "$R") 365 export AIEN_REQUIRE_BLACKWELL=1 366 if start_daemon daemon-1; then chk daemon_refused false; kill_daemon; else chk daemon_refused true "$DRC"; fi 367 unset AIEN_REQUIRE_BLACKWELL 368 chk exit_nonzero "$( [ "${DRC:-0}" != 0 ] && echo true || echo false)" "${DRC:-0}" 369 chk names_gb10_requirement "$(grep -q 'GB10 GPU is required' "$R/daemon-1.log" && echo true || echo false)" "$(q "$(grep -m1 Fatal "$R/daemon-1.log" | sed 's/\x1b\[[0-9;]*m//g')")" 370 chk no_socket "$( [ -S "$R/aien.sock" ] && echo false || echo true)" 371 chk home_unchanged "$(eq "$(home_digest "$R")" "$before")" 372 chk workspace_unchanged "$(eq "$(tree_list "$WS")" "$WS0")" 373 OUTCOME="refused: $(grep -m1 Fatal "$R/daemon-1.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-120)" 374 } 375 376 run_C3b() { 377 INJ="cpu-fault daemon, no GPU requirement; S3 propose" 378 up daemon-1 || return; pre_state pre 379 chk backend_cpu_reference "$(grep -q 'Backend:.*CPU-reference' "$R/daemon-1.log" && echo true || echo false)" "$(q "$(grep -m1 'Backend:' "$R/daemon-1.log" | sed 's/\x1b\[[0-9;]*m//g')")" 380 cx P1 propose --goal "$GOAL" --workspace "$WS" 381 local committed; committed=$(j P1 'if .report.committed == null then "none" else (.report.committed | tostring) end') 382 chk propose_outcome_explicit "$( { [ "$committed" = true ] || { [ "$committed" = false ] && [ -n "$(j P1 '.report.proposer_error // .report.uncommitted_proposal // empty')" ]; } || [ "$(j P1 .ok)" = false ]; } && echo true || echo false)" "$(q "committed=$committed $(j P1 '.report.proposer_error // .error // ""' | cut -c1-160)")" 383 chk no_gpu_claim "$(grep -qi 'OmegaGb10Backend (native' "$R/daemon-1.log" "$R/steps/P1.json" && echo false || echo true)" 384 ledger L1; chk no_intents "$(eq "$(j L1 '.ledger.intents | length')" 0)" 385 chk workspace_unchanged "$(eq "$(tree_list "$WS")" "$WS0")" 386 OUTCOME="CPU-reference daemon; propose committed=$committed" 387 rules final; stop_daemon 388 } 389 390 run_C4() { 391 INJ="authorize A1; stop; execute; Shutdown+restart; execute; resume; execute; authorize A2; execute" 392 up daemon-1 || return; pre_state pre 393 A1=$(authorize A1) 394 cx STOP stop --approver drake 395 execute X1 "$A1"; chk stopped_refused "$(eq "$(refusal X1)" Stopped)" "$(q "$(refusal X1)")" 396 stop_daemon; up daemon-2 || return 397 execute X2 "$A1"; chk stop_survives_restart "$(eq "$(refusal X2)" Stopped)" "$(q "$(refusal X2)")" 398 cx RESUME resume --approver drake 399 execute X3 "$A1"; chk old_grant_stale "$(eq "$(refusal X3)" Stale)" "$(q "$(refusal X3)")" 400 chk zero_writes_until_A2 "$(eq "$(tstat "$T")" "$T0")" 401 A2=$(authorize A2); execute X4 "$A2" 402 chk new_grant_DONE "$(eq "$(j X4 .state)" DONE)" "$(q "$(j X4 .state)")" 403 T1=$(tstat "$T"); execute X5 "$A2" 404 chk written_once "$(eq "$(tstat "$T")" "$T1")" 405 OUTCOME="$(refusal X1), $(refusal X2) after restart, $(refusal X3) after resume; A2 $(j X4 .state)" 406 rules final; stop_daemon 407 } 408 409 run_C5() { # a|b|c 410 up daemon-1 || return; pre_state pre 411 A1=$(authorize A1) 412 case $1 in 413 a) INJ="revoke A1 before execute" 414 cx RV revoke --authorization "$A1" --approver drake 415 chk revoke_true "$(eq "$(j RV .control.revoked)" true)" 416 execute X1 "$A1"; chk refused_Revoked "$(eq "$(refusal X1)" Revoked)" "$(q "$(refusal X1)")" 417 chk no_write "$(eq "$(tstat "$T")" "$T0")" 418 OUTCOME="revoked:true; execute $(refusal X1)";; 419 b) INJ="execute A1 to DONE, then revoke A1" 420 execute X1 "$A1"; chk execute_done "$(eq "$(j X1 .state)" DONE)" 421 cx n1 recall >/dev/null 422 cx RV revoke --authorization "$A1" --approver drake 423 chk revoke_false "$(eq "$(j RV .control.revoked)" false)" 424 chk nothing_recorded "$(eq "$(j RV .control.recorded)" null)" 425 cx n2 recall >/dev/null 426 chk record_count_unchanged "$(eq "$(j n2 .recall.records_total)" "$(j n1 .recall.records_total)")" 427 OUTCOME="revoke after spend: revoked:$(j RV .control.revoked), nothing recorded";; 428 c) INJ="authorize A1; harness writes other bytes to the target; execute A1" 429 mkdir -p "$(dirname "$T")"; printf 'changed by someone else after the grant\n' >"$T"; local th; th=$(tstat "$T") 430 execute X1 "$A1"; chk refused_Stale "$(eq "$(refusal X1)" Stale)" "$(q "$(refusal X1)")" 431 chk target_untouched "$(eq "$(tstat "$T")" "$th")" 432 OUTCOME="world changed after grant: $(refusal X1)";; 433 esac 434 rules final; stop_daemon 435 } 436 437 c6_base() { # control run plus one unspent grant A2, daemon stopped 438 up daemon-1 || return 1; pre_state pre 439 A1=$(authorize A1); execute X1 "$A1" 440 chk base_execute_done "$(eq "$(j X1 .state)" DONE)" 441 S1=$(stat -c %s "$R/compose/cortex.cx") 442 [ "${1:-}" = save_mark ] && cp "$R/compose.cortex-mark" "$R/mark-before-A2" 2>/dev/null 443 A2=$(authorize A2) 444 stop_daemon 445 T1=$(tstat "$T") 446 mkdir -p "$R/pre-damage" 447 (cd "$R" && cp -a --parents compose compose.machine-root state pre-damage/ 2>/dev/null 448 [ -f compose.cortex-mark ] && cp -a compose.cortex-mark pre-damage/) 449 return 0 450 } 451 452 # c6_score NAME GRANT FILE: the v2 C6 rule on the damaged home (ACCEPTANCE-v2 453 # section 5), plus the v3 mark rule (a refused start leaves the mark as it was). 454 c6_score() { 455 local d=$1 g=$2 f=$3 456 local dmg ds; dmg=$(sha "$R/damaged.bin"); ds=$(stat -c %s "$R/damaged.bin" 2>/dev/null || echo 0) 457 local refused=false 458 if start_daemon "$d"; then 459 local rl; rl=$(reconcile_line "$d") 460 cx RCL-$d recall 461 local rok; rok=$(j RCL-$d .ok) 462 execute X-$d "$g" 463 local named=false 464 if [ "$rok" = false ] && j RCL-$d .error | grep -Eq 'E_TORN|E_DIGEST|E_REPLAY|E_IDENTITY|E_MARK|expected 32|refused|CorruptLedger|digest'; then named=true; fi 465 chk named_refusal_on_recall "$named" "$(q "$(j RCL-$d '.error // "recall succeeded"' | cut -c1-240)")" 466 chk start_reconcile_reports "$( { echo "$rl" | grep -q 'refused' || [ "$named" = false ]; } && echo true || echo false)" "$(q "$(echo "$rl" | cut -c1-240)")" 467 chk execute_grant_refused "$(eq "$(j X-$d .ok)" false)" "$(q "$(j X-$d '.error // .state' | cut -c1-200)")" 468 echo "$rl" | grep -q 'refused' && refused=true 469 stop_daemon 470 OUTCOME="opened; recall ok=$rok; execute ok=$(j X-$d .ok); $(echo "$rl" | cut -c1-160)" 471 else 472 refused=true 473 chk daemon_refused_named "$(grep -Eq 'is damaged|Fatal' "$R/$d.log" && echo true || echo false)" "$(q "$(grep -m1 Fatal "$R/$d.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-200)")" 474 OUTCOME="daemon refused to start: $(grep -m1 Fatal "$R/$d.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-140)" 475 fi 476 chk no_write_on_damaged_state "$(eq "$(tstat "$T")" "$T1")" 477 if [ "$f" != compose/jspace/jspace.meta ] || [ -f "$R/damaged.bin" ]; then 478 # No silent repair or reset: every damaged byte is still there (records the 479 # daemon appends after a refusal-free open are allowed and shown). 480 local cs; cs=$(stat -c %s "$R/$f" 2>/dev/null || echo 0) 481 chk damaged_bytes_kept "$( [ "$cs" -ge "$ds" ] && cmp -s -n "$ds" "$R/damaged.bin" "$R/$f" && echo true || echo false)" "{\"damaged_sha256\":\"$dmg\",\"damaged_bytes\":$ds,\"now_bytes\":$cs}" 482 fi 483 # ACCEPTANCE-v3 section 5, C6a..h: compose.cortex-mark unchanged by a refused start. 484 if [ "$refused" = true ] && [ -f "$R/damaged-mark.bin" ]; then 485 chk mark_unchanged_by_refused_start "$(cmp -s "$R/damaged-mark.bin" "$R/compose.cortex-mark" && echo true || echo false)" "$(q "$(sha "$R/compose.cortex-mark")")" 486 fi 487 } 488 489 run_C6() { # a..i 490 c6_base || return 491 local f 492 case $1 in 493 a) f=compose/cortex.cx; INJ="truncate cortex.cx by 1 byte (inside the last record)" 494 truncate -s -1 "$R/$f";; 495 b) f=compose/cortex.cx; INJ="flip one byte inside the last record of cortex.cx" 496 local sz; sz=$(stat -c %s "$R/$f"); local off=$(( S1 + (sz - S1) / 2 )) 497 printf "$(printf '\\x%02x' $(( $(od -An -tu1 -j $off -N1 "$R/$f") ^ 0xff )))" | dd of="$R/$f" bs=1 seek=$off conv=notrunc 2>/dev/null;; 498 c) f=compose/cortex.cx; INJ="cut cortex.cx at the record boundary before the last record (A2 dropped)" 499 truncate -s "$S1" "$R/$f";; 500 d) run_C6d; return;; 501 e) f=compose/jspace/jspace.meta; INJ="flip one byte in the middle of jspace.meta" 502 local sz; sz=$(stat -c %s "$R/$f"); local off=$(( sz / 2 )) 503 printf "$(printf '\\x%02x' $(( $(od -An -tu1 -j $off -N1 "$R/$f") ^ 0xff )))" | dd of="$R/$f" bs=1 seek=$off conv=notrunc 2>/dev/null;; 504 f) f=compose.machine-root; INJ="truncate the machine root to 16 bytes" 505 truncate -s 16 "$R/$f";; 506 g) f=compose/machine.id; INJ="flip the first byte of machine.id" 507 printf "$(printf '\\x%02x' $(( $(od -An -tu1 -j 0 -N1 "$R/$f") ^ 0xff )))" | dd of="$R/$f" bs=1 seek=0 conv=notrunc 2>/dev/null;; 508 h) f=state/processed_operations.json; INJ="write '{' into processed_operations.json" 509 printf '{' >"$R/$f";; 510 i) f=compose/jspace/jspace.meta; INJ="delete jspace/jspace.meta (daemon stopped)" 511 rm -f "$R/$f";; 512 esac 513 if [ -f "$R/$f" ]; then cp "$R/$f" "$R/damaged.bin"; else rm -f "$R/damaged.bin"; fi 514 [ -f "$R/compose.cortex-mark" ] && cp "$R/compose.cortex-mark" "$R/damaged-mark.bin" 515 if [ -f "$R/$f" ] && cmp -s "$R/pre-damage/$f" "$R/$f"; then 516 NOTRUN="injection changed nothing: $f is $(stat -c %s "$R/$f") bytes before and after"; OUTCOME=$NOTRUN; return 517 fi 518 if [ ! -f "$R/$f" ] && [ ! -f "$R/pre-damage/$f" ]; then 519 NOTRUN="injection changed nothing: $f was already absent"; OUTCOME=$NOTRUN; return 520 fi 521 c6_score daemon-2 "$A2" "$f" 522 case $1 in 523 c) # ACCEPTANCE-v3 C6c: the cut is named E_MARK_TRUNCATED, nothing is rewritten. 524 chk start_line_refused_E_MARK_TRUNCATED "$(reconcile_line daemon-2 | grep -q 'Reconcile: refused.*E_MARK_TRUNCATED' && echo true || echo false)" "$(q "$(reconcile_line daemon-2 | cut -c1-240)")" 525 chk recall_refused_E_MARK_TRUNCATED "$( [ "$(j RCL-daemon-2 .ok)" = false ] && j RCL-daemon-2 .error | grep -q E_MARK_TRUNCATED && echo true || echo false)" "$(q "$(j RCL-daemon-2 '.error // "recall succeeded"' | cut -c1-240)")" 526 chk cortex_cx_identical_to_damaged "$(cmp -s "$R/damaged.bin" "$R/compose/cortex.cx" && echo true || echo false)" 527 chk mark_identical_to_damaged_state "$(cmp -s "$R/damaged-mark.bin" "$R/compose.cortex-mark" && echo true || echo false)";; 528 i) # ACCEPTANCE-v3 C6i: no silent re-creation; cortex.cx only grows by appends. 529 chk jspace_meta_still_absent "$( [ -e "$R/$f" ] && echo false || echo true)" "$(q "$(tstat "$R/$f")")" 530 local p0; p0=$(stat -c %s "$R/pre-damage/compose/cortex.cx") 531 chk cortex_cx_prefix_identical "$( [ "$(stat -c %s "$R/compose/cortex.cx")" -ge "$p0" ] && cmp -s -n "$p0" "$R/pre-damage/compose/cortex.cx" "$R/compose/cortex.cx" && echo true || echo false)" "{\"pre_bytes\":$p0,\"now_bytes\":$(stat -c %s "$R/compose/cortex.cx")}";; 532 esac 533 } 534 535 # C6d guard (ACCEPTANCE-v3 DECIDED 3). jspace.data is never written by compose 536 # at omega `62b6a28` (G6); spill_end is the u64 at offset 48 of jspace.meta. 537 c6d_trim() { 538 local f=$R/compose/jspace/jspace.data se; se=$(od -An -tu8 -j48 -N8 "$R/compose/jspace/jspace.meta" | tr -d ' ') 539 if [ "${se:-0}" -gt 0 ]; then truncate -s $((se - 1)) "$f"; INJ="truncate jspace.data to spill_end-1 = $((se - 1)) bytes" 540 else truncate -s -1 "$f"; INJ="truncate jspace.data by 1 byte (spill_end 0)"; fi 541 } 542 run_C6d() { 543 local f=compose/jspace/jspace.data ds se 544 ds=$(stat -c %s "$R/$f"); se=$(od -An -tu8 -j48 -N8 "$R/compose/jspace/jspace.meta" | tr -d ' ') 545 chk guard_read "$( [ -n "$ds" ] && [ -n "$se" ] && echo true || echo false)" "{\"data_bytes\":${ds:-null},\"spill_end\":${se:-null}}" 546 if [ "${ds:-0}" -gt 0 ] || [ "${se:-0}" -gt 0 ]; then 547 c6d_trim; cp "$R/$f" "$R/damaged.bin"; cp "$R/compose.cortex-mark" "$R/damaged-mark.bin" 2>/dev/null 548 c6_score daemon-2 "$A2" "$f"; return 549 fi 550 INJ="none: jspace.data 0 bytes and spill_end 0 (guard); case run uninjected" 551 up daemon-2 || return 552 cx RCL recall; chk recall_ok "$(eq "$(j RCL .ok)" true)" 553 execute X2 "$A2"; chk uninjected_A2_DONE "$(eq "$(j X2 .state)" DONE)" "$(q "$(j X2 '.state // .error')")" 554 A3=$(authorize A3) 555 stop_daemon 556 local de; de=$(stat -c %s "$R/$f") 557 if [ "$de" -eq 0 ]; then 558 chk end_of_case_jspace_data_still_0_bytes true 0 559 NOTAPPL=1; OUTCOME="NOT_APPLICABLE: jspace.data 0 bytes, spill_end 0 before and after the case (compose never spills at omega `62b6a28`)" 560 return 561 fi 562 # The guard fired late: inject now and score on the fresh grant A3. 563 chk end_of_case_jspace_data_still_0_bytes false "$de" 564 T1=$(tstat "$T") 565 rm -rf "$R/pre-damage"; mkdir -p "$R/pre-damage" 566 (cd "$R" && cp -a --parents compose compose.machine-root state pre-damage/ 2>/dev/null; cp -a compose.cortex-mark pre-damage/ 2>/dev/null) 567 c6d_trim; cp "$R/$f" "$R/damaged.bin"; cp "$R/compose.cortex-mark" "$R/damaged-mark.bin" 2>/dev/null 568 chk injected_late_after_guard true "$de" 569 c6_score daemon-3 "$A3" "$f" 570 } 571 572 # C6c-ctl: the on-disk state of a process that died after the A2 append and 573 # before its mark update (simulated: the older mark is put back). 574 run_C6c_ctl() { 575 c6_base save_mark || return 576 [ -f "$R/mark-before-A2" ] || { NOTRUN="no record mark before A2"; OUTCOME=$NOTRUN; return; } 577 INJ="put back the record mark copied just before authorize A2 (daemon stopped)" 578 cp "$R/mark-before-A2" "$R/compose.cortex-mark" 579 local m; m=$(mark_records "$R/compose.cortex-mark") 580 up daemon-2 || return 581 chk start_log_mark_advanced_M_to_M_plus_1 "$(grep -q "record mark advanced $m->$((m + 1)) " "$R/daemon-2.log" && echo true || echo false)" "$(q "$(grep -m1 'Cortex mark:' "$R/daemon-2.log" | sed 's/\x1b\[[0-9;]*m//g')")" 582 cx RCL recall; chk recall_ok "$(eq "$(j RCL .ok)" true)" "$(q "$(j RCL '.error // "ok"' | cut -c1-200)")" 583 execute X2 "$A2"; chk A2_DONE "$(eq "$(j X2 .state)" DONE)" "$(q "$(j X2 '.state // .error')")" 584 local t2; t2=$(tstat "$T"); execute X3 "$A2" 585 chk A2_retry_AlreadySpent "$(eq "$(refusal X3)" AlreadySpent)" "$(q "$(refusal X3)")" 586 chk written_once "$(eq "$(tstat "$T")" "$t2")" 587 OUTCOME="mark M=$m put back; $(grep -m1 'Cortex mark:' "$R/daemon-2.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-80); A2 $(j X2 .state)" 588 rules final; stop_daemon 589 } 590 591 run_C7a() { 592 # ACCEPTANCE-v4 C7a: the start-up reconcile returns an error (release builds 593 # abort on panic, so the error arm is the path they take). 594 INJ="daemon started with AIEN_FAULT_HOLD=reconcile_error (start-up reconcile returns an error)" 595 export AIEN_FAULT_HOLD=reconcile_error 596 start_daemon daemon-1; local up1=$? 597 unset AIEN_FAULT_HOLD 598 chk daemon_serves_socket_up "$( [ $up1 -eq 0 ] && [ -S "$R/aien.sock" ] && echo true || echo false)" "$(q "$(tail -2 "$R/daemon-1.log" | tr '\n' ' ' | cut -c1-200)")" 599 [ $up1 -eq 0 ] || return 600 local rl; rl=$(reconcile_line daemon-1) 601 chk start_line_refused_names_refusal "$(echo "$rl" | grep -q '^Reconcile: refused: fault hold reconcile_error.*effect commands refuse until a successful reconcile (aien compose reconcile)$' && echo true || echo false)" "$(q "$(echo "$rl" | cut -c1-240)")" 602 pre_state pre 603 A1=$(authorize A1); chk authorize_answers "$( [ -n "$A1" ] && echo true || echo false)" "$(q "$A1")" 604 execute X1 "$A1"; chk first_execute_refused_ReconcileFailed "$(eq "$(refusal X1)" ReconcileFailed)" "$(q "$(j X1 '.error // .state' | cut -c1-200)")" 605 ledger L1; chk no_intent "$(eq "$(intent_state L1 "$A1")" none)" 606 chk no_write "$(eq "$(tstat "$T")" "$T0")" 607 cx RC reconcile; chk reconcile_ok "$(eq "$(j RC .ok)" true)" "$(q "$(j RC '.error // "ok"' | cut -c1-200)")" 608 execute X2 "$A1"; chk second_execute_DONE "$(eq "$(j X2 .state)" DONE)" "$(q "$(j X2 '.state // .error')")" 609 local t1; t1=$(tstat "$T"); chk written "$( [ "$t1" != "$T0" ] && echo true || echo false)" 610 execute X3 "$A1" 611 chk written_once "$(eq "$(tstat "$T")" "$t1")" 612 stop_daemon; up daemon-2 || return 613 chk restart_reconcile_normal "$(reconcile_line daemon-2 | grep -q 'checked 0' && echo true || echo false)" "$(q "$(reconcile_line daemon-2)")" 614 OUTCOME="start reconcile refused (error hook); execute $(refusal X1); reconcile ok=$(j RC .ok); execute $(j X2 .state); restart clean" 615 rules final; stop_daemon 616 } 617 618 run_C7c() { 619 # ACCEPTANCE-v4 C7c: a real panic at start. Expected: daemon exits, no 620 # socket served, no write; the next start clears the left socket file. 621 INJ="daemon started with AIEN_FAULT_HOLD=reconcile_panic (real panic); restart without the hook, left socket file kept" 622 local h0; h0=$(home_digest "$R") 623 export AIEN_FAULT_HOLD=reconcile_panic 624 DRC=; start_daemon daemon-1 625 unset AIEN_FAULT_HOLD 626 if kill -0 "$DPID" 2>/dev/null; then 627 chk daemon_exits_by_itself false "$(q "still running: $(tail -2 "$R/daemon-1.log" | tr '\n' ' ' | cut -c1-160)")" 628 kill_daemon; return 629 fi 630 chk daemon_exits_by_itself true 631 chk exit_status_nonzero "$( [ -n "$DRC" ] && [ "$DRC" -ne 0 ] && echo true || echo false)" "$(q "$DRC")" 632 chk log_names_fault_hold "$(grep -q 'fault hold reconcile_panic' "$R/daemon-1.log" && echo true || echo false)" "$(q "$(grep -m1 'panicked at' "$R/daemon-1.log" | cut -c1-160)")" 633 cx NS recall 634 chk no_process_serves_socket "$(j NS '(.ok == false) and ((.error // "") | test("Failed to connect"))')" "$(q "$(j NS '.error // "connected"' | cut -c1-200)")" 635 chk socket_file_left_recorded_not_scored true "$(q "$( [ -S "$R/aien.sock" ] && echo present || echo absent)")" 636 local sockleft; sockleft=$( [ -S "$R/aien.sock" ] && echo present || echo absent) 637 chk home_identical "$(eq "$(home_digest "$R")" "$h0")" 638 chk target_unchanged "$(eq "$(tstat "$T")" "$T0")" 639 chk provenance_empty "$( [ -z "$(ls -A "$R/prov")" ] && echo true || echo false)" 640 KEEP_SOCK=1; up daemon-2; local up2=$?; unset KEEP_SOCK 641 [ $up2 -eq 0 ] || return 642 chk restart_reconcile_normal "$(reconcile_line daemon-2 | grep -q 'checked 0' && echo true || echo false)" "$(q "$(reconcile_line daemon-2)")" 643 pre_state pre; chk recall_ok "$(eq "$(j pre .ok)" true)" 644 ledger L1; chk ledger_no_intent "$(eq "$(j L1 '.ledger.intents | length')" 0)" "$(q "$(j L1 '.ledger.intents | length')")" 645 OUTCOME="panic at start: exit $DRC, no server, home identical, socket file $sockleft; restart clean" 646 rules final; stop_daemon 647 } 648 649 run_C7b() { 650 c6_base || return 651 INJ="cut cortex.cx at the record boundary before the last record (C6c), then recover" 652 cp "$R/compose.cortex-mark" "$R/damaged-mark.bin" 653 truncate -s "$S1" "$R/compose/cortex.cx" 654 up daemon-2 || return 655 local rl; rl=$(reconcile_line daemon-2) 656 chk start_refused_E_MARK_TRUNCATED "$(echo "$rl" | grep -q 'Reconcile: refused.*E_MARK_TRUNCATED' && echo true || echo false)" "$(q "$(echo "$rl" | cut -c1-240)")" 657 cx REC recover 658 chk recover_mark_lost_1 "$(eq "$(j REC .repair.mark_lost)" 1)" "$(q "$(j REC '.repair.mark_lost // .error')")" 659 local kept; kept=$(j REC '.repair.mark_kept_as // ""') 660 chk mark_kept_as_lost_seq_file "$(echo "$kept" | grep -Eq '\.cortex-mark\.lost-[0-9]+$' && [ -f "$kept" ] && echo true || echo false)" "$(q "$kept")" 661 chk kept_mark_identical_to_damaged_state "$(cmp -s "$R/damaged-mark.bin" "$kept" && echo true || echo false)" 662 local rr; rr=$(j REC '.repair.mark_repair_record // 0') 663 cx RCR recall --ids "$rr" 664 chk repair_constraint_record "$(j RCR "[.recall.cited[] | select(.note == \"constraint\") | .text | fromjson? | select(.repair == \"cortex-mark\" and .lost == 1)] | length == 1")" "$(q "$(j RCR '.recall.cited[0].text // .error' | cut -c1-240)")" 665 A3=$(authorize A3); chk authorize_A3_answers "$( [ -n "$A3" ] && echo true || echo false)" "$(q "$A3")" 666 execute X3 "$A3"; chk first_execute_refused_ReconcileFailed "$(eq "$(refusal X3)" ReconcileFailed)" "$(q "$(j X3 '.error // .state' | cut -c1-200)")" 667 chk no_write_before_reconcile "$(eq "$(tstat "$T")" "$T1")" 668 cx RC reconcile; chk reconcile_ok "$(eq "$(j RC .ok)" true)" "$(q "$(j RC '.error // "ok"' | cut -c1-200)")" 669 execute X4 "$A3"; chk second_execute_A3_DONE "$(eq "$(j X4 .state)" DONE)" "$(q "$(j X4 '.state // .error')")" 670 local t4; t4=$(tstat "$T"); execute X5 "$A3" 671 chk written_once "$(eq "$(tstat "$T")" "$t4")" 672 OUTCOME="start refused (mark); recover mark_lost=$(j REC .repair.mark_lost); execute $(refusal X3); reconcile ok=$(j RC .ok); execute A3 $(j X4 .state)" 673 rules final; stop_daemon 674 } 675 676 run_C8a() { 677 INJ="v2 home without a record mark (copy of F0v2)" 678 [ -f "$R/compose.cortex-mark" ] && { NOTRUN="FIX_OLD has a record mark"; OUTCOME=$NOTRUN; return; } 679 up daemon-1 || return 680 local na; na=$(grep -c 'Cortex mark: mark adopted (seq 1, records [0-9]*)' "$R/daemon-1.log") 681 chk first_start_one_adopted_line "$(eq "$na" 1)" "$(q "$(grep -m1 'Cortex mark:' "$R/daemon-1.log" | sed 's/\x1b\[[0-9;]*m//g')")" 682 chk mark_128_bytes "$(eq "$(stat -c %s "$R/compose.cortex-mark" 2>/dev/null)" 128)" 683 pre_state pre; chk recall_ok "$(eq "$(j pre .ok)" true)" 684 stop_daemon; up daemon-2 || return 685 chk second_start_no_adopt_or_advance "$(grep -Eq 'mark adopted|record mark advanced' "$R/daemon-2.log" && echo false || echo true)" "$(q "$(grep -m1 'Cortex mark:' "$R/daemon-2.log" | sed 's/\x1b\[[0-9;]*m//g')")" 686 cx R2 recall; chk second_recall_ok "$(eq "$(j R2 .ok)" true)" 687 OUTCOME="$(grep -m1 'Cortex mark:' "$R/daemon-1.log" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-80); second start quiet" 688 rules final; stop_daemon 689 } 690 691 run_C8b() { 692 run_control 693 INJ="after the control steps: delete compose.cortex-mark (daemon stopped)" 694 rm -f "$R/compose.cortex-mark" 695 up daemon-3 || return 696 chk start_one_adopted_line "$(eq "$(grep -c 'Cortex mark: mark adopted' "$R/daemon-3.log")" 1)" "$(q "$(grep -m1 'Cortex mark:' "$R/daemon-3.log" | sed 's/\x1b\[[0-9;]*m//g')")" 697 cx R3 recall; chk recall_ok "$(eq "$(j R3 .ok)" true)" 698 local t1; t1=$(tstat "$T"); execute X9 "$A1" 699 chk reexecute_AlreadySpent "$(eq "$(refusal X9)" AlreadySpent)" "$(q "$(refusal X9)")" 700 chk no_second_write "$(eq "$(tstat "$T")" "$t1")" 701 OUTCOME="control done; mark deleted; restart adopted; re-execute $(refusal X9)" 702 rules final2; stop_daemon 703 } 704 705 old_fixture_ok() { # F0v2 files sha re-check (ACCEPTANCE-v3 section 4) 706 local want got; want=$(jq -r .files_sha256 "$1/fixture.json" 2>/dev/null) 707 got=$( (tree_list "$1/compose"; sha256sum "$1/compose.machine-root"; [ -f "$1/compose.cortex-mark" ] && sha256sum "$1/compose.cortex-mark"; tree_list "$1/ws") | sha256sum | cut -d' ' -f1) 708 [ -n "$want" ] && [ "$want" = "$got" ] 709 } 710 711 for c in $CASES; do 712 case $c in 713 control) for k in C1 C2 C4 C5 C6 C7 C8; do new_run "control-$k"; run_control; finish "control-$k" 1; done;; 714 C1a|C1b) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C1 "${c#C1}"; finish "$c" "$r"; done;; 715 C2a) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C2a; finish "$c" "$r"; done;; 716 C2b|C2c|C2d) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C2bcd "${c#C2}"; finish "$c" "$r"; done;; 717 C3a) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C3a; finish "$c" "$r"; done;; 718 C3b) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C3b; finish "$c" "$r"; done;; 719 C4) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C4; finish "$c" "$r"; done;; 720 C5a|C5b|C5c) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C5 "${c#C5}"; finish "$c" "$r"; done;; 721 C6i) new_run "$c-1"; run_C6 i; finish "$c" 1;; # exactly once (DECIDED 4) 722 C6c-ctl) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C6c_ctl; finish "$c" "$r"; done;; 723 C6?) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C6 "${c#C6}"; finish "$c" "$r"; done;; 724 C7a) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C7a; finish "$c" "$r"; done;; 725 C7b) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C7b; finish "$c" "$r"; done;; 726 C7c) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C7c; finish "$c" "$r"; done;; 727 C8a) for r in $(seq 1 "$REPS"); do 728 if [ -z "${FIX_OLD:-}" ] || ! old_fixture_ok "$FIX_OLD"; then 729 new_run "$c-$r"; NOTRUN="FIX_OLD (F0v2) missing or its files sha256 does not match its fixture.json"; OUTCOME=$NOTRUN 730 else new_run "$c-$r" "$FIX_OLD"; run_C8a; fi 731 finish "$c" "$r"; done;; 732 C8b) for r in $(seq 1 "$REPS"); do new_run "$c-$r"; run_C8b; finish "$c" "$r"; done;; 733 *) echo "unknown case $c"; exit 2;; 734 esac 735 # never leave a daemon behind 736 [ -n "$DPID" ] && kill -0 "$DPID" 2>/dev/null && kill_daemon 737 done 738 exit 0