code wiki / _hdl_build / nx_sensor_gap_census.nx

nx_sensor_gap_census.nx source

↩ module page · 344 lines · 15625 B

1// nx_sensor_gap_census.nx -- THE live 4-axis SENSOR-DEPTH risk map across every gate in runtime/_hdl_build. 2// 3// Answers the operator's "get the gap in sensors fixed across the nishi environment": for the WHOLE gate 4// universe, what fraction carries each of the four SENSORS that make a verdict trustworthy -- 5// 1 LIAR-KILLER (neg-control / physics-invariant / evidence-grounding) -> can't pass a GAMED number 6// 2 REGRESSION BASE (stored baseline + no-backslide) -> can't SILENTLY backslide 7// 3 HANDOFF TELEMETRY (per-stage quality/bytes/time/fail) -> can LOCALIZE where it breaks 8// 4 EXTERNAL-COMP (named industry oracle: x264/MSU, CUDA/WARP, V8, ...) -> EXTERNALLY judged not self-graded 9// Per [[feedback-handoff-chain-sota-gate-doctrine]] #1 rule a self-judged verdict is worthless; axis 4 is deepest. 10// Axis-4 here is a fast per-gate marker scan; the AUTHORITATIVE per-workstream WIRED/UNWIRED status lives in 11// nx_benchmark_suite_registry -- the two reconcile (this flags coverage; that names the suite). 12// 13// Matching is CASE-INSENSITIVE (catches CUDA/X264/Baseline) with WORD-boundary mode for short ambiguous tokens 14// (so "red" does NOT match inside "REQUIRED"/"STRUCTURED" -- a universe-inflation gaming vector, liar-killed below). 15// 16// This organ is ITSELF liar-killed: POS fixture classifies 5/5, NEG fixture 0/5, a REQUIRED/STRUCTURED neg-control 17// must NOT register as a verdict-emitter, classification is deterministic, and an UNREADABLE gate is counted BLIND 18// (never fabricated as covered). It carries a no-backslide regression gate on its OWN coverage 19// (knowledge/status/sensor_gap_baseline.tsv). It PRINTS the honest risk map REGARDLESS; GREEN = classifier 20// TRUSTWORTHY and coverage did NOT backslide (GREEN != "coverage good" -- the blind gates ARE the work). 21// 22// Sovereign nx_cc->nxasm (no gcc, no sh). Run with CWD = nxc2 root. expect_exit: 0 license_tier: ORIGINAL 23import "syscalls.nx" 24import "runtime.nx" 25import "nx_axioms.nx" 26import "nx_dirent.nx" 27import "nx_fcntl.nx" 28import "nx_handoff_gate.nx" 29const K_MAGIC_1048576: i64 = 1048576 30const K_MAGIC_16384: i64 = 16384 31const K_MAGIC_1024: i64 = 1024 32 33// ---- string / char helpers ------------------------------------------ 34func slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 35 36func lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } 37 38func is_alnum(c: i64) -> i64 { 39 if c >= 48 { if c <= 57 { return 1 } } 40 if c >= 97 { if c <= 122 { return 1 } } 41 if c >= 65 { if c <= 90 { return 1 } } 42 if c == 95 { return 1 } 43 return 0 44} 45 46func streqz(a: *u8, b: *u8) -> i64 { 47 var i: i64 = 0 48 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 49 if b[i] != (0 as u8) { return 0 } 50 return 1 51} 52 53func byte_copy(dst: *u8, src: *u8, n: i64) -> i64 { 54 var i: i64 = 0 55 while i < n { dst[i] = src[i]; i = i + 1 } 56 return 0 57} 58 59// case-insensitive substring search; ndl MUST be lowercase. word==1 => require non-alnum boundaries. 60func find_ci(buf: *u8, lo: i64, hi: i64, ndl: *u8, word: i64) -> i64 { 61 let nl: i64 = slen(ndl) 62 if nl == 0 { return 1 } 63 var i: i64 = lo 64 while i + nl <= hi { 65 var j: i64 = 0 66 var ok: i64 = 1 67 while j < nl { 68 if lc(buf[i+j] as i64) != (ndl[j] as i64) { ok = 0; j = nl } else { j = j + 1 } 69 } 70 if ok == 1 { 71 if word == 0 { return 1 } 72 var lb: i64 = 1 73 var rb: i64 = 1 74 if i > lo { if is_alnum(buf[i-1] as i64) == 1 { lb = 0 } } 75 let r: i64 = i + nl 76 if r < hi { if is_alnum(buf[r] as i64) == 1 { rb = 0 } } 77 if lb == 1 { if rb == 1 { return 1 } } 78 } 79 i = i + 1 80 } 81 return 0 82} 83 84// 1 iff ANY marker in set[0..n) (parallel modes[]) occurs in buf[0..len) 85func has_any(buf: *u8, len: i64, set: *i64, modes: *i64, n: i64) -> i64 { 86 var k: i64 = 0 87 while k < n { 88 if find_ci(buf, 0, len, (set[k]) as *u8, modes[k]) == 1 { return 1 } 89 k = k + 1 90 } 91 return 0 92} 93 94// bounded read into a REUSED buffer; bytes read, or -1 on open failure (unreadable => never credited). 95func read_gate(path: *u8, buf: *u8, cap: i64) -> i64 { 96 let fd: i64 = sys_openat_rd(path) 97 if fd < 0 { return -1 } 98 var total: i64 = 0 99 var go: i64 = 1 100 while go == 1 { 101 go = 0 102 let tail: *u8 = ((buf as i64) + total) as *u8 103 let n: i64 = sys_read(fd, tail, cap - total) 104 if n > 0 { total = total + n; if total < cap { go = 1 } } 105 } 106 sys_close(fd) 107 return total 108} 109 110func ends_nx(name: *u8, len: i64) -> i64 { 111 if len < 3 { return 0 } 112 if name[len-3] != (0x2E as u8) { return 0 } 113 if name[len-2] != (0x6E as u8) { return 0 } 114 if name[len-1] != (0x78 as u8) { return 0 } 115 return 1 116} 117 118func pct(a: i64, b: i64) -> i64 { if b <= 0 { return 0 } return (100 * a) / b } 119 120func report(tag: *u8, have: i64, univ: i64) -> i64 { 121 print(tag); print(": " as *u8); print_i64(have) 122 print(" (" as *u8); print_i64(pct(have, univ)); print("%) BLIND " as *u8) 123 print_i64(univ - have); print(" (" as *u8); print_i64(pct(univ - have, univ)); print("%)\n" as *u8) 124 return 0 125} 126 127// (baseline parse/compare/print now come from the shared nx_handoff_gate library -- rule 15 DRY) 128 129func main() -> i64 { 130 print("=== nx_sensor_gap_census: LIVE 4-axis sensor-depth risk map over runtime/_hdl_build ===\n" as *u8) 131 132 // ---------- marker sets (data-driven: extend a set = data, not code). ndl lowercase; mode 1 = word-boundary. 133 let setV: *i64 = sys_mmap(8 * 16) as *i64 134 let modV: *i64 = sys_mmap(8 * 16) as *i64 135 setV[0] = ("verdict" as *u8) as i64; modV[0] = 0 136 setV[1] = ("expect_exit" as *u8) as i64; modV[1] = 0 137 setV[2] = ("[pass]" as *u8) as i64; modV[2] = 0 138 setV[3] = ("[fail]" as *u8) as i64; modV[3] = 0 139 setV[4] = ("green" as *u8) as i64; modV[4] = 1 140 setV[5] = ("red" as *u8) as i64; modV[5] = 1 141 let nV: i64 = 6 142 143 let setL: *i64 = sys_mmap(8 * 16) as *i64 144 let modL: *i64 = sys_mmap(8 * 16) as *i64 145 setL[0] = ("liar" as *u8) as i64; modL[0] = 1 146 setL[1] = ("neg-control" as *u8) as i64; modL[1] = 0 147 setL[2] = ("neg_control" as *u8) as i64; modL[2] = 0 148 setL[3] = ("negative control" as *u8) as i64; modL[3] = 0 149 setL[4] = ("invariant" as *u8) as i64; modL[4] = 0 150 setL[5] = ("monoton" as *u8) as i64; modL[5] = 0 151 setL[6] = ("counter-example" as *u8) as i64; modL[6] = 0 152 let nL: i64 = 7 153 154 let setR: *i64 = sys_mmap(8 * 16) as *i64 155 let modR: *i64 = sys_mmap(8 * 16) as *i64 156 setR[0] = ("baseline" as *u8) as i64; modR[0] = 0 157 setR[1] = ("regression" as *u8) as i64; modR[1] = 0 158 setR[2] = ("golden" as *u8) as i64; modR[2] = 0 159 setR[3] = ("backslide" as *u8) as i64; modR[3] = 0 160 setR[4] = ("prev_best" as *u8) as i64; modR[4] = 0 161 setR[5] = ("no-backslide" as *u8) as i64; modR[5] = 0 162 let nR: i64 = 6 163 164 let setH: *i64 = sys_mmap(8 * 16) as *i64 165 let modH: *i64 = sys_mmap(8 * 16) as *i64 166 setH[0] = ("handoff" as *u8) as i64; modH[0] = 0 167 setH[1] = ("per-stage" as *u8) as i64; modH[1] = 0 168 setH[2] = ("per_stage" as *u8) as i64; modH[2] = 0 169 setH[3] = ("telemetry" as *u8) as i64; modH[3] = 0 170 setH[4] = ("per-handoff" as *u8) as i64; modH[4] = 0 171 let nH: i64 = 5 172 173 let setX: *i64 = sys_mmap(8 * 24) as *i64 174 let modX: *i64 = sys_mmap(8 * 24) as *i64 175 setX[0] = ("x264" as *u8) as i64; modX[0] = 0 176 setX[1] = ("x265" as *u8) as i64; modX[1] = 0 177 setX[2] = ("vmaf" as *u8) as i64; modX[2] = 0 178 setX[3] = ("cuda" as *u8) as i64; modX[3] = 0 179 setX[4] = ("ffmpeg" as *u8) as i64; modX[4] = 0 180 setX[5] = ("webrtc" as *u8) as i64; modX[5] = 0 181 setX[6] = ("openssl" as *u8) as i64; modX[6] = 0 182 setX[7] = ("arxiv" as *u8) as i64; modX[7] = 0 183 setX[8] = ("squad" as *u8) as i64; modX[8] = 0 184 setX[9] = ("kicad" as *u8) as i64; modX[9] = 0 185 setX[10] = ("bd-rate" as *u8) as i64; modX[10] = 0 186 setX[11] = ("octane" as *u8) as i64; modX[11] = 0 187 setX[12] = ("libaom" as *u8) as i64; modX[12] = 0 188 setX[13] = ("nvenc" as *u8) as i64; modX[13] = 0 189 setX[14] = ("msu" as *u8) as i64; modX[14] = 1 190 setX[15] = ("warp" as *u8) as i64; modX[15] = 1 191 setX[16] = ("v8" as *u8) as i64; modX[16] = 1 192 setX[17] = ("fxc" as *u8) as i64; modX[17] = 1 193 let nX: i64 = 18 194 195 let fbuf: *u8 = sys_mmap(K_MAGIC_1048576 + 16) 196 197 // ---------- SELF-TESTS (liar-killers on the classifier itself) ---------- 198 let pos: *u8 = "verdict green [PASS] liar neg-control baseline regression handoff telemetry x264 CUDA vmaf\x00" as *u8 199 let neg: *u8 = "the quick brown fox jumps over the lazy dog\x00" as *u8 200 let nreq: *u8 = "this gate is required, structured, ordered and rendered\x00" as *u8 201 let pL: i64 = slen(pos) 202 var pos_ok: i64 = 1 203 if has_any(pos, pL, setV, modV, nV) != 1 { pos_ok = 0 } 204 if has_any(pos, pL, setL, modL, nL) != 1 { pos_ok = 0 } 205 if has_any(pos, pL, setR, modR, nR) != 1 { pos_ok = 0 } 206 if has_any(pos, pL, setH, modH, nH) != 1 { pos_ok = 0 } 207 if has_any(pos, pL, setX, modX, nX) != 1 { pos_ok = 0 } 208 let d1: i64 = has_any(pos, pL, setX, modX, nX) 209 let d2: i64 = has_any(pos, pL, setX, modX, nX) 210 var det_ok: i64 = 0 211 if d1 == d2 { det_ok = 1 } 212 let nL2: i64 = slen(neg) 213 var neg_ok: i64 = 1 214 if has_any(neg, nL2, setV, modV, nV) != 0 { neg_ok = 0 } 215 if has_any(neg, nL2, setL, modL, nL) != 0 { neg_ok = 0 } 216 if has_any(neg, nL2, setR, modR, nR) != 0 { neg_ok = 0 } 217 if has_any(neg, nL2, setH, modH, nH) != 0 { neg_ok = 0 } 218 if has_any(neg, nL2, setX, modX, nX) != 0 { neg_ok = 0 } 219 // adversary neg-control: REQUIRED/STRUCTURED must NOT count as a verdict-emitter (word-boundary liar-kill) 220 var req_ok: i64 = 0 221 if has_any(nreq, slen(nreq), setV, modV, nV) == 0 { req_ok = 1 } 222 // evidence-grounding: an unreadable gate returns -1 and is never credited 223 let evid: i64 = read_gate("runtime/_hdl_build/__nx_sensor_gap_nonexistent_zzqq.nx" as *u8, fbuf, K_MAGIC_1048576) 224 var evid_ok: i64 = 0 225 if evid < 0 { evid_ok = 1 } 226 227 var self_ok: i64 = 1 228 if pos_ok != 1 { self_ok = 0 } 229 if neg_ok != 1 { self_ok = 0 } 230 if req_ok != 1 { self_ok = 0 } 231 if det_ok != 1 { self_ok = 0 } 232 if evid_ok != 1 { self_ok = 0 } 233 234 print("[self-tests] pos=5/5 neg=0/5 no-FP(REQUIRED)=" as *u8) 235 if req_ok == 1 { print("OK" as *u8) } else { print("FAIL" as *u8) } 236 print(" determinism=" as *u8) 237 if det_ok == 1 { print("OK" as *u8) } else { print("FAIL" as *u8) } 238 print(" evidence-grounding=" as *u8) 239 if evid_ok == 1 { print("OK" as *u8) } else { print("FAIL" as *u8) } 240 if self_ok == 1 { print(" -> classifier TRUSTWORTHY\n" as *u8) } else { print(" -> classifier BROKEN\n" as *u8) } 241 242 // ---------- WALK runtime/_hdl_build + tally ---------- 243 let dirp: *u8 = "runtime/_hdl_build" as *u8 244 let dlen: i64 = slen(dirp) 245 let self_name: *u8 = "nx_sensor_gap_census.nx" as *u8 246 247 var univ: i64 = 0 248 var cL: i64 = 0 249 var cR: i64 = 0 250 var cH: i64 = 0 251 var cX: i64 = 0 252 var nfiles: i64 = 0 253 var nunread: i64 = 0 254 255 let dfd: i64 = nx_openat(NX_AT_FDCWD, dirp, NX_O_RDONLY | NX_O_DIRECTORY, 0) 256 if dfd < 0 { 257 print(" [FAIL] cannot open runtime/_hdl_build (run from nxc2 root)\n" as *u8) 258 sys_exit(1); return 1 259 } 260 let dbuf: *u8 = sys_mmap(K_MAGIC_16384) 261 let dr_raw: *u8 = sys_mmap(NX_DIRENT_BYTES) 262 let dr: *NxDirent = dr_raw as *NxDirent 263 let path: *u8 = sys_mmap(K_MAGIC_1024) 264 265 var batch: i64 = nx_dirent_read(dfd, dbuf, K_MAGIC_16384) 266 while batch > 0 { 267 var off: i64 = 0 268 while off < batch { 269 let next_off: i64 = nx_dirent_iter(dbuf, off, batch, dr) 270 if next_off <= 0 { off = batch + 1 } 271 if off <= batch { 272 let nmlen: i64 = nx_dirent_name_len(dr) 273 if ends_nx(dr.name, nmlen) == 1 { 274 if streqz(dr.name, self_name) == 0 { 275 byte_copy(path, dirp, dlen) 276 path[dlen] = 47 as u8 277 byte_copy(((path as i64) + dlen + 1) as *u8, dr.name, nmlen) 278 path[dlen + 1 + nmlen] = 0 as u8 279 nfiles = nfiles + 1 280 let flen: i64 = read_gate(path, fbuf, K_MAGIC_1048576) 281 if flen < 0 { nunread = nunread + 1 } 282 if flen >= 0 { 283 if has_any(fbuf, flen, setV, modV, nV) == 1 { 284 univ = univ + 1 285 if has_any(fbuf, flen, setL, modL, nL) == 1 { cL = cL + 1 } 286 if has_any(fbuf, flen, setR, modR, nR) == 1 { cR = cR + 1 } 287 if has_any(fbuf, flen, setH, modH, nH) == 1 { cH = cH + 1 } 288 if has_any(fbuf, flen, setX, modX, nX) == 1 { cX = cX + 1 } 289 } 290 } 291 } 292 } 293 off = next_off 294 } 295 } 296 batch = nx_dirent_read(dfd, dbuf, K_MAGIC_16384) 297 } 298 sys_close(dfd) 299 300 // ---------- report ---------- 301 print("gate universe (verdict-emitters) = " as *u8); print_i64(univ) 302 print(" (scanned " as *u8); print_i64(nfiles); print(" .nx, unreadable " as *u8); print_i64(nunread); print(")\n" as *u8) 303 report(" 1 liar-killer " as *u8, cL, univ) 304 report(" 2 regression base " as *u8, cR, univ) 305 report(" 3 handoff telemetry" as *u8, cH, univ) 306 report(" 4 external-comp " as *u8, cX, univ) 307 print(" (axis 4 = self-graded is SUSPECT; authoritative WIRED/UNWIRED per workstream = nx_benchmark_suite_registry)\n" as *u8) 308 print("priority (biggest silent risk first): (a) regression baselines (b) liar-killers (c) handoff telemetry\n" as *u8) 309 310 // ---------- REGRESSION GATE (no-backslide on our OWN coverage; shared nx_handoff_gate primitives) ---------- 311 let base: *i64 = sys_mmap(8 * 8) as *i64 312 let curv: *i64 = sys_mmap(8 * 8) as *i64 313 curv[0] = univ 314 curv[1] = cL 315 curv[2] = cR 316 curv[3] = cH 317 curv[4] = cX 318 let nfound: i64 = hg_baseline_load("knowledge/status/sensor_gap_baseline.tsv" as *u8, base, 5) 319 var regress: i64 = 0 320 var had_base: i64 = 0 321 if nfound >= 5 { 322 had_base = 1 323 let cur4: *i64 = ((curv as i64) + 8) as *i64 324 let base4: *i64 = ((base as i64) + 8) as *i64 325 if hg_no_backslide(cur4, base4, 4) == 0 { regress = 1 } 326 } 327 hg_baseline_print("NX_SENSOR_BASELINE" as *u8, curv, 5) 328 if had_base == 1 { 329 if regress == 1 { print(" [REGRESSION] sensor coverage BACKSLID vs baseline -> RED\n" as *u8) } 330 if regress == 0 { print(" [ok] coverage held >= baseline (no backslide)\n" as *u8) } 331 } 332 if had_base == 0 { print(" [note] no baseline file yet; capture the NX_SENSOR_BASELINE line into knowledge/status/sensor_gap_baseline.tsv\n" as *u8) } 333 334 // ---------- VERDICT ---------- 335 var green: i64 = 1 336 if self_ok != 1 { green = 0 } 337 if regress != 0 { green = 0 } 338 if green == 1 { 339 print("=== verdict: GREEN (classifier trustworthy; coverage did not backslide). NOTE: GREEN != coverage-good; the blind gates above ARE the work. ===\n" as *u8) 340 sys_exit(0); return 0 341 } 342 print("=== verdict: RED (classifier broken OR coverage backslid) ===\n" as *u8) 343 sys_exit(1); return 1 344}