interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / program_realize_receipt.sh

256 lines · 13539 bytes Raw Blame History
1#!/bin/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# program_realize_receipt.sh -- qualification receipt for program realization V0
18# (spec/program-realization.md): realization is driven by the actual Omega program.
19#
20# tools/program_realize_receipt.sh [out-dir] (default: evidence/REALIZE)
21#
22# Runs, on the committed tree only (AArch64 host: the realization test executes code natively):
23# - make test-program-realize (4 gates, physics-free)
24# - regression: test-program-id, test-effect-cap64, test-visor-core, test-visor-world,
25# test-visor-authority, the Visor V1 qualification campaign (run_qualification.sh),
26# omegatool test (M4), test-m8 test-m9 test-m10 test-m11 test-m14, test-crumbline, and the
27# non-energy host suites r3 r7 r8 r9 r10 r11 r12 action-graph state-projection
28# capability-query typed-results
29# Every make is wrapped in `flock $BENCH_LOCK`. Nothing under evidence/ is rewritten: the
30# receipt is a NEW file named by the SHA-256 of its own bytes. It says FAIL (and why) when any
31# suite fails, the tree is dirty or changes during the run, or a pin mismatches.
32# Shell and coreutils only (git, sha256sum, grep, sed, awk, tar, make). No Python.
33set -u
34
35HERE=$(cd "$(dirname "$0")/.." && pwd)
36cd "$HERE" || exit 2
37OUTDIR=${1:-evidence/REALIZE}
38AIENOS_REPO=${AIENOS_REPO:-$HOME/workspace/aienos-repo}
39PHYSICS_DIR=${PHYSICS_DIR:-$HOME/workspace/physics-r13}
40BENCH_LOCK=${BENCH_LOCK:-$HOME/workspace/.argus-bench.lock}
41Q=build/przq
42LOGS=$Q/logs
43REASONS=()
44
45head0=$(git rev-parse HEAD)
46tree0=$(git rev-parse 'HEAD^{tree}')
47dirty0=$(git status --porcelain)
48[ -z "$dirty0" ] || REASONS+=("tree dirty at start")
49run_id=$(date -u +%Y%m%dT%H%M%SZ)
50[ "$(uname -m)" = aarch64 ] || REASONS+=("host is $(uname -m), not aarch64: native differential cannot run")
51
52rm -rf "$Q" && mkdir -p "$LOGS" "$Q/aienos"
53# ---- pins -------------------------------------------------------------------
54aienos_pin=$(awk 'NF && $1 !~ /^#/ {print $1; exit}' aienos.lock)
55physics_pin=$(awk 'NF && $1 !~ /^#/ {print $1; exit}' physics.lock)
56physics_head=$(git -C "$PHYSICS_DIR" rev-parse HEAD 2>/dev/null || echo missing)
57[ "$physics_head" = "$physics_pin" ] || REASONS+=("physics checkout $physics_head != physics.lock $physics_pin")
58
59aienos_src_tree=$(git -C "$AIENOS_REPO" rev-parse "$aienos_pin:native/capability" 2>/dev/null || echo missing)
60if git -C "$AIENOS_REPO" archive "$aienos_pin" native/capability | tar -x -C "$Q/aienos" &&
61 flock "$BENCH_LOCK" make -C "$Q/aienos/native/capability" > "$LOGS/aienos-lib.log" 2>&1; then
62 lib_ok=1
63else
64 lib_ok=0
65 REASONS+=("AIENOS capability library did not build from $aienos_pin")
66fi
67LIB=$Q/aienos/native/capability/out/libaienos_capability.a
68lib_sha=$( [ -f "$LIB" ] && sha256sum "$LIB" | awk '{print $1}' || echo null)
69
70# ---- suites -----------------------------------------------------------------
71SUITES_JSON=""
72declare -A RC RUN FAILED
73
74counts() { # -> "run failed source"
75 local log=$1 r
76 r=$(awk '/^(PASS|FAIL) [0-9]+\/[0-9]+ *$/ { split($2, x, "/"); r += x[2]; f += x[2] - x[1]; n++ }
77 /TOTAL GATES: *[0-9]+ *\| *PASSED: *[0-9]+ *\| *FAILED: *[0-9]+/ {
78 match($0, /TOTAL GATES: *[0-9]+/); t = substr($0, RSTART, RLENGTH); gsub(/[^0-9]/, "", t)
79 match($0, /FAILED: *[0-9]+/); u = substr($0, RSTART, RLENGTH); gsub(/[^0-9]/, "", u)
80 r += t; f += u; n++ }
81 /^CRUMBLINE_CONFORMANCE pass=[0-9]+ fail=[0-9]+/ {
82 split($2, p, "="); split($3, q, "="); r += p[2] + q[2]; f += q[2]; n++ }
83 /^QUAL_SECTION [a-z]+ run=[0-9]+ failed=[0-9]+/ {
84 split($3, p, "="); split($4, q, "="); r += p[2]; f += q[2]; n++ }
85 END { if (n) printf "%d %d\n", r, f }' "$log")
86 if [ -n "$r" ]; then echo "$r output"; return; fi
87 local rcpt
88 rcpt=$(grep -oE 'receipt: [^ ]+\.json' "$log" | tail -n 1 | awk '{print $2}')
89 if [ -n "$rcpt" ] && [ -f "$rcpt" ]; then
90 local line c f
91 line=$(grep -m1 '^ "totals":' "$rcpt")
92 if [ -n "$line" ]; then
93 c=$(printf '%s' "$line" | grep -oE '"checks": [0-9]+' | grep -oE '[0-9]+')
94 f=$(printf '%s' "$line" | grep -oE '"failures": [0-9]+' | grep -oE '[0-9]+')
95 else
96 c=$(grep -m1 -E '^ "checks": [0-9]+' "$rcpt" | grep -oE '[0-9]+')
97 f=$(grep -m1 -E '^ "failures": [0-9]+' "$rcpt" | grep -oE '[0-9]+')
98 fi
99 if [ -n "$c" ] && [ -n "$f" ]; then echo "$c $f receipt:$rcpt"; return; fi
100 fi
101 echo "0 0 exit-status-only"
102}
103
104record() { # record <name> <rc> <log>
105 local name=$1 rc=$2 log=$3 n f src
106 read -r n f src < <(counts "$log")
107 RC[$name]=$rc
108 RUN[$name]=$n
109 FAILED[$name]=$f
110 local status=FAIL
111 [ "$rc" -eq 0 ] && [ "$f" -eq 0 ] && status=PASS
112 [ "$status" = PASS ] || REASONS+=("$name $status (rc=$rc, $f of $n failed)")
113 SUITES_JSON+="${SUITES_JSON:+,}
114 {\"target\": \"$name\", \"rc\": $rc, \"tests_run\": $n, \"tests_failed\": $f, \"count_source\": \"$src\", \"status\": \"$status\", \"log_sha256\": \"$(sha256sum "$log" | awk '{print $1}')\"}"
115 echo "suite $name: $status (rc=$rc run=$n failed=$f)" >&2
116}
117
118suite() { # suite <name> <out-dir> <make args...>
119 local name=$1 out=$2
120 shift 2
121 local log=$LOGS/$name.log
122 flock "$BENCH_LOCK" env OMEGA_CANDIDATE_COMMIT="$head0" AIENOS_COMMIT="$aienos_pin" \
123 PHYSICS_COMMIT="$physics_pin" make OUT_DIR="$out" "$@" "$name" > "$log" 2>&1
124 record "$name" $? "$log"
125}
126
127PF=(PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 AIENOS_R7_DIR="$Q/aienos")
128RT=(PHYSICS_DIR="$PHYSICS_DIR" AIENOS_R7_DIR="$Q/aienos" VISOR_AUTH_CAP_LIB="$LIB")
129
130suite test-program-realize "$Q/pf" "${PF[@]}"
131suite test-program-id "$Q/pf" "${PF[@]}"
132suite test-visor-core "$Q/pf" "${PF[@]}"
133suite test-visor-world "$Q/pf" "${RT[@]}"
134suite test-visor-authority "$Q/pf" "${RT[@]}"
135
136# Visor V1 qualification campaign (shell), physics-free omega binary.
137qlog=$LOGS/visor-qualification.log
138{ flock "$BENCH_LOCK" make OUT_DIR="$Q/q8" PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 "$Q/q8/omega" &&
139 flock "$BENCH_LOCK" env QUAL_WORK="$Q/q8/qual-work" tests/visor/qualification/run_qualification.sh "$Q/q8/omega"; } \
140 > "$qlog" 2>&1
141record visor-qualification $? "$qlog"
142
143CONSUMERS=(test-m8 test-m9 test-m10 test-m11 test-m14 test-crumbline)
144for t in "${CONSUMERS[@]}"; do suite "$t" "$Q/reg" "${RT[@]}"; done
145
146HOST=(test-effect-cap64 test test-r3 test-r7 test-r8 test-r9 test-r10 test-r11 test-r12 test-action-graph
147 test-state-projection test-capability-query test-typed-results)
148suite test-effect-cap64 "$Q/pf" "${PF[@]}"
149for t in "${HOST[@]:1}"; do suite "$t" "$Q/reg" "${RT[@]}"; done
150
151REGRESSION=(test-program-id test-visor-core test-visor-world test-visor-authority visor-qualification
152 "${CONSUMERS[@]}" "${HOST[@]}")
153
154# ---- gates ------------------------------------------------------------------
155prz_log=$LOGS/test-program-realize.log
156gate_line() { # -> "STATUS passed total"
157 local line
158 line=$(grep -E "^GATE $1 (PASS|FAIL) [0-9]+/[0-9]+$" "$prz_log" | tail -n 1)
159 [ -n "$line" ] || { echo "NOT_RUN 0 0"; return; }
160 local st=${line#GATE $1 }
161 local status=${st%% *} frac=${st#* }
162 echo "$status ${frac%/*} ${frac#*/}"
163}
164GATES_JSON=""
165all_pass=1
166add_gate() { # add_gate <name> <status> <run> <failed> <sources>
167 GATES_JSON+="${GATES_JSON:+,}
168 \"$1\": {\"status\": \"$2\", \"tests_run\": $3, \"tests_failed\": $4, \"sources\": \"$5\"}"
169 [ "$2" = PASS ] || { all_pass=0; REASONS+=("$1 $2"); }
170}
171test_gate() { # test_gate <gate> <sources>
172 local st p t
173 read -r st p t < <(gate_line "$1")
174 [ "${RC[test-program-realize]}" -eq 0 ] || st=FAIL
175 add_gate "$1" "$st" "$t" "$((t - p))" "$2"
176}
177test_gate OMEGA_PROGRAM_REALIZE_PASS \
178 "make test-program-realize (gate PROGRAM_REALIZE: omega_program_realize realizes + binds + executes named programs; builder/compose use it; 11 unsupported semantics fail closed with reasons)"
179test_gate OMEGA_REALIZATION_PROGRAM_DRIVEN_PASS \
180 "make test-program-realize (gate PROGRAM_DRIVEN: 600 programs pairwise distinct code + RealizationIds per and across machines, lift(sequential code) == body, schedule from machine, determinism, M14 3x-2 bytes preserved, legacy fixed-3x-2 synth rejected)"
181test_gate OMEGA_REALIZATION_DIFFERENTIAL_PASS \
182 "make test-program-realize (gate DIFFERENTIAL: native execution == independent semantic evaluator, 18 named + 582 seeded random pipelines, u8..u64, both canonical machines, boundary + random inputs)"
183test_gate OMEGA_REALIZATION_TRIPLE_BIND_PASS \
184 "make test-program-realize (gate TRIPLE_BIND: SEMANTIC_ID + MACHINE_ID + code -> REALIZATION_ID; rebinding with consistent triple, altered code, altered machine id, forged machine graph all rejected)"
185
186r_run=0; r_fail=0; r_st=PASS
187for t in "${REGRESSION[@]}"; do
188 r_run=$((r_run + RUN[$t])); r_fail=$((r_fail + FAILED[$t]))
189 { [ "${RC[$t]}" -eq 0 ] && [ "${FAILED[$t]}" -eq 0 ]; } || { r_st=FAIL; [ "${FAILED[$t]}" -eq 0 ] && r_fail=$((r_fail + 1)); }
190done
191add_gate OMEGA_REALIZATION_REGRESSION_PASS "$r_st" "$r_run" "$r_fail" "make ${REGRESSION[*]} (visor-qualification = run_qualification.sh)"
192
193sanity=$(grep -m1 '^SANITY legacy_fixed_3x2_synth' "$prz_log" || echo "SANITY line missing")
194case "$sanity" in *"PROGRAM_DRIVEN FAIL (expected)"*) ;; *) all_pass=0; REASONS+=("legacy sanity demo missing") ;; esac
195fail_closed=$(grep '^FAIL_CLOSED' "$prz_log" || true)
196
197# ---- tree stability ---------------------------------------------------------
198head1=$(git rev-parse HEAD)
199dirty1=$(git status --porcelain)
200stable=true
201{ [ "$head1" = "$head0" ] && [ "$dirty1" = "$dirty0" ]; } || { stable=false; REASONS+=("tree changed during the run"); }
202tree_dirty=false; [ -z "$dirty0" ] || tree_dirty=true
203verdict=OMEGA_PROGRAM_REALIZE_PASS
204{ [ "$all_pass" -eq 1 ] && [ "$stable" = true ] && [ "$tree_dirty" = false ] && [ "$lib_ok" -eq 1 ] &&
205 [ "$physics_head" = "$physics_pin" ] && [ "$(uname -m)" = aarch64 ]; } || verdict=OMEGA_PROGRAM_REALIZE_FAIL
206
207json_str() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | awk 'BEGIN{ORS=""} {if (NR>1) print "\\n"; print}'; }
208reasons_json=""
209for r in "${REASONS[@]}"; do reasons_json+="${reasons_json:+, }\"$(json_str "$r")\""; done
210
211body=$(cat <<EOF2
212{
213 "schema": "omega-program-realize-qualification/1",
214 "spec": "spec/program-realization.md",
215 "pipeline": "canonical program body -> V0 semantic gate -> machine-aware schedule (MachineGraph chooses schedule only) -> AArch64 V0 bytes (aarch64_encoder) -> REALIZATION_ID = triple(SEMANTIC_ID, MACHINE_ID, code) -> verification (bindings, V0 structural, native == semantic evaluator)",
216 "run_id": "$run_id",
217 "candidate_commit": "$head0",
218 "candidate_tree": "$tree0",
219 "tree_dirty": $tree_dirty,
220 "tree_stable_during_run": $stable,
221 "host": {"uname_m": "$(uname -m)", "uname_r": "$(uname -r)", "product_name": "$(json_str "$(cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null)")"},
222 "hardware_scope": "host CPU only (native AArch64 execution of generated code); no GPU, no silicon, no energy measurement",
223 "aienos": {"lock": "$aienos_pin", "source": "git archive $aienos_pin native/capability (tree $aienos_src_tree)", "lib_sha256": "$lib_sha", "lib_built": $([ "$lib_ok" -eq 1 ] && echo true || echo false)},
224 "physics": {"lock": "$physics_pin", "checkout_head": "$physics_head"},
225 "gates": {$GATES_JSON
226 },
227 "legacy_sanity_demo": "$(json_str "$sanity")",
228 "fail_closed": "$(json_str "$fail_closed")",
229 "suites": [$SUITES_JSON
230 ],
231 "not_run": [
232 "GPU / silicon targets (test-m12, test-m15, test-m17, test-m18, test-m19, r12 silicon seat, r13/r14 living runs, R15)",
233 "suites CI runs that read the package energy counter (test-semantic-comm, test-cognitive-routing, test-sem-incremental, test-workflow-fusion, test-plan-reuse): not run here (no energy measurements); CI runs them"
234 ],
235 "non_claims": [
236 "V0 unary constant-step chains only (ADD SUB MUL AND OR, unsigned u8..u64, <= 64 steps). DIV, signed, bitvector, conversions, calls, control flow fail closed.",
237 "The differential samples 84-116 inputs per program; it is not an equivalence proof.",
238 "No optimisation or measured cost: the schedule is a policy chosen from the canonical MachineGraph profiles (assumed, not observed hardware).",
239 "Canonical program realization ids (OMG_R0) now bind the program id; historical receipts are not rewritten."
240 ],
241 "verdict": "$verdict",
242 "verdict_reasons": [$reasons_json]
243}
244EOF2
245)
246mkdir -p "$OUTDIR"
247tmp=$(mktemp "$OUTDIR/.tmp-XXXXXX")
248printf '%s\n' "$body" > "$tmp"
249digest=$(sha256sum "$tmp" | awk '{print $1}')
250final=$OUTDIR/$digest.json
251if [ -e "$final" ]; then rm -f "$tmp"; else mv "$tmp" "$final"; fi
252chmod 0644 "$final"
253grep -E '"OMEGA_[A-Z_]+_PASS"' "$final" | sed 's/^ *//'
254echo "RECEIPT $final"
255echo "VERDICT $verdict"
256[ "$verdict" = OMEGA_PROGRAM_REALIZE_PASS ]