aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / tools / zero-legacy / README.md
| 1 | # Zero-legacy closure checker (seeded `.om`) |
| 2 | |
| 3 | Owner: [aien-architecture-mv #316](https://github.com/aien-dev/aien-architecture-mv/issues/316) |
| 4 | under the inventory authority [#300](https://github.com/aien-dev/aien-architecture-mv/issues/300). |
| 5 | Status: **v0, transitional inventory mode qualified on the host; release mode implemented and |
| 6 | gate-tested on fixtures; not yet wired into any release decision.** |
| 7 | |
| 8 | Two native Omega programs, built only by the pinned seed compiler in `omega.pin` |
| 9 | (`seed/out/omc` of `aien-dev/omega-mv`, born from `seed/rung0/seed0.hex` by |
| 10 | `sh seed/omega-from-seed.sh`). No C, Rust, Python or foreign runtime is on their |
| 11 | implementation path. The bootstrap loader independently authenticates the compiler; |
| 12 | scanner and fixture judgments are made by native `.om` programs. |
| 13 | |
| 14 | | Program | Role | |
| 15 | | --- | --- | |
| 16 | | `closure.om` | walk one checked-out tree, classify every regular file, apply a manifest, print rows and a summary, refuse in release mode | |
| 17 | | `expect.om` | judge a report against an expected-row file (order free, row counts equal) | |
| 18 | | `elfclose.om` | classify ELF files (`elf PATH...`) or every running process (`proc [PROCROOT]`): toolchain marks, linkage, `DT_NEEDED`, executable mappings (#316 item 2, DRA-178) | |
| 19 | |
| 20 | ## Build and run |
| 21 | |
| 22 | ``` |
| 23 | sh seed/omega-from-seed.sh # in omega-mv at the pinned commit |
| 24 | seed/out/omc < tools/zero-legacy/closure.om > closure && chmod +x closure |
| 25 | ./closure ROOT [release] [MANIFEST] |
| 26 | ``` |
| 27 | |
| 28 | Exit: 0 inventory done (transitional) or release accepted; 1 release refused, outstanding |
| 29 | first-party rows remain; 2 release refused, unknown rows remain; 64 usage; 65 manifest |
| 30 | unreadable. Program-mode traps exit 100 + code (103: the 1 MiB directory stack overflowed). |
| 31 | |
| 32 | Output: one `CATEGORY<TAB>path` row per file, then `# CATEGORY count` lines, `# MODE 0|1`, |
| 33 | `# OUTSTANDING n`, `# UNKNOWN n`. |
| 34 | |
| 35 | ## Classification (content first, then name) |
| 36 | |
| 37 | | Category | Rule | Counts as | |
| 38 | | --- | --- | --- | |
| 39 | | `ELF` | head bytes `7f 45 4c 46` | unknown unless declared `generated`/`external` | |
| 40 | | `ARCHIVE` | gzip, zip, xz, or `ustar` at byte 257 | unknown unless declared `external` | |
| 41 | | `OM` | `.om` | native | |
| 42 | | `WRAPPER` | `.om` containing the word `execprog` (a launcher of something else) | outstanding until reviewed | |
| 43 | | `C_H` `RUST` `PYTHON` `OSC` | `.c` `.h` `.cc` `.cpp` `.hpp` `.cu` `.cuh`, `.rs`, `.py`, `.osc` | outstanding | |
| 44 | | `SHELL` | `.sh` `.bash` | outstanding | |
| 45 | | `FOREIGN` | shell whose head mentions `python`, `perl`, `node` or `ruby` | outstanding | |
| 46 | | `HEXASM` | `.hex` `.hex1` `.s` `.S` `.s2` `.asm` | outstanding; `.hex`/`.hex1` may be declared `data` | |
| 47 | | `MAKE` | `Makefile`, `.mk` | outstanding (build logic) | |
| 48 | | `HIDDEN` | any name not in a source row above (including `.om`) whose head starts with `#!`, or contains `#include` or `fn main(` | outstanding | |
| 49 | | `DOC` | `.md .txt .json .toml .yml .yaml .lock .csv .svg .html .css .png .jpg .gif .pdf .gate .xml .pub .sig .tex .ini .cfg .pem .crumb .log`, dotfiles with one dot, all-capitals names | neither | |
| 50 | | `OTHER` | everything else | unknown | |
| 51 | | `SYMLINK` | not followed | neither | |
| 52 | | `UNREADABLE` | directory or file that could not be opened or read, or an entry whose path would exceed 4095 bytes (the parent directory is printed) | unknown | |
| 53 | |
| 54 | Rules are tried in the table's order after the two magic checks; the first match wins. Only the first 4096 bytes of a file are inspected. `.git` entries are skipped at every depth. |
| 55 | |
| 56 | ## Manifest |
| 57 | |
| 58 | Lines `data P`, `generated P`, `external P`, `skip P`; `P` is a path prefix relative to ROOT. |
| 59 | Other lines, and lines with an empty prefix, are ignored. The first matching line wins; `skip` on a directory stops the walk below it and is counted once under `SKIP`. A manifest of 65,535 bytes or more is refused (exit 65). Unreadable files under `data`/`generated` stay `UNREADABLE`. |
| 60 | |
| 61 | | Kind | Effect | Refused as `FORGED` when the file is | |
| 62 | | --- | --- | --- | |
| 63 | | `data` | golden vectors, non-executable hex: row `DATA` | any source category, `.s/.S/.s2/.asm` assembly text, an ELF or an archive | |
| 64 | | `generated` | emitted machine code or artifacts: row `GENERATED` | any source category or an archive | |
| 65 | | `external` | third-party or vendor files: row `EXTERNAL`, always listed | never (a reviewer reads these rows) | |
| 66 | | `skip` | not scanned (build directories): counted under `SKIP` | n/a | |
| 67 | |
| 68 | `FORGED` rows are outstanding: a manifest cannot turn a `.c` file into data. A handwritten |
| 69 | `.hex` seed declared as `data` is accepted by this tool; distinguishing executable from |
| 70 | golden hex is the manifest owner's claim, reviewed by the issue owner (#725 for the seed |
| 71 | rungs), not something this tool can decide from bytes. |
| 72 | |
| 73 | ## Gate |
| 74 | |
| 75 | `tests/gates/arch-zero-legacy-closure.gate` runs `tests/gates/run.sh zero-legacy` with |
| 76 | `AIEN_OMC` pointing at an omc whose sha256 equals `omega.pin`; otherwise NOT_RUN (exit 3). |
| 77 | The hostile fixture `fixtures/tree` (hidden C in a `.txt`, a shebang file without a suffix, |
| 78 | shell executing Python, a `.om` launcher, forged `data` over a `.c` and a `.s`, an ELF, an |
| 79 | archive, a stale `.hex`, a Makefile, a skipped directory) must be refused with exit 1 and match |
| 80 | `fixtures/tree.expected` row for row; `fixtures/clean` must be accepted with its manifest and |
| 81 | refused (undeclared hex) without it. |
| 82 | |
| 83 | The native `fixtures/io-build.om` generates an instrumented copy of the actual scanner |
| 84 | with exact-count anchor checks, appending `fixtures/io-errors.om`. The gate builds and |
| 85 | runs both error cases: a real negative directory read, and a bad directory descriptor |
| 86 | after one successful enumeration batch. No production fault switch is added. These |
| 87 | are host filesystem tests, not GB10 compute tests. Native execution of these added |
| 88 | tests is NOT_RUN until the pinned compiler is available; old receipts do not qualify |
| 89 | this changed scanner or gate. |
| 90 | |
| 91 | ## Limits of v0 (honest scope) |
| 92 | |
| 93 | - Source tree only. It does not follow the build; the ELF and running-process side is |
| 94 | `elfclose.om` (next section). Linked-object membership inside one ELF (which archive members |
| 95 | or crates were linked) is still not observed. |
| 96 | - Head-only inspection (4096 bytes); a `#include`, shebang or `execprog` past that is missed, as is |
| 97 | C or Python text that carries none of the three markers. The content rules are a floor, not a parser. |
| 98 | - `expect.om` consumes each matched output line, so repeated rows must each occur (multiset match). |
| 99 | - A file name containing a newline splits its row; entry types come from `getdents64` `d_type`. |
| 100 | - Capacities: manifest 64 KiB, path 4095 bytes, 999,999 directories per run, 1 MiB directory |
| 101 | stack. |
| 102 | - This repository's own `tools/crumb/crumb.c`, its Makefile and `scripts/*.sh` are reported as |
| 103 | outstanding by this checker; they are migration rows of this repository, not exemptions. |
| 104 | |
| 105 | ## ELF and process closure (`elfclose.om`, #316 item 2, DRA-178) |
| 106 | |
| 107 | ``` |
| 108 | seed/out/omc < tools/zero-legacy/elfclose.om > elfclose && chmod +x elfclose |
| 109 | ./elfclose elf PATH... # one row per file |
| 110 | ./elfclose proc [PROCROOT] # every process under PROCROOT (default /proc) |
| 111 | ``` |
| 112 | |
| 113 | An `ELF` row is `ELF path class machine type link interp needed producer verdict` (tabs): |
| 114 | |
| 115 | | Field | Values | |
| 116 | | --- | --- | |
| 117 | | class | `ELF64LE`; `UNSUPPORTED` (32-bit or big-endian); `MALFORMED` (a header, program-header, `PT_LOAD`, dynamic or section field points outside the file or breaks a rule, or `PT_INTERP` or a `DT_NEEDED` name holds a control byte (below 0x20, or 0x7f), or a `DT_NEEDED` name holds a comma); `NOT_ELF`; `UNREADABLE` (cannot be opened, or not a regular file: a FIFO, directory, device or socket; files are opened without blocking) | |
| 118 | | link | `static` (no `PT_INTERP`, no `PT_DYNAMIC`), `dynamic` (`PT_INTERP`), `static-pie` (`PT_DYNAMIC` only) | |
| 119 | | needed | the `DT_NEEDED` sonames in order, comma separated, read through `DT_STRTAB` mapped by `PT_LOAD` | |
| 120 | | producer | toolchain marks joined by `+`, or `none`: `gcc`, `clang`, `rustc`, `lld` (`.comment`), `go` (`.go.buildinfo`, `.note.go.buildid`), `gnu` (`PT_GNU_*` headers, `.gnu.*`/`.note.gnu.*` sections), `crt` (`.note.ABI-tag`), `note` (`PT_NOTE`) | |
| 121 | | verdict | `FOREIGN` when any mark is present or the file links dynamically; `UNMARKED` when an `ELF64LE` file has neither; `UNKNOWN` for every other class | |
| 122 | |
| 123 | `UNMARKED` is what seeded omc output looks like (only `PT_LOAD` headers, no sections). It is a |
| 124 | property of the bytes, not proof that the file came from Omega source; binding an `UNMARKED` |
| 125 | binary to its `.om` source still needs a rebuild or a receipt. Stripped distribution binaries |
| 126 | lose `.comment` but keep their GNU notes and headers, so they still come out `FOREIGN`. |
| 127 | |
| 128 | Rows are tab-separated and newline-terminated, and the files they describe are not trusted. The |
| 129 | path of an `ELF` row, the exe link target of a `PROC` row and the path of a `MAP` row are written |
| 130 | with every control byte (below 0x20, or 0x7f) and every backslash as `\xHH` (lowercase hex), so a |
| 131 | file name can neither end a row nor add a field. Interpreter and soname bytes are never escaped: |
| 132 | a file whose interpreter or `DT_NEEDED` names hold such bytes is `MALFORMED` instead. |
| 133 | |
| 134 | A `PROC` row is `PROC pid owner exe ...` followed by the same fields, classified by reading |
| 135 | `PROCROOT/pid/exe`, the running image (also when the file on disk was replaced or deleted); |
| 136 | `owner` is `self` for the scanning uid, else the uid. `MAP pid path` rows list the files of the |
| 137 | process's executable mappings from `PROCROOT/pid/maps`, dropping a path equal to the one on the |
| 138 | `MAP` row just before it (consecutive duplicates; a path that comes back later is listed again). |
| 139 | A missing exe link (kernel threads, exited processes) is counted under `# NOEXE`; any other link |
| 140 | error gives an `UNREADABLE` row, which is what another user's processes give an unprivileged |
| 141 | scanner. Capacities: 64 program headers, 1024 sections, a 64 KiB section-name table, the first |
| 142 | 512 dynamic entries, sonames up to 255 bytes, the first 4 KiB of `.comment`, 960 KiB of maps per |
| 143 | process (`# MAPTRUNC`), and a `PROCROOT` of at most 4027 bytes (a longer one is refused with exit |
| 144 | 64, since PROCROOT, a pid and `/maps` must fit one 4096-byte path). |
| 145 | |
| 146 | Gate stage (in `gate.om`, observations `elfgen_exit`, `elf_scan_exit`, `proc_scan_exit`, |
| 147 | `expect_elf_exit`, `expect_proc_exit`, `cross_expect_refused`): `fixtures/elfgen.om` writes 22 |
| 148 | synthetic ELF images (each one property: GNU/clang/rustc/Go marks, a dynamic file without marks, |
| 149 | static and static-PIE, a `PT_GNU_STACK`-only image, a bare `PT_LOAD`-only image, six malformed, |
| 150 | two unsupported (32-bit, big-endian), one non-ELF file, and six hostile-string images: a soname |
| 151 | holding a newline and a tab that would forge a row, a soname with a comma, a tab and a DEL in |
| 152 | `PT_INTERP`, a `PT_LOAD` whose file offset wraps past 2^64 onto the real string table, and a clean |
| 153 | image whose file name holds a tab and a backslash); `elfclose` must print exactly |
| 154 | `fixtures/elf.expected` for them, for `build/closure` (real omc output, `UNMARKED`), for a missing |
| 155 | path and for the directory `build/elf` (`UNREADABLE`); `fixtures/proc` is a fake process tree |
| 156 | (exe links into the generated fixtures, a maps file with repeated, non-executable, anonymous, |
| 157 | `[vdso]`, space-containing and tab-and-backslash-containing paths, an exe link whose target holds |
| 158 | a tab and a backslash, a pid without an exe link and a non-numeric entry) that must give exactly |
| 159 | `fixtures/proc.expected`; and judging the process report against the ELF expectations must be |
| 160 | refused. That last judgment is meant to fail, so a passing gate prints one |
| 161 | `expect: missing line: ...` line on stderr; it is the refusal the gate requires |
| 162 | (`cross_expect_refused 1`), not a failure. `sh fixtures/elf-mutants.sh "$PWD" OMC DIR` applies 15 |
| 163 | one-line mutants to `elfclose.om` (no `DT_NEEDED`, dynamic not foreign, no class check, no map |
| 164 | dedupe, wrong perms byte, virtual address used as file offset, no `PT_GNU_*`, no `.comment` scan, |
| 165 | no output escaping, control bytes or a comma accepted in a soname, control bytes accepted in |
| 166 | `PT_INTERP`, DEL not a control byte, `PT_LOAD` range unchecked, non-regular files opened); the |
| 167 | gate must exit 1 for each. Observed 2026-11-07 on the Spark host with omc `734f0a39`: gate exit |
| 168 | 0 with all 13 observations as the manifest expects, and the 15 mutants all killed. On 523 host files |
| 169 | (`/usr/bin`, `/usr/lib`, cargo, three omc builds) this version prints the same row as the one |
| 170 | before the hostile-string rules (`9026b0e8`), and for the 435 of them that are `ELF64LE` the |
| 171 | `needed`, `interp` and `type` fields equal binutils `readelf` (independent oracle, not part of the |
| 172 | gate). A fuzz harness (outside the gate) over 1,500 mutants of the 16 base fixtures, `build/closure` |
| 173 | and three host binaries (`true`, `ls`, `libm.so.6`), |
| 174 | including control bytes, commas and backslashes written into sonames and interpreter paths, gave no |
| 175 | trap, no non-zero exit and one well-formed row per file; the previous version gave 56 malformed |
| 176 | rows on the same inputs. |
| 177 | |
| 178 | `portfolio.sh LIST OUT ZLBUILD` fetches each `NAME SHA` of LIST from aien-dev at exactly that |
| 179 | commit (depth 1), runs `closure` over it and `elfclose` over every file closure calls `ELF`, and |
| 180 | writes one summary row per repository; `procsnap.sh ZLBUILD` prints a publishable process snapshot |
| 181 | (counts by owner/class/verdict, then the scanning account's executables outside the OS and agent |
| 182 | tool directories, with the sha256 of each running image from `sha256.om`). Both drivers are shell |
| 183 | and are themselves outstanding `SHELL` rows; the classification is native `.om`. Dated results are |
| 184 | in `ledgers/portfolio-20261107/`. |
| 185 | |
| 186 | ## Candidate product-dependency ledgers (`ledgers/`) |
| 187 | |
| 188 | `ledgers/aien-serve-http-bin-19173f9e.tsv` records the 87 members reported by |
| 189 | `ar t` of the `libomega_gpu.a` shipped beside bin-19173f9e (SHA256SUMS reported |
| 190 | verified by the author), resolved to 85 omega-mv a0eafa39 source paths (36,232 C lines) |
| 191 | and two physics-mv 048e5f5e paths (`nvrm/nvrm.c`, `m16/m16_native.c`). |
| 192 | It also records 30 workspace crates reached by `cargo metadata` from |
| 193 | `aien-serve-http` in sovereign-core 9699d928 (128,931 Rust lines). |
| 194 | |
| 195 | Rows are `ARCHIVE_MEMBER object source` and `WORKSPACE_DEPENDENCY name`. |
| 196 | Archive membership does not prove an object was extracted into the final executable; |
| 197 | dependency reachability does not prove which code was linked or executed. |
| 198 | `src/compiler/*` is absent from this inventory, not thereby proven absent from every |
| 199 | build/runtime dependency. These are candidate migration rows for Core #753 and |
| 200 | CUDApp #79, not a qualified live-product closure denominator. |
| 201 | |
| 202 | Exact final-ELF/link-map membership, dynamic libraries/process descendants, build |
| 203 | configuration/source-to-artifact binding and current deployment identity remain |
| 204 | UNKNOWN pending receipts under #316. The recorded binary hash identifies the |
| 205 | reported artifact; it is not a fresh observation of the running server. |
| 206 | |
| 207 | ## Gate runner and hasher in `.om` (replaces the shell step) |
| 208 | |
| 209 | `gate.om` is the gate: it compiles `closure.om`, `expect.om` and `sha256.om` with the compiler it |
| 210 | is given, hashes that compiler with the native `sha256` and refuses (exit 3, NOT_RUN) unless the |
| 211 | digest equals `omc_sha256` in `omega.pin`, runs the hostile and clean fixtures, judges them with |
| 212 | `expect`, prints the `AIEN-OBS` lines and exits 0 only when every expectation holds. A compiler |
| 213 | with one semantic edit in `omc.om` (`fail 12`→`fail 13`, digest `ca2aa132…`) is refused by this |
| 214 | check. `gate.sh` is the thin bootstrap loader: it independently authenticates the compiler |
| 215 | pin before compiling `gate.om` and handing over. Fixture judgments remain native `.om`. |
| 216 | |
| 217 | `sha256.om` is FIPS 180-4 SHA-256 (file or stdin, hex on stdout, 16 MiB cap, exit 65/66). Checked |
| 218 | byte for byte against coreutils on the empty string, `abc`, the million-`a` vector, random inputs of |
| 219 | 55, 56, 64 and 3,000,000 bytes, and the omc binary; 38 MB/s on one Spark core. It is a |
| 220 | `.om` implementation corresponding to an archive member (`src/sha256.c`, |
| 221 | `ledgers/aien-serve-http-bin-19173f9e.tsv`); the in-process cutover of that C file waits on an |
| 222 | `.om` object/C-ABI boundary (OM_COMPLETION FR-7), which belongs to the compiler owners. |
| 223 | |
| 224 | The compiler under test compiles the native hasher, so that self-check is defense in depth, |
| 225 | not an independent root of trust. Before executing the candidate compiler, `gate.sh` |
| 226 | authenticates it against the reviewed `omega.pin` using trusted system `sed` and |
| 227 | `sha256sum`. This temporary external bootstrap boundary is disclosed; fixture judgments |
| 228 | remain native `.om`. The former shell runner also performed an independent pre-execution |
| 229 | check; replacing that check with self-authentication was not equivalent. This assumes |
| 230 | trusted OS/tools/pin and a compiler file not concurrently replaced. |
| 231 | |
| 232 | ### Bootstrap rejection regression (NOT_RUN) |
| 233 | |
| 234 | Run only in an isolated fixture checkout with an independently verified pinned |
| 235 | absolute-path `AIEN_OMC`. The direct invocation proves the sentinel works before checking rejection. |
| 236 | This fixture has not been compiled or executed for this change. |
| 237 | |
| 238 | ```sh |
| 239 | set -eu |
| 240 | cd tools/zero-legacy |
| 241 | mkdir -p build |
| 242 | "$AIEN_OMC" < fixtures/loader-sentinel.om > build/loader-sentinel |
| 243 | chmod +x build/loader-sentinel |
| 244 | rm -f build/untrusted-compiler-ran |
| 245 | if build/loader-sentinel; then rc=0; else rc=$?; fi |
| 246 | [ "$rc" -eq 98 ] && [ -f build/untrusted-compiler-ran ] || exit 1 |
| 247 | rm -f build/untrusted-compiler-ran |
| 248 | if AIEN_OMC="$PWD/build/loader-sentinel" sh ./gate.sh; then rc=0; else rc=$?; fi |
| 249 | [ "$rc" -eq 3 ] && [ ! -e build/untrusted-compiler-ran ] || exit 1 |
| 250 | ``` |