code wiki / _hdl_build / nx_conductor_recall_gate.nx

nx_conductor_recall_gate.nx source

↩ module page · 136 lines · 6417 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" 17import "nx_gate_verdict.nx" 18 19const CR_LOG: *u8 = "knowledge/status/conductor_recall.log" 20const KICGATE_PREFIX: *u8 = "knowledge/store/kicgate-" 21 22func 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 } 23func cr_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 24 25func cr_streq(a: *u8, b: *u8) -> i64 { 26 var i: i64 = 0 27 while a[i] != (0 as u8) { 28 if a[i] != b[i] { return 0 } 29 i = i + 1 30 } 31 if b[i] != (0 as u8) { return 0 } 32 return 1 33} 34 35func cr_streq_store(key: *u8, val: *u8) -> i64 { 36 let pq: *i64 = sys_mmap(16) as *i64 37 let lq: *i64 = sys_mmap(16) as *i64 38 if ss_get(KICGATE_PREFIX, key, pq, lq) != 1 { return 0 } 39 let b: *u8 = pq[0] as *u8 40 let n: i64 = lq[0] 41 let vl: i64 = cr_len(val) 42 if n != vl { return 0 } 43 var i: i64 = 0 44 while i < n { if b[i] != val[i] { return 0 } i = i + 1 } 45 return 1 46} 47 48func cr_row(fd: i64, name: *u8, pass: i64) -> i64 { 49 cr_w(fd, " "); cr_w(fd, name) 50 if pass == 1 { cr_w(fd, " PASS\n" as *u8) } else { cr_w(fd, " FAIL\n" as *u8) } 51 return 0 52} 53 54func main() -> i64 { 55 // ---- seed the hermetic conductor-gate catalogue (idempotent / additive) ---- 56 let keys: *i64 = sys_mmap(8 * 4) as *i64 57 let vals: *i64 = sys_mmap(8 * 4) as *i64 58 keys[0] = "ki:ids" as *u8 as i64 59 vals[0] = "C-SEGV" as *u8 as i64 60 keys[1] = "ki:C-SEGV" as *u8 as i64 61 vals[1] = "C-SEGV\tTOOLCHAIN\tOPEN\tSIGSEGV\tnxasm-prologue-encoding-fix" as *u8 as i64 62 let nrec: i64 = 2 63 64 let w: *i64 = ss_begin() 65 var towrite: i64 = 0 66 var i: i64 = 0 67 while i < nrec { 68 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 } 69 i = i + 1 70 } 71 if towrite > 0 { 72 let segid: i64 = ki_seg_next_p(KICGATE_PREFIX) 73 ss_commit(KICGATE_PREFIX, w, segid) 74 } 75 76 let oid: *u8 = sys_mmap(64) 77 let orem: *u8 = sys_mmap(256) 78 let ostat: *u8 = sys_mmap(64) 79 80 let d_segv: *u8 = "engineer: child terminated by signal 11 SIGSEGV at canary step\n" as *u8 81 let d_novel: *u8 = "weird brand new failure zzqq-unseen-novel-9 nothing in the catalogue\n" as *u8 82 let d_tamp: *u8 = "engineer: child terminated by signal 11 SIGSEXV at canary step\n" as *u8 83 84 // G1: a give-up whose diagnostic matches a catalogued signature -> COND_SEEN + correct id 85 let v1: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_segv, cr_len(d_segv), oid, orem, ostat) 86 var g1: i64 = 0 87 if v1 == COND_SEEN { if cr_streq(oid, "C-SEGV" as *u8) == 1 { g1 = 1 } } 88 89 // G2: a give-up with a genuinely novel diagnostic -> stays COND_UNFIXABLE (honest) 90 let v2: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_novel, cr_len(d_novel), oid, orem, ostat) 91 var g2: i64 = 0 92 if v2 == COND_UNFIXABLE { g2 = 1 } 93 94 // G3: a NON-give-up verdict (clean) passes straight through -- recall never meddles 95 let v3: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_CLEAN, d_segv, cr_len(d_segv), oid, orem, ostat) 96 var g3: i64 = 0 97 if v3 == COND_CLEAN { g3 = 1 } 98 99 // G4: an arbitrary council verdict (99) passes through -- only COND_UNFIXABLE is special-cased 100 let v4: i64 = cond_recall_verdict(KICGATE_PREFIX, 99, d_segv, cr_len(d_segv), oid, orem, ostat) 101 var g4: i64 = 0 102 if v4 == 99 { g4 = 1 } 103 104 // G5 tamper: corrupt the signature in the diagnostic -> recall MISSES -> COND_UNFIXABLE (real match) 105 let v5: i64 = cond_recall_verdict(KICGATE_PREFIX, COND_UNFIXABLE, d_tamp, cr_len(d_tamp), oid, orem, ostat) 106 var g5: i64 = 0 107 if v5 == COND_UNFIXABLE { g5 = 1 } 108 109 var ok: i64 = 0 110 if g1 == 1 { if g2 == 1 { if g3 == 1 { if g4 == 1 { if g5 == 1 { ok = 1 } } } } } 111 112 cr_w(1, "CONDUCTOR-RECALL gate (recall wired into the give-up path)\n" as *u8) 113 cr_row(1, "G1 recall-rescues-giveup " as *u8, g1) 114 cr_row(1, "G2 honest-novel-unfixable" as *u8, g2) 115 cr_row(1, "G3 passthrough-clean " as *u8, g3) 116 cr_row(1, "G4 passthrough-council " as *u8, g4) 117 cr_row(1, "G5 tamper-miss " as *u8, g5) 118 if ok == 1 { cr_w(1, "verdict=GREEN\n" as *u8) } else { cr_w(1, "verdict=RED\n" as *u8) } 119 120 let lf: i64 = sys_openat_append(CR_LOG, 420) 121 if lf >= 0 { 122 cr_w(lf, "CONDUCTOR-RECALL authored=organ " as *u8) 123 if ok == 1 { cr_w(lf, "G1..G5=PASS verdict=GREEN\n" as *u8) } else { cr_w(lf, "verdict=RED\n" as *u8) } 124 sys_close(lf) 125 } 126 127 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 128 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 129 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 130 let ctr__dry: *i64 = gv_ctr() 131 ctr__dry[0] = ok 132 ctr__dry[1] = 1 133 let rc__dry: i64 = gv_verdict("CONDUCTOR-RECALL-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 134 sys_exit(rc__dry) 135 return rc__dry 136}