interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
interplane-mv / adapters / aien / scripts / demo-verified-fix.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Reproducible demo of the verified fix-the-test workflow (VAC M4a). |
| 3 | # |
| 4 | # One command runs the fix-the-test slice gate (scripts/test-fix-the-test.sh) against a real native |
| 5 | # `aien-cli daemon`, records every revision it depends on, and writes $OUT/DEMO-RESULT.md. It refuses to |
| 6 | # pass when the daemon reports a STUB compose library, when the verdict is anything other than the |
| 7 | # labelled-incomplete one a scripted run may earn, or when any recorded fact disagrees with its source. |
| 8 | # |
| 9 | # Prerequisites: git, jq, make, cc, cargo/rustc, sha256sum, the Llama-3.2-1B-Instruct snapshot (see |
| 10 | # adapters/aien/README.md "Reproducible demo"). `quietlock check` is honoured when quietlock exists. |
| 11 | # |
| 12 | # Daemon, one of: |
| 13 | # AIEN_BIN=<path> an aien-cli built natively (omega compose library linked). Its sovereign-core rev is |
| 14 | # caller-asserted via SOVEREIGN_CORE_REV unless the daemon prints it. |
| 15 | # build mode SC_DIR (aien-sovereign-core checkout), OMEGA_DIR (HEAD == SC_DIR/omega.lock), |
| 16 | # PHYSICS_DIR (HEAD == OMEGA_DIR/physics.lock), AIENOS_REPO (HEAD == OMEGA_DIR/aienos.lock); |
| 17 | # builds `cargo build -p aien-cli` on the CPU with the same env as sovereign-core's |
| 18 | # scripts/test-linked-compose.sh. CARGO_TARGET_DIR is honoured. |
| 19 | # Also: OUT (fresh directory, required), AIEN_LEDGER_MODEL_DIR, SOVEREIGN_CORE_REV, OMEGA_LOCK_REV. |
| 20 | # No process is killed here. Exit non-zero on any failure. |
| 21 | set -euo pipefail |
| 22 | |
| 23 | here="$(cd "$(dirname "$0")" && pwd)" |
| 24 | adapter="$(cd "$here/.." && pwd)" |
| 25 | repo="$(cd "$adapter/../.." && pwd)" |
| 26 | die() { echo "DEMO FAIL: $*" >&2; exit 1; } |
| 27 | : "${OUT:?OUT must name a fresh output directory}" |
| 28 | for t in git jq make cc sha256sum rustc cargo; do command -v "$t" >/dev/null || die "$t is required"; done |
| 29 | [ ! -e "$OUT/gate" ] || die "$OUT/gate exists: use a fresh OUT" |
| 30 | mkdir -p "$OUT"; OUT="$(cd "$OUT" && pwd)" |
| 31 | if command -v quietlock >/dev/null && ! quietlock check >/dev/null 2>&1; then die "quiet flag is held (quietlock check)"; fi |
| 32 | model_dir="${AIEN_LEDGER_MODEL_DIR:-$HOME/.cache/huggingface/hub/models--unsloth--Llama-3.2-1B-Instruct/snapshots/5a8abab4a5d6f164389b1079fb721cfab8d7126c}" |
| 33 | red() { sed -e "s#$HOME#~#g" -e "s#$repo#<interplane>#g"; } # no home paths in the record |
| 34 | started="$(date -u +%FT%TZ)" |
| 35 | [ -z "$(git -C "$repo" status --porcelain -- adapters provenance)" ] || die "adapters/ or provenance/ has uncommitted changes: the demo records a commit, so commit or stash first" |
| 36 | |
| 37 | # 1. The daemon: given, or built from the four checkouts and their locks. |
| 38 | build_note="" |
| 39 | if [ -z "${AIEN_BIN:-}" ]; then |
| 40 | : "${SC_DIR:?set AIEN_BIN, or SC_DIR OMEGA_DIR PHYSICS_DIR AIENOS_REPO to build}" |
| 41 | : "${OMEGA_DIR:?OMEGA_DIR}" "${PHYSICS_DIR:?PHYSICS_DIR}" "${AIENOS_REPO:?AIENOS_REPO}" |
| 42 | SC_DIR="$(cd "$SC_DIR" && pwd)"; OMEGA_DIR="$(cd "$OMEGA_DIR" && pwd)" |
| 43 | PHYSICS_DIR="$(cd "$PHYSICS_DIR" && pwd)"; AIENOS_REPO="$(cd "$AIENOS_REPO" && pwd)" |
| 44 | [ "$(git -C "$OMEGA_DIR" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$SC_DIR/omega.lock")" ] || die "omega HEAD != sovereign-core omega.lock" |
| 45 | [ "$(git -C "$PHYSICS_DIR" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMEGA_DIR/physics.lock")" ] || die "physics HEAD != omega physics.lock" |
| 46 | [ "$(git -C "$AIENOS_REPO" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMEGA_DIR/aienos.lock")" ] || die "aienos HEAD != omega aienos.lock" |
| 47 | export AIEN_OMEGA_COMPOSE_DIR="$OMEGA_DIR" AIEN_PHYSICS_DIR="$PHYSICS_DIR" AIEN_AIENOS_LOCK_REPO="$AIENOS_REPO" |
| 48 | unset AIEN_OMEGA_DIR AIEN_OMEGA_GPU_LIB AIEN_OMEGA_COMPOSE_LIB AIEN_OMEGA_COMPOSE_SHA AIEN_FORCE_CPU_STUB AIEN_DEV_FALLBACK |
| 49 | (cd "$SC_DIR" && cargo build -p aien-cli) >"$OUT/build.log" 2>&1 || { tail -5 "$OUT/build.log" >&2; die "daemon build failed (log $OUT/build.log)"; } |
| 50 | AIEN_BIN="${CARGO_TARGET_DIR:-$SC_DIR/target}/debug/aien-cli" |
| 51 | SOVEREIGN_CORE_REV="$(git -C "$SC_DIR" rev-parse HEAD)"; export SOVEREIGN_CORE_REV |
| 52 | [ -z "$(git -C "$SC_DIR" status --porcelain --untracked-files=no)" ] || die "sovereign-core checkout is dirty" |
| 53 | build_note="built here from SC_DIR at $SOVEREIGN_CORE_REV (CPU, debug)" |
| 54 | else |
| 55 | [ -x "$AIEN_BIN" ] || die "AIEN_BIN not executable: $AIEN_BIN" |
| 56 | build_note="supplied via AIEN_BIN, not built by this run" |
| 57 | OMEGA_DIR="${OMEGA_DIR:-${AIEN_OMEGA_COMPOSE_DIR:-}}"; PHYSICS_DIR="${PHYSICS_DIR:-${AIEN_PHYSICS_DIR:-}}"; AIENOS_REPO="${AIENOS_REPO:-${AIEN_AIENOS_LOCK_REPO:-}}" |
| 58 | SC_DIR="${SC_DIR:-}" |
| 59 | fi |
| 60 | export AIEN_BIN |
| 61 | rev_of() { [ -n "$1" ] && git -C "$1" rev-parse HEAD 2>/dev/null || echo "UNVERIFIED (checkout not given)"; } |
| 62 | omega_rev="${OMEGA_LOCK_REV:-$(rev_of "${OMEGA_DIR:-}")}" |
| 63 | physics_rev="$(rev_of "${PHYSICS_DIR:-}")"; aienos_rev="$(rev_of "${AIENOS_REPO:-}")" |
| 64 | omega_lock="n/a"; physics_lock="n/a"; aienos_lock="n/a" |
| 65 | [ -n "${SC_DIR:-}" ] && [ -f "$SC_DIR/omega.lock" ] && omega_lock="$(tr -d '[:space:]' <"$SC_DIR/omega.lock")" |
| 66 | [ -n "${OMEGA_DIR:-}" ] && [ -f "$OMEGA_DIR/physics.lock" ] && physics_lock="$(tr -d '[:space:]' <"$OMEGA_DIR/physics.lock")" |
| 67 | [ -n "${OMEGA_DIR:-}" ] && [ -f "$OMEGA_DIR/aienos.lock" ] && aienos_lock="$(tr -d '[:space:]' <"$OMEGA_DIR/aienos.lock")" |
| 68 | bin_sha="$(sha256sum "$AIEN_BIN" | cut -d' ' -f1)" |
| 69 | sc_rev="${SOVEREIGN_CORE_REV:-UNVERIFIED}" |
| 70 | if [ -n "${SC_DIR:-}" ] && [ -d "$SC_DIR/.git" -o -f "$SC_DIR/.git" ]; then sc_rev="$(git -C "$SC_DIR" rev-parse HEAD)"; sc_src="read from SC_DIR"; else sc_src="caller-asserted (SOVEREIGN_CORE_REV), not verified by this run"; fi |
| 71 | export SOVEREIGN_CORE_REV="$sc_rev" |
| 72 | [ "$sc_rev" != "UNVERIFIED" ] || echo "note: SOVEREIGN_CORE_REV not given; recorded as UNVERIFIED" >&2 |
| 73 | |
| 74 | # 2. The slice gate, once. A stub daemon is refused below, from the daemon's own report. |
| 75 | gate_rc=0 |
| 76 | OMEGA_LOCK_REV="$omega_rev" OUT="$OUT/gate" "$here/test-fix-the-test.sh" >"$OUT/gate.log" 2>&1 || gate_rc=$? |
| 77 | [ "$gate_rc" -eq 0 ] || { tail -5 "$OUT/gate.log" | red >&2; die "slice gate failed with $gate_rc (log $OUT/gate.log)"; } |
| 78 | g="$OUT/gate"; rec="$g/receipt.json"; b="$g/rows/slice1/bundle"; r="$b/records" |
| 79 | dlog="$g/rows/slice1/daemon.log" |
| 80 | [ -f "$rec" ] && [ -f "$b/COMPANION.json" ] && [ -f "$dlog" ] || die "gate left no receipt, bundle or daemon log" |
| 81 | |
| 82 | # 3. Facts, each read from the daemon's or the run's own output. |
| 83 | compose_line="$(grep -m1 '^Compose:' "$dlog" || true)" |
| 84 | [ -n "$compose_line" ] || die "daemon log has no Compose: line" |
| 85 | case "$compose_line" in "Compose: native ("*) ;; *) die "STUB daemon (daemon says: $compose_line): the demo does not pass on a stub";; esac |
| 86 | recall_native="$(jq -r '.compose_native // "absent"' "$r/aien/compose-recall.json")" |
| 87 | recall_omega="$(jq -r '.omega_sha // "absent"' "$r/aien/compose-recall.json")" |
| 88 | [ "$recall_native" = "true" ] || die "ComposeRecall compose_native=$recall_native (need true)" |
| 89 | line_omega="$(printf '%s' "$compose_line" | sed -n 's/^Compose: native (omega \([0-9a-f]*\)).*/\1/p')" |
| 90 | [ "$line_omega" = "$recall_omega" ] || die "Compose line omega ($line_omega) != ComposeRecall omega_sha ($recall_omega)" |
| 91 | if [ "$omega_rev" != "${omega_rev#UNVERIFIED}" ] || [ "$omega_rev" = "n/a" ]; then omega_check="not compared (omega checkout not given)" |
| 92 | else [ "$omega_rev" = "$recall_omega" ] || die "omega checkout $omega_rev != daemon omega $recall_omega"; omega_check="matches the daemon's report"; fi |
| 93 | [ "$(jq -r .aien.native.claimed "$b/COMPANION.json")" = "true" ] || die "bundle does not claim native" |
| 94 | verdict="$(jq -r .verdict "$rec")" |
| 95 | want="PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn" |
| 96 | [ "$verdict" = "$want" ] || die "verdict is not the expected labelled-incomplete one: $verdict" |
| 97 | case "$verdict" in PASS|"PASS complete"*) die "a scripted run cannot be PASS complete";; esac |
| 98 | [ "$(jq -r .aien_cli_sha256 "$rec")" = "$bin_sha" ] || die "daemon binary hash changed during the run" |
| 99 | |
| 100 | model_sha="$(sed -n 's/.*model_sha256=\([0-9a-f]*\).*/\1/p' "$dlog" | head -1)" |
| 101 | tok_sha="$(sed -n 's/.*tokenizer_sha256=\([0-9a-f]*\).*/\1/p' "$dlog" | head -1)" |
| 102 | [ -n "$model_sha" ] && [ -n "$tok_sha" ] || die "daemon load log lacks model/tokenizer sha256" |
| 103 | [ "$model_sha" = "$(sha256sum "$model_dir/model.safetensors" | cut -d' ' -f1)" ] || die "model sha256 in the daemon log != the file on disk" |
| 104 | [ "$tok_sha" = "$(sha256sum "$model_dir/tokenizer.json" | cut -d' ' -f1)" ] || die "tokenizer sha256 in the daemon log != the file on disk" |
| 105 | backend="$(grep -m1 -i 'backend' "$dlog" | red || true)" |
| 106 | |
| 107 | grant="$(jq -r .text "$r/aien/ledger-grant.json")"; ack="$(jq -r .text "$r/aien/ledger-ack.json")"; intent="$(jq -r .text "$r/aien/ledger-intent.json")" |
| 108 | appr_id="$(jq -r .approval_id <<<"$grant")"; appr_key="$(jq -r .approval_key <<<"$grant")"; approver="$(jq -r .approver <<<"$grant")" |
| 109 | w_path="$(jq -r .path <<<"$intent")"; w_sha="$(jq -r .content_sha256 <<<"$intent")"; w_prior="$(jq -r .prior_sha256 <<<"$intent")" |
| 110 | ack_phase="$(jq -r .phase <<<"$ack")"; ack_disk="$(jq -r .disk_sha256 <<<"$ack")"; ack_err="$(jq -r '.disk_error // "null"' <<<"$ack")" |
| 111 | [ "$ack_phase" = "ack" ] && [ "$ack_disk" = "$w_sha" ] && [ "$ack_err" = "null" ] || die "ack does not confirm the approved bytes on disk" |
| 112 | # The intent carries no approval id; it binds to the grant by `authorization` (= the grant record id), and the |
| 113 | # grant carries the approval. So all three must hold: intent -> this grant, grant -> an approval, same proposal. |
| 114 | grant_id="$(jq -r .id "$r/aien/ledger-grant.json")" |
| 115 | [ "$(jq -r .authorization <<<"$intent")" = "$grant_id" ] || die "intent.authorization is not this grant ($grant_id)" |
| 116 | case "$appr_id" in ""|null) die "grant carries no approval_id";; esac |
| 117 | [ "$(jq -r .proposal_sha256 <<<"$intent")" = "$(jq -r .proposal_sha256 <<<"$grant")" ] || die "intent and grant name different proposals" |
| 118 | approved_content_sha="$(jq -r .content_sha256 <<<"$grant")" |
| 119 | [ "$approved_content_sha" = "$w_sha" ] || die "grant content sha != written content sha" |
| 120 | trace_content_sha="$(jq -j ".[0].payload.arguments.content" "$r/interplane/trace.json" | sha256sum | cut -d" " -f1)" |
| 121 | [ "$trace_content_sha" = "$w_sha" ] || die "the INTERPLANE request content digest ($trace_content_sha) != the approved content digest" |
| 122 | t_before_exit="$(jq -r .task.test_exit_before "$rec")"; t_after_exit="$(jq -r .task.test_exit_after "$rec")" |
| 123 | out_before_sha="$(jq -r .before.stdout_sha256 "$r/task/test-run.json")"; out_after_sha="$(jq -r .stdout_sha256 "$r/task/test-run.json")" |
| 124 | [ "$out_after_sha" = "$(sha256sum "$r/task/test-stdout.txt" | cut -d' ' -f1)" ] || die "retained stdout digest != test-run record" |
| 125 | neg_n="$(jq '.negative_checks | length' "$rec")"; [ "$neg_n" -eq 8 ] || die "expected 8 negative checks (control + 7), got $neg_n" |
| 126 | rustc_v="$(rustc --version)" |
| 127 | finished="$(date -u +%FT%TZ)" |
| 128 | mf() { jq -r "$1" "$rec"; } |
| 129 | |
| 130 | # 4. DEMO-RESULT.md |
| 131 | res="$OUT/DEMO-RESULT.md" |
| 132 | { |
| 133 | cat <<MD |
| 134 | # Verified fix-the-test demo (VAC M4a) |
| 135 | |
| 136 | Machine-written by \`adapters/aien/scripts/demo-verified-fix.sh\`. Started $started, finished $finished (UTC). |
| 137 | Labels: [O] observed in this run's own output, [I] inferred, [U] UNVERIFIED. |
| 138 | |
| 139 | ## 1. Revisions |
| 140 | | item | value | |
| 141 | |---|---| |
| 142 | | interplane HEAD | $(git -C "$repo" rev-parse HEAD) (clean adapters/ and provenance/) [O] | |
| 143 | | sovereign-core rev | $sc_rev ($sc_src) | |
| 144 | | daemon binary | $build_note | |
| 145 | | daemon sha256 | $bin_sha [O] | |
| 146 | | daemon "Compose:" line | \`$compose_line\` [O] | |
| 147 | | omega.lock (sovereign-core) | $omega_lock | |
| 148 | | omega checkout HEAD | $omega_rev ($omega_check) | |
| 149 | | physics.lock (omega) | $physics_lock | |
| 150 | | physics checkout HEAD | $physics_rev | |
| 151 | | aienos.lock (omega) | $aienos_lock | |
| 152 | | aienos checkout HEAD | $aienos_rev | |
| 153 | | host | $(uname -sr), $(uname -m), $(nproc) cpus [O] | |
| 154 | | rustc | $rustc_v [O] | |
| 155 | | build env | AIEN_OMEGA_COMPOSE_DIR, AIEN_PHYSICS_DIR, AIEN_AIENOS_LOCK_REPO set to the checkouts above; AIEN_OMEGA_DIR, AIEN_FORCE_CPU_STUB, AIEN_DEV_FALLBACK unset (CPU only) | |
| 156 | | model dir | $(printf '%s' "$model_dir" | red) | |
| 157 | | model.safetensors sha256 | $model_sha (daemon load log, equals file on disk) [O] | |
| 158 | | tokenizer.json sha256 | $tok_sha (daemon load log, equals file on disk) [O] | |
| 159 | | verifier binary sha256 | $(mf .verifier_sha256) | |
| 160 | |
| 161 | ### Native or stub, as reported by the daemon |
| 162 | - Daemon log: \`$compose_line\` |
| 163 | - ComposeRecall: compose_native=$recall_native, omega_sha=$recall_omega (retained in the bundle as \`records/aien/compose-recall.json\`) [O] |
| 164 | - Bundle \`aien.native\`: $(jq -c .aien.native "$b/COMPANION.json") |
| 165 | - The demo exits non-zero on a stub; this run was not one. |
| 166 | |
| 167 | ## 2. Starting task |
| 168 | Task id \`$(mf .task.task_id)\`. Fixture \`adapters/aien/fixtures/fix_the_test/\` (\`TASK.md\`): |
| 169 | |
| 170 | \`\`\` |
| 171 | $(cat "$adapter/fixtures/fix_the_test/TASK.md") |
| 172 | \`\`\` |
| 173 | Source commit (harness git init of the fixture): $(mf .task.source_commit) |
| 174 | |
| 175 | ## 3. Authorized action |
| 176 | - Tool: write_file, path \`$w_path\` |
| 177 | - Content sha256: $w_sha (bytes the approval is bound to) |
| 178 | - Prior sha256 (bytes replaced): $w_prior |
| 179 | - Approval binding id: \`$appr_id\` (approval key $appr_key), approver \`$approver\` |
| 180 | - The grant, intent and ack records all carry that content digest [O] |
| 181 | |
| 182 | ## 4. Outcome |
| 183 | - Ledger ack: phase=$ack_phase, disk_sha256=$ack_disk (equals the approved content), disk_error=$ack_err [O] |
| 184 | |
| 185 | ## 5. Tests |
| 186 | | | exit code | retained stdout sha256 | |
| 187 | |---|---|---| |
| 188 | | before the write | $t_before_exit | $out_before_sha | |
| 189 | | after the write | $t_after_exit | $out_after_sha | |
| 190 | |
| 191 | Command: \`make test\` in the task workspace (GNU make exits 2 on a failing recipe). Tree commit after: $(mf .task.tree_commit_after). |
| 192 | |
| 193 | ## 6. Verifier verdict |
| 194 | \`\`\` |
| 195 | $verdict |
| 196 | \`\`\` |
| 197 | |
| 198 | ## 7. Tamper summary (each on a hard-linked copy of the bundle) |
| 199 | \`\`\` |
| 200 | $(jq -r '.negative_checks[]' "$rec" | cut -c1-160) |
| 201 | \`\`\` |
| 202 | |
| 203 | ## 8. Reproduction |
| 204 | \`\`\` |
| 205 | git clone <interplane> && cd interplane |
| 206 | # prerequisites: git jq make cc cargo; the Llama-3.2-1B-Instruct snapshot at \$AIEN_LEDGER_MODEL_DIR |
| 207 | # a native aien-cli (see the build-mode comment in the script), then: |
| 208 | AIEN_BIN=<native aien-cli> SOVEREIGN_CORE_REV=$sc_rev OUT=<fresh dir> adapters/aien/scripts/demo-verified-fix.sh |
| 209 | # or build it: SC_DIR=<sovereign-core @ rev above> OMEGA_DIR=<omega @ omega.lock> PHYSICS_DIR=<physics @ omega's physics.lock> \\ |
| 210 | # AIENOS_REPO=<aienos @ omega's aienos.lock> OUT=<fresh dir> adapters/aien/scripts/demo-verified-fix.sh |
| 211 | \`\`\` |
| 212 | This run: daemon $build_note; AIEN_OMEGA_COMPOSE_DIR/AIEN_PHYSICS_DIR/AIEN_AIENOS_LOCK_REPO as in the table; the script calls \`scripts/test-fix-the-test.sh\` once (one live row, a real daemon, CPU). |
| 213 | |
| 214 | ## 9. What is proven |
| 215 | - The approved write is bound to exact bytes: grant, intent and ack share one content digest, and the ack's on-disk digest equals it [O]. |
| 216 | - The write went through the daemon's approved ledger (claim, grant, intent, ack, committed records retained) [O]. |
| 217 | - Tests failed before and passed after; their stdout digests are retained and checked by the verifier [O]. |
| 218 | - The source pin matches the grant's prior_sha256; the native claim agrees with the daemon's own report; seven tampers are each refused with their specific code [O]. |
| 219 | - The daemon was native (not a stub) by its own report, and its model/tokenizer hashes equal the files on disk [O]. |
| 220 | |
| 221 | ## 10. What is not proven |
| 222 | - The model turn is scripted: the verdict is labelled incomplete (\`missing=link:model_turn\`), never PASS complete. No authorship claim for the proposal. |
| 223 | - Records are unsigned exports: the verifier cannot tell an export from a hand-written file. |
| 224 | - The test run is harness evidence, not a daemon effect (the daemon only writes the file). |
| 225 | - The desk MAC for ComposeAuthorize stays default-off (unchanged here). No security default was changed. |
| 226 | - CPU reference backend only; no GPU path was exercised. |
| 227 | - Sovereign-core rev: $sc_src. |
| 228 | - The demo checks the native report after the gate's run, not before it: a stub daemon is refused (exit non-zero) but only after the run. |
| 229 | MD |
| 230 | } | red >"$res" |
| 231 | grep -q "$HOME" "$res" && die "home path leaked into the record" |
| 232 | echo "DEMO PASS (labelled incomplete): $res" |