diff --git a/docs/GOAL_MICROJOBS.md b/docs/GOAL_MICROJOBS.md index 86512f7..3e506b9 100644 --- a/docs/GOAL_MICROJOBS.md +++ b/docs/GOAL_MICROJOBS.md @@ -248,6 +248,94 @@ HOST_TESTED is not hardware qualification. P1 two-machine, P2 federation, GPU, deployment and merge are NOT_RUN. General DAG conversion and P-256 verification in Omega are not claimed. +### M1 loopback execution and interruption acceptance + +`tests/goal_microjobs/aienet-m1/sequence.sh` is a shell migration adapter +under [aien#22](https://github.com/aien-dev/aien/issues/22), not a new +admission or signature implementation. It reads the current generation from +kernel status and routes the kernel-validated journal through `recovery.om` +to derive the effective operand, then calls `canon emit`, persists the unchanged +signed bundle before DISPATCH, resends with the worker's durable `--retry` +state, checks signatures and independent recomputation through Open Humanity, +then calls `canon ingest` and proposes RESULT and VERIFY through the kernel. +`recovery.om` compares every field of an already-persisted RESULT with the +canonical RESULT before VERIFY-only recovery (mismatch: exit 33). The current +kernel generation is supplied to canonical ingestion. Immediately before ingest, +recovery replays the current trusted plan+journal again. The sequencer routes +the objective from its effective header and operand from its effective node into +the final eight words of canon's 23-word expected record; neither pin comes from +the submitted document or bundle. Stale receipts with changed operands refuse +at the earlier operand check (exit 24). A correction round-trip returning to the +original operand isolates stale-generation refusal (exit 14). These decisions +remain in Omega, not shell admission rules. +`recovery-build.sh` checks the same e5b32567 compiler digest as canon-build.sh. + +Effective-operand folding streams the unchanged kernel plan+journal bytes after +a `1\n` mode prefix, retaining only one event. It has no event-count ceiling. +The prefix is excluded from the byte count. The same input-size rule as +`kernel.om:10,60-79` applies: its 262144-byte buffer refuses input length +greater than or equal to 262143 (exit 3), including trailing whitespace. +`recovery.om` emits the updated 40-word header/node before the sequencer adds +the current status and explicit binding for canonical emission. + +Build `canon` with the preceding pinned build command. Materialize the SHA +oracle source without modifying its checkout: + +```sh +mkdir -p /tmp/aienet-m1-sha +git -C "$OMEGA_MV" archive 55845e70 om/sha256/sha256-om2.om | + tar -x -C /tmp/aienet-m1-sha +taskset -c 10-14 nice -n 19 ionice -c3 env \ + OH_TREE=/home/drakestapleton/fix/aienet-oh-seal \ + PROTOCOLS=/tmp/aienet/aien-protocols-mv \ + OMEGA_WORKTREE=/home/drakestapleton/workspace/allen-harness-evolution-omega \ + RECOMPUTE_OMC=/home/drakestapleton/workspace/omega-mcp/build/omc \ + SHA_OMEGA_TREE=/tmp/aienet-m1-sha CANON=/tmp/aienet-m1-canon \ + bash tests/goal_microjobs/aienet-m1/run.sh /tmp/aienet-m1-fresh-output +``` + +The output directory must not exist. The harness builds both OH release +binaries from the explicitly supplied seal-document worktree and resolves +their executables from Cargo's reported artifacts, including when +`CARGO_TARGET_DIR` is set. It verifies the recompute pin and records the exact +OH revision, both OH binary digests, canonical source revision and canonical +binary digest in `summary.tsv`, with one expected/observed row per case. +`mutants.tsv` counts a mutant as killed only for its named semantic failure; +setup errors are not kills. Baseline failures prevent mutant qualification. + +Cases cover happy completion; SIGKILL after bundle persistence, DISPATCH, +receipt plus AN0V publication and RESULT; worker SIGKILL after durable admission +and after durable completion; generation correction; signature-covered MJR1 +mutation; executor-signed wrong output; duplicate receipt and an independently +signed second completion; signature-only AN0V mutation; and RESULT-only recovery +with a kernel-valid but conflicting persisted time charge. Negative self-tests +prove the DONE helper rejects RESULTED, missing and duplicate node-1 status +records. History regressions exercise multiple CORRECTs, 257 and 1000 CORRECTs, +and two CORRECTs after a persisted RESULT. Capacity probes check the largest +accepted kernel input and refused boundary/over-capacity inputs against both +kernel and recovery, with matching observed exits in `capacity.tsv`. +Authenticated substitution regressions replace a complete validly signed job, +receipt and countersign after publication but before ingest. Different objective +and operand substitutions must pass Open Humanity's pinned-key check but refuse +at canon with 23 and 24 respectively, emit no events, preserve the journal and +leave the generation running. A generation-two pre-CORRECT operand substitution +also refuses with 24. Restoring the original checked bytes then completes the +same dispatch exactly once. Observed exits are filed in `pin-refusals.tsv`. +Guard-removal mutants challenge persist-before-DISPATCH, check-before-ingest, +current-generation routing and Omega RESULT conflict checking. A fifth mutant +stops folding after the first CORRECT; the last-CORRECT regression must kill it. +Two further mutants pass the submitted document's own objective or operand as +the expected pin; the authenticated substitution cases must kill both. +Every accepted generation has one DISPATCH, RESULT and VERIFY. +Recovery checks that persisted bundle bytes never change. + +All identities and payload bindings here are explicit synthetic test values. +Disposable private scalars are generated by `openssl rand -hex 32` in an +owner-private `/dev/shm` directory and deleted on exit. Only loopback ephemeral +ports are used; workers have owned state directories and owned process IDs. +No GPU, model server, P1 second machine, P2 federation, Core TUR settlement, +production deployment or hardware qualification is exercised by this harness. + ## NL-5: default-off private-local shadow experiment Issue [#19](https://github.com/aien-dev/aien/issues/19), parent diff --git a/scripts/goal_microjobs/.crumb b/scripts/goal_microjobs/.crumb index e346b8e..d5d693d 100644 --- a/scripts/goal_microjobs/.crumb +++ b/scripts/goal_microjobs/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-30T00:33:51Z", + "compiled_at": "2026-10-30T01:10:49Z", "compiler": "crumb-compile/1", - "digest": "sha256:c5d3d614db0d2fbf7aa0e6d2d69e1624f889fe9039d09c3574b0da6c60c99372", + "digest": "sha256:4a6f2197662b761038689453ede951dede96ca642877970805ea0fb3b1174d40", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 3, - "generated_at_commit": "b02bc7fb8c28bf90803d5bd357d1749cabdfc974", - "source_tree": "sha256:1b9d104e879fb6b953e29b751ae6506e28e1cc7f87d3fcfad6c4c84bcca58f69" + "files": 4, + "generated_at_commit": "8f83b0361f3d666d71d0fbde54e493b86ca469f4", + "source_tree": "sha256:522ecff2133d13ff498cb0865dc004c13649b77df6d56678a77bc57444c4c12d" } }, "name": "goal-microjobs", diff --git a/scripts/goal_microjobs/recovery-build.sh b/scripts/goal_microjobs/recovery-build.sh new file mode 100755 index 0000000..a6373f8 --- /dev/null +++ b/scripts/goal_microjobs/recovery-build.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Migration-only build adapter, aien-dev/aien#22; runtime decisions are Omega. +set -eu +HERE=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +OUT=${1:?output binary} +SOURCE=${2:-$HERE/src/goal_microjobs/recovery.om} +[ "$(sha256sum < "${OMEGA_OMC:?pinned omc}" | cut -c1-64)" = 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f ] || { echo 'BLOCKED: omc hash mismatch' >&2; exit 3; } +T=$(mktemp -d) +trap 'rm -rf "$T"' EXIT HUP INT TERM +"$OMEGA_OMC" < "$SOURCE" > "$T/recovery" +chmod +x "$T/recovery" +mv "$T/recovery" "$OUT" +sha256sum "$OUT" diff --git a/src/goal_microjobs/.crumb b/src/goal_microjobs/.crumb index 7337b29..d8df91f 100644 --- a/src/goal_microjobs/.crumb +++ b/src/goal_microjobs/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-31T02:20:58Z", + "compiled_at": "2026-10-31T02:23:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:9531f0de727d79d9ae6f41772b937309a6c072c6038da5a0fe3c1993b0b95e28", + "digest": "sha256:902c528e766c31d6b4a26cf554d684a7a881311332b158232ba6c4b49b5842b6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 3, - "generated_at_commit": "4e11a8954699953f9e741a868b355f15d55de0d2", - "source_tree": "sha256:b993fc12b3c56446d76e18c7325239d6cab9de45a619ac75104166a64ddbcc92" + "files": 4, + "generated_at_commit": "7a98e6150f97500224d54fb3970f2fe4f7cc4bb8", + "source_tree": "sha256:b62245e9834bce39c49a50031a439e2c453fff97c421bafefd839d312fbc595c" } }, "name": "goal-microjobs", diff --git a/src/goal_microjobs/recovery.om b/src/goal_microjobs/recovery.om new file mode 100644 index 0000000..0d3c5ed --- /dev/null +++ b/src/goal_microjobs/recovery.om @@ -0,0 +1,157 @@ +om2 +note SPDX-License-Identifier: AGPL-3.0-or-later +note One-node M1 recovery over the kernel-validated original plan and journal. +note Mode 1 prefix is 1 newline, followed by the unchanged kernel input bytes. +note Capacity follows kernel.om:10,60-79: Inb=262144, load refuses >= len Inb - 1. +note Chunked parsing keeps one event, with no independent event-count ceiling. +global Ib uchar 4096 +global Cur ulong 6 +global Ob uchar 8192 +global Op ulong 1 +text conflict "RECOVERY_RESULT_CONFLICT\n" +fn die c int to void +exit c +end +fn ws c ulong to bool +ret or eq c 32 or eq c 10 or eq c 13 eq c 9 +end +fn raw to ulong +if eq get Cur 5 1 +ret 256 +end +if eq get Cur 0 get Cur 1 +r = read 0 Ib 0 len Ib +if lt r 0 +die 4 +end +if eq r 0 +put Cur 5 1 +ret 256 +end +put Cur 0 0 +put Cur 1 ulong r +end +c = ulong get Ib get Cur 0 +put Cur 0 add get Cur 0 1 +if eq get Cur 3 1 +put Cur 2 add get Cur 2 1 +if ge get Cur 2 262143 +die 3 +end +end +ret c +end +fn next to ulong +c = get Cur 4 +if ne c 257 +put Cur 4 257 +ret c +end +ret raw +end +fn more to bool +c = next +while ws c bound 262144 +c = raw +end +put Cur 4 c +ret ne c 256 +end +fn word to ulong +if not more +die 2 +end +c = next +v = ulong 0 +while true bound 262144 +if eq c 256 +ret v +end +if ws c +ret v +end +if or lt c 48 gt c 57 +die 3 +end +d = sub c 48 +if or gt v 1844674407370955161 and eq v 1844674407370955161 gt d 5 +die 3 +end +v = add mul v 10 d +c = raw +end +ret v +end +fn digit v ulong to void +if gt v 9 +digit div v 10 +end +put Ob get Op 0 uchar add rem v 10 48 +put Op 0 add get Op 0 1 +end +fn dec v ulong to void +digit v +put Ob get Op 0 32 +put Op 0 add get Op 0 1 +end +fn checkresult a view ulong 14 b view ulong 14 to void +for i ulong 14 +if ne get a i get b i +w = write 2 conflict 0 len conflict +die 33 +end +end +end +fn prepare to void +a = new ulong 40 0 +e = new ulong 14 0 +put Cur 3 1 +for i ulong 40 +put a i word +end +while more bound 262144 +for j ulong 14 +put e j word +end +if and eq get e 2 6 eq get e 3 1 +for j ulong 4 +put a add 35 j get e add 8 j +end +note RECOVERY-MUTANT first-correct-stop +end +end +for i ulong 40 +dec get a i +end +put Ob get Op 0 10 +put Op 0 add get Op 0 1 +w = write 1 Ob 0 get Op 0 +end +fn resume to void +a = new ulong 14 0 +b = new ulong 14 0 +for i ulong 14 +put a i word +end +for i ulong 14 +put b i word +end +if more +die 3 +end +note RECOVERY-GUARD result-conflict +checkresult a b +end +fn main to int +put Cur 4 257 +mode = word +if eq mode 1 +prepare +ret 0 +end +if eq mode 2 +resume +ret 0 +end +ret 2 +end diff --git a/tests/goal_microjobs/.crumb b/tests/goal_microjobs/.crumb index e5b7b96..f92959f 100644 --- a/tests/goal_microjobs/.crumb +++ b/tests/goal_microjobs/.crumb @@ -2,6 +2,12 @@ "extensions": { "generated": { "children": [ + { + "digest": "6b23710000b0f9f1da795e5dd96fefa8f29ffc7549158dc24bcfc52354e70a8e", + "last_commit": "918ffaf", + "name": "aienet-m1", + "purpose": "Host-only Allen journal to canonical Aienet-0 execution, recovery and refusal acceptance" + }, { "digest": "e1d8451acf26b764832cedb86714f72fd238deb4c632ab418df81fbb9962b0b0", "last_commit": "b5057df", @@ -9,15 +15,15 @@ "purpose": "Synthetic canonical Aienet-0 byte oracles, refusal probes and guard-removal mutants" } ], - "children_root": "sha256:0d16a180e37a367d57b67f95c31ba2227fa974ea63b13ef53cf9650dad0f8ed6", - "compiled_at": "2026-10-31T02:20:58Z", + "children_root": "sha256:1c5340992dd7c7310d19546b1d0b46fcf0192ef1a8460309566e3843a13d38cd", + "compiled_at": "2026-10-31T11:04:32Z", "compiler": "crumb-compile/1", - "digest": "sha256:63c714e665d89c601f7a5f8ab14d582efe36d2a6f83863bb90b8ac9ac4007409", + "digest": "sha256:0327866d92415a130fbc7ea99e964e59e65bdd87f192328a6be803a921bfbe65", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 38, - "generated_at_commit": "4e11a8954699953f9e741a868b355f15d55de0d2", - "source_tree": "sha256:1804d07390823f415d5ee5d5da79e95bcaaaa23ef1837e6e64125e2aedc66668" + "files": 40, + "generated_at_commit": "918ffaf549bfc1cb37baef0633105cf55dbd5923", + "source_tree": "sha256:416fd7957d432ae01e19740038bcce0855eaa3e728624c93f236e06586c19726" } }, "name": "goal-microjobs", diff --git a/tests/goal_microjobs/aienet-m1/.crumb b/tests/goal_microjobs/aienet-m1/.crumb new file mode 100644 index 0000000..b09852d --- /dev/null +++ b/tests/goal_microjobs/aienet-m1/.crumb @@ -0,0 +1,19 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-10-31T11:04:32Z", + "compiler": "crumb-compile/1", + "digest": "sha256:6b23710000b0f9f1da795e5dd96fefa8f29ffc7549158dc24bcfc52354e70a8e", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 2, + "generated_at_commit": "918ffaf549bfc1cb37baef0633105cf55dbd5923", + "source_tree": "sha256:44b66b0c062ec78e1fb9d59a2de3404a76bc1836f5077650b09e2e1adf548145" + } + }, + "name": "aienet-m1", + "purpose": "Host-only Allen journal to canonical Aienet-0 execution, recovery and refusal acceptance", + "schema_version": "1.0.0" +} diff --git a/tests/goal_microjobs/aienet-m1/run.sh b/tests/goal_microjobs/aienet-m1/run.sh new file mode 100755 index 0000000..b7eb60b --- /dev/null +++ b/tests/goal_microjobs/aienet-m1/run.sh @@ -0,0 +1,563 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: AGPL-3.0-or-later +# Host-only acceptance. Shell sequencing is a migration adapter for aien#22. +# No GPU, settlement, public listener, remote host or persistent identities. +set -euo pipefail +repo=$(cd "$(dirname "$0")/../../.." && pwd) +here="$repo/tests/goal_microjobs/aienet-m1" +: "${OH_TREE:?own Open Humanity seal-document worktree}" +: "${PROTOCOLS:?protocols source tree}" +: "${OMEGA_WORKTREE:?Allen pinned compiler tree}" +: "${RECOMPUTE_OMC:?e5b32567 omc}" +: "${SHA_OMEGA_TREE:?tree containing pinned SHA unit}" +: "${CANON:?compiled canon from feat/aienet-m1-canon}" +canon_source=b5057df61bc2175e6e1bf23d1ebce0a2857f8584 +canon_binary=4d7d2a0bda184622980f61570b8ae5294a1989c89af2aa498bdbfa443abf2b1b +# Pin the canon sources by git blob id, not by commit ancestry: a squash merge +# of feat/aienet-m1-canon leaves b5057df off main while the sources stay equal. +test "$(git -C "$repo" rev-parse HEAD:src/goal_microjobs/canon.om)" = 5719dc992cb358d7ea29dbec4ab82e310369de29 +test "$(git -C "$repo" rev-parse HEAD:scripts/goal_microjobs/canon-build.sh)" = 226fcae40b2daa9dcc3da785571b1cef70b41c4b +test "$(sha256sum "$CANON" | cut -d' ' -f1)" = "$canon_binary" +export CARGO_BUILD_JOBS=4 PYTHONDONTWRITEBYTECODE=1 +umask 077 +E=${1:?usage: run.sh FRESH_EVIDENCE_DIRECTORY} +test ! -e "$E" +mkdir -p "$E" +E=$(cd "$E" && pwd) +K=$(mktemp -d /dev/shm/aienet-m1-keys.XXXXXX) +cleanup() { rm -rf -- "$K"; } +trap cleanup EXIT +mkdir "$K/requester" "$K/worker" "$K/pins" "$K/wpins" +export KEYS="$K/requester" WKEYS="$K/worker" PINS="$K/pins" WPINS="$K/wpins" +for file in "$KEYS/transport.seed" "$KEYS/submitter.p256" "$KEYS/verifier.p256" "$WKEYS/transport.seed" "$WKEYS/executor.p256"; do + openssl rand -hex -out "$file" 32 +done +(cd "$OH_TREE"; cargo build --locked --release --bin aienet0-run --bin aienet0-serve --message-format=json) > "$E/build.jsonl" 2> "$E/build.log" +export RUN SERVE +RUN=$(jq -r 'select(.reason == "compiler-artifact" and .target.name == "aienet0-run" and .profile.test == false) | .executable // empty' "$E/build.jsonl") +SERVE=$(jq -r 'select(.reason == "compiler-artifact" and .target.name == "aienet0-serve" and .profile.test == false) | .executable // empty' "$E/build.jsonl") +test -x "$RUN"; test -x "$SERVE" +oh_source=$(git -C "$OH_TREE" rev-parse HEAD) +oh_run_sha=$(sha256sum "$RUN" | cut -d' ' -f1) +oh_serve_sha=$(sha256sum "$SERVE" | cut -d' ' -f1) +# The test executable enables only the worker's pre-existing cfg(test) pauses. +(cd "$OH_TREE"; cargo test --locked -p oh-volunteer --bin aienet0-serve --no-run --message-format=json) > "$E/test-build.jsonl" 2> "$E/test-build.log" +TEST_WORKER=$(jq -r 'select(.reason == "compiler-artifact" and .profile.test == true) | .executable // empty' "$E/test-build.jsonl") +test -x "$TEST_WORKER" +"$RUN" keys --keys "$KEYS" > "$E/requester-public" +"$SERVE" keys --keys "$WKEYS" > "$E/worker-public" +while read -r name key; do printf '%s\n' "$key" > "$WPINS/$name"; done < "$E/requester-public" +while read -r name key; do printf '%s\n' "$key" > "$PINS/$name"; done < "$E/worker-public" +export GM_KERNEL="$E/kernel" RECOMPUTE="$E/recompute" +bash "$repo/scripts/goal_microjobs/build.sh" "$repo/src/goal_microjobs/kernel.om" "$GM_KERNEL" > "$E/kernel-build.log" 2>&1 +OMEGA_OMC="$RECOMPUTE_OMC" OMEGA_MV="$SHA_OMEGA_TREE" bash "$PROTOCOLS/specs/aienet/jobpath/build.sh" "$RECOMPUTE" > "$E/recompute-build.log" 2>&1 +export RECOMPUTE_SHA256=d2cd7382e0dc64e49498ae3b1ceffc73f1ddcbd3ddcf93e6d607498ccd58ea12 +test "$(sha256sum "$RECOMPUTE" | cut -d' ' -f1)" = "$RECOMPUTE_SHA256" +export RECOVERY="$E/recovery" +OMEGA_OMC="$RECOMPUTE_OMC" sh "$repo/scripts/goal_microjobs/recovery-build.sh" "$RECOVERY" > "$E/recovery-build.log" 2>&1 +words() { local hex=$1; printf '%u %u %u %u\n' "0x${hex:0:16}" "0x${hex:16:16}" "0x${hex:32:16}" "0x${hex:48:16}"; } +hash_words() { words "$(sha256sum | cut -d' ' -f1)"; } +export EXECUTOR_WORDS VERIFIER_WORDS +EXECUTOR_WORDS=$(xxd -r -p "$PINS/executor.p256" | hash_words) +VERIFIER_WORDS=$(xxd -r -p "$WPINS/verifier.p256" | hash_words) +objective=$(printf aienet-m1-synthetic-objective | hash_words) +tenant=$(printf AIENET0-TENANT-TUR-TEST-V1 | hash_words) +capability=$(printf AIENET0-CAPABILITY-MATMUL-U32-V1 | hash_words) +subject=$(printf aienet-m1-explicit-subject | hash_words) +approval=$(printf aienet-m1-explicit-approval | hash_words) +expires=$(date -u -d tomorrow +%s) +driver="$repo/scripts/goal_microjobs/microjobs.sh" +sequence="$here/sequence.sh" +export STATE LISTEN +new_state() { + local state_seed=${2:-7} state_objective=${3:-$objective} + STATE="$E/${CASE_PREFIX:-}$1" + mkdir -p "$STATE/bindings" + printf '01000200030002%016x' "$state_seed" | xxd -r -p > "$STATE/payload1" + operand=$(hash_words < "$STATE/payload1") + { + printf '1 1 %s 7 9 1 1 1 4 0 0 0 0 120000\n' "$state_objective" + printf '2 1 1 2 0 0 1 0 0 0 0 1 5 1 1 7 120000 1 %s 0\n' "$operand" + } > "$STATE/input-plan" + printf '4 %s %s %s %s %s %s 2 3 2 %s 1\n' "$state_objective" "$tenant" "$subject" "$approval" "$capability" "$expires" "$state_seed" > "$STATE/bindings/1" + bash "$driver" init "$STATE" "$STATE/input-plan" + port=$(shuf -i 49152-65535 -n 1) + test -z "$(ss -H -ltn "sport = :$port")" + LISTEN="127.0.0.1:$port" +} +assert_done() { + local status_file=$1 wanted=$2 tag id st gen rest matches=0 + while read -r tag id st gen rest; do + if test "$tag" = 101 && test "$id" = 1; then + matches=$((matches+1)) + test "$st" = 4 || return 1 + test "$gen" = "$wanted" || return 1 + fi + done < "$status_file" + test "$matches" = 1 || return 1 +} +done_negative() { + printf '%s\n' "$2" > "$E/done-$1.input" + local rc=0 + assert_done "$E/done-$1.input" 1 || rc=$? + test "$rc" = 1 +} +exactly_once() { + bash "$driver" status "$STATE" > "$STATE/final-status" + assert_done "$STATE/final-status" "${1:-1}" || return 1 + local tag id gen rest + local dispatch=0 result=0 verify=0 + while read -r tag seq type node attempt gen rest; do + if test "$node" = 1 && test "$gen" = "${1:-1}"; then + case "$type" in 1) dispatch=$((dispatch+1));; 2) result=$((result+1));; 3) verify=$((verify+1));; esac + fi + done < "$STATE/journal" + test "$dispatch/$result/$verify" = 1/1/1 +} +wait_file() { + local file=$1 pid=$2 + for ((i=0;i<600;i++)); do + test ! -f "$file" || return 0 + kill -0 "$pid" || return 1 + sleep 0.05 + done + echo "boundary not reached: $file" >&2 + return 1 +} +semantic() { + local name=$1; shift + if ! "$@"; then echo "M1_SEMANTIC $name" >&2; return 1; fi +} +cleanup_case() { + if test -n "${active_pid:-}"; then + kill "$active_pid" 2>/dev/null || true + wait "$active_pid" 2>/dev/null || true + fi +} +run_sequence() { bash "$sequence"; } +happy() { new_state happy; run_sequence; exactly_once; } +crash() { + local boundary=$1 + new_state "crash-$boundary" + M1_PAUSE="$boundary" bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + # Persisted artifact must already exist at every post-dispatch boundary. + if test "$boundary" != persisted; then semantic persist-before-dispatch test -s "$STATE/g1/job.an0b"; fi + sha256sum "$STATE/g1/job.an0b" > "$STATE/bundle.before" + kill -KILL "$pid" + wait "$pid" || true + rm -f "$STATE/paused" + run_sequence + sha256sum -c "$STATE/bundle.before" + exactly_once +} +worker_crash() { + local phase=${1:-admitted} + new_state "crash-worker-$phase" + M1_TEST_WORKER="$TEST_WORKER" M1_WORKER_PAUSE="$phase" bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/g1/worker.ready" "$pid" + read -r worker < "$STATE/g1/worker.pid" + sha256sum "$STATE/g1/job.an0b" > "$STATE/bundle.before" + kill -KILL "$worker" + wait "$pid" || true + run_sequence + sha256sum -c "$STATE/bundle.before" + exactly_once +} +correct() { + printf '010002000300020000000000000008' | xxd -r -p > "$STATE/payload2" + local changed; changed=$(hash_words < "$STATE/payload2") + bash "$driver" propose "$STATE" 6 1 0 1 7 0 $changed 0 0 + printf '4 %s %s %s %s %s %s 2 3 2 8 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/2" +} +stale() { + local mode=${1:-single} expected=24 target=2 guard=operand-pin + new_state "stale-$mode" + M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + correct + if test "$mode" = roundtrip; then + bash "$driver" propose "$STATE" 6 1 0 2 7 0 $operand 0 0 + printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/3" + expected=14; target=3; guard=generation-match + fi + cp "$STATE/journal" "$STATE/before-stale" + rm "$STATE/paused" + local rc=0; wait "$pid" || rc=$? + semantic "$guard" test "$rc" = "$expected" + cmp "$STATE/journal" "$STATE/before-stale" + # Independently challenge canon with the saved generation1 wire receipt. + local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) + local trusted + { printf '1\n'; cat "$STATE/plan" "$STATE/journal"; } | "$RECOVERY" > "$STATE/stale.effective" + read -r -a trusted < "$STATE/stale.effective" + { + cat "$STATE/g1/document" "$STATE/g1/out/$dag.mjr1" "$STATE/g1/out/$dag.mjv" + printf '5 1 %s 1 20 5 %s %s %s %s %s\n' "$target" "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$(( $(wc -l < "$STATE/journal") + 1 ))" "${trusted[*]:2:4}" "${trusted[*]:35:4}" + } > "$STATE/stale.ingest" + rc=0; "$CANON" ingest < "$STATE/stale.ingest" > "$STATE/stale.events" 2> "$STATE/stale.err" || rc=$? + test "$rc" = "$expected" && test ! -s "$STATE/stale.events" + run_sequence + exactly_once "$target" +} +generation_probe() { stale roundtrip; } +publish_only() { + M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + kill -KILL "$pid"; wait "$pid" || true + rm "$STATE/paused" +} +altered() { + new_state altered + publish_only + local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) + cp "$STATE/g1/out/$dag.mjr1" "$STATE/receipt.original" + # Signature-covered byte, not a malformed wire header. + local old; old=$(od -An -tu1 -j176 -N1 "$STATE/g1/out/$dag.mjr1") + printf '%b' "\\$(printf '%03o' "$((old ^ 1))")" | dd of="$STATE/g1/out/$dag.mjr1" bs=1 seek=176 conv=notrunc status=none + cp "$STATE/journal" "$STATE/before" + local rc=0; run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? + printf 'altered signature expected_exit=12 observed_exit=%s\n' "$rc" + test "$rc" = 12 + cmp "$STATE/journal" "$STATE/before" + cp "$STATE/receipt.original" "$STATE/g1/out/$dag.mjr1" + run_sequence + exactly_once +} +wrong_output() { + new_state signed-wrong-output + local rc=0; M1_MISBEHAVE=wrong-output run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? + test "$rc" = 13 + test "$(wc -l < "$STATE/journal")" = 1 + test -z "$(compgen -G "$STATE/g1/out/*.mjv")" +} +duplicate() { + new_state duplicate + run_sequence + cp "$STATE/journal" "$STATE/before" + # Ingest the same signed artifacts again, then ask the kernel to admit the + # newly sequenced RESULT. The immutable journal must refuse with code 33. + local line rest rc dag + dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) + { + cat "$STATE/g1/document" "$STATE/g1/out/$dag.mjr1" "$STATE/g1/out/$dag.mjv" + printf '5 1 1 1 20 5 %s %s 4 %s %s\n' "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$objective" "$operand" + } | "$CANON" ingest > "$STATE/replayed.events" + read -r line < "$STATE/replayed.events" + read -r _ _ rest <<< "$line" + rc=0; bash "$driver" propose "$STATE" $rest || rc=$? + test "$rc" = 33 + # A distinct, genuinely executor-signed completion from the test worker + # (different source_hash) is independently checked and also cannot commit. + mkdir "$STATE/second-out" + printf '%s\n' --connect "$LISTEN" --keys "$WKEYS" --pins "$WPINS" --state "$STATE/second-worker" --retry --connect-timeout 10 > "$STATE/second.args" + AN0_TEST_SERVE_ARGS="$STATE/second.args" AN0_TEST_PAUSE= \ + "$TEST_WORKER" --ignored --exact tests::serve_crash_worker --nocapture > "$STATE/second-worker.log" 2>&1 & + local second_pid=$!; active_pid=$second_pid + "$RUN" run --resend "$STATE/g1/job.an0b" --listen "$LISTEN" --keys "$KEYS" --pins "$PINS" --out "$STATE/second-out" \ + --recompute "$RECOMPUTE" --recompute-sha256 "$RECOMPUTE_SHA256" --accept-timeout 10 + wait "$second_pid" + if cmp -s "$STATE/g1/out/$dag.mjr1" "$STATE/second-out/$dag.mjr1"; then echo SECOND_RECEIPT_NOT_DISTINCT >&2; return 1; fi + "$RUN" check --bundle "$STATE/second-out/$dag.an0b" --mjr1 "$STATE/second-out/$dag.mjr1" --mjv "$STATE/second-out/$dag.mjv" --keys "$KEYS" --pins "$PINS" + { + cat "$STATE/g1/document" "$STATE/second-out/$dag.mjr1" "$STATE/second-out/$dag.mjv" + printf '5 1 1 1 20 5 %s %s 4 %s %s\n' "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$objective" "$operand" + } | "$CANON" ingest > "$STATE/second.events" + read -r line < "$STATE/second.events" + read -r _ _ rest <<< "$line" + rc=0; bash "$driver" propose "$STATE" $rest || rc=$? + test "$rc" = 33 + run_sequence + cmp "$STATE/journal" "$STATE/before" + exactly_once +} +# Signature-only AN0V mutation leaves binding hashes valid. canon deliberately +# does not verify P-256, so removing OH check must make this case accept falsely. +attestation_signature() { + new_state attestation-signature + publish_only + local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) + local old; old=$(od -An -tu1 -j235 -N1 "$STATE/g1/out/$dag.mjv") + printf '%b' "\\$(printf '%03o' "$((old ^ 1))")" | dd of="$STATE/g1/out/$dag.mjv" bs=1 seek=235 conv=notrunc status=none + cp "$STATE/journal" "$STATE/before" + local rc=0; run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? + semantic check-before-ingest test "$rc" = 14 + cmp "$STATE/journal" "$STATE/before" +} +pin_substitution() { + local mode=$1 guard=operand-pin expected=24 source_gen=1 target_gen=1 source_state source_dag + local other_objective old_operand target_dag pid rc=0 tag id st generation rest matches=0 + case "$mode" in + objective) + guard=objective-pin; expected=23 + other_objective=$(printf aienet-m1-other-objective | hash_words) + new_state foreign-objective 7 "$other_objective" + ;; + operand) new_state foreign-operand 8 ;; + after-correct) + new_state foreign-old-operand 8 + old_operand=$(printf '010002000300020000000000000007' | xxd -r -p | hash_words) + bash "$driver" propose "$STATE" 6 1 0 1 7 0 $old_operand 0 0 + printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/2" + source_gen=2; target_gen=2 + ;; + *) return 2 ;; + esac + run_sequence + exactly_once "$source_gen" + source_state=$STATE + source_dag=$(sha256sum "$STATE/g$source_gen/document" | cut -d' ' -f1) + new_state "substitute-$mode" + if test "$mode" = after-correct; then correct; fi + # The real sequencer is paused after authentic artifacts arrive but before + # its check/ingest. Replace the entire signed submission, not isolated bytes. + M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & + pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + target_dag=$(sha256sum "$STATE/g$target_gen/document" | cut -d' ' -f1) + local art="$STATE/g$target_gen" foreign="$source_state/g$source_gen" + mkdir "$STATE/original" + cp "$art/document" "$art/job.an0b" "$art/out/$target_dag.mjr1" "$art/out/$target_dag.mjv" "$STATE/original/" + cp "$foreign/document" "$art/document" + cp "$foreign/job.an0b" "$art/job.an0b" + cp "$foreign/out/$source_dag.mjr1" "$art/out/$target_dag.mjr1" + cp "$foreign/out/$source_dag.mjv" "$art/out/$target_dag.mjv" + "$RUN" check --bundle "$art/job.an0b" --mjr1 "$art/out/$target_dag.mjr1" --mjv "$art/out/$target_dag.mjv" --keys "$KEYS" --pins "$PINS" > "$STATE/substitute-check.log" 2>&1 + cp "$STATE/journal" "$STATE/before-substitute" + rm "$STATE/paused" + wait "$pid" || rc=$? + active_pid= + printf '%s%s\t%s\t%s\n' "${CASE_PREFIX:-}" "$mode" "$expected" "$rc" >> "$E/pin-refusals.tsv" + semantic "$guard" test "$rc" = "$expected" + test ! -s "$art/events" + cmp "$STATE/journal" "$STATE/before-substitute" + bash "$driver" status "$STATE" > "$STATE/refused-status" + while read -r tag id st generation rest; do + if test "$tag/$id" = 101/1; then + matches=$((matches+1)) + test "$st/$generation" = "2/$target_gen" + fi + done < "$STATE/refused-status" + test "$matches" = 1 + # Restore the originally checked bytes: the same dispatch can then complete. + cp "$STATE/original/document" "$art/document" + cp "$STATE/original/job.an0b" "$art/job.an0b" + cp "$STATE/original/$target_dag.mjr1" "$art/out/$target_dag.mjr1" + cp "$STATE/original/$target_dag.mjv" "$art/out/$target_dag.mjv" + run_sequence + exactly_once "$target_gen" +} +operand_substitution() { pin_substitution operand; } +objective_substitution() { pin_substitution objective; } +conflicting_result() { + new_state conflicting-result + M1_PAUSE=resulted bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + kill -KILL "$pid"; wait "$pid" || true + rm "$STATE/paused" + local lines fields rc=0 + mapfile -t lines < "$STATE/journal" + read -r -a fields <<< "${lines[1]}" + fields[13]=$((fields[13]+1)) + printf '%s\n%s\n' "${lines[0]}" "${fields[*]}" > "$STATE/journal" + bash "$driver" status "$STATE" > "$STATE/resulted-status" + cp "$STATE/journal" "$STATE/before-conflict" + run_sequence > "$STATE/conflict.log" 2>&1 || rc=$? + semantic result-conflict test "$rc" = 33 + cmp "$STATE/journal" "$STATE/before-conflict" +} +history() { + local count=$1 gen=$(( $1+1 )) i current=1 changed expected seed effective + new_state "history-$count" + printf '010002000300020000000000000008' | xxd -r -p > "$STATE/payload2" + changed=$(hash_words < "$STATE/payload2") + for ((i=1;i<=count;i++)); do + if ((i%2)); then effective=$changed; else effective=$operand; fi + printf '3 %s 6 1 0 %s 7 0 %s 0 0\n' "$i" "$current" "$effective" >> "$STATE/journal" + current=$((current+1)) + done + if ((count%2)); then seed=8; expected=$changed; else seed=7; expected=$operand; fi + printf '4 %s %s %s %s %s %s 2 3 2 %s 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" "$seed" > "$STATE/bindings/$gen" + bash "$driver" status "$STATE" > "$STATE/history-status" + { printf '1\n'; cat "$STATE/plan" "$STATE/journal"; } | "$RECOVERY" > "$STATE/effective-probe" + read -r -a fields < "$STATE/effective-probe" + semantic latest-correct test "${fields[*]:35:4}" = "$expected" + run_sequence + exactly_once "$gen" +} +multiple_corrects() { history 2; } +correct_after_result() { + new_state correct-after-result + M1_PAUSE=resulted bash "$sequence" > "$STATE/first.log" 2>&1 & + local pid=$!; active_pid=$pid + wait_file "$STATE/paused" "$pid" + kill -KILL "$pid"; wait "$pid" || true + rm "$STATE/paused" + correct + bash "$driver" propose "$STATE" 6 1 0 2 7 0 $operand 0 0 + printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/3" + run_sequence + exactly_once 3 + local tag seq type node attempt generation rest stale_verify=0 + while read -r tag seq type node attempt generation rest; do + if test "$type/$node/$generation" = 3/1/1; then stale_verify=$((stale_verify+1)); fi + done < "$STATE/journal" + test "$stale_verify" = 0 +} +capacity_boundaries() { + new_state capacity + # kernel.om:10,60-79: buffer length 262144, load refuses >= length-1. + local capacity=262144 size bytes expected kr hr + cat "$STATE/plan" "$STATE/journal" > "$STATE/base-input" + bytes=$(wc -c < "$STATE/base-input") + printf 'bytes\texpected_kernel\texpected_recovery\tobserved_kernel\tobserved_recovery\n' > "$STATE/capacity.tsv" + for size in "$((capacity-2))" "$((capacity-1))" "$capacity" "$((capacity+1))"; do + cp "$STATE/base-input" "$STATE/kernel-input" + printf '%*s' "$((size-bytes))" '' >> "$STATE/kernel-input" + expected=3; if test "$size" = "$((capacity-2))"; then expected=0; fi + kr=0; "$GM_KERNEL" < "$STATE/kernel-input" > "$STATE/capacity-status" || kr=$? + hr=0; { printf '1\n'; cat "$STATE/kernel-input"; } | "$RECOVERY" > "$STATE/capacity-fold" || hr=$? + printf '%s\t%s\t%s\t%s\t%s\n' "$size" "$expected" "$expected" "$kr" "$hr" >> "$STATE/capacity.tsv" + test "$kr" = "$expected"; test "$hr" = "$expected" + if test "$expected" = 0; then + { + cat "$STATE/capacity-fold" + while read -r tag rest; do if test "$tag" = 101; then printf '%s %s\n' "$tag" "$rest"; fi; done < "$STATE/capacity-status" + cat "$STATE/bindings/1" + } | "$CANON" emit > "$STATE/capacity-emission" + test "$(wc -c < "$STATE/capacity-emission")" = 687 + else + test ! -s "$STATE/capacity-fold" + fi + done +} +omega_mutant() { + local name=$1 guard=$2 probe=$3 original=$RECOVERY line skip=0 + local source="$E/recovery-$name.om" binary="$E/recovery-$name" + : > "$source" + while IFS= read -r line; do + if test "$skip" = 1; then skip=0; continue; fi + if test "$name" = conflict && test "$line" = 'note RECOVERY-GUARD result-conflict'; then skip=1; fi + printf '%s\n' "$line" >> "$source" + if test "$name" = first-correct && test "$line" = 'note RECOVERY-MUTANT first-correct-stop'; then printf 'break\n' >> "$source"; fi + done < "$repo/src/goal_microjobs/recovery.om" + OMEGA_OMC="$RECOMPUTE_OMC" sh "$repo/scripts/goal_microjobs/recovery-build.sh" "$binary" "$source" > "$E/recovery-$name-build.log" 2>&1 + export RECOVERY="$binary" CASE_PREFIX="mutant-$name-" + local rc=0 + set +e + (set -e; trap cleanup_case EXIT; "$probe") > "$E/mutant-$name.log" 2>&1 + rc=$? + set -e + export RECOVERY=$original + unset CASE_PREFIX + test "$rc" = 1 + local killed=0 + while IFS= read -r line; do + if test "$line" = "M1_SEMANTIC $guard"; then killed=1; fi + done < "$E/mutant-$name.log" + test "$killed" = 1 + printf '%s\tKILLED\t1\n' "$guard" >> "$E/mutants.tsv" +} +# Mutations are generated into evidence-local copies by removing exactly the +# named guard line. No candidate source, compiler or historical receipt changes. +mutant() { + local name=$1 guard=$2 probe=$3 + local original=$sequence + sequence="$E/mutant-$name.sh" + local skip=0 line + : > "$sequence" + while IFS= read -r line; do + if test "$skip" = 1; then skip=0; continue; fi + if test "$line" = "# M1-GUARD $guard"; then skip=1; fi + printf '%s\n' "$line" >> "$sequence" + if test "$name" = persist && test "$line" = '# M1-MUTANT late-persist insertion point'; then printf 'persist\n' >> "$sequence"; fi + if test "$name/$line" = 'doc-objective/# M1-GUARD objective-pin'; then + printf 'objective_pin=$(od -An -tu8 --endian=big -j8 -N32 "$art/document")\n' >> "$sequence" + fi + if test "$name/$line" = 'doc-operand/# M1-GUARD operand-pin'; then + printf 'operand_pin=$(od -An -tu8 --endian=big -j488 -N32 "$art/document")\n' >> "$sequence" + fi + done < "$original" + # The copy is outside the repository; preserve its known adapter root. + export M1_REPO="$repo" + local rc=0 + export CASE_PREFIX="mutant-$name-" + set +e + (set -e; trap cleanup_case EXIT; "$probe") > "$E/mutant-$name.log" 2>&1 + rc=$? + set -e + unset CASE_PREFIX + sequence=$original + test "$rc" = 1 + local killed=0 + while IFS= read -r line; do + if test "$line" = "M1_SEMANTIC $guard"; then killed=1; fi + done < "$E/mutant-$name.log" + test "$killed" = 1 + printf '%s\tKILLED\t%s\n' "$name" "$rc" >> "$E/mutants.tsv" +} +persist_probe() { crash dispatched; } +checks=0 failures=0 +printf '# canon_source\t%s\n# canon_binary_sha256\t%s\ncase\texpected\tobserved\texit\n' "$canon_source" "$canon_binary" > "$E/summary.tsv" +printf '# oh_source\t%s\n# oh_run_sha256\t%s\n# oh_serve_sha256\t%s\n' "$oh_source" "$oh_run_sha" "$oh_serve_sha" > "$E/metadata.tsv" +cat "$E/summary.tsv" >> "$E/metadata.tsv" +mv "$E/metadata.tsv" "$E/summary.tsv" +printf 'case\texpected_refusal\tobserved_exit\n' > "$E/pin-refusals.tsv" +case_run() { + local name=$1; shift + local rc=0 + set +e + (set -e; trap cleanup_case EXIT; "$@") > "$E/$name.log" 2>&1 + rc=$? + set -e + checks=$((checks+1)) + if test "$rc" = 0; then + printf '%s\tPASS\tPASS\t0\n' "$name" >> "$E/summary.tsv" + else + failures=$((failures+1)) + printf '%s\tPASS\tFAIL\t%s\n' "$name" "$rc" >> "$E/summary.tsv" + fi +} +case_run done-reject-resulted done_negative resulted '101 1 3 1 1 0 0 0' +case_run done-reject-missing done_negative missing '100 1 1 0' +case_run done-reject-duplicate done_negative duplicate $'101 1 4 1 1 0 0 0\n101 1 4 1 1 0 0 0' +case_run result-conflict conflicting_result +case_run multiple-corrects multiple_corrects +case_run history-257 history 257 +case_run history-1000 history 1000 +case_run correct-after-result correct_after_result +case_run kernel-capacity-boundaries capacity_boundaries +case_run happy happy +for boundary in persisted dispatched published resulted; do case_run "crash-$boundary" crash "$boundary"; done +case_run crash-worker-admitted worker_crash +case_run crash-worker-done worker_crash done +case_run stale stale +case_run stale-restored-operand generation_probe +case_run altered altered +case_run signed-wrong-output wrong_output +case_run duplicate duplicate +case_run attestation-signature attestation_signature +case_run substitute-operand operand_substitution +case_run substitute-objective objective_substitution +case_run substitute-pre-correct pin_substitution after-correct +if test "$failures" != 0; then + cat "$E/summary.tsv" + echo 'mutants NOT_RUN: baseline cases must all pass' + exit 1 +fi +printf 'mutant\tverdict\tprobe_exit\n' > "$E/mutants.tsv" +case_run mutant-persist mutant persist persist-before-dispatch persist_probe +case_run mutant-check mutant check check-before-ingest attestation_signature +case_run mutant-generation mutant generation generation-match generation_probe +case_run mutant-result-conflict omega_mutant conflict result-conflict conflicting_result +case_run mutant-first-correct omega_mutant first-correct latest-correct multiple_corrects +case_run mutant-doc-objective mutant doc-objective objective-pin objective_substitution +case_run mutant-doc-operand mutant doc-operand operand-pin operand_substitution +cat "$E/summary.tsv" "$E/mutants.tsv" +printf 'M1 cases=%s failures=%s evidence=%s\n' "$checks" "$failures" "$E" +test "$failures" = 0 diff --git a/tests/goal_microjobs/aienet-m1/sequence.sh b/tests/goal_microjobs/aienet-m1/sequence.sh new file mode 100755 index 0000000..6295b56 --- /dev/null +++ b/tests/goal_microjobs/aienet-m1/sequence.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: AGPL-3.0-or-later +# Migration adapter, aien-dev/aien#22 (shell retirement): files, locks and +# processes only. canon.om binds wire identities; kernel.om admits every event; +# OH verifies P-256 signatures and runs the independently pinned Omega verifier. +set -euo pipefail +: "${STATE:?}" "${GM_KERNEL:?}" "${CANON:?}" "${RUN:?}" "${SERVE:?}" +: "${KEYS:?}" "${WKEYS:?}" "${PINS:?}" "${WPINS:?}" "${RECOMPUTE:?}" +: "${RECOMPUTE_SHA256:?}" "${LISTEN:?}" +repo=${M1_REPO:-$(cd "$(dirname "$0")/../../.." && pwd)} +driver="$repo/scripts/goal_microjobs/microjobs.sh" +exec 8>"$STATE/sequence.lock" +flock -n 8 || exit 75 +pause() { + if test "${M1_PAUSE:-}" = "$1"; then + test -p "$STATE/pause.fifo" || mkfifo "$STATE/pause.fifo" + exec 9<>"$STATE/pause.fifo" + printf '%s\n' "$1" > "$STATE/paused" + while test -e "$STATE/paused"; do read -r -t 0.05 -u 9 _ || true; done + exec 9>&- + fi +} +status=$(bash "$driver" status "$STATE") +while read -r tag id st gen attempts blocked ready effect; do + if test "$tag" = 101 && test "$id" = 1; then break; fi +done <<< "$status" +test "$tag" = 101 && test "$id" = 1 +if test "$st" = 4; then echo ALREADY_ACCEPTED; exit 0; fi +test "$st" = 1 || test "$st" = 2 || test "$st" = 3 +art="$STATE/g$gen" +mkdir -p "$art" +# Kernel replay validates the journal; Omega derives the effective operand. +{ + printf '1\n' + cat "$STATE/plan" "$STATE/journal" +} | "${RECOVERY:?}" > "$art/effective.next" +{ + cat "$art/effective.next" + printf '101 1 %s %s %s %s %s %s\n' "$st" "$gen" "$attempts" "$blocked" "$ready" "$effect" + cat "$STATE/bindings/$gen" +} | "$CANON" emit > "$art/emission.next" +dd if="$art/emission.next" of="$art/document.next" bs=1 count=640 status=none +dd if="$art/emission.next" of="$art/payload.next" bs=1 skip=640 count=15 status=none +if test -e "$art/document"; then + cmp "$art/document" "$art/document.next" +else + mv "$art/document.next" "$art/document" +fi +if test -e "$art/payload"; then + cmp "$art/payload" "$art/payload.next" +else + mv "$art/payload.next" "$art/payload" +fi +sync "$art/document" "$art/payload" "$art" +rm -f "$art/emission.next" "$art/document.next" "$art/payload.next" +bundle="$art/job.an0b" +persist() { + if ! test -e "$bundle"; then + "$RUN" bundle --keys "$KEYS" --out "$bundle" --document "$art/document" --payload "$art/payload" + fi + sync "$bundle" "$art" +} +# M1-GUARD persist-before-dispatch +persist +pause persisted +if test "$st" = 1; then + bash "$driver" propose "$STATE" 1 1 1 "$gen" 20 0 0 0 0 0 0 0 +fi +pause dispatched +# M1-MUTANT late-persist insertion point +if test "${M1_STOP_AFTER_DISPATCH:-0}" = 1; then exit 0; fi +dag=$(sha256sum "$art/document" | cut -d' ' -f1) +out="$art/out" +mkdir -p "$out" +worker_pid= +cleanup() { + if test -n "$worker_pid"; then kill "$worker_pid" 2>/dev/null || true; wait "$worker_pid" 2>/dev/null || true; fi +} +trap cleanup EXIT +if ! test -f "$out/$dag.mjr1" || ! test -f "$out/$dag.mjv"; then + worker_args=(--connect "$LISTEN" --keys "$WKEYS" --pins "$WPINS" --state "$art/worker" --retry --connect-timeout 10) + if test -n "${M1_MISBEHAVE:-}"; then worker_args+=(--misbehave "$M1_MISBEHAVE"); fi + if test -n "${M1_TEST_WORKER:-}"; then + printf '%s\n' "${worker_args[@]}" > "$art/worker.args" + AN0_TEST_SERVE_ARGS="$art/worker.args" AN0_TEST_PAUSE="${M1_WORKER_PAUSE:-admitted}" AN0_TEST_READY="$art/worker.ready" \ + "$M1_TEST_WORKER" --ignored --exact tests::serve_crash_worker --nocapture > "$art/worker.log" 2>&1 & + else + "$SERVE" "${worker_args[@]}" > "$art/worker.log" 2>&1 & + fi + worker_pid=$! + printf '%s\n' "$worker_pid" > "$art/worker.pid" + "$RUN" run --resend "$bundle" --listen "$LISTEN" --keys "$KEYS" --pins "$PINS" --out "$out" \ + --recompute "$RECOMPUTE" --recompute-sha256 "$RECOMPUTE_SHA256" --accept-timeout 10 + wait "$worker_pid" + worker_pid= +fi +pause published +# M1-GUARD check-before-ingest +"$RUN" check --bundle "$bundle" --mjr1 "$out/$dag.mjr1" --mjv "$out/$dag.mjv" --keys "$KEYS" --pins "$PINS" +# An owner correction during network execution must win over the old response. +current=$(bash "$driver" status "$STATE") +while read -r tag id current_state current_gen rest; do + if test "$tag" = 101 && test "$id" = 1; then break; fi +done <<< "$current" +ingest_gen=$gen +# M1-GUARD generation-match +ingest_gen=$current_gen +# Recovery, not submitted wire bytes, supplies the objective and latest operand. +{ + printf '1\n' + cat "$STATE/plan" "$STATE/journal" +} | "$RECOVERY" > "$art/ingest-effective" +read -r -a trusted < "$art/ingest-effective" +# M1-GUARD objective-pin +objective_pin="${trusted[*]:2:4}" +# M1-GUARD operand-pin +operand_pin="${trusted[*]:35:4}" +next=$(( $(wc -l < "$STATE/journal") + 1 )) +if test "$st" = 3; then next=$((next - 1)); fi +{ + cat "$art/document" "$out/$dag.mjr1" "$out/$dag.mjv" + printf '5 1 %s 1 20 5 %s %s %s %s %s\n' "$ingest_gen" "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$next" "$objective_pin" "$operand_pin" +} | "$CANON" ingest > "$art/events" +# Each event is independently journaled via the kernel. Recovery from a torn +# pair proves the persisted RESULT is identical before proposing only VERIFY. +mapfile -t events < "$art/events" +test "${#events[@]}" = 2 +if test "$st" = 3; then + last=$(cat "$STATE/journal" | { mapfile -t lines; printf '%s\n' "${lines[-1]}"; }) + printf '2\n%s\n%s\n' "$last" "${events[0]}" | "$RECOVERY" +else + read -r _ _ rest <<< "${events[0]}" + bash "$driver" propose "$STATE" $rest +fi +pause resulted +read -r _ _ rest <<< "${events[1]}" +bash "$driver" propose "$STATE" $rest +bash "$driver" status "$STATE"