code wiki / _hdl_build / nx_atlas_discover_gate.nx

nx_atlas_discover_gate.nx source

↩ module page · 119 lines · 5268 B

1// nx_atlas_discover_gate.nx -- gate for atlas recombination discovery (authored ON nx_gate_verdict 2// per the migrate-on-touch law). Per-run-unique /tmp fixture planes: 3// T1 proposes novel MCP-live pairs above minscore (data-adjacent + cross-owner scoring) 4// T2 EXCLUDES the already-composed pair (both organs in the exclusion plan = no proposal) 5// T3 EXCLUDES non-mcp-live organs (internal/GAP rows never proposed) 6// T4 deterministic (two runs -> byte-identical discovery plane) 7// T5 unseeded catalog -> fail-closed nonzero exit 8// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 9import "nx_store_seed_lib.nx" 10import "nx_seg_store.nx" 11import "nx_deploy_lib.nx" 12import "nx_gate_verdict.nx" 13import "nx_syscalls.nx" 14 15const AG_CAP: i64 = 262144 16const AG_PFX: i64 = 128 17 18func ag_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 19func ag_has(q: *u8, n: i64, s: *u8) -> i64 { 20 let sn: i64 = ag_slen(s) 21 if sn == 0 { return 1 } 22 var i: i64 = 0 23 while i + sn <= n { 24 var hit: i64 = 1 25 var j: i64 = 0 26 while j < sn { if q[i+j] != s[j] { hit = 0; j = sn } else { j = j + 1 } } 27 if hit == 1 { return 1 } 28 i = i + 1 29 } 30 return 0 31} 32func ag_mkpfx(dst: *u8, stem: *u8, epoch: i64) -> i64 { 33 var o: i64 = ss_cat(dst, 0, stem) 34 o = ss_catn(dst, o, epoch) 35 o = ss_cat(dst, o, "-" as *u8) 36 dst[o] = 0 as u8 37 return o 38} 39 40func main() -> i64 { 41 let ctr: *i64 = gv_ctr() 42 gv_head("nx_atlas_discover gate -- novel recombination proposals from the capability catalog" as *u8) 43 let elf: *u8 = "/tmp/nx_atlas_discover.sov.elf" as *u8 44 let outf: *u8 = "/tmp/agd_run.out" as *u8 45 let epoch: i64 = sys_now_realtime_sec() 46 47 // fixture catalog: alpha+beta+gamma mcp-live (alpha/beta plane-noted, gamma not), delta internal 48 let cp: *u8 = sys_mmap(AG_PFX) 49 ag_mkpfx(cp, "/tmp/agdc" as *u8, epoch) 50 let xp: *u8 = sys_mmap(AG_PFX) 51 ag_mkpfx(xp, "/tmp/agdx" as *u8, epoch) 52 let op: *u8 = sys_mmap(AG_PFX) 53 ag_mkpfx(op, "/tmp/agdo" as *u8, epoch) 54 let cb: *u8 = sys_mmap(AG_CAP) 55 var co: i64 = 0 56 co = ss_cat(cb, co, "verba\x09org_alpha\x09own1\x09mcp-live\x09LIVE\x090\x09writes the plane store\n" as *u8) 57 co = ss_cat(cb, co, "verbb\x09org_beta\x09own2\x09mcp-live\x09LIVE\x090\x09reads the plane store\n" as *u8) 58 co = ss_cat(cb, co, "verbc\x09org_gamma\x09own3\x09mcp-live\x09LIVE\x090\x09no data words here\n" as *u8) 59 co = ss_cat(cb, co, "verbd\x09org_delta\x09own4\x09internal\x09GAP\x090\x09plane store but not exposed\n" as *u8) 60 sts_seed(cp, cb, co) 61 // exclusion plan: alpha+beta already composed 62 var xo: i64 = 0 63 xo = ss_cat(cb, xo, "10\x09org_alpha\x09json\n20\x09org_beta\x09json\n" as *u8) 64 sts_seed(xp, cb, xo) 65 66 let av: *i64 = sys_mmap(8*8) as *i64 67 av[0] = cp as i64 68 av[1] = xp as i64 69 av[2] = op as i64 70 av[3] = "2" as *u8 as i64 71 let rc1: i64 = dep_run_capture(elf, av, 4, outf) 72 let dump: *u8 = sys_mmap(AG_CAP) 73 var dn: i64 = sts_load(op, dump, AG_CAP) 74 if dn < 0 { dn = 0 } 75 76 // T1: novel pairs proposed (alpha->gamma impossible: gamma lacks data words -> score 1 <2; 77 // but beta->? ... the score-2 path needs BOTH plane-noted: only alpha+beta qualify and they 78 // are excluded -> with minscore 2 nothing lands. Re-run with minscore 1 for the novelty tooth.) 79 av[3] = "1" as *u8 as i64 80 let rc1b: i64 = dep_run_capture(elf, av, 4, outf) 81 dn = sts_load(op, dump, AG_CAP) 82 if dn < 0 { dn = 0 } 83 var t1: i64 = 0 84 if rc1b == 0 { if ag_has(dump, dn, "org_alpha->org_gamma" as *u8) == 1 { if ag_has(dump, dn, "proposed" as *u8) == 1 { t1 = 1 } } } 85 gv_check("T1 novel cross-owner pair proposed (alpha->gamma, status=proposed)" as *u8, t1, ctr) 86 87 // T2: the already-composed alpha->beta pair is EXCLUDED even though it scores highest 88 var t2: i64 = 0 89 if ag_has(dump, dn, "org_alpha->org_beta" as *u8) == 0 { if ag_has(dump, dn, "org_beta->org_alpha" as *u8) == 0 { t2 = 1 } } 90 gv_check("T2 already-composed pair EXCLUDED (alpha<->beta absent despite top score)" as *u8, t2, ctr) 91 92 // T3: internal/GAP organ never proposed 93 var t3: i64 = 0 94 if ag_has(dump, dn, "org_delta" as *u8) == 0 { t3 = 1 } 95 gv_check("T3 non-mcp-live organ NEVER proposed (delta absent)" as *u8, t3, ctr) 96 97 // T4: deterministic re-run byte-identical 98 let d2: *u8 = sys_mmap(AG_CAP) 99 let rc4: i64 = dep_run_capture(elf, av, 4, outf) 100 let n2: i64 = sts_load(op, d2, AG_CAP) 101 var t4: i64 = 0 102 if rc4 == 0 { if n2 == dn { 103 t4 = 1 104 var k: i64 = 0 105 while k < n2 { if d2[k] != dump[k] { t4 = 0; k = n2 } else { k = k + 1 } } 106 } } 107 gv_check("T4 deterministic (two runs -> byte-identical discovery plane)" as *u8, t4, ctr) 108 109 // T5: unseeded catalog fail-closed 110 av[0] = "/tmp/agd_nope-" as *u8 as i64 111 let rc5: i64 = dep_run_capture(elf, av, 4, outf) 112 var t5: i64 = 0 113 if rc5 != 0 { t5 = 1 } 114 gv_check("T5 unseeded catalog -> fail-closed nonzero exit" as *u8, t5, ctr) 115 116 let rc: i64 = gv_verdict("ATLAS-DISCOVER-GATE" as *u8, ctr, "novel recombination proposals: scored, exclusion-aware, mcp-live-only, deterministic" as *u8) 117 sys_exit(rc) 118 return rc 119}