code wiki / _hdl_build / nx_recall_or_red_gate.nx
nx_recall_or_red_gate.nx source
↩ module page · 163 lines · 7773 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"
22
23const RR_LOG: *u8 = "knowledge/status/recall_or_red.log"
24const KIGATE_PREFIX: *u8 = "knowledge/store/kigate-"
25
26func 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 }
27func rr_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
28
29// NUL-terminated byte-equality
30func rr_streq(a: *u8, b: *u8) -> i64 {
31 var i: i64 = 0
32 while a[i] != (0 as u8) {
33 if a[i] != b[i] { return 0 }
34 i = i + 1
35 }
36 if b[i] != (0 as u8) { return 0 }
37 return 1
38}
39
40// 1 if store value for key byte-equals val (idempotent seed helper)
41func rr_streq_store(key: *u8, val: *u8) -> i64 {
42 let pq: *i64 = sys_mmap(16) as *i64
43 let lq: *i64 = sys_mmap(16) as *i64
44 if ss_get(KIGATE_PREFIX, key, pq, lq) != 1 { return 0 }
45 let b: *u8 = pq[0] as *u8
46 let n: i64 = lq[0]
47 let vl: i64 = rr_len(val)
48 if n != vl { return 0 }
49 var i: i64 = 0
50 while i < n { if b[i] != val[i] { return 0 } i = i + 1 }
51 return 1
52}
53
54func rr_row(fd: i64, name: *u8, pass: i64) -> i64 {
55 rr_w(fd, " "); rr_w(fd, name)
56 if pass == 1 { rr_w(fd, " PASS\n" as *u8) } else { rr_w(fd, " FAIL\n" as *u8) }
57 return 0
58}
59
60func main() -> i64 {
61 // ---- seed the hermetic test store (idempotent / additive) ----
62 let keys: *i64 = sys_mmap(8 * 8) as *i64
63 let vals: *i64 = sys_mmap(8 * 8) as *i64
64 keys[0] = "ki:ids" as *u8 as i64
65 vals[0] = "T-RKW\tT-SEGV\tT-DISC" as *u8 as i64
66 keys[1] = "ki:T-RKW" as *u8 as i64
67 vals[1] = "T-RKW\tDIALECT\tAUTO\treserved keyword '\tnx_doctor_fix:doc_heal_token" as *u8 as i64
68 keys[2] = "ki:T-SEGV" as *u8 as i64
69 vals[2] = "T-SEGV\tTOOLCHAIN\tOPEN\tSIGSEGV\tnxasm-prologue-encoding-fix" as *u8 as i64
70 keys[3] = "ki:T-DISC" as *u8 as i64
71 vals[3] = "T-DISC\tMATH\tDISCIPLINE\t-\tmask-after-shift" as *u8 as i64
72 let nrec: i64 = 4
73
74 let w: *i64 = ss_begin()
75 var towrite: i64 = 0
76 var i: i64 = 0
77 while i < nrec {
78 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 }
79 i = i + 1
80 }
81 if towrite > 0 {
82 let segid: i64 = ki_seg_next_p(KIGATE_PREFIX)
83 ss_commit(KIGATE_PREFIX, w, segid)
84 }
85
86 let outid: *u8 = sys_mmap(64)
87 let outrem: *u8 = sys_mmap(256)
88 let outstat: *u8 = sys_mmap(64)
89
90 // ---- T1: recall completeness -- a real-shaped reserved-keyword diagnostic must be RECALLED ----
91 let d_rkw: *u8 = "nx_parse: reserved keyword 'match' cannot be used as an identifier name\n" as *u8
92 let r1: i64 = ki_recall(KIGATE_PREFIX, d_rkw, rr_len(d_rkw), outid, outrem, outstat)
93 var t1: i64 = 0
94 if r1 == KI_HIT { if rr_streq(outid, "T-RKW" as *u8) == 1 { t1 = 1 } }
95
96 // ---- T2: route correctness -- the hit routes to the WIRED auto-fix + AUTO status ----
97 var t2: i64 = 0
98 if t1 == 1 {
99 if rr_streq(outrem, "nx_doctor_fix:doc_heal_token" as *u8) == 1 {
100 if rr_streq(outstat, "AUTO" as *u8) == 1 { t2 = 1 }
101 }
102 }
103
104 // ---- T3: second-row recall -- proves a DATA-driven walk, not a single hardcoded branch ----
105 let d_segv: *u8 = "engineer: child terminated by signal 11 SIGSEGV at canary step\n" as *u8
106 let r3: i64 = ki_recall(KIGATE_PREFIX, d_segv, rr_len(d_segv), outid, outrem, outstat)
107 var t3: i64 = 0
108 if r3 == KI_HIT { if rr_streq(outid, "T-SEGV" as *u8) == 1 { t3 = 1 } }
109
110 // ---- T4: neg-control -- a genuinely novel failure must be honest UNKNOWN (no rubber-stamp) ----
111 let d_novel: *u8 = "weird brand new failure zzqq-unseen-novel-9 nothing in the catalogue\n" as *u8
112 let r4: i64 = ki_recall(KIGATE_PREFIX, d_novel, rr_len(d_novel), outid, outrem, outstat)
113 var t4: i64 = 0
114 if r4 == KI_UNKNOWN { t4 = 1 }
115
116 // ---- T5: tamper -- break the matched signature in the diagnostic; recall MUST miss (real match) ----
117 let d_tamper: *u8 = "nx_parse: reserved keyworX 'match' cannot be used as an identifier name\n" as *u8
118 let r5: i64 = ki_recall(KIGATE_PREFIX, d_tamper, rr_len(d_tamper), outid, outrem, outstat)
119 var t5: i64 = 0
120 if r5 == KI_UNKNOWN { t5 = 1 }
121
122 // ---- T6: PRODUCTION recall -- a REAL measured diagnostic recalls from the LIVE ki- catalogue.
123 // Bridges the mechanism to production: goes RED if the CC-UNDEFFN row is ever dropped. The
124 // diagnostic is the exact byte-string nx_cc_sovereign emitted (measured 2026-06-14). ----
125 let d_undef: *u8 = "main:nx_parse: call to undefined function: frobnicate_undefined\n" as *u8
126 let r6: i64 = ki_recall(KI_PREFIX, d_undef, rr_len(d_undef), outid, outrem, outstat)
127 var t6: i64 = 0
128 if r6 == KI_HIT {
129 if rr_streq(outid, "CC-UNDEFFN" as *u8) == 1 {
130 if rr_streq(outrem, "nx_doctor_import:di_heal" as *u8) == 1 { t6 = 1 }
131 }
132 }
133
134 // flat pass-tally (avoids the LM-002 deep-nested-if landmine as the test count grows)
135 var passes: i64 = 0
136 if t1 == 1 { passes = passes + 1 }
137 if t2 == 1 { passes = passes + 1 }
138 if t3 == 1 { passes = passes + 1 }
139 if t4 == 1 { passes = passes + 1 }
140 if t5 == 1 { passes = passes + 1 }
141 if t6 == 1 { passes = passes + 1 }
142 var ok: i64 = 0
143 if passes == 6 { ok = 1 }
144
145 rr_w(1, "RECALL-OR-RED gate (no-unseen-repeat law)\n" as *u8)
146 rr_row(1, "T1 recall-completeness " as *u8, t1)
147 rr_row(1, "T2 route-correctness " as *u8, t2)
148 rr_row(1, "T3 second-row-recall " as *u8, t3)
149 rr_row(1, "T4 neg-control-unknown " as *u8, t4)
150 rr_row(1, "T5 tamper-miss " as *u8, t5)
151 rr_row(1, "T6 production-recall " as *u8, t6)
152 if ok == 1 { rr_w(1, "verdict=GREEN\n" as *u8) } else { rr_w(1, "verdict=RED\n" as *u8) }
153
154 let lf: i64 = sys_openat_append(RR_LOG, 420)
155 if lf >= 0 {
156 rr_w(lf, "RECALL-OR-RED authored=organ " as *u8)
157 if ok == 1 { rr_w(lf, "T1..T5=PASS verdict=GREEN\n" as *u8) } else { rr_w(lf, "verdict=RED\n" as *u8) }
158 sys_close(lf)
159 }
160
161 if ok == 1 { return 0 }
162 return 1
163}