code wiki / _hdl_build / nx_galx_census.nx

nx_galx_census.nx source

↩ module page · 159 lines · 7317 B

1// nx_galx_census.nx -- no-wave MEASURED BASELINE for the GALX "S-class gallery exceed" rung; the gallery-domain 2// twin of nx_cms_census / nx_competitive_census. Per-feature reach vs the best image gallery/management tools 3// (Hydrus, Eagle, ComfyUI-gallery, Diffusionbee, Elder svc-review): 4// - reads the S-class gallery feature surface from knowledge/registry/gallery_incumbent_ref.tsv (the QUESTIONS), 5// - COMPUTES each STATUS via re_has against the REAL gated gallery evidence (galx_serve.log + eval_lanes.log 6// + eval_kat_genrec.log, concatenated into one read buffer) -- NEVER tutor-asserted; a feature is PRESENT 7// only if a real gate ARM wrote its probe substring, 8// - writes knowledge/registry/gallery_census.tsv + emits a CENSUSGATE line (the no-wave measured reach permil). 9// Self-validating: pos control "browse_real_cids" MUST be PRESENT in the evidence, neg control MUST be ABSENT. 10// license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 13import "nx_research_extract.nx" 14import "nx_benchmark.nx" 15const GC_MAGIC_800000: i64 = 800000 16const GC_MAGIC_80000: i64 = 80000 17const GC_MAGIC_300000: i64 = 300000 18 19const GC_SELF: *u8 = "knowledge/status/galx_serve.log" 20const GC_EVAL: *u8 = "knowledge/status/eval_lanes.log" 21const GC_GREC: *u8 = "knowledge/status/eval_kat_genrec.log" 22const GC_REF: *u8 = "knowledge/registry/gallery_incumbent_ref.tsv" 23const GC_OUT: *u8 = "knowledge/registry/gallery_census.tsv" 24const GC_MAXF: i64 = 256 25 26func gc_msg(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 27// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 28// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 29// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 30// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 31func gc_putn(v: i64) -> i64 { nxi_out(v); return 0 } 32 33// append a whole file into buf starting at off; returns new off (read-into-tail concat of real gate evidence) 34func gc_read_into(path: *u8, buf: *u8, off: i64, cap: i64) -> i64 { 35 let fd: i64 = sys_openat_rd(path) 36 if fd < 0 { return off } 37 var tot: i64 = off 38 var r: i64 = 1 39 while r > 0 { 40 let dst: *u8 = ((buf as i64) + tot) as *u8 41 r = sys_read(fd, dst, cap - tot) 42 if r > 0 { tot = tot + r } 43 } 44 sys_close(fd) 45 return tot 46} 47 48func gc_read_file(path: *u8, buf: *u8, cap: i64) -> i64 { 49 let fd: i64 = sys_openat_rd(path) 50 if fd < 0 { return 0 - 1 } 51 var tot: i64 = 0 52 var r: i64 = 1 53 while r > 0 { 54 let dst: *u8 = ((buf as i64) + tot) as *u8 55 r = sys_read(fd, dst, cap - tot) 56 if r > 0 { tot = tot + r } 57 } 58 sys_close(fd) 59 return tot 60} 61 62func gc_scan_to(buf: *u8, n: i64, start: i64, delim: i64) -> i64 { 63 var i: i64 = start 64 var s: i64 = 1 65 while s == 1 { if i >= n { s = 0 } else { if buf[i] == (delim as u8) { s = 0 } else { i = i + 1 } } } 66 return i 67} 68 69func gc_app(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i } 70 71func gc_vstr(v: i64) -> *u8 { 72 if v == BM_AHEAD { return "AHEAD" as *u8 } 73 if v == BM_PARITY { return "PARITY" as *u8 } 74 if v == BM_BEHIND { return "BEHIND" as *u8 } 75 if v == BM_DIFFERENTIATED { return "DIFFERENTIATED" as *u8 } 76 return "REFUSE-cherrypick" as *u8 77} 78 79func main() -> i64 { 80 // concatenate the THREE real gate evidence files into one buffer -- all are GATED records, never asserted 81 let sm: *u8 = sys_mmap(GC_MAGIC_800000) 82 var smn: i64 = gc_read_into(GC_SELF, sm, 0, GC_MAGIC_800000) 83 if smn <= 0 { gc_msg("CENSUSGATE verdict=RED reason=galx-serve-log-unreadable\n" as *u8); return 1 } 84 // separator newline so probes never straddle file boundaries 85 sm[smn] = 10 as u8; smn = smn + 1 86 smn = gc_read_into(GC_EVAL, sm, smn, GC_MAGIC_800000) 87 sm[smn] = 10 as u8; smn = smn + 1 88 smn = gc_read_into(GC_GREC, sm, smn, GC_MAGIC_800000) 89 90 let rb: *u8 = sys_mmap(GC_MAGIC_80000) 91 let rbn: i64 = gc_read_file(GC_REF, rb, GC_MAGIC_80000) 92 if rbn <= 0 { gc_msg("CENSUSGATE verdict=RED reason=ref-unreadable\n" as *u8); return 1 } 93 94 let feat: *i64 = sys_mmap(8 * GC_MAXF) as *i64 95 let prob: *i64 = sys_mmap(8 * GC_MAXF) as *i64 96 let unin: *i64 = sys_mmap(8 * GC_MAXF) as *i64 97 var nf: i64 = 0 98 var p: i64 = 0 99 while p < rbn { 100 if rb[p] == (35 as u8) { let e: i64 = gc_scan_to(rb, rbn, p, 10); p = e + 1 } 101 else { if rb[p] == (10 as u8) { p = p + 1 } 102 else { 103 let a0: i64 = p 104 let t1: i64 = gc_scan_to(rb, rbn, a0, 9); rb[t1] = 0 as u8 105 let a1: i64 = t1 + 1 106 let t2: i64 = gc_scan_to(rb, rbn, a1, 9); rb[t2] = 0 as u8 107 let a2: i64 = t2 + 1 108 let t3: i64 = gc_scan_to(rb, rbn, a2, 10); rb[t3] = 0 as u8 109 if nf < GC_MAXF { feat[nf] = (rb as i64) + a0; prob[nf] = (rb as i64) + a1; unin[nf] = (rb as i64) + a2; nf = nf + 1 } 110 p = t3 + 1 111 } } 112 } 113 114 let ob: *u8 = sys_mmap(GC_MAGIC_300000) 115 var o: i64 = 0 116 o = gc_app(ob, o, "# AUTHORED BY nx_galx_census (GALX no-wave BASELINE) -- per-feature reach COMPUTED via re_has against the REAL gated gallery evidence (galx_serve.log + eval_lanes.log + eval_kat_genrec.log). NOT tutor-asserted. ABSENT rows = the UI/backend build backlog.\n" as *u8) 117 var present: i64 = 0 118 var i: i64 = 0 119 while i < nf { 120 let st: i64 = re_has(sm, smn, (prob[i]) as *u8) 121 if st == 1 { o = gc_app(ob, o, "PRESENT\t" as *u8); present = present + 1 } else { o = gc_app(ob, o, "ABSENT\t" as *u8) } 122 o = gc_app(ob, o, (feat[i]) as *u8) 123 o = gc_app(ob, o, "\t" as *u8) 124 o = gc_app(ob, o, (unin[i]) as *u8) 125 o = gc_app(ob, o, "\tcomputed:gate-has=" as *u8) 126 o = gc_app(ob, o, (prob[i]) as *u8) 127 o = gc_app(ob, o, "\n" as *u8) 128 i = i + 1 129 } 130 131 let fd: i64 = sys_openat_wr(GC_OUT, 420) 132 if fd < 0 { gc_msg("CENSUSGATE verdict=RED reason=out-unwritable\n" as *u8); return 1 } 133 sys_write(fd, ob, o) 134 sys_close(fd) 135 136 // self-validation: pos control must be in the real evidence, neg control must NOT be 137 let cpos: i64 = re_has(sm, smn, "browse_real_cids" as *u8) 138 let cneg: i64 = re_has(sm, smn, "zzqnonexistentcapability" as *u8) 139 let valid: i64 = bm_is_valid(nf, nf, 800) 140 var our_cov: i64 = 0 141 if nf > 0 { our_cov = (present * 1000) / nf } 142 let verdict: i64 = bm_verdict(valid, our_cov, 1000) 143 144 gc_msg("CENSUSGATE authored=organ source=gallery_incumbent_ref.tsv features=" as *u8); gc_putn(nf) 145 gc_msg(" present=" as *u8); gc_putn(present) 146 gc_msg(" absent=" as *u8); gc_putn(nf - present) 147 gc_msg(" control_pos=" as *u8); gc_putn(cpos) 148 gc_msg(" control_neg=" as *u8); gc_putn(cneg) 149 gc_msg(" reach_permil=" as *u8); gc_putn(our_cov) 150 gc_msg(" exceed_verdict=" as *u8); gc_msg(gc_vstr(verdict)) 151 152 var ok: i64 = 1 153 if cpos != 1 { ok = 0 } 154 if cneg != 0 { ok = 0 } 155 if nf <= 0 { ok = 0 } 156 if ok == 1 { gc_msg(" verdict=GREEN\n" as *u8); return 0 } 157 gc_msg(" verdict=RED reason=control-or-empty\n" as *u8) 158 return 1 159}