interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / adapters / aien / scripts / demo-verified-fix.sh

232 lines · 15869 bytes Raw Blame History
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.
21set -euo pipefail
22
23here="$(cd "$(dirname "$0")" && pwd)"
24adapter="$(cd "$here/.." && pwd)"
25repo="$(cd "$adapter/../.." && pwd)"
26die() { echo "DEMO FAIL: $*" >&2; exit 1; }
27: "${OUT:?OUT must name a fresh output directory}"
28for 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"
30mkdir -p "$OUT"; OUT="$(cd "$OUT" && pwd)"
31if command -v quietlock >/dev/null && ! quietlock check >/dev/null 2>&1; then die "quiet flag is held (quietlock check)"; fi
32model_dir="${AIEN_LEDGER_MODEL_DIR:-$HOME/.cache/huggingface/hub/models--unsloth--Llama-3.2-1B-Instruct/snapshots/5a8abab4a5d6f164389b1079fb721cfab8d7126c}"
33red() { sed -e "s#$HOME#~#g" -e "s#$repo#<interplane>#g"; } # no home paths in the record
34started="$(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.
38build_note=""
39if [ -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)"
54else
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:-}"
59fi
60export AIEN_BIN
61rev_of() { [ -n "$1" ] && git -C "$1" rev-parse HEAD 2>/dev/null || echo "UNVERIFIED (checkout not given)"; }
62omega_rev="${OMEGA_LOCK_REV:-$(rev_of "${OMEGA_DIR:-}")}"
63physics_rev="$(rev_of "${PHYSICS_DIR:-}")"; aienos_rev="$(rev_of "${AIENOS_REPO:-}")"
64omega_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")"
68bin_sha="$(sha256sum "$AIEN_BIN" | cut -d' ' -f1)"
69sc_rev="${SOVEREIGN_CORE_REV:-UNVERIFIED}"
70if [ -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
71export 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.
75gate_rc=0
76OMEGA_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)"; }
78g="$OUT/gate"; rec="$g/receipt.json"; b="$g/rows/slice1/bundle"; r="$b/records"
79dlog="$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.
83compose_line="$(grep -m1 '^Compose:' "$dlog" || true)"
84[ -n "$compose_line" ] || die "daemon log has no Compose: line"
85case "$compose_line" in "Compose: native ("*) ;; *) die "STUB daemon (daemon says: $compose_line): the demo does not pass on a stub";; esac
86recall_native="$(jq -r '.compose_native // "absent"' "$r/aien/compose-recall.json")"
87recall_omega="$(jq -r '.omega_sha // "absent"' "$r/aien/compose-recall.json")"
88[ "$recall_native" = "true" ] || die "ComposeRecall compose_native=$recall_native (need true)"
89line_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)"
91if [ "$omega_rev" != "${omega_rev#UNVERIFIED}" ] || [ "$omega_rev" = "n/a" ]; then omega_check="not compared (omega checkout not given)"
92else [ "$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"
94verdict="$(jq -r .verdict "$rec")"
95want="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"
97case "$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
100model_sha="$(sed -n 's/.*model_sha256=\([0-9a-f]*\).*/\1/p' "$dlog" | head -1)"
101tok_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"
105backend="$(grep -m1 -i 'backend' "$dlog" | red || true)"
106
107grant="$(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")"
108appr_id="$(jq -r .approval_id <<<"$grant")"; appr_key="$(jq -r .approval_key <<<"$grant")"; approver="$(jq -r .approver <<<"$grant")"
109w_path="$(jq -r .path <<<"$intent")"; w_sha="$(jq -r .content_sha256 <<<"$intent")"; w_prior="$(jq -r .prior_sha256 <<<"$intent")"
110ack_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.
114grant_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)"
116case "$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"
118approved_content_sha="$(jq -r .content_sha256 <<<"$grant")"
119[ "$approved_content_sha" = "$w_sha" ] || die "grant content sha != written content sha"
120trace_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"
122t_before_exit="$(jq -r .task.test_exit_before "$rec")"; t_after_exit="$(jq -r .task.test_exit_after "$rec")"
123out_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"
125neg_n="$(jq '.negative_checks | length' "$rec")"; [ "$neg_n" -eq 8 ] || die "expected 8 negative checks (control + 7), got $neg_n"
126rustc_v="$(rustc --version)"
127finished="$(date -u +%FT%TZ)"
128mf() { jq -r "$1" "$rec"; }
129
130# 4. DEMO-RESULT.md
131res="$OUT/DEMO-RESULT.md"
132{
133cat <<MD
134# Verified fix-the-test demo (VAC M4a)
135
136Machine-written by \`adapters/aien/scripts/demo-verified-fix.sh\`. Started $started, finished $finished (UTC).
137Labels: [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
168Task 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\`\`\`
173Source 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
191Command: \`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\`\`\`
205git 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:
208AIEN_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\`\`\`
212This 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.
229MD
230} | red >"$res"
231grep -q "$HOME" "$res" && die "home path leaked into the record"
232echo "DEMO PASS (labelled incomplete): $res"