aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / docs / omegese45 / CONTRACT.md
| 1 | # Omegese #45 contract: R45, messages, binding, MJR1 |
| 2 | |
| 3 | Status: IMPLEMENTED and EXERCISED on the GB10 Spark Grace CPU host (cores 10-14, nice 19). Receipt: |
| 4 | [`evidence/OMEGESE45/contract/RECEIPT.md`](../../evidence/OMEGESE45/contract/RECEIPT.md) (fresh-clone run; commit named there). Source of truth for the shared |
| 5 | interface is the parent-owned interface v1.3 for [aien-train#45](https://github.com/aien-dev/aien-train/issues/45). This file restates it with |
| 6 | pins and adds what the code fixes. It changes no token, id, grammar rule or exit code. |
| 7 | |
| 8 | ## 1. Vocabulary pin |
| 9 | |
| 10 | - `docs/omegese45/vocab.tsv`: 41 rows, 2188 bytes, `id TAB word TAB class TAB provenance LF`, no header. |
| 11 | - **sha256 `c1d7e15466e6585a776314c5c05f35466b2697d9631ad2e11c7918a434a4c18d`.** Checkpoints and datasets pin this value (exit 52 CKPT_VOCAB on mismatch, pipeline lane). |
| 12 | - `native/omegese45/vocab.om` embeds the same bytes (`text ocvtsv`); driver mode `T` prints them and the suite compares with `cmp`. |
| 13 | |
| 14 | R45 is a **fixed lexical vocabulary, not a trained tokenizer**: no merges, no learned statistics, no byte fallback. A |
| 15 | word maps to exactly one id or is rejected. Storage: the table is 2188 bytes; an id needs |
| 16 | `Ceiling[Log2[41]]` = 6 bits (Wolfram: `N[Log2[41],6]` → 5.35755, `Ceiling[Log2[41]]` → 6), stored as one byte per id, so |
| 17 | the longest message (31 ids) is 31 bytes and MAXLEN is 176 bytes in id form. The DFA table is 256×41 = 10496 bytes |
| 18 | (Wolfram: `256*41` → 10496). |
| 19 | |
| 20 | ## 2. Restricted profile |
| 21 | |
| 22 | The only surface is single-space-separated lowercase ASCII words from R45 plus `0x` hex words (`0x` followed by 1..4 |
| 23 | digits per the grammar). No free prose, no comment channel, no `note`, no quotes, no numbers in decimal. Rejected bytes |
| 24 | and shapes (driver `V`, exit 40 `INVALID <byte pos> <reason>`): `empty`, `space` (leading, trailing, double), `tab`, `cr`, |
| 25 | `nonascii`, `upper`, `hexcase` (`0X`), `ctrl` (any other byte < 32, including an embedded LF), `unknown`, `long` (> 1024 |
| 26 | bytes or > 176 ids), `grammar`, `noend`, `trailing`, `kind`. In id form (driver `D`): `badid` (> 40), `digit` (digit id |
| 27 | not after `0x` or a digit). `<pad>` (id 0) round-trips through the codec but is illegal in every message. |
| 28 | |
| 29 | ## 3. Grammar (interface §3, unchanged) |
| 30 | |
| 31 | ``` |
| 32 | H := 0|1|…|9|a|…|f |
| 33 | D := ushort 0x H H H 5 ids |
| 34 | S := ulong 0x H H H H 6 ids |
| 35 | C := bound|replay|budget|worker|transport|receipt|recomp|verdict|io C' := C without bound |
| 36 | G := goal mm D D D S end (24) | goal pair D D D S S end (30) |
| 37 | A := act job mm D D D S end (25) | act refuse bound end (4) |
| 38 | R := res ok end (3) | res refused C' end (4) | res fail C' end (4) |
| 39 | P := rep ok mm D D D S end (25) | rep ok pair D D D S S end (31) | rep refused C end (4) | rep fail C end (4) |
| 40 | ``` |
| 41 | |
| 42 | `msg.om` builds this as a trie DFA (`ocdinit`): state 0 dead, state 1 accept (after `end`, every id dead). Start kinds: |
| 43 | 1 G, 2 A, 3 R, 4 P, and **5 "model message"** (`act` or `rep` first, then the A or P automaton). Kind 5 extends the |
| 44 | interface's 1..4 start domain as §3 "grammar-guided decoder" requires; it adds no rule. |
| 45 | |
| 46 | ## 4. Episode format `oe45 v1` and length facts |
| 47 | |
| 48 | First line `oe45 v1`, then one message per line in causal order, final LF. Sequence (interface v1.3 §3, refuse-position |
| 49 | pin): `G act-refuse P | G (act-job R?)+ P`. `act refuse` may occur only as the first and only A, directly after G, and is |
| 50 | followed directly by P (`rep refused bound end`): no R or further A after it, no `act refuse` after an R or an `act job`, |
| 51 | and a P directly after G (no A) is invalid. |
| 52 | |
| 53 | **No episode-level check lives in this lane.** `msg.om` validates single messages (DFA, driver `V`/`N`/`E`/`D`), one |
| 54 | G–A pair (binding, driver `B`) and one A (lowering, driver `L`); it has no notion of message order, so the v1.3 sequence |
| 55 | rule is enforced elsewhere: the core (`fix/45-core-refuse-prefix` `00d66c37`, `opprefix`), the eval shape oracle and |
| 56 | hive's `ohline`. The contract suite therefore adds no sequence test or mutant for it. |
| 57 | |
| 58 | Lengths (Wolfram: `d=5; s=6; {gmm=2+3d+s+1, gpair=2+3d+2s+1, ajob=3+3d+s+1, aref=4, pokmm=3+3d+s+1, pokpair=3+3d+2s+1, naive=gpair+4(ajob+4)+pokpair, maxok=gpair+2(ajob+4+ajob+3)+pokpair, maxfail=gpair+(ajob+4+ajob+3)+(ajob+4+ajob+4)+4}` |
| 59 | → `{24, 30, 25, 4, 25, 31, 177, 175, 149}`; check `30+2*(3+3*d+s+1+4+3+3*d+s+1+3)+31` → 175): |
| 60 | |
| 61 | - **Longest attained episode: 175 ids** — `pair`, each job `res fail transport end` then `res ok end`, then P ok pair. |
| 62 | - **MAXLEN = 176** (`ocmaxi`) is a bound with one id of headroom, not an attained length. Interface v1.1 gave 176 as the |
| 63 | longest episode by pairing a failed job 2 with a 31-id P; a failed job ends in a 4-id P (total 149). Interface v1.2 §3 |
| 64 | item 3 corrects the longest episode to 175 (contract issue 1, resolved). |
| 65 | - Longest single message 31 ids (P ok pair); decode budget 31 (pipeline exit 53). |
| 66 | |
| 67 | ## 5. Reference policy |
| 68 | |
| 69 | As interface §3 (bound refusal; per-job dispatch; one identical retry after the first `fail transport`; otherwise stop |
| 70 | and mirror R's class and code; P ok copies G's operands). The contract code does not implement the policy; it only |
| 71 | checks messages, binding and receipts. |
| 72 | |
| 73 | ## 6. Exit codes owned here |
| 74 | |
| 75 | | Code | Meaning | stdout | |
| 76 | |---|---|---| |
| 77 | | 0 | ok | mode output | |
| 78 | | 2 | usage (bad mode, malformed id list) | — | |
| 79 | | 40 MSG_INVALID | validator | `INVALID <pos> <reason>` (byte pos for text, id index for `D`) | |
| 80 | | 41 BIND_MISMATCH | binding | `BIND_MISMATCH notjob\|jobindex\|dims\|seed` | |
| 81 | | 42 BIND_BOUND | binding (a dim outside 0x001..0x100) | `BIND_BOUND` | |
| 82 | | 43 MJR1_INVALID | MJR1 parse | `MJR1_INVALID <pos> <reason>` | |
| 83 | |
| 84 | Binding order (`ocbcore`): not `act job` → 41 notjob; job index not 1 (`mm`) or 1..2 (`pair`) → 41 jobindex; dims ≠ G → |
| 85 | 41 dims; seed ≠ seed of job → 41 seed; else any dim outside 1..256 → 42; else 0. Mismatch is reported before bound. |
| 86 | Lowering (`oclower`, driver `L`): `LOWER m k n seed` in decimal; `act refuse` → 41 notjob. |
| 87 | Exit 43 covers **every static rule of `decode_receipt`** plus `io` (cannot open/read), a superset of the interface's |
| 88 | "wrong length or unknown outcome" (contract issue 3). |
| 89 | |
| 90 | ## 7. MJR1 field table (aien-protocols-mv `e705fdc9`) |
| 91 | |
| 92 | Pins: `crates/aien-microjob/src/lib.rs` L34 `RECEIPT_MAGIC`, L36 `VERSION`, L38 `RECEIPT_LEN` 404, L40 `RECEIPT_SIGNED_LEN` 340, |
| 93 | L103-109 `outcome` 1..5, L887-928 `decode_receipt`; `specs/microjob/SPEC.md` L162-190 (§5 table). |
| 94 | |
| 95 | Each row states the condition a valid receipt **must satisfy**; a receipt that violates it is refused with the reason |
| 96 | word and reported position in the last column (exit 43 `MJR1_INVALID <pos> <reason>`). Rules are checked top to bottom. |
| 97 | |
| 98 | | Bytes | Field | Required (valid receipt) | Violation → reason, reported pos | |
| 99 | |---|---|---|---| |
| 100 | | len | — | exactly 404 bytes | any other length → `length`, pos = actual length | |
| 101 | | 0..4 | magic | `MJR1` | otherwise → `magic` 0 | |
| 102 | | 4 | version | 1 | otherwise → `version` 4 | |
| 103 | | 7, 84..88, 337..340 | reserved0/1/2 | all zero | any nonzero byte → `reserved` 7 / 84 / 337 | |
| 104 | | 5 | outcome | 1..5 | 0 or 6..255 → `outcome` 5 | |
| 105 | | 6 | attempt | ≠ 0 | 0 → `attempt` 6 | |
| 106 | | 304 | signer_key prefix | 0x02 or 0x03 | otherwise → `signer` 304 | |
| 107 | | 176..208 | source_hash | not all zero | all zero → `zerohash` 176 | |
| 108 | | 240..272 | policy_hash | not all zero | all zero → `zerohash` 240 | |
| 109 | | 144..176 | output_digest | not all zero if COMPLETED (1); all zero otherwise | zero on COMPLETED, or nonzero on 2..5 → `output` 144 | |
| 110 | | 272..304 | verifier_verdict | not all zero if COMPLETED; any value otherwise | all zero on COMPLETED → `verdict` 272 | |
| 111 | | 8..40 | dag_digest | — | printed | |
| 112 | | 40..56 | job_id | — | printed | |
| 113 | | 72..76 | generation (u32 BE) | — | printed | |
| 114 | | 340..404 | signature | not checked (as `decode_receipt`; aienet0-run verifies) | — | |
| 115 | |
| 116 | Driver `J` prints `MJR1 <outcome word> <attempt> <generation> <dag hex> <job_id hex> <output hex>`. The real receipt |
| 117 | fixture `tests/omegese45/contract/fixtures/aadc3775…94cb.mjr1` (404 bytes, sha256 |
| 118 | `3306d180de1885a2759b324618d11eca523ef4d7aa22c4144813d71187014855`) is copied from aien-protocols-mv `e705fdc9` |
| 119 | `evidence/aienet0-20261028/exercised/artifacts/` (last changed in `b356717d`). |
| 120 | |
| 121 | ## 8. Vocabulary provenance against omega-mv `bf54b19f` |
| 122 | |
| 123 | Checked with omc bf54b19f (sha256 `62775d2a…712b`) by compiling each word as a fn name and as a local, and by reading |
| 124 | `fn kw` (`seed/omc/omc.om` L810; the interface says L808, which is the preceding `note` line — issue 2). |
| 125 | |
| 126 | | ids | Words | Finding | |
| 127 | |---|---|---| |
| 128 | | 0 | `<pad>` | reserved, not an Omega word | |
| 129 | | 1-4, 6-12, 14-21 | goal act res rep mm pair job refuse ok refused fail replay budget worker transport receipt recomp verdict io | profile words; none is an Omega keyword (each compiles as a name; `transport` is a 9-byte name → error 13, a length limit, not a keyword) | |
| 130 | | 5 | `end` | Omega keyword, `fn kw` omc.om:1099 (`6581861`) — holds | |
| 131 | | 13 | `bound` | profile code **and** Omega keyword, omc.om:1111 (`431349919586`) — flagged, id unchanged (issue 4) | |
| 132 | | 22 | `ushort` | Omega type keyword omc.om:973, OMEGESE.md:114 — holds | |
| 133 | | 23 | `ulong` | Omega type keyword omc.om:985, OMEGESE.md:114 — holds | |
| 134 | | 24-40 | `0x`, `0`..`f` | Omega hex literals, OMEGESE.md:691-693 — hold **only in profile OM-2** (OMEGESE.md:668 §9.13); an OM-1 unit gives error 6 (issue 5) | |
| 135 | |
| 136 | ## 9. Build and API |
| 137 | |
| 138 | ```sh |
| 139 | cat native/omegese45/vocab.om native/omegese45/msg.om [native/omegese45/mjr1.om] <your main.om> | omc > out.elf |
| 140 | ``` |
| 141 | |
| 142 | Order is fixed: `vocab.om` first (globals, codec), `msg.om` second (DFA, binding), `mjr1.om` optional. Names starting `oc` |
| 143 | are reserved for this lane. Call `ocvinit` and `ocdinit` once before use (the driver does). |
| 144 | |
| 145 | Globals: `ocin uchar 4096` text in; `ocids ulong 256` ids; `ocipos ulong 256` byte offset per id; `ocout uchar 4096` text |
| 146 | out; `ocerr ulong 2` = [pos, reason]; `ocnids`; `ocmk uchar 41` mask; `ocgv` G operands; `oclv ulong 4` = m k n seed; |
| 147 | `ocrb uchar 512`, `ocpath uchar 4096`, `ocmv ulong 3` = outcome attempt generation. |
| 148 | |
| 149 | | fn | returns | |
| 150 | |---|---| |
| 151 | | `ocenc n ulong to long` | id count, or −reason | |
| 152 | | `ocdec n ulong to long` | byte count, or −reason | |
| 153 | | `ocstart kind ulong to ulong`, `ocstep st ulong id ulong to ulong` | state (0 dead, 1 accept) | |
| 154 | | `oclegal st ulong id ulong to bool`, `ocfinal st ulong to bool` | | |
| 155 | | `ocmask st ulong to ulong` | legal count; fills `ocmk` | |
| 156 | | `ocvids n ulong kind ulong to long`, `ocvline n ulong kind ulong to long` | kind 1..4, or −reason (kind 0 infers) | |
| 157 | | `ocsetg n ulong to long`, `ocsetgl n ulong to long` | 0 or −reason | |
| 158 | | `ocbind n ulong job ulong to long`, `ocbindl n ulong job ulong to long` | 0, 41, 42, or −reason | |
| 159 | | `oclower n ulong to long`, `oclowerl n ulong to long` | 0 (`oclv`), 41, or −reason | |
| 160 | | `ocmjr n ulong to long`, `ocmjrf plen ulong to long` | outcome 1..5, or −reason | |
| 161 | |
| 162 | Reason codes: 1 empty, 2 space, 3 tab, 4 cr, 5 nonascii, 6 upper, 7 hexcase, 8 ctrl, 9 unknown, 10 long, 11 badid, |
| 163 | 12 digit, 13 grammar, 14 noend, 15 trailing, 16 kind, 17 notjob, 18 jobindex, 19 dims, 20 seed. MJR1: 1 length, |
| 164 | 2 magic, 3 version, 4 reserved, 5 outcome, 6 attempt, 7 signer, 8 zerohash, 9 output, 10 verdict, 11 io. |
| 165 | |
| 166 | Driver (`tests/omegese45/contract/main.om`), stdin `<mode> LF <payload>`: `V` line, `N` kind-letter LF ids, `B` G LF job |
| 167 | LF A, `L` A, `E` line, `D` ids, `T`, `J` path. |
| 168 | |
| 169 | ## 10. Suite |
| 170 | |
| 171 | `OMC=/tmp/om-main/seed/out/omc OUT=<dir> sh tests/omegese45/contract/run-contract.sh` → last line |
| 172 | `OE45_CONTRACT_PASS`. It checks the T table by `cmp`; every id round trip; binding and bound; lowering; the real receipt, |
| 173 | 19 refusals built from it by byte edits (including `zerohash` 240 and `verdict` 272) and 3 accepted edits (refused with |
| 174 | zero output and zero verdict; attempt 2 with generation `01 02 03 04` → 16909060, Wolfram `FromDigits[{1,2,3,4},256]`; |
| 175 | signer prefix 0x03); 140 generated valid messages (7 dims × 4 seeds × 5 forms; edges 0x000/0x001/0x100/0x101/0xfff, |
| 176 | seeds 0x0000/0xffff) plus 39 fixed ones, of all four kinds, each with its id count, E→D round trip and every prefix mask |
| 177 | (next id legal, FINAL only after `end`, empty mask after `end`); full N↔V agreement for all 41 ids at every prefix of 11 |
| 178 | messages; 32 rejections; dead-state and start masks. |
| 179 | |
| 180 | Negative control: 21 one-line mutants built by the script, each of which must fail first at the named check: |
| 181 | |
| 182 | | Tag | Unit | Mutation | Killed by | |
| 183 | |---|---|---|---| |
| 184 | | m1 | msg.om | DFA: R `refused` admits the C set (`bound`) | `rej-R-bound` | |
| 185 | | m2 | msg.om | DFA: shared digit transition omits `f` | `bind-bound-101` | |
| 186 | | b1 | msg.om | binding 41: seed always compared with job 1 | `bind-ok2` | |
| 187 | | b2 | msg.om | binding 42: upper admission bound 257 | `bind-bound-101` | |
| 188 | | b3 | msg.om | binding 42: lower admission bound 0 | `bind-bound-000` | |
| 189 | | b4 | msg.om | binding 41: k not compared with G | `bind-dims` | |
| 190 | | b5 | msg.om | binding 41: `act refuse` not reported `notjob` | `bind-notjob` | |
| 191 | | b6 | msg.om | binding 41: job 2 admitted for `mm` | `bind-mm-job2` | |
| 192 | | c1 | vocab.om | codec: hex digit `f` not encoded | `rt40-e` | |
| 193 | | c2 | vocab.om | codec: digit id decoded after a word | `rej-dec-digit` | |
| 194 | | c3 | vocab.om | codec: `0X` reported `upper`, not `hexcase` | `rej-0X` | |
| 195 | | c4 | vocab.om | codec: 177 ids admitted | `rej-overlong-ids` | |
| 196 | | c5 | vocab.om | codec: id 23 (`ulong`) not looked up | `rt23-e` | |
| 197 | | j1 | mjr1.om | MJR1: zero verdict admitted on COMPLETED | `mjr1-zero-verdict` | |
| 198 | | j2 | mjr1.om | MJR1: zero policy_hash admitted | `mjr1-zero-policy` | |
| 199 | | j3 | mjr1.om | MJR1: zero verdict refused when not COMPLETED | `mjr1-refused-zero-verdict` | |
| 200 | | j4 | mjr1.om | MJR1: attempt 0 admitted | `mjr1-attempt-6-0` | |
| 201 | | j5 | mjr1.om | MJR1: outcome 6 admitted | `mjr1-outcome-5-6` | |
| 202 | | j6 | mjr1.om | MJR1: signer prefix 0x03 refused | `mjr1-signer-03` | |
| 203 | | j7 | mjr1.om | MJR1: generation read little-endian | `mjr1-real` | |
| 204 | | j8 | mjr1.om | MJR1: attempt not reported | `mjr1-attempt2-gen` | |
| 205 | |
| 206 | ## 11. Contract issues |
| 207 | |
| 208 | 1. Interface v1.1 §3 item 3 example summed to 176 via an unreachable path; attained maximum is 175. Resolved in interface v1.2; MAXLEN 176 kept as a bound. |
| 209 | 2. Interface cites `fn kw` at omc.om:808; it is at L810. |
| 210 | 3. Exit 43 is a superset of the interface's wording (all `decode_receipt` static rules + `io`). |
| 211 | 4. `bound` (id 13) is also an Omega keyword; provenance column says only "code". |
| 212 | 5. `0x` and hex digits are Omega syntax only in OM-2 (OMEGESE.md:668); fine for the profile, which is not compiled as Omega. |
| 213 | 6. Kind 5 (model message) start and `L` on `act refuse` → 41 notjob are additions, not changes. |