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 / gate14_combine.sh

259 lines · 14225 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# gate14_combine.sh -- M19R Combined Foundation Admission Gate (Gate 14).
18#
19# tools/gate14_combine.sh [--omega-candidate SHA] [--physics-candidate SHA]
20# [--evidence-dir DIR] RECEIPT...
21#
22# Read-only aggregation of the foundation leg receipts
23# (docs/m19r-recovery-program.md in aien-architecture, "Combined Foundation
24# Admission Gate"). Each RECEIPT is one leg, recognised by its schema:
25#
26# AIEN_M19R_QUALIFICATION_V1 Gates 1/2 tools/m19r_qualify.sh (receipt-preview.json
27# or evidence/M19R/<digest>.json)
28# AIEN_M19R_FORGE_GATES_V1 Gates 3/4 physics tests/run_forge_gates.sh
29# AIEN_OMEGA_NUMERIC_0_V1 Gate 5 tests/run_numeric_gates.sh
30#
31# Accepts only when every one of the eight Gate 14 criteria is backed by a
32# PASS leg and, for every leg: the file is valid JSON; receipt_digest is the
33# SHA-256 of the canonical body without it (and equals the file name when
34# the file is named <64-hex>.json); candidate_git_commit (omega) and
35# physics_candidate_git_commit are full 40-hex ids, identical across ALL legs
36# (and equal to --omega-candidate / --physics-candidate when given);
37# candidate_trees_clean.omega and .physics are both true. Any
38# hardware_descriptor_digest present must agree across legs. A schema seen
39# twice or not known is refused.
40#
41# On accept prints the combined receipt digest, and with --evidence-dir
42# writes <dir>/<receipt_digest>.json (pretty, created exclusively, mode 0444;
43# the spec location is evidence/GATE14-FOUNDATION/). On refuse prints
44# "REFUSED: <reason>" on stderr and writes nothing.
45# Exit 0 accept, 1 refuse, 2 bad arguments.
46#
47# Digests use tools/json_canon.c (the same canonical form as the legs). They
48# make alteration detectable; they are not signatures. Shell + coreutils +
49# jq + that C helper. No Python.
50
51G14_OMEGA=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
52G14_SCHEMA=AIEN_M19R_GATE14_FOUNDATION_V1
53G14_ERR=
54
55g14_refuse() { G14_ERR=$1; return 1; }
56
57g14_build_canon() {
58 G14_TMP=$(mktemp -d "${TMPDIR:-/tmp}/gate14.XXXXXX") || return 1
59 JSON_CANON=$G14_TMP/json_canon
60 "$G14_OMEGA/seed/out/omc" < "$G14_OMEGA/tools/json_canon.om" > "$JSON_CANON" && chmod +x "$JSON_CANON"
61}
62
63# g14_criteria SCHEMA -- the Gate 14 criteria one leg backs.
64g14_criteria() {
65 case $1 in
66 AIEN_M19R_QUALIFICATION_V1)
67 echo EVIDENCE_IMMUTABLE RECEIPTS_OBSERVED_NOT_ASSERTED DEVICE_MEMORY_LIFECYCLE COMPLETION_EXACTLY_ONCE LONG_RUNNING_GPU_SOAK;;
68 AIEN_M19R_FORGE_GATES_V1) echo FORGE_BOUNDARY HARDWARE_ID_OBSERVED;;
69 AIEN_OMEGA_NUMERIC_0_V1) echo FP32_CPU_GB10_PARITY;;
70 *) return 1;;
71 esac
72}
73G14_ALL_CRITERIA="EVIDENCE_IMMUTABLE RECEIPTS_OBSERVED_NOT_ASSERTED DEVICE_MEMORY_LIFECYCLE COMPLETION_EXACTLY_ONCE LONG_RUNNING_GPU_SOAK FORGE_BOUNDARY HARDWARE_ID_OBSERVED FP32_CPU_GB10_PARITY"
74
75# g14_pass_rule SCHEMA -- jq expression, true when the leg receipt records a PASS.
76# results (every leg but Gate 1/2): a non-empty test_results list, every
77# entry PASS, its length equal to observed_test_count and observed_pass_count.
78# Gate 1/2 also needs the soak thresholds m19r_qualify.sh enforces (>= 100000
79# cycles, bytes churned > 2x physical memory) and exactly 18 OMEGA_ACCEL_RESIDENT_
80# results. The Gate 5 leg must have run on its candidates (run_git_commit,
81# physics_lock).
82# The Gate 1/2 receipt has no status field (it is written only on success),
83# so its PASS is read from its observed counts, results and soak.
84G14_RESULTS_RULE='((.test_results | type) == "array"
85 and (.test_results | length) > 0
86 and (.test_results | length) == .observed_test_count
87 and .observed_pass_count == .observed_test_count
88 and all(.test_results[]; .status == "PASS"))'
89g14_pass_rule() {
90 case $1 in
91 AIEN_M19R_QUALIFICATION_V1) echo '
92 (has("status") | not)
93 and .observed_fail_count == 0
94 and (.observed_gate_results_count | type) == "number"
95 and .observed_gate_results_count > 0
96 and .observed_pass_count == .observed_gate_results_count
97 and (.test_results | type) == "array"
98 and (.test_results | length) == .observed_gate_results_count
99 and all(.test_results[]; .status == "PASS")
100 and .soak.passed == true
101 and (.soak.cycles | type) == "number" and .soak.cycles >= 100000
102 and (.soak.physical_memory_bytes | type) == "number" and .soak.physical_memory_bytes > 0
103 and (.soak.bytes_churned | type) == "number"
104 and .soak.bytes_churned > 2 * .soak.physical_memory_bytes
105 and ([.test_results[] | select((.id | type) == "string" and (.id | startswith("OMEGA_ACCEL_RESIDENT_"))) | .id] | unique | length) == 18
106 and ([.test_results[] | select((.id | type) == "string" and (.id | startswith("OMEGA_ACCEL_RESIDENT_")))] | length) == 18
107 and (.m19_observations | type) == "object"
108 and .m19_observations.m19_gates_completed == 18
109 and .m19_observations.m19_gates_passed == 18
110 and (.m19_observations.regression_gates_completed | type) == "number"
111 and .m19_observations.regression_gates_completed > 0
112 and .m19_observations.regression_gates_passed == .m19_observations.regression_gates_completed';;
113 AIEN_M19R_FORGE_GATES_V1) echo '
114 .status == "PASS"
115 and .observed_fail_count == 0
116 and .gates.GATE_3_FORGE_0.status == "PASS"
117 and .gates.GATE_3_FORGE_0.gate_binary_exit_status == 0
118 and .gates.GATE_4_FORGE_HWID.status == "PASS"
119 and .gates.GATE_4_FORGE_HWID.gate_binary_exit_status == 0
120 and ([.gates[].candidate_binary_sha256] | all(type == "string" and test("^[0-9a-f]{64}$")))
121 and .gates.GATE_4_FORGE_HWID.hardware_descriptor_digest == .hardware_descriptor_digest
122 and (.hardware_descriptor_digest | type) == "string"
123 and results';;
124 AIEN_OMEGA_NUMERIC_0_V1) echo '
125 .status == "PASS"
126 and .gate_binary_exit_status == 0
127 and .observed_fail_count == 0
128 and .run_git_commit == .candidate_git_commit
129 and .physics_lock == .physics_candidate_git_commit
130 and (.hardware_descriptor_digest | type) == "string"
131 and results';;
132 esac
133}
134
135# g14_check_leg FILE -- validate one leg. Sets G14_LEG_SCHEMA, G14_LEG_DIGEST,
136# G14_LEG_OMEGA, G14_LEG_PHYSICS, G14_LEG_DESC.
137g14_check_leg() {
138 local f=$1 name recomputed rule s
139 [ -f "$f" ] && [ -r "$f" ] || g14_refuse "cannot read receipt $f" || return 1
140 # every check reads one private copy, so the file cannot change between checks
141 s=$(mktemp "$G14_TMP/leg.XXXXXX") && cp -- "$f" "$s" || g14_refuse "cannot copy receipt $f" || return 1
142 "$JSON_CANON" --check < "$s" || g14_refuse "$f is not valid JSON" || return 1
143 jq -e 'type == "object"' "$s" > /dev/null || g14_refuse "$f is not a JSON object" || return 1
144 G14_LEG_SCHEMA=$(jq -r '.schema // ""' "$s")
145 g14_criteria "$G14_LEG_SCHEMA" > /dev/null || g14_refuse "$f has unknown schema '$G14_LEG_SCHEMA'" || return 1
146 G14_LEG_DIGEST=$(jq -r '.receipt_digest // ""' "$s")
147 [[ $G14_LEG_DIGEST =~ ^[0-9a-f]{64}$ ]] || g14_refuse "$f has no 64-hex receipt_digest" || return 1
148 recomputed=$(jq -c 'del(.receipt_digest)' "$s" | "$JSON_CANON" --sha256) ||
149 g14_refuse "cannot digest $f" || return 1
150 [ "$recomputed" = "$G14_LEG_DIGEST" ] || g14_refuse "$f receipt_digest does not match its content" || return 1
151 name=$(basename "$f")
152 if [[ $name =~ ^[0-9a-fA-F]{64}\.json$ ]]; then
153 [ "${name%.json}" = "$G14_LEG_DIGEST" ] || g14_refuse "$f is named for a different digest" || return 1
154 fi
155 G14_LEG_OMEGA=$(jq -r '.candidate_git_commit // ""' "$s")
156 G14_LEG_PHYSICS=$(jq -r '.physics_candidate_git_commit // ""' "$s")
157 [[ $G14_LEG_OMEGA =~ ^[0-9a-f]{40}$ ]] || g14_refuse "$f candidate_git_commit is not a full 40-hex id" || return 1
158 [[ $G14_LEG_PHYSICS =~ ^[0-9a-f]{40}$ ]] || g14_refuse "$f physics_candidate_git_commit is not a full 40-hex id" || return 1
159 jq -e '.candidate_trees_clean.omega == true and .candidate_trees_clean.physics == true' "$s" > /dev/null ||
160 g14_refuse "$f was not made from clean omega and physics trees" || return 1
161 rule=$(g14_pass_rule "$G14_LEG_SCHEMA")
162 jq -e "def results: $G14_RESULTS_RULE; $rule" "$s" > /dev/null 2>&1 || g14_refuse "$f ($G14_LEG_SCHEMA) does not record a PASS" || return 1
163 G14_LEG_DESC=$(jq -r '.hardware_descriptor_digest // ""' "$s")
164 [ -z "$G14_LEG_DESC" ] || { [[ $G14_LEG_DESC =~ ^[0-9a-f]{64}$ ]] && [[ ! $G14_LEG_DESC =~ ^0+$ ]]; } ||
165 g14_refuse "$f hardware_descriptor_digest is not 64 hex (or is all zeros)" || return 1
166}
167
168# g14_combine OMEGA_EXPECTED PHYSICS_EXPECTED TS RECEIPT... -- check every leg
169# and build the combined receipt. Sets G14_DIGEST and G14_RECEIPT.
170g14_combine() {
171 local want_o=${1,,} want_p=${2,,} ts=$3 f omega= physics= desc= seen= c crit legs= criteria= body
172 shift 3
173 [ $# -gt 0 ] || g14_refuse "no receipts given" || return 1
174 declare -A by_crit=()
175 for f in "$@"; do
176 g14_check_leg "$f" || return 1
177 case " $seen " in *" $G14_LEG_SCHEMA "*) g14_refuse "two receipts for $G14_LEG_SCHEMA" || return 1;; esac
178 seen="$seen $G14_LEG_SCHEMA"
179 if [ -z "$omega" ]; then
180 omega=$G14_LEG_OMEGA physics=$G14_LEG_PHYSICS
181 fi
182 [ "$G14_LEG_OMEGA" = "$omega" ] ||
183 g14_refuse "omega commit mismatch: $f has $G14_LEG_OMEGA, first leg has $omega" || return 1
184 [ "$G14_LEG_PHYSICS" = "$physics" ] ||
185 g14_refuse "physics commit mismatch: $f has $G14_LEG_PHYSICS, first leg has $physics" || return 1
186 if [ -n "$G14_LEG_DESC" ]; then
187 [ -z "$desc" ] || [ "$desc" = "$G14_LEG_DESC" ] ||
188 g14_refuse "hardware_descriptor_digest differs between legs" || return 1
189 desc=$G14_LEG_DESC
190 fi
191 for c in $(g14_criteria "$G14_LEG_SCHEMA"); do by_crit[$c]=$G14_LEG_DIGEST; done
192 legs+="${legs:+,}{\"schema\":\"$G14_LEG_SCHEMA\",\"receipt_digest\":\"$G14_LEG_DIGEST\"}"
193 done
194 [ -z "$want_o" ] || [ "$want_o" = "$omega" ] ||
195 g14_refuse "legs are for omega $omega, not the expected $want_o" || return 1
196 [ -z "$want_p" ] || [ "$want_p" = "$physics" ] ||
197 g14_refuse "legs are for physics $physics, not the expected $want_p" || return 1
198 for crit in $G14_ALL_CRITERIA; do
199 [ -n "${by_crit[$crit]:-}" ] || g14_refuse "missing leg: no receipt backs $crit" || return 1
200 criteria+="${criteria:+,}\"$crit\":{\"status\":\"PASS\",\"receipt_digest\":\"${by_crit[$crit]}\"}"
201 done
202 body="{\"schema\":\"$G14_SCHEMA\",\"gate\":\"M19R_GATE14_COMBINED_FOUNDATION_ADMISSION\",\"status\":\"PASS\""
203 body+=",\"timestamp_utc\":\"$ts\""
204 body+=",\"candidate_git_commit\":\"$omega\",\"physics_candidate_git_commit\":\"$physics\""
205 body+=",\"candidate_trees_clean\":{\"omega\":true,\"physics\":true}"
206 body+=",\"constituent_receipts\":[$legs],\"criteria\":{$criteria}"
207 [ -z "$desc" ] || body+=",\"hardware_descriptor_digest\":\"$desc\""
208 body+=",\"digest_meaning\":\"integrity only, not authenticity: re-hash the constituent receipts named here\"}"
209 G14_DIGEST=$(printf '%s' "$body" | "$JSON_CANON" --sha256) || g14_refuse "combined body is not valid JSON" || return 1
210 G14_RECEIPT="{\"receipt_digest\":\"$G14_DIGEST\",${body#\{}"
211}
212
213# g14_write DIR -- write G14_RECEIPT to DIR/<digest>.json (pretty, exclusive, 0444).
214g14_write() {
215 local dir=$1 pretty
216 mkdir -p "$dir" || g14_refuse "cannot create $dir" || return 1
217 pretty=$G14_TMP/combined.pretty
218 printf '%s' "$G14_RECEIPT" | "$JSON_CANON" --pretty > "$pretty" || g14_refuse "cannot format receipt" || return 1
219 "$JSON_CANON" --write-exclusive "$dir/$G14_DIGEST.json" < "$pretty" 2> "$pretty.err" ||
220 g14_refuse "cannot write $dir/$G14_DIGEST.json: $(cat "$pretty.err")" || return 1
221 chmod 0444 "$dir/$G14_DIGEST.json" || g14_refuse "cannot chmod $dir/$G14_DIGEST.json"
222}
223
224g14_usage() {
225 echo "usage: $0 [--omega-candidate SHA] [--physics-candidate SHA] [--evidence-dir DIR] RECEIPT..." >&2
226 exit 2
227}
228
229g14_main() {
230 local want_o= want_p= ev= receipts=() ts
231 while [ $# -gt 0 ]; do
232 case $1 in
233 --omega-candidate) [ $# -ge 2 ] || g14_usage; want_o=$2; shift 2;;
234 --physics-candidate) [ $# -ge 2 ] || g14_usage; want_p=$2; shift 2;;
235 --evidence-dir) [ $# -ge 2 ] || g14_usage; ev=$2; shift 2;;
236 --) shift; receipts+=("$@"); break;;
237 -*) g14_usage;;
238 *) receipts+=("$1"); shift;;
239 esac
240 done
241 [ ${#receipts[@]} -gt 0 ] || g14_usage
242 for c in "$want_o" "$want_p"; do
243 [ -z "$c" ] || [[ $c =~ ^[0-9a-fA-F]{40}$ ]] || { echo "candidates must be full 40-hex SHAs" >&2; exit 2; }
244 done
245 g14_build_canon || { echo "REFUSED: cannot build tools/json_canon.c" >&2; exit 1; }
246 trap 'rm -rf "$G14_TMP"' EXIT
247 ts=$(date -u +%Y-%m-%dT%H:%M:%S.%6NZ)
248 g14_combine "$want_o" "$want_p" "$ts" "${receipts[@]}" || { echo "REFUSED: $G14_ERR" >&2; exit 1; }
249 if [ -n "$ev" ]; then
250 g14_write "$ev" || { echo "REFUSED: $G14_ERR" >&2; exit 1; }
251 echo "Gate 14 PASS: receipt $ev/$G14_DIGEST.json"
252 else
253 echo "Gate 14 PASS: receipt digest $G14_DIGEST (not written; no --evidence-dir)"
254 fi
255}
256
257if [ "${BASH_SOURCE[0]}" = "$0" ]; then
258 g14_main "$@"
259fi