code wiki / _hdl_build / nx_atlas_gapscan_gate.nx

nx_atlas_gapscan_gate.nx source

↩ module page · 303 lines · 12014 B

1// nx_atlas_gapscan_gate.nx -- gate for graph-native atlas recombination (authored ON nx_gate_verdict per the 2// migrate-on-touch law). Two graphs, because fixture gates prove CORRECTNESS and never SCALE 3// ([[feedback-scale-law-no-toys-declare-envelopes]] -- the ark-v1 lesson institutionalized): 4// FIXTURE graph (16 nodes, hand-built so every expectation is unambiguous): 5// T5 neg-control: a pair with the IDENTICAL score to the positive one but WITH an import edge is NOT 6// proposed -- the only difference between T5 and T6 is the edge, so this isolates novelty exactly 7// T6 positive: the unconnected cross-wing maturity-gap pair IS proposed 8// T7 island (ca=0,ce=0) never proposed T8 _gate scaffolding never proposed 9// PRODUCTION-SHAPE graph (12000 nodes / ~21000 edges, ~9000 candidates -> the AR_MAXCAND 8192 cap is 10// deliberately EXCEEDED so the truncation path is exercised, not assumed): 11// T1 completes at production shape T2 the cap is HIT and DECLARED (no silent truncation) 12// T3 topk respected T4 scores non-increasing (true top-K, not first-past-the-post) 13// T9 absent store -> fail-closed nonzero exit 14// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 15import "nx_eco_graph.nx" 16import "nx_store_seed_lib.nx" 17import "nx_seg_store.nx" 18import "nx_deploy_lib.nx" 19import "nx_gate_verdict.nx" 20import "nx_syscalls.nx" 21 22const RG_CAP: i64 = 1048576 23const RG_PFX: i64 = 128 24const RG_NAME: i64 = 64 25const RG_TAB: i64 = 9 26const RG_NL: i64 = 10 27const RG_ZERO: i64 = 48 28const RG_NINE: i64 = 57 29const RG_B10: i64 = 10 30// fixture graph 31const RG_FX_NODE: i64 = 640 32const RG_FX_EDGE: i64 = 1400 33const RG_FX_ARENA: i64 = 32768 34const RG_FX_HASH: i64 = 1024 35const RG_FX_GIANT: i64 = 505 36// production-shape graph 37const RG_SC_WINGS: i64 = 60 38const RG_SC_PER: i64 = 200 39const RG_SC_NODE: i64 = 13000 40const RG_SC_EDGE: i64 = 32000 41const RG_SC_ARENA: i64 = 524288 42const RG_SC_HASH: i64 = 32768 43const RG_SC_SKIP: i64 = 4 44const RG_TOPK: i64 = 64 45 46func rg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 47func rg_has(q: *u8, n: i64, s: *u8) -> i64 { 48 let sn: i64 = rg_slen(s) 49 if sn == 0 { return 1 } 50 var i: i64 = 0 51 while i + sn <= n { 52 var hit: i64 = 1 53 var j: i64 = 0 54 while j < sn { if q[i+j] != s[j] { hit = 0; j = sn } else { j = j + 1 } } 55 if hit == 1 { return 1 } 56 i = i + 1 57 } 58 return 0 59} 60func rg_mkpfx(dst: *u8, stem: *u8, epoch: i64) -> i64 { 61 var o: i64 = ss_cat(dst, 0, stem) 62 o = ss_catn(dst, o, epoch) 63 o = ss_cat(dst, o, "-" as *u8) 64 dst[o] = 0 as u8 65 return o 66} 67func rg_node(g: *EcoGraph, s: *u8) -> i64 { let l: i64 = rg_slen(s); return eg_intern(g, s, l) } 68// "nx_wg<w>_org<j>.nx" -- two underscores so the wing prefix resolves to nx_wg<w> 69func rg_mkname(dst: *u8, w: i64, j: i64) -> i64 { 70 var o: i64 = ss_cat(dst, 0, "nx_wg" as *u8) 71 o = ss_catn(dst, o, w) 72 o = ss_cat(dst, o, "_org" as *u8) 73 o = ss_catn(dst, o, j) 74 o = ss_cat(dst, o, ".nx" as *u8) 75 dst[o] = 0 as u8 76 return o 77} 78func rg_rows(q: *u8, n: i64) -> i64 { 79 var c: i64 = 0 80 var i: i64 = 0 81 while i < n { if q[i] == (RG_NL as u8) { c = c + 1 } i = i + 1 } 82 return c 83} 84// scores live in tab-column 2 of every row; 1 if non-increasing across all rows 85func rg_desc(q: *u8, n: i64) -> i64 { 86 var prev: i64 = 0 - 1 87 var ok: i64 = 1 88 var i: i64 = 0 89 while i < n { 90 var le: i64 = i 91 var s: i64 = 1 92 while s == 1 { if le >= n { s = 0 } else { if q[le] == (RG_NL as u8) { s = 0 } else { le = le + 1 } } } 93 if le > i { 94 var t: i64 = 0 95 var p: i64 = i 96 var col2: i64 = 0 - 1 97 while p < le { 98 if q[p] == (RG_TAB as u8) { t = t + 1; if t == 2 { col2 = p + 1; p = le } } 99 p = p + 1 100 } 101 if col2 >= 0 { 102 var v: i64 = 0 103 var d: i64 = col2 104 while d < le { 105 let c: i64 = q[d] as i64 106 if c >= RG_ZERO { if c <= RG_NINE { v = v * RG_B10 + (c - RG_ZERO) } } 107 if q[d] == (RG_TAB as u8) { d = le } else { d = d + 1 } 108 } 109 if prev >= 0 { if v > prev { ok = 0 } } 110 prev = v 111 } 112 } 113 i = le + 1 114 } 115 return ok 116} 117 118func main() -> i64 { 119 let ctr: *i64 = gv_ctr() 120 gv_head("nx_atlas_gapscan gate -- graph-native recombination: novelty by edge-absence, declared envelope, true top-K" as *u8) 121 let elf: *u8 = "/tmp/nx_atlas_gapscan.sov.elf" as *u8 122 let outf: *u8 = "/tmp/arg_run.out" as *u8 123 let epoch: i64 = sys_now_realtime_sec() 124 125 let fxs: *u8 = sys_mmap(RG_PFX) 126 rg_mkpfx(fxs, "/tmp/argfx" as *u8, epoch) 127 let fxo: *u8 = sys_mmap(RG_PFX) 128 rg_mkpfx(fxo, "/tmp/argfo" as *u8, epoch) 129 let scs: *u8 = sys_mmap(RG_PFX) 130 rg_mkpfx(scs, "/tmp/argsc" as *u8, epoch) 131 let sco: *u8 = sys_mmap(RG_PFX) 132 rg_mkpfx(sco, "/tmp/argso" as *u8, epoch) 133 134 // ---------- FIXTURE GRAPH ---------- 135 // alpha: mature (ca=6) cross-wing vs beta: under-connected (ca=1) -> score 3+2+1 = 6, NO edge -> PROPOSE 136 // gamma: mature (ca=6) cross-wing vs delta: under-connected (ca=1) -> score 6, edge gamma->delta -> SKIP 137 let fg: *EcoGraph = eg_new(RG_FX_NODE, RG_FX_EDGE, RG_FX_ARENA, RG_FX_HASH) 138 let alpha: i64 = rg_node(fg, "nx_zz0_alpha.nx" as *u8) 139 let beta: i64 = rg_node(fg, "nx_zz1_beta.nx" as *u8) 140 let gamma: i64 = rg_node(fg, "nx_yy0_gamma.nx" as *u8) 141 let delta: i64 = rg_node(fg, "nx_yy1_delta.nx" as *u8) 142 let lonely: i64 = rg_node(fg, "nx_ii0_lonely.nx" as *u8) 143 let scaff: i64 = rg_node(fg, "nx_gg0_thing_gate.nx" as *u8) 144 let sink: i64 = rg_node(fg, "nx_fl0_sink.nx" as *u8) 145 // giant: a ubiquity hub (Ca=505 >= AR_HUB_CA 500). It would otherwise score like alpha, so its ABSENCE 146 // isolates the hub cut exactly -- this is the nx_syscalls.nx (Ca=13539) pathology found on the live graph. 147 let giant: i64 = rg_node(fg, "nx_hh0_giant.nx" as *u8) 148 // give alpha / gamma / scaffolding ca=6 from same-wing filler importers 149 var f: i64 = 0 150 while f < 6 { 151 let fb: *u8 = sys_mmap(RG_NAME) 152 var fo: i64 = ss_cat(fb, 0, "nx_fl0_imp" as *u8) 153 fo = ss_catn(fb, fo, f) 154 fo = ss_cat(fb, fo, ".nx" as *u8) 155 fb[fo] = 0 as u8 156 let fi: i64 = rg_node(fg, fb) 157 eg_add_edge(fg, fi, alpha) 158 eg_add_edge(fg, fi, gamma) 159 eg_add_edge(fg, fi, scaff) 160 f = f + 1 161 } 162 // push giant over the ubiquity cut with its own importer population 163 var q: i64 = 0 164 while q < RG_FX_GIANT { 165 let gb: *u8 = sys_mmap(RG_NAME) 166 var go2: i64 = ss_cat(gb, 0, "nx_fl0_gimp" as *u8) 167 go2 = ss_catn(gb, go2, q) 168 go2 = ss_cat(gb, go2, ".nx" as *u8) 169 gb[go2] = 0 as u8 170 let gi: i64 = rg_node(fg, gb) 171 if gi >= 0 { eg_add_edge(fg, gi, giant) } 172 q = q + 1 173 } 174 eg_add_edge(fg, giant, sink) 175 // ce>=1 for every probe (the bridge point) ; beta/delta get ca=1 from the sink side 176 eg_add_edge(fg, alpha, sink) 177 eg_add_edge(fg, gamma, delta) // <-- the ONLY difference between the T5 and T6 pairs 178 eg_add_edge(fg, scaff, sink) 179 eg_add_edge(fg, beta, sink) 180 eg_add_edge(fg, delta, sink) 181 eg_add_edge(fg, sink, beta) // beta ca=1 182 if lonely == 0 - 1 { gv_check("fixture intern failed" as *u8, 0, ctr) } 183 eg_finalize(fg) 184 eg_save(fg, fxs) 185 186 let av: *i64 = sys_mmap(8*8) as *i64 187 av[0] = fxs as i64 188 av[1] = fxo as i64 189 av[2] = "5" as *u8 as i64 190 av[3] = "64" as *u8 as i64 191 let rcf: i64 = dep_run_capture(elf, av, 4, outf) 192 let fd: *u8 = sys_mmap(RG_CAP) 193 var fn: i64 = sts_load(fxo, fd, RG_CAP) 194 if fn < 0 { fn = 0 } 195 196 var t6: i64 = 0 197 if rcf == 0 { 198 if rg_has(fd, fn, "nx_zz0_alpha.nx->nx_zz1_beta.nx" as *u8) == 1 { t6 = 1 } 199 if rg_has(fd, fn, "nx_zz1_beta.nx->nx_zz0_alpha.nx" as *u8) == 1 { t6 = 1 } 200 } 201 var t5: i64 = 0 202 if rg_has(fd, fn, "nx_yy0_gamma.nx->nx_yy1_delta.nx" as *u8) == 0 { 203 if rg_has(fd, fn, "nx_yy1_delta.nx->nx_yy0_gamma.nx" as *u8) == 0 { t5 = 1 } 204 } 205 var t7: i64 = 0 206 if rg_has(fd, fn, "nx_ii0_lonely.nx" as *u8) == 0 { t7 = 1 } 207 var t8: i64 = 0 208 if rg_has(fd, fn, "nx_gg0_thing_gate.nx" as *u8) == 0 { t8 = 1 } 209 210 // ---------- PRODUCTION-SHAPE GRAPH ---------- 211 let sg: *EcoGraph = eg_new(RG_SC_NODE, RG_SC_EDGE, RG_SC_ARENA, RG_SC_HASH) 212 let nb: *u8 = sys_mmap(RG_NAME) 213 var w: i64 = 0 214 while w < RG_SC_WINGS { 215 rg_mkname(nb, w, 0) 216 rg_node(sg, nb) 217 w = w + 1 218 } 219 w = 0 220 while w < RG_SC_WINGS { 221 rg_mkname(nb, w, 0) 222 let hub: i64 = rg_node(sg, nb) 223 var nw: i64 = w + 1 224 if nw >= RG_SC_WINGS { nw = 0 } 225 rg_mkname(nb, nw, 0) 226 let nexthub: i64 = rg_node(sg, nb) 227 var j: i64 = 1 228 while j < RG_SC_PER { 229 rg_mkname(nb, w, j) 230 let nd: i64 = rg_node(sg, nb) 231 if nd >= 0 { 232 eg_add_edge(sg, nd, hub) 233 if j % RG_SC_SKIP != 0 { eg_add_edge(sg, nd, nexthub) } 234 } 235 j = j + 1 236 } 237 w = w + 1 238 } 239 eg_finalize(sg) 240 eg_save(sg, scs) 241 242 av[0] = scs as i64 243 av[1] = sco as i64 244 let rcs: i64 = dep_run_capture(elf, av, 4, outf) 245 let sd: *u8 = sys_mmap(RG_CAP) 246 var sn: i64 = sts_load(sco, sd, RG_CAP) 247 if sn < 0 { sn = 0 } 248 let env: *u8 = sys_mmap(RG_CAP) 249 var en: i64 = dp_read(outf, env, RG_CAP) 250 if en < 0 { en = 0 } 251 252 var t1: i64 = 0 253 if rcs == 0 { if rg_has(env, en, "nodes=12000" as *u8) == 1 { t1 = 1 } } 254 gv_check("T1 completes at PRODUCTION SHAPE (12000-node graph, exit 0, node count declared)" as *u8, t1, ctr) 255 256 var t2: i64 = 0 257 if rg_has(env, en, "candidates=8192/8192" as *u8) == 1 { 258 if rg_has(env, en, "truncated=1" as *u8) == 1 { t2 = 1 } 259 } 260 gv_check("T2 candidate cap HIT and DECLARED in the envelope (no silent truncation)" as *u8, t2, ctr) 261 262 let nrows: i64 = rg_rows(sd, sn) 263 var t3: i64 = 0 264 if nrows > 0 { if nrows <= RG_TOPK { t3 = 1 } } 265 gv_check("T3 topk envelope respected (rows <= 64)" as *u8, t3, ctr) 266 267 var t4: i64 = 0 268 if nrows > 1 { if rg_desc(sd, sn) == 1 { t4 = 1 } } 269 gv_check("T4 TRUE top-K: scores non-increasing across rows (not first-past-the-post)" as *u8, t4, ctr) 270 271 gv_check("T5 NEG-CONTROL: identical-score pair WITH an import edge is NOT proposed" as *u8, t5, ctr) 272 gv_check("T6 unconnected cross-wing maturity-gap pair IS proposed" as *u8, t6, ctr) 273 gv_check("T7 island node (ca=0,ce=0) never proposed" as *u8, t7, ctr) 274 gv_check("T8 _gate scaffolding never proposed" as *u8, t8, ctr) 275 276 var t10: i64 = 0 277 if rg_has(fd, fn, "nx_hh0_giant.nx" as *u8) == 0 { t10 = 1 } 278 gv_check("T10 ubiquity hub (Ca>=500) never proposed -- the nx_syscalls saturation pathology" as *u8, t10, ctr) 279 280 var t11: i64 = 0 281 if rg_has(env, en, "hub_ca_cut=500" as *u8) == 1 { 282 if rg_has(env, en, "anchor_cap=2" as *u8) == 1 { 283 if rg_has(env, en, "dropped_anchor_cap=" as *u8) == 1 { t11 = 1 } 284 } 285 } 286 gv_check("T11 hub cut + anchor cap + their drop count are DECLARED in the envelope" as *u8, t11, ctr) 287 288 var t12: i64 = 0 289 if rg_has(env, en, "shared1x8" as *u8) == 1 { 290 if rg_has(fd, fn, "shared=" as *u8) == 1 { t12 = 1 } 291 } 292 gv_check("T12 shared-substrate discriminator declared in envelope + evidenced per row" as *u8, t12, ctr) 293 294 av[0] = "/tmp/arg_nope-" as *u8 as i64 295 let rc9: i64 = dep_run_capture(elf, av, 4, outf) 296 var t9: i64 = 0 297 if rc9 != 0 { t9 = 1 } 298 gv_check("T9 absent graph store -> fail-closed nonzero exit" as *u8, t9, ctr) 299 300 let rc: i64 = gv_verdict("ATLAS-GAPSCAN-GATE" as *u8, ctr, "graph-native recombination: novelty=edge-absence, envelope declared at production shape, true top-K" as *u8) 301 sys_exit(rc) 302 return rc 303}