code wiki / _hdl_build / nx_gatebuilt_gate.nx

nx_gatebuilt_gate.nx source

↩ module page · 195 lines · 7588 B

1// nx_gatebuilt_gate.nx -- THE UNBUILT-GATE CENSUS. For every authored *_gate.nx, does a promoted *_gate.elf 2// actually exist? A gate that lives only in source makes its subject PERMANENTLY UNVERIFIABLE, and nothing 3// in the ecosystem reports it. 4// 5// WHY (found by accident 2026-07-30, id 1785472297): I tried to VERIFY the FD_CLOEXEC port-hostage fix before 6// eating three sev-9 rows that depend on it. `POST /api/gate_run target=nx_cloexec_gate` returned 7// **exit_code=127 verdict=NOT-FOUND bytes=0** -- a fully-written gate (T1 control proving the disease state is 8// reachable, T5 neg-control, T6 non-vacuity) that had NEVER BEEN COMPILED. Building it took one call and it 9// came back 6/6 GREEN. Until then, three sev-9 incidents rested on a fix nobody could prove. 10// A two-glob spot check then said the gap is systemic: ~2877 *_gate.nx sources vs ~187 *_gate.elf binaries. 11// 12// WHY NOTHING ELSE CATCHES IT -- an unbuilt gate is invisible in EVERY direction: 13// nx_gate_rollup reads LOGS -> no binary means no log means the gate is ABSENT from the roster, not RED. 14// nx_wirecensus S3 counts promoted-but-unregistered -- never authored-but-unbuilt. 15// every debt row citing 'gate-proven' reads as evidence regardless. 16// It is the exact INVERSE of PROVEN_UNWIRED (4952 capabilities BUILT+GATED+never called): there the gate 17// exists and the capability is unused; here the capability is used and the gate does not exist. 18// BOTH SCORE AS DONE. 19// 20// LAW: AN UNBUILT GATE IS INDISTINGUISHABLE FROM A PASSING ONE IN EVERY REPORT THAT MENTIONS IT. 21// 22// ENVELOPE, declared in the output and never silent: FLAT scan of the two named dirs (no recursion, so the 23// _attic/_retired/_stage_local shadow trees are deliberately EXCLUDED and this counts LIVE gates only); 24// existence is probed with openat, not a read, so it is cheap and cannot be fooled by an empty file being 25// unreadable; the shown list is capped and the cap is printed. 26// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 27import "nx_syscalls.nx" 28 29const GB_DIR1: *u8 = "buildroot/runtime" as *u8 30const GB_DIR2: *u8 = "buildroot/runtime/_hdl_build" as *u8 31const GB_DIRBUF: i64 = 262144 32const GB_NAMEBUF: i64 = 512 33const GB_MAXSHOW: i64 = 25 34const GB_RECLEN_OFF: i64 = 16 35const GB_NAME_OFF: i64 = 19 36 37func gb_puts(s: *u8) { 38 var n: i64 = 0 39 while s[n] != (0 as u8) { n = n + 1 } 40 sys_write(1, s, n) 41} 42 43func gb_puti(x: i64) { 44 var buf: *u8 = sys_mmap(64) as *u8 45 var v: i64 = x 46 var neg: i64 = 0 47 if v < 0 { 48 neg = 1 49 v = 0 - v 50 } 51 var i: i64 = 40 52 if v == 0 { 53 i = i - 1 54 buf[i] = 48 as u8 55 } 56 while v > 0 { 57 let d: i64 = v - (v / 10) * 10 58 i = i - 1 59 buf[i] = (d + 48) as u8 60 v = v / 10 61 } 62 if neg == 1 { 63 i = i - 1 64 buf[i] = 45 as u8 65 } 66 sys_write(1, ((buf as i64) + i) as *u8, 40 - i) 67} 68 69// does name end with "_gate.nx" ? 70func gb_is_gate_src(nm: *u8, n: i64) -> i64 { 71 if n < 8 { return 0 } 72 let t: *u8 = "_gate.nx" as *u8 73 var k: i64 = 0 74 while k < 8 { 75 if nm[n - 8 + k] != t[k] { return 0 } 76 k = k + 1 77 } 78 return 1 79} 80 81// cheap existence probe: openat for read. Never reads the file. 82func gb_exists(path: *u8) -> i64 { 83 let fd: i64 = sys_openat_rd(path) 84 if fd < 0 { return 0 } 85 sys_close(fd) 86 return 1 87} 88 89// scan ONE dir flat; ctr[0]=gate srcs seen, ctr[1]=built, ctr[2]=unbuilt, ctr[3]=shown 90func gb_scan(dir: *u8, ctr: *i64) -> i64 { 91 let fd: i64 = sys_openat_rd(dir) 92 if fd < 0 { return 0 - 1 } 93 let dbuf: *u8 = sys_mmap(GB_DIRBUF) 94 let probe: *u8 = sys_mmap(GB_NAMEBUF) 95 var rounds: i64 = 0 96 var n: i64 = sys_getdents64(fd, dbuf, GB_DIRBUF) 97 while n > 0 { 98 rounds = rounds + 1 99 var p: i64 = 0 100 while p < n { 101 let reclen: i64 = (dbuf[p + GB_RECLEN_OFF] as i64) + ((dbuf[p + GB_RECLEN_OFF + 1] as i64) * 256) 102 if reclen <= 0 { p = n } 103 else { 104 let nm: *u8 = ((dbuf as i64) + p + GB_NAME_OFF) as *u8 105 var ln: i64 = 0 106 while nm[ln] != (0 as u8) { ln = ln + 1 } 107 if gb_is_gate_src(nm, ln) == 1 { 108 ctr[0] = ctr[0] + 1 109 // probe = <basename minus ".nx"> + ".elf" (promoted organs live at cwd = nishihost root) 110 var w: i64 = 0 111 while w < ln - 3 { 112 probe[w] = nm[w] 113 w = w + 1 114 } 115 probe[w] = 46 as u8 116 probe[w + 1] = 101 as u8 117 probe[w + 2] = 108 as u8 118 probe[w + 3] = 102 as u8 119 probe[w + 4] = 0 as u8 120 if gb_exists(probe) == 1 { ctr[1] = ctr[1] + 1 } 121 else { 122 ctr[2] = ctr[2] + 1 123 if ctr[3] < GB_MAXSHOW { 124 gb_puts(" UNBUILT " as *u8) 125 gb_puts(nm) 126 gb_puts("\n" as *u8) 127 ctr[3] = ctr[3] + 1 128 } 129 } 130 } 131 p = p + reclen 132 } 133 } 134 n = sys_getdents64(fd, dbuf, GB_DIRBUF) 135 } 136 sys_close(fd) 137 return rounds 138} 139 140func main(argc: i64, argv: *i64) -> i64 { 141 var ctr: *i64 = sys_mmap(64) as *i64 142 ctr[0] = 0 143 ctr[1] = 0 144 ctr[2] = 0 145 ctr[3] = 0 146 147 gb_puts("=== nx_gatebuilt_gate -- does every AUTHORED gate have a COMPILED binary? ===\n" as *u8) 148 gb_puts(" (an unbuilt gate is indistinguishable from a passing one in every report that mentions it)\n" as *u8) 149 150 let r1: i64 = gb_scan(GB_DIR1, ctr) 151 let r2: i64 = gb_scan(GB_DIR2, ctr) 152 153 if r1 < 0 { 154 gb_puts("VERDICT=RED cannot open " as *u8) 155 gb_puts(GB_DIR1) 156 gb_puts(" -- a census that cannot read its corpus must refuse, never report zero.\n" as *u8) 157 return 1 158 } 159 if r2 < 0 { 160 gb_puts("VERDICT=RED cannot open " as *u8) 161 gb_puts(GB_DIR2) 162 gb_puts(" -- a census that cannot read its corpus must refuse, never report zero.\n" as *u8) 163 return 1 164 } 165 166 if ctr[2] > GB_MAXSHOW { 167 gb_puts(" ... " as *u8) 168 gb_puti(ctr[2] - GB_MAXSHOW) 169 gb_puts(" more UNBUILT not shown (list capped at " as *u8) 170 gb_puti(GB_MAXSHOW) 171 gb_puts(", the cap is declared not silent)\n" as *u8) 172 } 173 174 gb_puts("\nNX-GATEBUILT gate_sources=" as *u8); gb_puti(ctr[0]) 175 gb_puts(" built=" as *u8); gb_puti(ctr[1]) 176 gb_puts(" UNBUILT=" as *u8); gb_puti(ctr[2]) 177 var permil: i64 = 0 178 if ctr[0] > 0 { permil = ctr[1] * 1000 / ctr[0] } 179 gb_puts(" built_permil=" as *u8); gb_puti(permil) 180 gb_puts("\n" as *u8) 181 gb_puts("envelope: FLAT scan of buildroot/runtime + _hdl_build (no recursion -- _attic/_retired/_stage_local\n" as *u8) 182 gb_puts(" shadow trees deliberately EXCLUDED so this counts LIVE gates); existence probed with openat, not\n" as *u8) 183 gb_puts(" a read; promoted organs resolve at cwd. A gate built but promoted under another name reads UNBUILT.\n" as *u8) 184 185 if ctr[0] == 0 { 186 gb_puts("VERDICT=RED found ZERO gate sources -- a census that finds nothing has failed, not passed.\n" as *u8) 187 return 1 188 } 189 if ctr[2] == 0 { 190 gb_puts("VERDICT=GREEN every authored gate has a compiled binary.\n" as *u8) 191 return 0 192 } 193 gb_puts("VERDICT=RED authored gates with NO binary exist -- every claim resting on one is UNPROVEN.\n" as *u8) 194 return 1 195}