code wiki / _hdl_build / nx_recall_or_red_gate.nx
nx_recall_or_red_gate.nx source
↩ module page · 171 lines · 8312 B
1// nx_recall_or_red_gate.nx -- THE LOCK for the "recall-or-RED" guarantee (the no-unseen-repeat law).
2// Structural twin of the no-hang error-emit keystone: just as nx_netscope T2 proves every error PATH
3// emits a verdict within a deadline (never hangs), THIS proves every SEEN issue is RECALLED + ROUTED
4// to its remedy (never a silent "can't identify/fix this if we've seen it before"). A regression that
5// lets a catalogued signature go unrecognized turns this gate RED within one heartbeat.
6//
7// HERMETIC: the gate seeds its OWN test store (knowledge/store/kigate-) with controlled fixtures
8// (clearly T-* ids -- NOT production claims), so recall is exercised over MULTIPLE signatured rows
9// (proving a real DATA-driven table walk, not one hardcoded branch). Assertions:
10// T1 recall completeness : a diagnostic embedding row T-RKW's signature -> HIT, id=T-RKW
11// T2 route correctness : that hit routes to remedy nx_doctor_fix:doc_heal_token + status AUTO
12// T3 second-row recall : a diagnostic embedding row T-SEGV's signature -> HIT, id=T-SEGV
13// T4 neg-control : a genuinely novel diagnostic -> UNKNOWN (no rubber-stamp; UNFIXABLE
14// stays legal ONLY for truly-unseen issues -- twin of T5 no-false-positive)
15// T5 tamper : corrupt the matched signature in the diagnostic -> recall MISSES
16// (UNKNOWN) -- proves the match is a real substring, not a constant TRUE
17// (twin of BL-011 tamper discipline)
18// GREEN only if T1 .. T5 all hold. Evidence -> knowledge/status/recall_or_red.log. license_tier: ORIGINAL
19import "nx_known_issue_store.nx"
20import "nx_seg_store.nx"
21import "nx_syscalls.nx"
22import "nx_gate_verdict.nx"
23
24const RR_LOG: *u8 = "knowledge/status/recall_or_red.log"
25const KIGATE_PREFIX: *u8 = "knowledge/store/kigate-"
26
27func rr_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 }
28func rr_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
29
30// NUL-terminated byte-equality
31func rr_streq(a: *u8, b: *u8) -> i64 {
32 var i: i64 = 0
33 while a[i] != (0 as u8) {
34 if a[i] != b[i] { return 0 }
35 i = i + 1
36 }
37 if b[i] != (0 as u8) { return 0 }
38 return 1
39}
40
41// 1 if store value for key byte-equals val (idempotent seed helper)
42func rr_streq_store(key: *u8, val: *u8) -> i64 {
43 let pq: *i64 = sys_mmap(16) as *i64
44 let lq: *i64 = sys_mmap(16) as *i64
45 if ss_get(KIGATE_PREFIX, key, pq, lq) != 1 { return 0 }
46 let b: *u8 = pq[0] as *u8
47 let n: i64 = lq[0]
48 let vl: i64 = rr_len(val)
49 if n != vl { return 0 }
50 var i: i64 = 0
51 while i < n { if b[i] != val[i] { return 0 } i = i + 1 }
52 return 1
53}
54
55func rr_row(fd: i64, name: *u8, pass: i64) -> i64 {
56 rr_w(fd, " "); rr_w(fd, name)
57 if pass == 1 { rr_w(fd, " PASS\n" as *u8) } else { rr_w(fd, " FAIL\n" as *u8) }
58 return 0
59}
60
61func main() -> i64 {
62 // ---- seed the hermetic test store (idempotent / additive) ----
63 let keys: *i64 = sys_mmap(8 * 8) as *i64
64 let vals: *i64 = sys_mmap(8 * 8) as *i64
65 keys[0] = "ki:ids" as *u8 as i64
66 vals[0] = "T-RKW\tT-SEGV\tT-DISC" as *u8 as i64
67 keys[1] = "ki:T-RKW" as *u8 as i64
68 vals[1] = "T-RKW\tDIALECT\tAUTO\treserved keyword '\tnx_doctor_fix:doc_heal_token" as *u8 as i64
69 keys[2] = "ki:T-SEGV" as *u8 as i64
70 vals[2] = "T-SEGV\tTOOLCHAIN\tOPEN\tSIGSEGV\tnxasm-prologue-encoding-fix" as *u8 as i64
71 keys[3] = "ki:T-DISC" as *u8 as i64
72 vals[3] = "T-DISC\tMATH\tDISCIPLINE\t-\tmask-after-shift" as *u8 as i64
73 let nrec: i64 = 4
74
75 let w: *i64 = ss_begin()
76 var towrite: i64 = 0
77 var i: i64 = 0
78 while i < nrec {
79 if rr_streq_store(keys[i] as *u8, vals[i] as *u8) == 0 { ss_add(w, 1, keys[i] as *u8, vals[i] as *u8, rr_len(vals[i] as *u8)); towrite = towrite + 1 }
80 i = i + 1
81 }
82 if towrite > 0 {
83 let segid: i64 = ki_seg_next_p(KIGATE_PREFIX)
84 ss_commit(KIGATE_PREFIX, w, segid)
85 }
86
87 let outid: *u8 = sys_mmap(64)
88 let outrem: *u8 = sys_mmap(256)
89 let outstat: *u8 = sys_mmap(64)
90
91 // ---- T1: recall completeness -- a real-shaped reserved-keyword diagnostic must be RECALLED ----
92 let d_rkw: *u8 = "nx_parse: reserved keyword 'match' cannot be used as an identifier name\n" as *u8
93 let r1: i64 = ki_recall(KIGATE_PREFIX, d_rkw, rr_len(d_rkw), outid, outrem, outstat)
94 var t1: i64 = 0
95 if r1 == KI_HIT { if rr_streq(outid, "T-RKW" as *u8) == 1 { t1 = 1 } }
96
97 // ---- T2: route correctness -- the hit routes to the WIRED auto-fix + AUTO status ----
98 var t2: i64 = 0
99 if t1 == 1 {
100 if rr_streq(outrem, "nx_doctor_fix:doc_heal_token" as *u8) == 1 {
101 if rr_streq(outstat, "AUTO" as *u8) == 1 { t2 = 1 }
102 }
103 }
104
105 // ---- T3: second-row recall -- proves a DATA-driven walk, not a single hardcoded branch ----
106 let d_segv: *u8 = "engineer: child terminated by signal 11 SIGSEGV at canary step\n" as *u8
107 let r3: i64 = ki_recall(KIGATE_PREFIX, d_segv, rr_len(d_segv), outid, outrem, outstat)
108 var t3: i64 = 0
109 if r3 == KI_HIT { if rr_streq(outid, "T-SEGV" as *u8) == 1 { t3 = 1 } }
110
111 // ---- T4: neg-control -- a genuinely novel failure must be honest UNKNOWN (no rubber-stamp) ----
112 let d_novel: *u8 = "weird brand new failure zzqq-unseen-novel-9 nothing in the catalogue\n" as *u8
113 let r4: i64 = ki_recall(KIGATE_PREFIX, d_novel, rr_len(d_novel), outid, outrem, outstat)
114 var t4: i64 = 0
115 if r4 == KI_UNKNOWN { t4 = 1 }
116
117 // ---- T5: tamper -- break the matched signature in the diagnostic; recall MUST miss (real match) ----
118 let d_tamper: *u8 = "nx_parse: reserved keyworX 'match' cannot be used as an identifier name\n" as *u8
119 let r5: i64 = ki_recall(KIGATE_PREFIX, d_tamper, rr_len(d_tamper), outid, outrem, outstat)
120 var t5: i64 = 0
121 if r5 == KI_UNKNOWN { t5 = 1 }
122
123 // ---- T6: PRODUCTION recall -- a REAL measured diagnostic recalls from the LIVE ki- catalogue.
124 // Bridges the mechanism to production: goes RED if the CC-UNDEFFN row is ever dropped. The
125 // diagnostic is the exact byte-string nx_cc_sovereign emitted (measured 2026-06-14). ----
126 let d_undef: *u8 = "main:nx_parse: call to undefined function: frobnicate_undefined\n" as *u8
127 let r6: i64 = ki_recall(KI_PREFIX, d_undef, rr_len(d_undef), outid, outrem, outstat)
128 var t6: i64 = 0
129 if r6 == KI_HIT {
130 if rr_streq(outid, "CC-UNDEFFN" as *u8) == 1 {
131 if rr_streq(outrem, "nx_doctor_import:di_heal" as *u8) == 1 { t6 = 1 }
132 }
133 }
134
135 // flat pass-tally (avoids the LM-002 deep-nested-if landmine as the test count grows)
136 var passes: i64 = 0
137 if t1 == 1 { passes = passes + 1 }
138 if t2 == 1 { passes = passes + 1 }
139 if t3 == 1 { passes = passes + 1 }
140 if t4 == 1 { passes = passes + 1 }
141 if t5 == 1 { passes = passes + 1 }
142 if t6 == 1 { passes = passes + 1 }
143 var ok: i64 = 0
144 if passes == 6 { ok = 1 }
145
146 rr_w(1, "RECALL-OR-RED gate (no-unseen-repeat law)\n" as *u8)
147 rr_row(1, "T1 recall-completeness " as *u8, t1)
148 rr_row(1, "T2 route-correctness " as *u8, t2)
149 rr_row(1, "T3 second-row-recall " as *u8, t3)
150 rr_row(1, "T4 neg-control-unknown " as *u8, t4)
151 rr_row(1, "T5 tamper-miss " as *u8, t5)
152 rr_row(1, "T6 production-recall " as *u8, t6)
153 if ok == 1 { rr_w(1, "verdict=GREEN\n" as *u8) } else { rr_w(1, "verdict=RED\n" as *u8) }
154
155 let lf: i64 = sys_openat_append(RR_LOG, 420)
156 if lf >= 0 {
157 rr_w(lf, "RECALL-OR-RED authored=organ " as *u8)
158 if ok == 1 { rr_w(lf, "T1..T5=PASS verdict=GREEN\n" as *u8) } else { rr_w(lf, "verdict=RED\n" as *u8) }
159 sys_close(lf)
160 }
161
162 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
163 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
164 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
165 let ctr__dry: *i64 = gv_ctr()
166 ctr__dry[0] = ok
167 ctr__dry[1] = 1
168 let rc__dry: i64 = gv_verdict("RECALL-OR-RED-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
169 sys_exit(rc__dry)
170 return rc__dry
171}