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 / seed / helix / ollm_factory / closed-loop-gate.sh

192 lines · 11027 bytes Raw Blame History
1#!/bin/sh
2# seed/helix/ollm_factory/closed-loop-gate.sh
3# 5-Stage Closed-Loop Verified Self-Play & Training Factory Gate for Omega LLM.
4#
5# 100% pure seeded Omega + Lean 4 (zero C, zero Python, zero CUDA on host):
6# Stage 1: Cold-regrow 4-strand BFT seeds (or reuse regrown omc_A & omc_B_fast) + build
7# dual-strand identical `rlvr_factory`, `arboris_train`, `bench`, `ollm`, `ollm-helix-gb10`.
8# Stage 2: Infinite Mechanical RLVR Filter + Zero-Leakage Guarantee:
9# - Emit 252 distinct OM-2 functions + 8 error-to-fix repair/antibody records
10# - Compile `rlvr_oracle.om` identically across Strand A & Strand B and EXECUTE it ->
11# proves 100% (252/252) of generated functions compile & return exact ground truth!
12# - Run `bench check` + `bench seen train/omega-llm/tools/bench/tasks.om verified_rlvr.om`
13# and FAIL CLOSED if even 1 generated task leaks any of the 165 frozen benchmark tasks!
14# Stage 3: Frozen-Core `OLLMSP01` Merkle-Chained Specialist Evolution + `spclip` Multi-Helix:
15# - Train `base (L=2) -> growpro (L=3) -> fcache -> trainfc -> spext P1_rlvr.sp`
16# - Chain `P1_rlvr.sp (L=3) -> growpro (L=4) -> fcache -> trainfc -> spext P2_repair.sp`
17# - Verify frozen base bit-identity, `spchaineval`/`spchainsamp` exact parity,
18# DNA-style `spclip` entropy-gated multi-helix (`MODE=1`), AND all 3 tamper controls
19# (`rc=60` truncated, `rc=61` 1-bit flipped payload, `rc=62` wrong base / swapped link)!
20# Stage 4: Arboris Smart Curriculum + Preemptive Anti-Forgetting Rehearsal + Adaptive Loop Depth
21# + Sealed Judge (`core/rsi/om/eval/`) + V2 ECDSA P-256 Promotion Ratchet (`v2_main.om`)!
22# Stage 5: Optional `--full` runs the entire Four-Wall Loop-1 RSI + 29 Lean 4 theorems gate.
23#
24# Usage (from repository root on AArch64 Linux):
25# sh seed/helix/ollm_factory/closed-loop-gate.sh [--full]
26set -eu
27R=$(CDPATH= cd -- "$(dirname "$0")/../../.." && pwd)
28cd "$R"
29
30FULL=0
31for arg in "$@"; do
32 case "$arg" in
33 --full) FULL=1 ;;
34 *) printf 'usage: closed-loop-gate.sh [--full]\n' >&2; exit 2 ;;
35 esac
36done
37
38bad() { printf 'OLLM_FACTORY FAIL: %s\n' "$*" >&2; exit 1; }
39sha() { sha256sum "$1" | cut -d' ' -f1; }
40
41B=build/ollm-factory
42rm -rf "$B"
43mkdir -p "$B/bin" "$B/rlvr" "$B/spec" "$B/bench"
44
45if [ "$FULL" = "1" ]; then
46 printf '=== [STAGE 0/5] FULL FOUR-WALL RSI + 4-STRAND BFT + 29 LEAN 4 THEOREMS ===\n'
47 sh seed/helix/rsi-loop1.sh --lean
48 OMC_A=build/cold-regrowth/omc_A
49 OMC_B=build/cold-regrowth/omc_B_fast
50else
51 printf '=== [STAGE 1/5] REGROW STRAND A & STRAND B FROM 804B SEEDS ===\n'
52 sh seed/helix/helix-from-seeds.sh
53 OMC_A=seed/out/omc
54 OMC_B=build/helix/A_fast
55fi
56
57printf '\n=== [STAGE 1b/5] DUAL-STRAND BUILD OF FACTORY, ARBORIS, BENCH, OLLM & OLLM-HELIX-GB10 ===\n'
58for item in "rlvr_factory:seed/helix/ollm_factory/rlvr_factory.om" \
59 "rlvr_compositional:seed/helix/ollm_factory/rlvr_compositional.om" \
60 "rlvr_idioms:seed/helix/ollm_factory/rlvr_idioms.om" \
61 "arboris_train:seed/helix/ollm_factory/arboris_train.om" \
62 "bench:train/omega-llm/tools/bench/bench.om"; do
63 name="${item%%:*}"
64 src="${item#*:}"
65 "$OMC_A" < "$src" > "$B/bin/${name}.A"
66 "$OMC_B" < "$src" > "$B/bin/${name}.B"
67 cmp -s "$B/bin/${name}.A" "$B/bin/${name}.B" || bad "$name diverged across strands"
68 mv "$B/bin/${name}.A" "$B/bin/${name}"
69 rm -f "$B/bin/${name}.B"
70 chmod +x "$B/bin/${name}"
71 printf 'PASS %s dual-strand identical (%s)\n' "$name" "$(sha "$B/bin/${name}")"
72done
73
74sh seed/helix/ollm_factory/build-ollm-jit.sh "$OMC_A" "$OMC_B" "$B/bin"
75
76printf '\n=== [STAGE 2/5] MECHANICAL RLVR DATA & REPAIR FACTORY + ZERO-LEAKAGE AUDIT ===\n'
77"$B/bin/rlvr_factory" corpus > "$B/rlvr/verified_rlvr.om"
78"$B/bin/rlvr_factory" repair > "$B/rlvr/verified_repair.om"
79"$B/bin/rlvr_factory" oracle > "$B/rlvr/rlvr_oracle.om"
80"$B/bin/rlvr_compositional" corpus 1 | tr '\0' '\n' > "$B/rlvr/verified_comp.om"
81"$B/bin/rlvr_compositional" oracle 1 > "$B/rlvr/comp_oracle.om"
82"$B/bin/rlvr_idioms" corpus 1 | tr '\0' '\n' > "$B/rlvr/verified_idioms.om"
83"$B/bin/rlvr_idioms" oracle 1 > "$B/rlvr/idioms_oracle.om"
84"$B/bin/rlvr_factory" teacher
85
86# Mechanically compile & execute ALL synthesized functions across BOTH strands!
87"$OMC_A" < "$B/rlvr/rlvr_oracle.om" > "$B/rlvr/rlvr_oracle.A"
88"$OMC_B" < "$B/rlvr/rlvr_oracle.om" > "$B/rlvr/rlvr_oracle.B"
89cmp -s "$B/rlvr/rlvr_oracle.A" "$B/rlvr/rlvr_oracle.B" || bad "rlvr_oracle diverged across strands"
90chmod +x "$B/rlvr/rlvr_oracle.A"
91"$B/rlvr/rlvr_oracle.A"
92
93"$OMC_A" < "$B/rlvr/comp_oracle.om" > "$B/rlvr/comp_oracle.A"
94"$OMC_B" < "$B/rlvr/comp_oracle.om" > "$B/rlvr/comp_oracle.B"
95cmp -s "$B/rlvr/comp_oracle.A" "$B/rlvr/comp_oracle.B" || bad "comp_oracle diverged across strands"
96chmod +x "$B/rlvr/comp_oracle.A"
97"$B/rlvr/comp_oracle.A"
98
99"$OMC_A" < "$B/rlvr/idioms_oracle.om" > "$B/rlvr/idioms_oracle.A"
100"$OMC_B" < "$B/rlvr/idioms_oracle.om" > "$B/rlvr/idioms_oracle.B"
101cmp -s "$B/rlvr/idioms_oracle.A" "$B/rlvr/idioms_oracle.B" || bad "idioms_oracle diverged across strands"
102chmod +x "$B/rlvr/idioms_oracle.A"
103"$B/rlvr/idioms_oracle.A"
104FN_CNT=$(cat "$B/rlvr/verified_rlvr.om" "$B/rlvr/verified_comp.om" "$B/rlvr/verified_idioms.om" | grep -c '^fn solve ')
105printf 'PASS Mechanical RLVR Oracles: %s verified OM-2 records compiled identically across both strands & 100%% executed PASS\n' "$FN_CNT"
106
107# Frozen benchmark integrity + ZERO-LEAKAGE audit across ALL 3 RLVR generators!
108"$B/bin/bench" check train/omega-llm/tools/bench/tasks.om train/omega-llm/tools/bench/expect.txt "$OMC_A" "$B/bench"
109cat "$B/rlvr/verified_rlvr.om" "$B/rlvr/verified_comp.om" "$B/rlvr/verified_idioms.om" > "$B/rlvr/all_rlvr_gate.om"
110SEEN_OUT=$("$B/bin/bench" seen train/omega-llm/tools/bench/tasks.om "$B/rlvr/all_rlvr_gate.om")
111printf '%s\n' "$SEEN_OUT"
112case "$SEEN_OUT" in
113 *"seen 0"*) printf 'PASS Zero-Leakage Guarantee: 0 of 165 frozen benchmark tasks appear in %s RLVR records!\n' "$FN_CNT" ;;
114 *) bad "RLVR corpus leaked a frozen benchmark task: $SEEN_OUT" ;;
115esac
116
117printf '\n=== [STAGE 3/5] FROZEN-CORE OLLMSP01 MERKLE SPECIALIST CHAIN + SPCLIP + TAMPER CONTROLS ===\n'
118OLLM="$B/bin/ollm"
119SD="$B/spec"
120# Init compact base byte-level checkpoint (V=256, T=16, D=32, H=2, F=64, L=2, B=2)
121"$OLLM" init "$SD/base.ck" 256 16 32 2 64 2 2 42 20 5000 1 >/dev/null
122# Split verified_rlvr.om into train / heldout slices (bytes)
123cp "$B/rlvr/verified_rlvr.om" "$SD/rlvr_train.bin"
124cp "$B/rlvr/verified_repair.om" "$SD/repair_train.bin"
125head -c 256 "$B/rlvr/verified_rlvr.om" > "$SD/held.bin"
126
127BASE_EVAL=$("$OLLM" eval "$SD/base.ck" "$SD/held.bin" 4)
128printf ' Base L=2 eval: %s\n' "$BASE_EVAL"
129
130# Specialist P1 (OM-2 RLVR Systems Specialist, L=2 -> 3 via growpro + fcache + trainfc + spext)
131"$OLLM" growpro "$SD/base.ck" "$SD/s1.ck" 3 40 5000
132S1_STEP0=$("$OLLM" eval "$SD/s1.ck" "$SD/held.bin" 4)
133[ "$BASE_EVAL" = "$S1_STEP0" ] || bad "growpro step-0 not bit-identical to base ($BASE_EVAL vs $S1_STEP0)"
134"$OLLM" fcache "$SD/base.ck" "$SD/rlvr_train.bin" 16 "$SD/s1.hc"
135"$OLLM" trainfc "$SD/s1.ck" "$SD/s1.hc" 8 4 2 2
136"$OLLM" spext "$SD/base.ck" "$SD/s1.ck" "$SD/P1_rlvr.sp"
137P1_EVAL=$("$OLLM" speval "$SD/base.ck" "$SD/P1_rlvr.sp" "$SD/held.bin" 4)
138S1_EVAL=$("$OLLM" eval "$SD/s1.ck" "$SD/held.bin" 4)
139[ "$(printf '%s' "$P1_EVAL" | awk '{print $3,$4,$5}')" = "$(printf '%s' "$S1_EVAL" | awk '{print $3,$4,$5}')" ] || bad "speval P1 mismatch ($P1_EVAL vs $S1_EVAL)"
140printf ' PASS Specialist P1 (OM-2 RLVR, L=2->3, %s B): %s\n' "$(wc -c < "$SD/P1_rlvr.sp" | tr -d ' ')" "$P1_EVAL"
141
142# Specialist P2 (Helix Repair Specialist chained onto base + P1 -> L=3->4 Merkle chain!)
143"$OLLM" growpro "$SD/s1.ck" "$SD/s2.ck" 4 40 5000
144"$OLLM" fcache "$SD/s1.ck" "$SD/repair_train.bin" 8 "$SD/s2.hc"
145"$OLLM" trainfc "$SD/s2.ck" "$SD/s2.hc" 14 6 3 2
146"$OLLM" spext "$SD/s1.ck" "$SD/s2.ck" "$SD/P2_repair.sp"
147CH_EVAL=$("$OLLM" spchaineval "$SD/base.ck" "$SD/held.bin" 4 - 2 "$SD/P1_rlvr.sp" "$SD/P2_repair.sp")
148S2_EVAL=$("$OLLM" eval "$SD/s2.ck" "$SD/held.bin" 4)
149[ "$(printf '%s' "$CH_EVAL" | awk '{print $3,$4,$5}')" = "$(printf '%s' "$S2_EVAL" | awk '{print $3,$4,$5}')" ] || bad "spchaineval P1->P2 mismatch ($CH_EVAL vs $S2_EVAL)"
150printf ' PASS Merkle Chain P1->P2 (L=2->3->4, %s B): %s\n' "$(wc -c < "$SD/P2_repair.sp" | tr -d ' ')" "$CH_EVAL"
151
152# Parallel Specialist P1b (Repair branch off base) + DNA-style entropy-gated multi-helix `spclip`
153"$OLLM" growpro "$SD/base.ck" "$SD/s1b.ck" 3 40 5000
154"$OLLM" fcache "$SD/base.ck" "$SD/repair_train.bin" 8 "$SD/s1b.hc"
155"$OLLM" trainfc "$SD/s1b.ck" "$SD/s1b.hc" 8 4 2 2
156"$OLLM" spext "$SD/base.ck" "$SD/s1b.ck" "$SD/P1b_helix.sp"
157"$OLLM" spclip "$SD/base.ck" 1 "fn solve " 16 0 42 - 2 500 2 "$SD/P1_rlvr.sp" "$SD/P2_repair.sp" 500 1 "$SD/P1b_helix.sp" > "$SD/spclip.out"
158printf ' PASS DNA Multi-Helix spclip (MODE=1 entropy-gated, %s bytes emitted)\n' "$(wc -c < "$SD/spclip.out" | tr -d ' ')"
159
160# Negative tamper controls on OLLMSP01 Merkle chain (rc=60, rc=61, rc=62)
161head -c 32 "$SD/P1_rlvr.sp" > "$SD/trunc.sp"
162rc=0; "$OLLM" speval "$SD/base.ck" "$SD/trunc.sp" "$SD/held.bin" 4 >/dev/null 2>&1 || rc=$?
163[ "$rc" = "60" ] || bad "truncated pack expected rc=60 got $rc"
164
165cp "$SD/P2_repair.sp" "$SD/flip.sp"
166printf '\377' | dd of="$SD/flip.sp" bs=1 seek=64 count=1 conv=notrunc 2>/dev/null
167rc=0; "$OLLM" spchaineval "$SD/base.ck" "$SD/held.bin" 4 - 2 "$SD/P1_rlvr.sp" "$SD/flip.sp" >/dev/null 2>&1 || rc=$?
168[ "$rc" = "61" ] || bad "1-bit flipped pack expected rc=61 got $rc"
169
170rc=0; "$OLLM" spchaineval "$SD/base.ck" "$SD/held.bin" 4 - 2 "$SD/P2_repair.sp" "$SD/P1_rlvr.sp" >/dev/null 2>&1 || rc=$?
171[ "$rc" = "62" ] || bad "swapped Merkle link order expected rc=62 got $rc"
172printf ' PASS OLLMSP01 Merkle tamper controls: truncated=rc60 flipped=rc61 swapped_link=rc62\n'
173
174printf '\n=== [STAGE 4/5] ARBORIS CURRICULUM/REHEARSAL/DEPTH + SEALED RSI V2 P-256 RATCHET ===\n'
175"$B/bin/arboris_train"
176
177# Dual-strand Sealed Judge evaluator + ECDSA P-256 promotion ratchet
178EVAL_SRCS="si/directives/om2.om core/rsi/om/eval/evaluator.om om/tls/sha2.om core/rsi/om/eval/canary.om core/rsi/om/eval/rollback.om core/rsi/om/eval/eval_test.om"
179cat $EVAL_SRCS | "$OMC_A" > "$B/bin/rsi_eval_test.A"
180cat $EVAL_SRCS | "$OMC_B" > "$B/bin/rsi_eval_test.B"
181cmp -s "$B/bin/rsi_eval_test.A" "$B/bin/rsi_eval_test.B" || bad "rsi_eval_test diverged"
182chmod +x "$B/bin/rsi_eval_test.A"
183"$B/bin/rsi_eval_test.A"
184
185P256_GATE_SRCS="core/rsi/om/p256/sha256.om core/rsi/om/p256/p256.om core/rsi/om/governance/receipt_v2.om core/rsi/om/governance/v2_main.om"
186cat $P256_GATE_SRCS | "$OMC_A" > "$B/bin/rsi_v2_gate.A"
187cat $P256_GATE_SRCS | "$OMC_B" > "$B/bin/rsi_v2_gate.B"
188cmp -s "$B/bin/rsi_v2_gate.A" "$B/bin/rsi_v2_gate.B" || bad "rsi_v2_gate diverged"
189chmod +x "$B/bin/rsi_v2_gate.A"
190"$B/bin/rsi_v2_gate.A" selfcheck
191
192printf '\nOLLM_CLOSED_LOOP_FACTORY PASS rlvr_records=%s seen=0 merkle_links=2 spclip=PASS tamper_controls=3/3 arboris_train=PASS p256_ratchet=PASS ollm_helix_gb10=DUAL_STRAND_STATIC\n' "$FN_CNT"