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
omega-mv / tools / r15_receipt.sh
| 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 | # r15_receipt.sh -- write the R15 receipt (spec/r15-performance-proof.md §12, |
| 18 | # §13, §14) from one qualification run directory. |
| 19 | # |
| 20 | # tools/r15_receipt.sh <raw-dir> <out-dir> [candidate-commit] [reruns.json] [notes.tsv] |
| 21 | # |
| 22 | # Inputs, all read, none changed: |
| 23 | # <raw-dir>/summary.json the reducer output (every metric, comparison, CI, |
| 24 | # gate threshold and gate outcome) |
| 25 | # <raw-dir>/machine.json hardware identity and commits (§13), written by |
| 26 | # tools/r15_qualify.sh at run time |
| 27 | # <raw-dir>/SHA256SUMS the raw file digests |
| 28 | # <raw-dir>/build-provenance.json, final-state.json and |
| 29 | # PROVENANCE_SHA256SUMS bind the archived sources, |
| 30 | # toolchain, sealed executables and final tree state |
| 31 | # candidate-commit the commit proposed for R15 (default: env |
| 32 | # OMEGA_CANDIDATE_COMMIT; empty = not candidate-bound) |
| 33 | # reruns.json the §14 correctness reruns (+ §16 item 9 SEQ parity) |
| 34 | # as one JSON object, e.g. {"R3":"PASS",...}; absent = |
| 35 | # not done |
| 36 | # notes.tsv human-written, tab-separated lines (# = comment): |
| 37 | # regression<TAB>metric<TAB>resident<TAB>SEQ<TAB>justification |
| 38 | # limit<TAB>text |
| 39 | # every metric where the resident path is worse |
| 40 | # than SEQ (spec §11) and the receipt's stated |
| 41 | # limits; values are copied from summary.json by |
| 42 | # hand and cited, never used to decide the outcome |
| 43 | # |
| 44 | # Output: <out-dir>/<sha256>.json, schema AIEN_RX_R15_REACTION_PERFORMANCE_V1, |
| 45 | # named by the SHA-256 of its own bytes. The path is printed on stdout. |
| 46 | # |
| 47 | # No number is computed or edited here: summary.json and machine.json are |
| 48 | # embedded byte for byte. The writer only decides the outcome: |
| 49 | # PASS only if every gate G1-G16 is PASS (all_gates_pass true), the raw |
| 50 | # directory verifies against SHA256SUMS and the reducer's raw digest, the |
| 51 | # run is candidate-bound (run commit == candidate, clean initial/final tree, |
| 52 | # archive-built binaries unchanged through execution), silicon was observed, |
| 53 | # aienos and physics commits equal the pins at the run commit, and every |
| 54 | # required correctness rerun is PASS. Anything else is FAIL, with reasons. |
| 55 | # Shell, coreutils, git and the seeded Omega compiler. No jq, Python or C is |
| 56 | # introduced on this path; reruns.json is parsed by seed/json/json.om. |
| 57 | set -u |
| 58 | export GIT_NO_REPLACE_OBJECTS=1 GIT_GRAFT_FILE=/nonexistent/r15-receipt-grafts |
| 59 | |
| 60 | RAW=${1:?raw run directory} |
| 61 | OUTDIR=${2:?output directory} |
| 62 | CANDIDATE=${3:-${OMEGA_CANDIDATE_COMMIT:-}} |
| 63 | RERUNS=${4:-} |
| 64 | NOTES=${5:-} |
| 65 | HERE=$(cd "$(dirname "$0")/.." && pwd) |
| 66 | |
| 67 | # A run stopped by the instrument preflight is BLOCKED_INSTRUMENT: the run never |
| 68 | # measured anything, so there is nothing to receipt. Refuse, write nothing. |
| 69 | if [ -s "$RAW/instrument-unavailable.txt" ]; then |
| 70 | echo "r15_receipt: BLOCKED_INSTRUMENT: this run stopped before any trial (instrument unavailable); no receipt written. $(sed -n 2p "$RAW/instrument-unavailable.txt")" >&2 |
| 71 | exit 4 |
| 72 | fi |
| 73 | SUM=$RAW/summary.json |
| 74 | MACH=$RAW/machine.json |
| 75 | PROV=$RAW/build-provenance.json |
| 76 | FINAL=$RAW/final-state.json |
| 77 | PROV_SUMS=$RAW/PROVENANCE_SHA256SUMS |
| 78 | for f in "$SUM" "$MACH" "$RAW/SHA256SUMS"; do |
| 79 | [ -s "$f" ] || { echo "r15_receipt: missing $f" >&2; exit 2; } |
| 80 | done |
| 81 | mkdir -p "$OUTDIR" || exit 2 |
| 82 | |
| 83 | REQUIRED_RERUNS="R3 R7 R8 R9 R10 R11 R12_host R12_silicon R13_host R13_silicon R14_host R14_silicon R15_SEQ_parity" |
| 84 | |
| 85 | # ---- small readers (flat keys only; the inputs are written by our own tools) |
| 86 | mstr() { grep -o "\"$1\":\"[^\"]*\"" "$MACH" | head -1 | sed 's/^"[^"]*":"//; s/"$//'; } |
| 87 | mraw() { grep -o "\"$1\":[^,}]*" "$MACH" | head -1 | sed 's/^"[^"]*"://'; } |
| 88 | sraw() { grep -o "\"$1\":[^,}]*" "$SUM" | tail -1 | sed 's/^"[^"]*"://'; } |
| 89 | fstr() { grep -o "\"$2\":\"[^\"]*\"" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*":"//; s/"$//'; } |
| 90 | fraw() { grep -o "\"$2\":[^,}]*" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*"://'; } |
| 91 | fobj() { grep -o "\"$2\":{[^}]*}" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*"://'; } |
| 92 | jstr() { printf '"%s"' "$(printf '%s' "$1" | tr -d '"\\' | tr '\n' ' ')"; } |
| 93 | is_sha256() { [[ "$1" =~ ^[0-9a-f]{64}$ ]]; } |
| 94 | is_commit() { [[ "$1" =~ ^[0-9a-f]{40}$ ]]; } |
| 95 | |
| 96 | REASONS=() |
| 97 | fail() { REASONS+=("$1"); } |
| 98 | |
| 99 | RUN_ID=$(mstr run_id) |
| 100 | MODE=$(mstr mode) |
| 101 | RUN_COMMIT=$(mstr candidate_commit) # qualify.sh records HEAD at run time here |
| 102 | TREE_DIRTY=$(mraw tree_dirty) |
| 103 | AIENOS=$(mstr aienos_commit) |
| 104 | PHYSICS=$(mstr physics_commit) |
| 105 | REDUCER_SRC=$(mstr reducer_source_sha256) |
| 106 | BINARIES=$(grep -o '"binaries":{[^}]*}' "$MACH" | sed 's/^"binaries"://') |
| 107 | PROV_SCHEMA=$(fstr "$PROV" schema) |
| 108 | PROV_COMMIT=$(fstr "$PROV" candidate_commit) |
| 109 | PROV_CANDIDATE_ARCHIVE=$(fstr "$PROV" candidate_archive_sha256) |
| 110 | PROV_PHYSICS=$(fstr "$PROV" physics_commit) |
| 111 | PROV_PHYSICS_ARCHIVE=$(fstr "$PROV" physics_archive_sha256) |
| 112 | PROV_AIENOS=$(fstr "$PROV" aienos_commit) |
| 113 | PROV_AIENOS_ARCHIVE=$(fstr "$PROV" aienos_archive_sha256) |
| 114 | PROV_BUILD_COMMAND=$(fstr "$PROV" build_command) |
| 115 | PROV_COMPILER=$(fstr "$PROV" compiler_sha256) |
| 116 | PROV_MAKE=$(fstr "$PROV" make_sha256) |
| 117 | PROV_BUILD_LOG=$(fstr "$PROV" build_log_sha256) |
| 118 | PROV_BINARIES=$(fobj "$PROV" binaries) |
| 119 | PROV_TRIAL=$(fstr "$PROV" trial) |
| 120 | PROV_NODIGEST=$(fstr "$PROV" nodigest) |
| 121 | PROV_REDUCER=$(fstr "$PROV" reducer) |
| 122 | FINAL_SCHEMA=$(fstr "$FINAL" schema) |
| 123 | FINAL_COMMIT=$(fstr "$FINAL" candidate_commit) |
| 124 | FINAL_HEAD=$(fstr "$FINAL" final_head) |
| 125 | FINAL_DIRTY=$(fraw "$FINAL" tracked_tree_dirty) |
| 126 | FINAL_HEAD_UNCHANGED=$(fraw "$FINAL" head_unchanged) |
| 127 | FINAL_BINARIES_UNCHANGED=$(fraw "$FINAL" binaries_unchanged) |
| 128 | FINAL_BINARIES=$(fobj "$FINAL" binaries) |
| 129 | SCHEMA_IN=$(grep -o '"schema":"[^"]*"' "$SUM" | head -1 | sed 's/.*:"//; s/"$//') |
| 130 | ALL_PASS=$(sraw all_gates_pass) |
| 131 | DIGEST_CLAIMED=$(grep -o '"raw_digest_sha256_of_SHA256SUMS":"[0-9a-f]*"' "$SUM" | sed 's/.*:"//; s/"$//') |
| 132 | DIGEST_ACTUAL=$(sha256sum "$RAW/SHA256SUMS" | cut -d' ' -f1) |
| 133 | GATES=$(grep -o '"gates":\[[^]]*\]' "$SUM" | sed 's/^"gates"://') |
| 134 | |
| 135 | [ "$SCHEMA_IN" = AIEN_RX_R15_SUMMARY_V1 ] || fail "summary.json schema is '$SCHEMA_IN', not AIEN_RX_R15_SUMMARY_V1" |
| 136 | [ -n "$GATES" ] || fail "summary.json has no gate table" |
| 137 | RUN_COMMIT_OK=true |
| 138 | is_commit "$RUN_COMMIT" || { RUN_COMMIT_OK=false; fail "run commit is missing or malformed"; } |
| 139 | MODE_OK=true |
| 140 | case "$MODE" in host|silicon) ;; *) MODE_OK=false; fail "run mode '$MODE' is invalid";; esac |
| 141 | |
| 142 | # ---- gates (§11): every one of G1-G16 present and PASS |
| 143 | NGATES=0 |
| 144 | for g in $(seq 1 16); do |
| 145 | ent=$(printf '%s' "$GATES" | grep -o "{\"id\":\"G$g\"[^}]*}") |
| 146 | if [ -z "$ent" ]; then fail "gate G$g missing from summary.json"; continue; fi |
| 147 | NGATES=$((NGATES + 1)) |
| 148 | out=$(printf '%s' "$ent" | grep -o '"outcome":"[A-Z]*"' | sed 's/.*:"//; s/"$//') |
| 149 | [ "$out" = PASS ] || fail "gate G$g $out: $(printf '%s' "$ent" | grep -o '"note":"[^"]*"' | sed 's/^"note":"//; s/"$//')" |
| 150 | done |
| 151 | [ "$ALL_PASS" = true ] || fail "reducer reports all_gates_pass=$ALL_PASS" |
| 152 | |
| 153 | # ---- raw evidence integrity (§12) |
| 154 | RAW_FILES_OK=false |
| 155 | if (cd "$RAW" && sha256sum --quiet -c SHA256SUMS >/dev/null 2>&1); then RAW_FILES_OK=true |
| 156 | else fail "raw files do not verify against SHA256SUMS"; fi |
| 157 | DIGEST_OK=false |
| 158 | if [ -n "$DIGEST_CLAIMED" ] && [ "$DIGEST_CLAIMED" = "$DIGEST_ACTUAL" ]; then DIGEST_OK=true |
| 159 | else fail "raw digest in summary.json ($DIGEST_CLAIMED) != SHA-256 of SHA256SUMS ($DIGEST_ACTUAL)"; fi |
| 160 | |
| 161 | # ---- build and execution provenance |
| 162 | PROV_FILES_OK=false |
| 163 | PROV_DIGEST="" |
| 164 | if [ ! -s "$PROV_SUMS" ]; then |
| 165 | fail "PROVENANCE_SHA256SUMS missing" |
| 166 | elif [ "$MODE_OK" != true ]; then |
| 167 | fail "cannot validate executable provenance for invalid run mode" |
| 168 | elif ! awk -v b1="bin/rx_r15_perf_$MODE" -v b2="bin/rx_r15_perf_${MODE}_nodigest" ' |
| 169 | NF != 2 { bad = 1; next } |
| 170 | $2 != "build.log" && $2 != "build-provenance.json" && $2 != "final-state.json" && |
| 171 | $2 != b1 && $2 != b2 && $2 != "bin/r15_reduce" { bad = 1 } |
| 172 | { if (++seen[$2] != 1) bad = 1 } |
| 173 | END { if (NR != 6 || bad) exit 1 } |
| 174 | ' "$PROV_SUMS"; then |
| 175 | fail "PROVENANCE_SHA256SUMS has an unexpected, duplicate or malformed path" |
| 176 | elif ! (cd "$RAW" && sha256sum --quiet -c PROVENANCE_SHA256SUMS >/dev/null 2>&1); then |
| 177 | fail "build provenance files do not verify against PROVENANCE_SHA256SUMS" |
| 178 | else |
| 179 | MANIFEST_COMPLETE=true |
| 180 | for rel in build.log build-provenance.json final-state.json \ |
| 181 | "bin/rx_r15_perf_$MODE" "bin/rx_r15_perf_${MODE}_nodigest" bin/r15_reduce; do |
| 182 | awk -v want="$rel" 'NF == 2 && $2 == want { found = 1 } END { exit !found }' "$PROV_SUMS" \ |
| 183 | || { MANIFEST_COMPLETE=false; fail "$rel missing from PROVENANCE_SHA256SUMS"; } |
| 184 | done |
| 185 | if [ "$MANIFEST_COMPLETE" = true ]; then PROV_FILES_OK=true; fi |
| 186 | PROV_DIGEST=$(sha256sum "$PROV_SUMS" | cut -d' ' -f1) |
| 187 | fi |
| 188 | |
| 189 | PROVENANCE_OK=true |
| 190 | [ "$PROV_SCHEMA" = AIEN_RX_R15_BUILD_PROVENANCE_V1 ] || { PROVENANCE_OK=false; fail "build provenance schema is '$PROV_SCHEMA'"; } |
| 191 | [ "$PROV_COMMIT" = "$RUN_COMMIT" ] || { PROVENANCE_OK=false; fail "build provenance commit $PROV_COMMIT != run commit $RUN_COMMIT"; } |
| 192 | [ "$PROV_PHYSICS" = "$PHYSICS" ] || { PROVENANCE_OK=false; fail "build provenance physics commit $PROV_PHYSICS != recorded $PHYSICS"; } |
| 193 | [ "$PROV_AIENOS" = "$AIENOS" ] || { PROVENANCE_OK=false; fail "build provenance aienos commit $PROV_AIENOS != recorded $AIENOS"; } |
| 194 | [ "$PROV_BINARIES" = "$BINARIES" ] || { PROVENANCE_OK=false; fail "build provenance binary hashes differ from machine.json"; } |
| 195 | [ -n "$PROV_BUILD_COMMAND" ] || { PROVENANCE_OK=false; fail "build provenance has no build command"; } |
| 196 | for ent in "candidate archive:$PROV_CANDIDATE_ARCHIVE" "physics archive:$PROV_PHYSICS_ARCHIVE" \ |
| 197 | "aienos archive:$PROV_AIENOS_ARCHIVE" "compiler:$PROV_COMPILER" "make:$PROV_MAKE" \ |
| 198 | "build log:$PROV_BUILD_LOG"; do |
| 199 | label=${ent%%:*}; value=${ent#*:} |
| 200 | is_sha256 "$value" || { PROVENANCE_OK=false; fail "$label digest is missing or malformed"; } |
| 201 | done |
| 202 | if [ -s "$RAW/build.log" ]; then |
| 203 | [ "$PROV_BUILD_LOG" = "$(sha256sum "$RAW/build.log" | cut -d' ' -f1)" ] \ |
| 204 | || { PROVENANCE_OK=false; fail "build log digest differs from build provenance"; } |
| 205 | else |
| 206 | PROVENANCE_OK=false; fail "build.log missing" |
| 207 | fi |
| 208 | if [ "$MODE_OK" = true ]; then |
| 209 | for ent in "bin/rx_r15_perf_$MODE:$PROV_TRIAL" \ |
| 210 | "bin/rx_r15_perf_${MODE}_nodigest:$PROV_NODIGEST" "bin/r15_reduce:$PROV_REDUCER"; do |
| 211 | rel=${ent%%:*}; expected=${ent#*:} |
| 212 | if ! is_sha256 "$expected"; then |
| 213 | PROVENANCE_OK=false; fail "$rel digest is missing or malformed" |
| 214 | elif [ ! -f "$RAW/$rel" ] || [ "$(sha256sum "$RAW/$rel" | cut -d' ' -f1)" != "$expected" ]; then |
| 215 | PROVENANCE_OK=false; fail "$rel does not match the source-to-binary manifest" |
| 216 | fi |
| 217 | done |
| 218 | else |
| 219 | PROVENANCE_OK=false |
| 220 | fi |
| 221 | |
| 222 | FINAL_OK=true |
| 223 | [ "$FINAL_SCHEMA" = AIEN_RX_R15_FINAL_STATE_V1 ] || { FINAL_OK=false; fail "final state schema is '$FINAL_SCHEMA'"; } |
| 224 | [ "$FINAL_COMMIT" = "$RUN_COMMIT" ] || { FINAL_OK=false; fail "final state commit $FINAL_COMMIT != run commit $RUN_COMMIT"; } |
| 225 | [ "$FINAL_HEAD" = "$RUN_COMMIT" ] || { FINAL_OK=false; fail "final HEAD $FINAL_HEAD != run commit $RUN_COMMIT"; } |
| 226 | [ "$FINAL_DIRTY" = false ] || { FINAL_OK=false; fail "run tree was dirty at final seal"; } |
| 227 | [ "$FINAL_HEAD_UNCHANGED" = true ] || { FINAL_OK=false; fail "HEAD did not remain unchanged through the run"; } |
| 228 | [ "$FINAL_BINARIES_UNCHANGED" = true ] || { FINAL_OK=false; fail "an executed binary changed during the run"; } |
| 229 | [ "$FINAL_BINARIES" = "$BINARIES" ] || { FINAL_OK=false; fail "final binary hashes differ from machine.json"; } |
| 230 | |
| 231 | SILICON=false |
| 232 | if [ "$MODE" = silicon ]; then SILICON=true |
| 233 | elif [ "$MODE_OK" = true ]; then fail "run mode is '$MODE', not silicon" |
| 234 | fi |
| 235 | |
| 236 | # ---- pinned dependencies (aienos.lock / physics.lock at the run commit) |
| 237 | AIENOS_LOCK=""; PHYSICS_LOCK="" |
| 238 | if [ "$RUN_COMMIT_OK" = true ]; then |
| 239 | AIENOS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:aienos.lock" 2>/dev/null | tr -d '[:space:]') |
| 240 | PHYSICS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:physics.lock" 2>/dev/null | tr -d '[:space:]') |
| 241 | fi |
| 242 | DEPENDENCIES_OK=true |
| 243 | [ "$RUN_COMMIT_OK" = true ] || DEPENDENCIES_OK=false |
| 244 | if [ -z "$AIENOS" ]; then DEPENDENCIES_OK=false; fail "aienos_commit not recorded in machine.json" |
| 245 | elif [ "$AIENOS" != "$AIENOS_LOCK" ]; then DEPENDENCIES_OK=false; fail "aienos_commit $AIENOS != aienos.lock $AIENOS_LOCK"; fi |
| 246 | if [ -z "$PHYSICS" ]; then DEPENDENCIES_OK=false; fail "physics_commit not recorded in machine.json" |
| 247 | elif [ "$PHYSICS" != "$PHYSICS_LOCK" ]; then DEPENDENCIES_OK=false; fail "physics_commit $PHYSICS != physics.lock $PHYSICS_LOCK"; fi |
| 248 | |
| 249 | # ---- candidate binding: every source, executable and final-state control |
| 250 | BOUND=false |
| 251 | if [ -z "$CANDIDATE" ]; then fail "no candidate commit given" |
| 252 | elif [ "$CANDIDATE" != "$RUN_COMMIT" ]; then fail "run commit $RUN_COMMIT is not the candidate $CANDIDATE" |
| 253 | elif [ "$TREE_DIRTY" != false ]; then fail "run tree was dirty at start" |
| 254 | elif [ "$PROV_FILES_OK" != true ] || [ "$PROVENANCE_OK" != true ] || \ |
| 255 | [ "$FINAL_OK" != true ] || [ "$DEPENDENCIES_OK" != true ]; then : |
| 256 | else BOUND=true; fi |
| 257 | |
| 258 | # ---- correctness reruns (§14, §16 item 9) |
| 259 | # Parse before embedding. The schema-specific Omega validator composes the |
| 260 | # repository's strict RFC 8259 reader and rejects non-root, missing, extra, |
| 261 | # duplicate or non-PASS members (including escaped spellings of a duplicate). |
| 262 | if [ -n "$RERUNS" ] && [ -s "$RERUNS" ]; then |
| 263 | OMC=$HERE/seed/out/omc |
| 264 | JSON_UNIT=$HERE/seed/json/json.om |
| 265 | RERUN_UNIT=$HERE/tools/r15_reruns_validate.om |
| 266 | for f in "$OMC" "$HERE/seed/out/omc.sha256" "$JSON_UNIT" "$RERUN_UNIT"; do |
| 267 | [ -s "$f" ] || { echo "r15_receipt: missing $f" >&2; exit 2; } |
| 268 | done |
| 269 | [ -x "$OMC" ] || { echo "r15_receipt: seeded compiler $OMC is not executable" >&2; exit 2; } |
| 270 | (cd "$HERE" && sha256sum --quiet -c seed/out/omc.sha256) || { |
| 271 | echo "r15_receipt: seeded compiler does not match seed/out/omc.sha256" >&2 |
| 272 | exit 2 |
| 273 | } |
| 274 | # omc and the programs it emits are AArch64. The digest above binds the |
| 275 | # compiler bytes. On any other machine, qemu-user runs those same bytes. |
| 276 | OM_PFX=() |
| 277 | if [ "$(uname -m)" != aarch64 ]; then |
| 278 | command -v qemu-aarch64 >/dev/null 2>&1 || { |
| 279 | echo "r15_receipt: seeded compiler is AArch64 and qemu-aarch64 is not installed" >&2 |
| 280 | exit 2 |
| 281 | } |
| 282 | OM_PFX=(qemu-aarch64 -L /usr/aarch64-linux-gnu) |
| 283 | fi |
| 284 | RERUN_CHECK=$(mktemp "$OUTDIR/.r15-reruns-check.XXXXXX") || exit 2 |
| 285 | if ! { printf 'om2\n'; cat "$JSON_UNIT" "$RERUN_UNIT"; } | "${OM_PFX[@]}" "$OMC" > "$RERUN_CHECK"; then |
| 286 | rm -f "$RERUN_CHECK" |
| 287 | echo "r15_receipt: cannot build strict rerun validator" >&2 |
| 288 | exit 2 |
| 289 | fi |
| 290 | chmod 700 "$RERUN_CHECK" || { rm -f "$RERUN_CHECK"; exit 2; } |
| 291 | "${OM_PFX[@]}" "$RERUN_CHECK" < "$RERUNS" |
| 292 | RERUN_RC=$? |
| 293 | rm -f "$RERUN_CHECK" |
| 294 | if [ "$RERUN_RC" = 0 ]; then |
| 295 | RERUN_JSON=$(tr -d '\r\n' < "$RERUNS") |
| 296 | elif [ "$RERUN_RC" = 1 ]; then |
| 297 | RERUN_JSON='{"status":"invalid"}' |
| 298 | fail "correctness reruns must be one exact root object with every required key once and string value PASS" |
| 299 | else |
| 300 | echo "r15_receipt: rerun validator failed with exit $RERUN_RC" >&2 |
| 301 | exit 2 |
| 302 | fi |
| 303 | else |
| 304 | RERUN_JSON='{"status":"not done"}' |
| 305 | fail "correctness reruns (§14) not recorded" |
| 306 | fi |
| 307 | |
| 308 | # ---- RES-1-NODIGEST flag, checked from raw (every process records |
| 309 | # causal_digest): the NODIGEST measurement build must have digests off |
| 310 | # (0) and every other process (RES-4, RES-1, SEQ trials, L2) must have them on. |
| 311 | ND_OK=true; ND_FILES=0; PROD_FILES=0 |
| 312 | for f in "$RAW"/trial-*.jsonl "$RAW"/l2-*.jsonl; do |
| 313 | [ -e "$f" ] || continue |
| 314 | vals=$(grep -o '"causal_digest":[0-9]*' "$f" | sort -u | sed 's/.*://' | paste -sd, -) |
| 315 | case $(basename "$f") in |
| 316 | trial-RES1ND-*) ND_FILES=$((ND_FILES + 1)); want=0 ;; |
| 317 | *) PROD_FILES=$((PROD_FILES + 1)); want=1 ;; |
| 318 | esac |
| 319 | if [ "$vals" != "$want" ]; then |
| 320 | ND_OK=false |
| 321 | fail "$(basename "$f"): causal_digest values '$vals', expected $want" |
| 322 | fi |
| 323 | done |
| 324 | [ "$ND_FILES" -gt 0 ] || { ND_OK=false; fail "no RES-1-NODIGEST trial files found"; } |
| 325 | |
| 326 | OUTCOME=FAIL |
| 327 | [ ${#REASONS[@]} -eq 0 ] && OUTCOME=PASS |
| 328 | |
| 329 | # ---- regressions: every failed gate, with its value and threshold |
| 330 | REGR=$(printf '%s' "$GATES" | grep -o '{"id":"G[0-9]*"[^}]*"outcome":"FAIL"[^}]*}' \ |
| 331 | | sed 's/}$/,"justification":"none: a failed gate means no PASS (spec §11)"}/' | paste -sd, -) |
| 332 | |
| 333 | # ---- human-written regressions (spec §11) and stated limits |
| 334 | NOTE_REGR=""; LIMITS="" |
| 335 | if [ -n "$NOTES" ]; then |
| 336 | [ -s "$NOTES" ] || { echo "r15_receipt: notes file $NOTES missing or empty" >&2; exit 2; } |
| 337 | while IFS=$'\t' read -r kind a b c d; do |
| 338 | case $kind in |
| 339 | regression) |
| 340 | e="{\"metric\":$(jstr "$a"),\"resident\":$(jstr "$b"),\"seq\":$(jstr "$c"),\"justification\":$(jstr "$d")}" |
| 341 | NOTE_REGR=${NOTE_REGR:+$NOTE_REGR,}$e ;; |
| 342 | limit) |
| 343 | LIMITS=${LIMITS:+$LIMITS,}$(jstr "$a") ;; |
| 344 | ''|'#'*) ;; |
| 345 | *) echo "r15_receipt: bad notes line kind '$kind'" >&2; exit 2 ;; |
| 346 | esac |
| 347 | done < "$NOTES" |
| 348 | fi |
| 349 | [ -n "$NOTE_REGR" ] && REGR=${REGR:+$REGR,}$NOTE_REGR |
| 350 | |
| 351 | reasons_json() { |
| 352 | local first=1 r |
| 353 | printf '[' |
| 354 | for r in "${REASONS[@]}"; do |
| 355 | [ $first = 1 ] || printf ',' |
| 356 | first=0 |
| 357 | jstr "$r" |
| 358 | done |
| 359 | printf ']' |
| 360 | } |
| 361 | |
| 362 | TMP=$(mktemp "$OUTDIR/.r15-receipt.XXXXXX") || exit 2 |
| 363 | { |
| 364 | printf '{\n' |
| 365 | printf ' "schema": "AIEN_RX_R15_REACTION_PERFORMANCE_V1",\n' |
| 366 | printf ' "run_id": %s,\n' "$(jstr "$RUN_ID")" |
| 367 | printf ' "outcome": "%s",\n' "$OUTCOME" |
| 368 | printf ' "outcome_reasons": %s,\n' "$(reasons_json)" |
| 369 | printf ' "candidate_commit": %s,\n' "$(jstr "$CANDIDATE")" |
| 370 | printf ' "run_commit": %s,\n' "$(jstr "$RUN_COMMIT")" |
| 371 | printf ' "candidate_bound": %s,\n' "$BOUND" |
| 372 | printf ' "tree_dirty": %s,\n' "${TREE_DIRTY:-null}" |
| 373 | printf ' "silicon_observed": %s,\n' "$SILICON" |
| 374 | printf ' "aienos_commit": %s,\n' "$(jstr "$AIENOS")" |
| 375 | printf ' "aienos_lock": %s,\n' "$(jstr "$AIENOS_LOCK")" |
| 376 | printf ' "physics_commit": %s,\n' "$(jstr "$PHYSICS")" |
| 377 | printf ' "physics_lock": %s,\n' "$(jstr "$PHYSICS_LOCK")" |
| 378 | printf ' "benchmark_binaries_sha256": %s,\n' "${BINARIES:-null}" |
| 379 | printf ' "provenance_digest_sha256": %s,\n' "$(jstr "$PROV_DIGEST")" |
| 380 | printf ' "provenance_files_verified": %s,\n' "$PROV_FILES_OK" |
| 381 | printf ' "build_provenance": ' |
| 382 | if [ -s "$PROV" ]; then tr -d '\n' < "$PROV"; else printf 'null'; fi |
| 383 | printf ',\n "final_state": ' |
| 384 | if [ -s "$FINAL" ]; then tr -d '\n' < "$FINAL"; else printf 'null'; fi |
| 385 | printf ',\n' |
| 386 | printf ' "raw_digest_sha256": %s,\n' "$(jstr "$DIGEST_ACTUAL")" |
| 387 | printf ' "raw_digest_matches_reducer": %s,\n' "$DIGEST_OK" |
| 388 | printf ' "raw_files_verified": %s,\n' "$RAW_FILES_OK" |
| 389 | printf ' "reducer_source_sha256": %s,\n' "$(jstr "$REDUCER_SRC")" |
| 390 | printf ' "legacy_status": "NOT DIRECTLY COMPARABLE (spec §2): sovereign-core run_until_complete/step is LLM batched decode; aegis-runtime execute_task is an LLM tool-calling loop; the baseline is the sequential control SEQ",\n' |
| 391 | printf ' "seq_selector_symbol": "rx_world_init_native_sequential_reference",\n' |
| 392 | printf ' "nodigest_macro": {"name": "RX_MEASURE_NO_CAUSAL_DIGEST", "used_by": "RES-1-NODIGEST measurement build only", "checked_from_raw": %s, "nodigest_processes_digest_off": %s, "production_processes_digest_on": %s},\n' \ |
| 393 | "$ND_OK" "$ND_FILES" "$PROD_FILES" |
| 394 | printf ' "gates_present": %s,\n' "$NGATES" |
| 395 | printf ' "all_gates_pass": %s,\n' "${ALL_PASS:-null}" |
| 396 | printf ' "gates": %s,\n' "${GATES:-[]}" |
| 397 | printf ' "correctness_reruns_required": %s,\n' \ |
| 398 | "[$(for k in $REQUIRED_RERUNS; do jstr "$k"; printf ','; done | sed 's/,$//')]" |
| 399 | printf ' "correctness_reruns": %s,\n' "$RERUN_JSON" |
| 400 | printf ' "regressions": [%s],\n' "$REGR" |
| 401 | printf ' "limits": [%s],\n' "$LIMITS" |
| 402 | printf ' "not_claimed": ["R16", "whole-project performance beyond the measured workloads", "LLM decode or agent-loop performance (the legacy loops, spec §2)", "general cognition", "open-ended synthesis", "energy of anything outside the measured windows"],\n' |
| 403 | printf ' "hardware_identity": ' |
| 404 | tr -d '\n' < "$MACH" |
| 405 | printf ',\n "summary": ' |
| 406 | tr -d '\n' < "$SUM" |
| 407 | printf '\n}\n' |
| 408 | } > "$TMP" |
| 409 | SHA=$(sha256sum "$TMP" | cut -d' ' -f1) |
| 410 | mv "$TMP" "$OUTDIR/$SHA.json" || exit 2 |
| 411 | echo "$OUTDIR/$SHA.json" |
| 412 | [ "$OUTCOME" = PASS ] && exit 0 || exit 1 |