code wiki / _hdl_build / nx_conductor_recall_gate.nx

nx_conductor_recall_gate.nx source

↩ module page · 128 lines · 5875 B

1// nx_conductor_recall_gate.nx -- THE LOCK for rung 3 (recall wired into the live give-up path). 2// Proves cond_recall_verdict converts a self-heal verdict correctly + honestly. HERMETIC: seeds its 3// OWN catalogue (knowledge/store/kicgate-) with one non-reserved-keyword signatured fixture (C-SEGV), 4// so it exercises the give-up->recall path that the production catalogue cannot yet (the only 5// production signature, reserved-keyword, is already caught by the Doctor's PRIMARY classifier and 6// never reaches give-up). No compiler is driven -- the decision layer is pure. 7// 8// G1 recall-rescues-giveup : (COND_UNFIXABLE, diag w/ C-SEGV signature) -> COND_SEEN, id=C-SEGV 9// G2 honest-novel : (COND_UNFIXABLE, novel diag) -> COND_UNFIXABLE (no rubber-stamp) 10// G3 passthrough-clean : (COND_CLEAN, anything) -> COND_CLEAN (recall never meddles) 11// G4 passthrough-council : (arbitrary verdict 99, anything) -> 99 (only give-up is special-cased) 12// G5 tamper : (COND_UNFIXABLE, diag w/ corrupted sig) -> COND_UNFIXABLE (real match) 13// GREEN only if G1..G5 all hold. Evidence -> knowledge/status/conductor_recall.log. license_tier: ORIGINAL 14import "nx_conductor_recall.nx" 15import "nx_seg_store.nx" 16import "nx_syscalls.nx" 17 18const CR_LOG: *u8 = "knowledge/status/conductor_recall.log" 19const KICGATE_PREFIX: *u8 = "knowledge/store/kicgate-" 20 21func cr_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 22func cr_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 23 24func cr_streq(a: *u8, b: *u8) -> i64 { 25 var i: i64 = 0 26 while a[i] != (0 as u8) { 27 if a[i] != b[i] { return 0 } 28 i = i + 1 29 } 30 if b[i] != (0 as u8) { return 0 } 31 return 1 32} 33 34func cr_streq_store(key: *u8, val: *u8) -> i64 { 35 let pq: *i64 = sys_mmap(16) as *i64 36 let lq: *i64 = sys_mmap(16) as *i64 37 if ss_get(KICGATE_PREFIX, key, pq, lq) != 1 { return 0 } 38 let b: *u8 = pq[0] as *u8 39 let n: i64 = lq[0] 40 let vl: i64 = cr_len(val) 41 if n != vl { return 0 } 42 var i: i64 = 0 43 while i < n { if b[i] != val[i] { return 0 } i = i + 1 } 44 return 1 45} 46 47func cr_row(fd: i64, name: *u8, pass: i64) -> i64 { 48 cr_w(fd, " "); cr_w(fd, name) 49 if pass == 1 { cr_w(fd, " PASS\n" as *u8) } else { cr_w(fd, " FAIL\n" as *u8) } 50 return 0 51} 52 53func main() -> i64 { 54 // ---- seed the hermetic conductor-gate catalogue (idempotent / additive) ---- 55 let keys: *i64 = sys_mmap(8 * 4) as *i64 56 let vals: *i64 = sys_mmap(8 * 4) as *i64 57 keys[0] = "ki:ids" as *u8 as i64 58 vals[0] = "C-SEGV" as *u8 as i64 59 keys[1] = "ki:C-SEGV" as *u8 as i64 60 vals[1] = "C-SEGV\tTOOLCHAIN\tOPEN\tSIGSEGV\tnxasm-prologue-encoding-fix" as *u8 as i64 61 let nrec: i64 = 2 62 63 let w: *i64 = ss_begin() 64 var towrite: i64 = 0 65 var i: i64 = 0 66 while i < nrec { 67 if cr_streq_store(keys[i] as *u8, vals[i] as *u8) == 0 { ss_add(w, 1, keys[i] as *u8, vals[i] as *u8, cr_len(vals[i] as *u8)); towrite = towrite + 1 } 68 i = i + 1 69 } 70 if towrite > 0 { 71 let segid: i64 = ki_seg_next_p(KICGATE_PREFIX) 72 ss_commit(KICGATE_PREFIX, w, segid) 73 } 74 75 let oid: *u8 = sys_mmap(64) 76 let orem: *u8 = sys_mmap(256) 77 let ostat: *u8 = sys_mmap(64) 78 79 let d_segv: *u8 = "engineer: child terminated by signal 11 SIGSEGV at canary step\n" as *u8 80 let d_novel: *u8 = "weird brand new failure zzqq-unseen-novel-9 nothing in the catalogue\n" as *u8 81 let d_tamp: *u8 = "engineer: child terminated by signal 11 SIGSEXV at canary step\n" as *u8 82 83 // G1: a give-up whose diagnostic matches a catalogued signature -> COND_SEEN + correct id 84 let v1: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_segv, cr_len(d_segv), oid, orem, ostat) 85 var g1: i64 = 0 86 if v1 == COND_SEEN { if cr_streq(oid, "C-SEGV" as *u8) == 1 { g1 = 1 } } 87 88 // G2: a give-up with a genuinely novel diagnostic -> stays COND_UNFIXABLE (honest) 89 let v2: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_novel, cr_len(d_novel), oid, orem, ostat) 90 var g2: i64 = 0 91 if v2 == COND_UNFIXABLE { g2 = 1 } 92 93 // G3: a NON-give-up verdict (clean) passes straight through -- recall never meddles 94 let v3: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_CLEAN, d_segv, cr_len(d_segv), oid, orem, ostat) 95 var g3: i64 = 0 96 if v3 == COND_CLEAN { g3 = 1 } 97 98 // G4: an arbitrary council verdict (99) passes through -- only COND_UNFIXABLE is special-cased 99 let v4: i64 = cond_recall_verdict(KICGATE_PREFIX, 99, d_segv, cr_len(d_segv), oid, orem, ostat) 100 var g4: i64 = 0 101 if v4 == 99 { g4 = 1 } 102 103 // G5 tamper: corrupt the signature in the diagnostic -> recall MISSES -> COND_UNFIXABLE (real match) 104 let v5: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_tamp, cr_len(d_tamp), oid, orem, ostat) 105 var g5: i64 = 0 106 if v5 == COND_UNFIXABLE { g5 = 1 } 107 108 var ok: i64 = 0 109 if g1 == 1 { if g2 == 1 { if g3 == 1 { if g4 == 1 { if g5 == 1 { ok = 1 } } } } } 110 111 cr_w(1, "CONDUCTOR-RECALL gate (recall wired into the give-up path)\n" as *u8) 112 cr_row(1, "G1 recall-rescues-giveup " as *u8, g1) 113 cr_row(1, "G2 honest-novel-unfixable" as *u8, g2) 114 cr_row(1, "G3 passthrough-clean " as *u8, g3) 115 cr_row(1, "G4 passthrough-council " as *u8, g4) 116 cr_row(1, "G5 tamper-miss " as *u8, g5) 117 if ok == 1 { cr_w(1, "verdict=GREEN\n" as *u8) } else { cr_w(1, "verdict=RED\n" as *u8) } 118 119 let lf: i64 = sys_openat_append(CR_LOG, 420) 120 if lf >= 0 { 121 cr_w(lf, "CONDUCTOR-RECALL authored=organ " as *u8) 122 if ok == 1 { cr_w(lf, "G1..G5=PASS verdict=GREEN\n" as *u8) } else { cr_w(lf, "verdict=RED\n" as *u8) } 123 sys_close(lf) 124 } 125 126 if ok == 1 { return 0 } 127 return 1 128}