code wiki / _hdl_build / nx_extract_persist_gate.nx

nx_extract_persist_gate.nx source

↩ module page · 68 lines · 4169 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_extract_persist_gate.nx -- proves DURABLE self-healing: a pattern learned in one "process" (table A) is 4// saved to disk, then a FRESH, empty table B loads it -- and the once-missed adversary URL now classifies via 5// the persisted learned pattern. This is what makes "auto-heal" real end-to-end: healing outlives the run, 6// so a site we adapted to once stays adapted after a restart. license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_media_signal.nx" 9import "nx_extract_heal.nx" 10import "nx_gate_verdict.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15func cls(t: *i64, url: *u8, kb: *i64) -> i64 { return xh_classify(t, url, gsl(url), kb) } 16 17func main() -> i64 { 18 gw("extract-persist SOVEREIGN gate (learn -> save -> FRESH load -> still healed: durable self-heal)\n" as *u8) 19 var pass: i64 = 0 20 var ttl: i64 = 0 21 let kb: *i64 = sys_mmap(8) as *i64 22 let path: *u8 = "/tmp/xh_patterns.tbl" as *u8 23 let adv: *u8 = "https://cdn-x7.streamhost.net/deliver/vod/abc123" as *u8 // novel host, unseeded 24 25 // --- PROCESS A: seed, hit the adversary miss, LEARN, SAVE --- 26 let a: *i64 = xh_new() 27 xh_seed(a) 28 let seed_n: i64 = a[0] 29 let la: i64 = xh_learn(a, adv, gsl(adv), XT_DIRECT) // heal 30 let a_n: i64 = a[0] 31 let sv: i64 = xh_save(a, path) // persist 32 ttl=ttl+1; pass=pass+grow("P1 process-A learned + saved OK\x00" as *u8, ((la == 1)) as i64 * ((sv == 0) as i64)) 33 34 // --- PROCESS B: FRESH empty table, LOAD from disk (no seed call) --- 35 let b: *i64 = xh_new() 36 let loaded: i64 = xh_load(b, path) 37 ttl=ttl+1; pass=pass+grow("P2 process-B loaded ALL patterns (seed + learned)\x00" as *u8, (loaded == a_n) as i64) 38 ttl=ttl+1; pass=pass+grow("P3 loaded table size == saved table size\x00" as *u8, (b[0] == a_n) as i64) 39 40 // P4: the once-missed adversary URL now classifies in the FRESH table (healing survived the restart) 41 cls(b, adv, kb) 42 ttl=ttl+1; pass=pass+grow("P4 adversary URL classifies DIRECT after fresh load (durable heal)\x00" as *u8, (kb[0] == XT_DIRECT) as i64) 43 // P5: seed knowledge also restored (a plain .m3u8 -> HLS) 44 cls(b, "https://c/x.m3u8" as *u8, kb) 45 ttl=ttl+1; pass=pass+grow("P5 seed patterns also restored (.m3u8 -> HLS)\x00" as *u8, (kb[0] == XT_HLS) as i64) 46 // P6: a same-host sibling of the adversary also generalizes in the loaded table 47 cls(b, "https://cdn-x7.streamhost.net/deliver/live/xyz" as *u8, kb) 48 ttl=ttl+1; pass=pass+grow("P6 same-host sibling generalizes in loaded table\x00" as *u8, (kb[0] == XT_DIRECT) as i64) 49 // P7: an unrelated host is still a miss (persistence didn't corrupt discrimination) 50 cls(b, "https://videos.unrelated.net/clip" as *u8, kb) 51 ttl=ttl+1; pass=pass+grow("P7 unrelated host still NONE (no over-generalize after load)\x00" as *u8, (kb[0] == XT_NONE) as i64) 52 // P8: idempotent load -- loading again into a THIRD fresh table yields the same count (save is stable) 53 let c: *i64 = xh_new() 54 let loaded2: i64 = xh_load(c, path) 55 ttl=ttl+1; pass=pass+grow("P8 re-load stable (idempotent count)\x00" as *u8, (loaded2 == loaded) as i64) 56 57 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 58 gw("(saved " as *u8); gn(a_n); gw(" patterns; seed=" as *u8); gn(seed_n); gw(", learned=+1 -> persisted)\n" as *u8) 59 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 60 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 61 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 62 let ctr__dry: *i64 = gv_ctr() 63 ctr__dry[0] = pass 64 ctr__dry[1] = ttl 65 let rc__dry: i64 = gv_verdict("EXTRACT-PERSIST-GATE" as *u8, ctr__dry, "durable self-healing: a pattern learned once survives a restart via the saved table)" as *u8) 66 sys_exit(rc__dry) 67 return rc__dry 68}