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 / docs / polyglot / review-polyglot-0.md

320 lines · 23008 bytes Raw Blame History Source

POLYGLOT-0 independent adversarial review (lane G)

Lane B3 (Mojo) removed on 2026-10-15. Modular MAX and Mojo were dropped from AIEN, and the Mojo lane's source, build rules and test were deleted from this repo. Mojo text below is the original design record, kept unchanged; the Mojo receipts stay in evidence/.

Reviewer: worker G (Opus 5.5), did not author any reviewed code. Reviewed: branch feat/polyglot-0 at 17d2854 (worktree ~/workspace/omega-polyglot-review, branch polyglot/review). Scope: spec/polyglot-0.md, docs/polyglot/POLYGLOT_AGENT_OWNERSHIP.md, mk/polyglot*.mk, src/polyglot/**, polyglot/mojo/omx_mojo.mojo, tests/polyglot/**.

What was run (correctness only, plus one smoke bench; no full timed bench):

Headline: the shipped kernels are correct on everything I threw at them, and they preserve callee-saved registers. The weak spots are the gate machinery: the bench breaks its own 1 ms rule on S1, two receipt fields are wrong for Mojo and the encoder, and the shared verifier misses five of my ten mutants.

Mutant results

iddefect injectedverify plainverify ASanlane testbench would catch
Aasm_crumb reads 16 B past the end of the packed weights (ldr q5,[x5] at .Lcr_ok)missedmissedcaught (test-polyglot-asm segfault)no
Basm_sdot tail mask off by one lanecaught (41,376 fails)caughtn/ayes
Casm_sdot zeroes d8 and d15 (callee-saved)missedmissedmissed (test-polyglot-asm PASS)no
Dasm_sdot zeroes x27, x28caught (crash)caught (crash)caught (crash)n/a
Easm_sdot reads x[n..n+15]caught (guard fault)caughtn/an/a
M1-1 * x computed as int8 negation (wrong only at x = -128)caught (32,760 fails)
M2weight column offset kept in 16 bits (wraps at n > 65536)missedno (n <= 4096)
M3rows with index >= 301 off by onemissedyes (S3, m = 4096)
M4memoises the last two results keyed on (plan, x pointer, m, n, first 16 bytes of x)missedno, and would win S1-S3
M5vectorised validator: only the last (m*n) % 16 weights really validatedmissedno

Commands: /tmp/pgrev/mut.sh NAME FILE 'perl-subst' [asm] (applies the edit, builds into build-mut/NAME, runs both verifiers and optionally test-polyglot-asm, then git checkout the file). C mutants: /tmp/pgrev/mut_lane.c defines a strong omx_lane_mojo[]; built with `cc -std=gnu11 -O2 -march=armv8.6-a+dotprod+i8mm+sve -Isrc -o verify_mut tests/polyglot/verify_polyglot.c src/polyglot/omx_lang.c src/polyglot/omx_bench.c src/sha256.c mut_lane.c build/polyglot/o2/*.o -lm`. The mutant bodies are quoted in the findings below so they can be recreated without /tmp.

BLOCKING

G-B1. Timed samples on S1 are shorter than the 1 ms the spec requires

tests/polyglot/bench_polyglot.c:647-655 (calibration) and :670-686 (sampling). Spec section 7, gate 10.5.

Calibration times ONE call with two clock_gettime reads around it, so for S1 (about 35 ns per call) the timer overhead dominates: one came out as 64 ns for R1_sdot, giving reps = ceil(1.25e6 / 64) = 19,532 and a real sample of 19,532 x 36.3 ns = 0.71 ms. Nothing checks the sample length afterwards. Smoke run evidence (calls_per_sample * latency median from the receipts): 13 of 18 S1 cells are below 1 ms, from 0.709 ms (R1_sdot, R1_sdot@O3) to 0.991 ms (R1_smmla). S2-S4 are fine. Fix: calibrate with a doubling loop of sample() until one sample is >= 1 ms, and reject or re-take any sample with t < 1e6 (count it in the receipt).

G-B2. code_size_bytes is wrong for Mojo and the own encoder; encoder compile time measures the wrong thing

tests/polyglot/bench_polyglot.c:342-343, 403-406; src/polyglot/omx_mojo.c:48-80; src/polyglot/omx_encoder.c:671-679. Spec section 7 ("code size of the realization's text section").

The rule "run + pack function symbol sizes" resolves im->run to the C adapter, not the realization: MJ1_sdot/MJ2c_crumb report run_i8/run_crumb = 72 B (the Mojo kernels omx_mj_i8_run etc. are not counted); enc_sdot/enc_crumb report enc_*_run = 112 B (a thunk; the 156 / 200 emitted instructions = 624 / 800 B are not counted). asm_sdot correctly reports 624 B. A ledger built from these receipts would say Mojo's run code is 9x smaller than hand assembly. Encoder compile_time_s_min_of_5 (0.189 s) is the gcc compile of omx_encoder.c, not the time Omega's encoder takes to emit the kernel at run time. Fix: let each lane name its realization symbols (or byte count) in omx_candidate; for the encoder use omx_encoder_code(k, &bytes) and time omx_encoder_build.

SHOULD-FIX

G-S1. Shared verifier never guards the packed weights; non-C kernels are not ASan-instrumented

tests/polyglot/verify_polyglot.c:187-201. Mutant A. Guard pages surround the canonical W, but run kernels read p->mem (heap, from oma_rz_alloc, rounded to 64 B). ASan does not see assembly, JIT code or the Mojo object. Mutant A (16-byte over-read past the packed buffer) PASSES both verifier builds. B1 and B2's own tests move p->mem against a guard page and catch it; the Mojo lane test has no guard pages at all, so a Mojo packed-weight over-read is caught by nothing. Fix: in run_case, copy p.mem into a guarded buffer (flush against the trailing guard, and once flush against the leading one) for every candidate, as tests/polyglot/test_asm.c:172-190 does.

G-S2. Random cases never reach n > 65536 with random data, or m > 300

tests/polyglot/verify_polyglot.c:341-357. Mutants M2, M3. Random n <= 8200 and m <= 300; the only n > 65536 cases (:345, :347, :348) use all -1 or all +1 weights with x = -128, so a 16-bit column wrap reads a different column with the same value and passes (M2: a += W[i*n + (uint16_t)j] * x[j], 0 failures). M3 (y[i] += 1 for i >= 301) passes the verifier; only the bench's S3 check would catch it, without guard pages. Fix: add random-data cases at the four bench shapes (S3 is m = 4096, n = 4096) and at n in {65537, 131073, 1,000,003} with m in {1, 5}, plus a few with m in 1000-4100.

G-S3. Error contract tested only on a 2x3 matrix

tests/polyglot/verify_polyglot.c:232-260. Mutant M5. Six weights never reach a 16-byte vector body, so a validator that only checks the scalar tail passes (M5: loop for (i = (m*n) & ~15; i < m*n; i++)). MJ1_sdot's pack is exactly this shape (polyglot/mojo/omx_mojo.mojo:67-72); it is correct today and the Mojo lane test covers it (shapes up to 7x129), but the shared gate does not. Fix: bad weight at first, last and a random position for shapes like 4x65, 7x129, 3x1000.

G-S4. No test checks callee-saved registers

Mutant C (d8 and d15 zeroed in asm_sdot) passes verify plain, verify ASan and test-polyglot-asm. x19-x28 clobbers happen to crash the caller (mutant D), d8-d15 clobbers are silent. Current code is clean: the sentinel harness in the appendix ran all 18 candidates on 7 shapes (126 calls), 0 clobbers of x19-x28 / d8-d15; the same harness flags mutant C on all 7 shapes. Fix: add the trampoline to test_asm.c and test_encoder.c (or the shared verifier).

G-S5. The bench cannot detect a memoising candidate

tests/polyglot/bench_polyglot.c:67-69, 176-190. Mutant M4. S1-S3 use one x (nx = 1), so every call in a sample has identical inputs and the checksum is the same whether or not the kernel ran. M4 (returns a cached y when plan, x pointer, m, n and the first 16 bytes of x match) passes the verifier (the verifier never calls run twice in a row with the same x) and would report near-zero latency on S1-S3. My own lanes do not do this; the harness should still make it impossible. Fix: rotate at least 2 x vectors per workload (S4 already rotates 256), or flip one byte of x between calls and fold it into the expected checksum.

G-S6. Explainer selects from smoke, N < 20, and leftover receipts of other runs

tests/polyglot/polyglot_explain.c:225, 316-323, 378-389. gate_eligible and smoke only print a NOTE. Run on the smoke receipts it prints SELECT/CHOSEN lines from N = 3 data. Tamper test: copy the smoke receipts, add ghost_sdot__S1.json (asm_sdot with id renamed, run_id ...-OLDRUN, median 1.0): the explainer lists both runs and SELECTS ghost_sdot for S1 (median 1.0 with min 35.2 is not questioned). This becomes blocking if evidence/POLYGLOT/ ever holds more than one run. Fix: eligibility requires gate_eligible, tree_dirty_files == 0, one run_id (or one per workload, refused otherwise), and min <= median.

G-S7. Noise band too narrow to support "CHOSEN"

tests/polyglot/polyglot_explain.c:405. Band = 3 x max(MAD/median) from within-run samples. On S1 the smoke run gives asm_sdot MAD 0.0 and R1_sdot@O3 a 0.2% band, so a 3.2% gap is called CHOSEN. Within-run MAD does not include run-to-run, core-to-core or boot-state spread (see the X925 clock-cap episode). Fix: a floor (for example 2%) or a second full run on a different X925 core that must agree before CHOSEN is printed; report TIE otherwise.

G-S8. Own-encoder candidate breaks section 1's "effects: none" and run's error contract

src/polyglot/omx_encoder.c:620-676. The first run() call does mmap + mprotect (global state, a syscall) through pthread_once, and if that fails every later run() returns OMA_RZ_E_NOMEM, which section 1 lists only for pack. W^X and cache maintenance are right (RW, write, mprotect RX, then __builtin___clear_cache on the code range; DC CVAU on a read-only page is allowed), and test_encoder.c checks the mapping permissions. Fix: build the code in pack (or an explicit init step recorded in the plan), or add the exception to section 1.

G-S9. Compile time comparability

tests/polyglot/bench_polyglot.c:212-252, mk/polyglot.mk:141-153. Compile commands run as children of the pinned bench process, so they inherit one-core affinity: mojo build (multithreaded) is handicapped relative to gcc. C timings compile the whole MA-3 file (4 realizations per object, noted in the receipt). Record the affinity in compile_note, or unpin before timing compiles.

NOTE

Rules check (item 5)

Explainer checks passed

Appendix: callee-saved sentinel harness

cs_call(fn, p, x, y, out) sets x19-x28 and d8-d15 to known values, calls fn(p, x, y), and stores the registers to out[0..17]. The driver packs each candidate at shapes (1,1) (3,15) (4,16) (5,17) (7,100) (9,1025) (33,4099), calls through cs_call, and compares the registers and y against the oracle.

	.text
	.globl cs_call
	.type cs_call, %function
cs_call:                        // x0 fn, x1 p, x2 x, x3 y, x4 out
	stp x29, x30, [sp, #-176]!
	mov x29, sp
	stp x19, x20, [sp, #16]
	stp x21, x22, [sp, #32]
	stp x23, x24, [sp, #48]
	stp x25, x26, [sp, #64]
	stp x27, x28, [sp, #80]
	stp d8, d9, [sp, #96]
	stp d10, d11, [sp, #112]
	stp d12, d13, [sp, #128]
	stp d14, d15, [sp, #144]
	str x4, [sp, #160]
	mov x16, x0
	mov x0, x1
	mov x1, x2
	mov x2, x3
	movz x19, #0x1919
	movz x20, #0x2020
	movz x21, #0x2121
	movz x22, #0x2222
	movz x23, #0x2323
	movz x24, #0x2424
	movz x25, #0x2525
	movz x26, #0x2626
	movz x27, #0x2727
	movz x28, #0x2828
	fmov d8, x19
	fmov d9, x20
	fmov d10, x21
	fmov d11, x22
	fmov d12, x23
	fmov d13, x24
	fmov d14, x25
	fmov d15, x26
	blr x16
	ldr x4, [sp, #160]
	stp x19, x20, [x4]
	stp x21, x22, [x4, #16]
	stp x23, x24, [x4, #32]
	stp x25, x26, [x4, #48]
	stp x27, x28, [x4, #64]
	stp d8, d9, [x4, #80]
	stp d10, d11, [x4, #96]
	stp d12, d13, [x4, #112]
	stp d14, d15, [x4, #128]
	ldp x19, x20, [sp, #16]
	ldp x21, x22, [sp, #32]
	ldp x23, x24, [sp, #48]
	ldp x25, x26, [sp, #64]
	ldp x27, x28, [sp, #80]
	ldp d8, d9, [sp, #96]
	ldp d10, d11, [sp, #112]
	ldp d12, d13, [sp, #128]
	ldp d14, d15, [sp, #144]
	ldp x29, x30, [sp], #176
	ret
	.size cs_call, .-cs_call
	.section .note.GNU-stack,"",%progbits

Result on 17d2854: cs_check: 18 candidates, 126 calls, 0 problems (x19-x28, d8-d15). With mutant C linked in place of omx_sdot.S.o: 7 problems, all asm_sdot reg#10 (d8).

Fix verification

Fixes on feat/polyglot-0 after this review (commits dd1ba22, 0d46b87, f6f34ea, 8f8babe, 3ef4f69). No timed benchmark was run for this section (no make bench-polyglot, no smoke bench); the bench changes are checked by bench_polyglot --selftest, which does no timing and is now part of make test-polyglot.

findingfix
G-B1Calibration doubles the call count until one whole sample (same loop as the timed one) lasts >= 1.25 ms. A timed sample under 1 ms is re-taken with twice the calls (kept only after 20 retakes). Receipt cells record short_samples_retaken, short_samples_kept, shortest_sample_ns.
G-B2omx_candidate.code lets a lane name its code parts. Mojo: C adapter run + pack plus omx_mj_*_run / omx_mj_*_pack (symbol sizes). Encoder: C thunk + the bytes Omega's encoder emitted + C pack. Receipts carry code_parts; code_size_bytes is null if any part is unknown, never a partial sum. Encoder compile_time_s_min_of_5 is now min of 5 in-process emissions (omx_encoder_emit_ns), not gcc of omx_encoder.c. Self-test code sizes: MJ1_sdot 2036 B, MJ2c_crumb 1716 B, enc_sdot 1160 B, enc_crumb 1276 B (asm_sdot 1112 B).
G-S1The verifier copies each plan's packed weights into a read-only guarded mapping for two of the five runs per case: flush against the trailing guard page, then right after the leading one. Plans with an aux allocation (only MA-3's C R3_sparse) stay in place; ASan covers them.
G-S216 large random-data cases: the four bench shapes (up to 4096 x 4096), n in {65537, 131073, 1000003} with m in {1, 5}, and six cases with m in 1000..4100.
G-S3E_TRIT with one bad weight (2, -2, -128, 127, 3) at the first, last and a random position on 1x17, 5x16, 4x65, 7x129, 3x1000, 2x4099, 33x257, flush against a guard page.
G-S4tests/polyglot/cs_call.S (the appendix trampoline, distinct 64-bit sentinels) wraps the first run of every verifier case, all candidates, plain and ASan builds: x19-x28 and d8-d15 are compared after the call.
G-S5Verifier: runs 4 and 5 use one x pointer whose bytes at n-1 and n/2 change in place between them. Bench: before every timed call one byte of that call's x is flipped in place (x ^= 1) at a column with non-zero column sum; the checksum prediction follows every flip. The self-test proves the prediction for every candidate and that a memoising control candidate is caught.
G-S6Explainer: eligible also requires not smoke, the current run (--run, or the only non-smoke run; several runs and no --run select nothing), gate_eligible, tree_dirty_files == 0, 0 < min <= median, no kept sample under 1 ms. Tamper test repeated: the ghost receipt (run ...-OLDRUN, median 1.0) makes "current run: none" without --run, and is rejected as "not from the current run" with --run; a receipt with min > median is rejected; smoke receipts select nothing. Output still byte-identical over two runs.
G-S7Band = max(3 x max relative MAD, 5%). The 5% floor comes from the 360 paired medians of evidence/MIXED_ALGEBRA/ma3_bench_run1.json / _run2.json: run-to-run shift p50 0.27%, p95 3.6%, p99 10.4%; 22/360 exceed 3 x within-run noise; 5% is the smallest whole percent that leaves at most 2.5% (8/360) outside max(3 x noise, floor). The S1 asm_sdot vs R1_sdot@O3 gap (3.2%) is now TIE.
G-S8The encoder kernel is emitted by pack (once per process); pack returns E_NOMEM if the W^X mapping fails. run only reads the code pointer (no syscall, no global write); a plan that never went through pack gets E_ARG.
G-S9The bench restores its original CPU affinity before timing compile commands; compile_note records it.

Also found while running the mutant lane: omx_candidate_get subscripted the one-element weak lane tables, which UBSan flags for index >= 2 in the sanitizer build. Fixed (3ef4f69).

Mutants re-run against the fixed suite

Each mutant was applied to the working tree (or linked as a scratch lane), built into a scratch output directory, run, and removed; none is committed. A and C: perl edit of the .S file, make OUT_DIR=build-mut/<id> of both verifiers, git checkout of the file afterwards. M1-M5: the review's mut_lane.c (strong omx_lane_mojo[] with the five mutants) linked in place of the Mojo lane, plain and ASan+UBSan builds.

iddefectbefore (review)after: verify plainafter: verify ASan+UBSancaught by
Aasm_crumb ldr q5,[x5] at .Lcr_ok (16 B past the packed weights)missedFAIL, rc 139FAIL, rc 139packed-weight guard page: "guard-page fault (signal) in candidate asm_crumb"
Casm_sdot zeroes v8 and v15 at entrymissedFAIL, 45,190 failuresFAIL, 45,190 failurescallee-saved check: "callee-saved d8 not preserved" (and d15), every case
M1-1 * x as int8 negationcaughtFAIL, 54,597 failuresFAIL, 54,597 failuresoracle compare (unchanged)
M2column offset kept in 16 bitsmissedFAIL, 30 failuresFAIL, 30 failureslarge random cases, first at m=1 n=65537
M3rows >= 301 off by onemissedFAIL, 35 failuresFAIL, 35 failureslarge cases, first at m=4096 n=4096
M4memoises last two results by (plan, x pointer, m, n, first 16 B of x)missedFAIL, 17,337 failuresFAIL, 17,337 failuresin-place x change behind one pointer (run 5); the bench self-test's memoising control is caught by the checksum too
M5validator checks only the (m*n) % 16 tailmissedFAIL, 150 failuresFAIL, 150 failureserror contract on larger shapes, first "1x17 weight 2 at 0: rc 0, want E_TRIT"

Test results on the fixed tree (18 candidates):

Not done here: a new timed run. Existing receipts (none committed for POLYGLOT-0 yet) predate the new fields and would be refused by the explainer ("no sample-length record").