code wiki / _hdl_build / nx_evidence_verdict_gate.nx
nx_evidence_verdict_gate.nx source
↩ module page · 248 lines · 12823 B
1// nx_evidence_verdict_gate.nx -- proves the shared evidence law (nx_evidence_verdict.nx) REFUSES every
2// defect it was built to kill, and still passes an honestly-earned claim.
3//
4// This gate is written to its own rule 4 (NON-VACUITY): every clause below has a NEGATIVE CONTROL that
5// makes it fire. A gate that only ever demonstrates PASS has measured nothing -- that is precisely the
6// defect this library outlaws, so this gate must not commit it. T1 is the real, measured production
7// regression, replayed as a test: it is the exact medbilling evidence record from 2026-07-30.
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_evidence_verdict.nx"
11import "nx_gate_verdict.nx"
12
13// D001 MIGRATION 2026-08-26: the verdict now comes from the shared base class, so this gate's outcome is
14// readable FROM OUTSIDE via its exit code (/api/gate_run) and it records a harness frame -- previously it
15// printed a perfect verdict line that nothing could consume. The hand-rolled fails[] counter survives only
16// to feed the legacy `fails=` line, which is this gate's public signature; gv_ctr is now the canonical
17// count, so a tooth that silently stops running can no longer read GREEN.
18// The counter is reached through file-scope state rather than a new ck() parameter on purpose: ck has 22
19// call sites, and a signature change is 22 chances to mistype a migration whose entire value is being
20// behaviour-neutral.
21static evg_ctr: i64
22
23func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
24func wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
25func ck(pass: i64, label: *u8, fails: *i64) -> i64 {
26 // gv_check emits the IDENTICAL ` <label>: PASS|FAIL` line, so ck no longer prints its own -- the first
27 // cut of this migration emitted every tooth TWICE. fails[] is still tallied here because the legacy
28 // `fails=` line is this gate's public signature and readers key on it.
29 if pass==0 { fails[0]=fails[0]+1 }
30 gv_check(label, pass, evg_ctr as *i64)
31 return 0
32}
33
34// build a fully-honest record: 5 of 5 gates green, fresh, provenanced, non-vacuous, triangulated.
35// Each test below then breaks EXACTLY ONE field and asserts the verdict degrades to the named state.
36func ev_seed_good(r: *i64, now: i64) -> i64 {
37 r[EV_R_GREEN] = 5
38 r[EV_R_RAN] = 5
39 r[EV_R_DECLARED] = 5
40 r[EV_R_EPOCH] = now - 60
41 r[EV_R_HOSTLEN] = 12
42 r[EV_R_DIGLEN] = 64
43 r[EV_R_REDSEEN] = 5
44 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_HUMAN
45 r[EV_R_DISSENT] = 0
46 return 0
47}
48
49func main() -> i64 {
50 let fails: *i64 = sys_mmap(16) as *i64
51 fails[0]=0
52 evg_ctr = gv_ctr() as i64
53 let now: i64 = 1785433876
54 let r: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
55 let p: *i64 = sys_mmap(EV_P_SLOTS*8) as *i64
56 p[EV_P_TTL] = 604800
57 p[EV_P_MINCLASSES] = 2
58 p[EV_P_REQHUMAN] = 0
59
60 w("=== nx_evidence_verdict_gate -- the evidence law refuses what it was built to refuse ===\n" as *u8)
61
62 // T0: the honest record PASSES. Without this the gate could refuse everything and look strict.
63 ev_seed_good(r, now)
64 var t0: i64=0
65 if ev_verdict(r, p, now)==EV_PROVEN { t0=1 }
66 ck(t0, "T0 fully-earned claim -> PROVEN (the law is accurate, not merely strict)" as *u8, fails)
67
68 // T1: THE MEASURED PRODUCTION REGRESSION, replayed. medbilling 2026-07-30: 5 gates declared, the old
69 // rule `liar_green = (green >= 1)` stamped ok=1 on a single green gate. Under the law: RED.
70 ev_seed_good(r, now)
71 r[EV_R_GREEN] = 1
72 var t1: i64=0
73 if ev_verdict(r, p, now)==EV_RED { t1=1 }
74 ck(t1, "T1 REGRESSION 1-of-5 gates green (the live medbilling record) -> RED, was PROVEN" as *u8, fails)
75
76 // T1b: the old rule, stated directly, to show this gate discriminates. `green>=1` accepts the very
77 // record the law rejects -- so T1 is a real behaviour change, not a restatement.
78 var t1b: i64=0
79 if (r[EV_R_GREEN] >= 1) == 1 { if ev_verdict(r, p, now) != EV_PROVEN { t1b=1 } }
80 ck(t1b, "T1b NEG-CONTROL: old rule green>=1 accepts this record; the law rejects it" as *u8, fails)
81
82 // T2: a gate that did not RUN cannot be counted. declared 5, ran 4, all 4 green -> RED, not 4/4 PROVEN.
83 ev_seed_good(r, now)
84 r[EV_R_RAN] = 4
85 r[EV_R_GREEN] = 4
86 var t2: i64=0
87 if ev_verdict(r, p, now)==EV_RED { t2=1 }
88 ck(t2, "T2 a declared gate that never ran -> RED (cannot shrink its own denominator)" as *u8, fails)
89
90 // T3: EXPIRY. The measured 13.7-day-old stamp (1183616s) against a 7-day TTL -> STALE, not PROVEN.
91 ev_seed_good(r, now)
92 r[EV_R_EPOCH] = now - 1183616
93 var t3: i64=0
94 if ev_verdict(r, p, now)==EV_STALE { t3=1 }
95 ck(t3, "T3 the live 1183616s-old stamp vs 7d TTL -> STALE (a verdict has an expiry)" as *u8, fails)
96
97 // T4: PROVENANCE. A v1 stamp carrying no host and no digest fails CLOSED -- no grandfathering.
98 ev_seed_good(r, now)
99 r[EV_R_HOSTLEN] = 0
100 r[EV_R_DIGLEN] = 0
101 var t4: i64=0
102 if ev_verdict(r, p, now)==EV_UNPROVEN { t4=1 }
103 ck(t4, "T4 legacy stamp with no host/digest -> UNPROVEN (fails closed, not grandfathered)" as *u8, fails)
104
105 // T5: NON-VACUITY. Gates that have never been observed RED have not been shown to measure anything.
106 ev_seed_good(r, now)
107 r[EV_R_REDSEEN] = 0
108 var t5: i64=0
109 if ev_verdict(r, p, now)==EV_VACUOUS { t5=1 }
110 ck(t5, "T5 gates never observed failing -> VACUOUS (coverage is not detection)" as *u8, fails)
111
112 // T5b: PARTIAL non-vacuity is still vacuity -- 4 of 5 proven-able-to-fail leaves one permanently green.
113 ev_seed_good(r, now)
114 r[EV_R_REDSEEN] = 4
115 var t5b: i64=0
116 if ev_verdict(r, p, now)==EV_VACUOUS { t5b=1 }
117 ck(t5b, "T5b 4-of-5 gates proven able to fail -> still VACUOUS" as *u8, fails)
118
119 // T6: AN LLM MAY NOT CONVICT. Model judgment alone, however confident, cannot reach PROVEN.
120 ev_seed_good(r, now)
121 r[EV_R_CLASSMASK] = EV_CLASS_LLM
122 var t6: i64=0
123 if ev_verdict(r, p, now)==EV_UNPROVEN { t6=1 }
124 ck(t6, "T6 LLM-only evidence -> UNPROVEN (a model corroborates, it never convicts)" as *u8, fails)
125
126 // T6b: LLM + HUMAN, two classes but NO mechanistic leg, is still not proof.
127 ev_seed_good(r, now)
128 r[EV_R_CLASSMASK] = EV_CLASS_LLM + EV_CLASS_HUMAN
129 var t6b: i64=0
130 if ev_verdict(r, p, now)==EV_UNPROVEN { t6b=1 }
131 ck(t6b, "T6b LLM+human with no mechanistic leg -> UNPROVEN (>=1 leg must be mechanistic)" as *u8, fails)
132
133 // T7: A SINGLE mechanistic method is one measurement, not a triangulation.
134 ev_seed_good(r, now)
135 r[EV_R_CLASSMASK] = EV_CLASS_MECH
136 var t7: i64=0
137 if ev_verdict(r, p, now)==EV_UNPROVEN { t7=1 }
138 ck(t7, "T7 mechanistic alone -> UNPROVEN (one method is a measurement, not a triangulation)" as *u8, fails)
139
140 // T8: DISAGREEMENT IS NOT AVERAGED. An independent method reporting FAIL is RED, outranking all else.
141 ev_seed_good(r, now)
142 r[EV_R_DISSENT] = EV_CLASS_HUMAN
143 var t8: i64=0
144 if ev_verdict(r, p, now)==EV_RED { t8=1 }
145 ck(t8, "T8 a dissenting method on an otherwise-perfect record -> RED (never averaged)" as *u8, fails)
146
147 // T9: the honesty ratio keeps an honest denominator -- 10 PROVEN of 40 domains is 250, not 1000.
148 var t9: i64=0
149 if ev_honesty_permil(10, 40)==250 { t9=1 }
150 ck(t9, "T9 honesty ratio 10 of 40 domains = 250 permil (the live measured number)" as *u8, fails)
151
152 // T10: clock skew (a stamp from the future) is refused, not treated as maximally fresh.
153 ev_seed_good(r, now)
154 r[EV_R_EPOCH] = now + 3600
155 var t10: i64=0
156 if ev_verdict(r, p, now)==EV_STALE { t10=1 }
157 ck(t10, "T10 stamp dated in the future -> STALE (skew is refused, not trusted)" as *u8, fails)
158
159 // T11: a domain declaring ZERO gates does not pass on an empty conjunction -- but it is UNPROVEN, not
160 // RED. Nothing ran, so nothing failed. RED is reserved for a method that reported failure.
161 ev_seed_good(r, now)
162 r[EV_R_DECLARED] = 0
163 r[EV_R_RAN] = 0
164 r[EV_R_GREEN] = 0
165 var t11: i64=0
166 if ev_verdict(r, p, now)==EV_UNPROVEN { t11=1 }
167 ck(t11, "T11 zero declared gates -> UNPROVEN (nothing ran, so nothing failed)" as *u8, fails)
168
169 // T11b: RED and UNPROVEN must be DISTINGUISHABLE, not merely both non-PROVEN. A domain whose gate ran
170 // and failed, and a domain with no gate at all, are different problems needing different work.
171 let rb: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
172 ev_seed_good(rb, now)
173 rb[EV_R_GREEN] = 2
174 var t11b: i64=0
175 if ev_verdict(rb, p, now)==EV_RED { if ev_verdict(r, p, now)==EV_UNPROVEN { t11b=1 } }
176 ck(t11b, "T11b a failed gate reads RED while a missing gate reads UNPROVEN (distinct diagnoses)" as *u8, fails)
177
178 // T11c/d/e: AN ABSTENTION IS NOT A DISSENT (2026-08-26). A gate that exits SKIP because a PRECONDITION
179 // was absent examined nothing, and this function's own doctrine says that is UNPROVEN territory, never
180 // RED. Counting it in the quorum convicted a live domain of failures nobody measured and blocked a
181 // deploy on gates whose own output says they must never do so.
182 // T11c and T11d are the DISCRIMINATING PAIR: the two records are identical in every field except
183 // skipped, so an implementation that ignores that field cannot pass both -- which is the only thing
184 // that distinguishes this law from a blanket weakening of the quorum.
185 let rsk: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
186 ev_seed_good(rsk, now)
187 rsk[EV_R_DECLARED] = 3
188 rsk[EV_R_RAN] = 3
189 rsk[EV_R_GREEN] = 1
190 rsk[EV_R_SKIPPED] = 2
191 var t11c: i64=0
192 if ev_verdict(rsk, p, now)!=EV_RED { t11c=1 }
193 ck(t11c, "T11c 1 green + 2 ABSTAINED of 3 -> not RED (an abstention is not a dissent)" as *u8, fails)
194
195 let rns: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
196 ev_seed_good(rns, now)
197 rns[EV_R_DECLARED] = 3
198 rns[EV_R_RAN] = 3
199 rns[EV_R_GREEN] = 1
200 rns[EV_R_SKIPPED] = 0
201 var t11d: i64=0
202 if ev_verdict(rns, p, now)==EV_RED { t11d=1 }
203 ck(t11d, "T11d neg-control-identical-record-without-the-abstention: 1 green of 3 -> RED (real dissent still convicts)" as *u8, fails)
204
205 let rall: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
206 ev_seed_good(rall, now)
207 rall[EV_R_DECLARED] = 3
208 rall[EV_R_RAN] = 3
209 rall[EV_R_GREEN] = 0
210 rall[EV_R_SKIPPED] = 3
211 var t11e: i64=0
212 if ev_verdict(rall, p, now)==EV_UNPROVEN { t11e=1 }
213 ck(t11e, "T11e neg-control-every-gate-abstained -> UNPROVEN: unobserved is never promotable to proven" as *u8, fails)
214
215 // T12: THE HUMAN LEG CANNOT BE SELF-GRANTED. With require_human on, mechanistic + model agreement is
216 // still not proof -- one agent can produce both in a single session, which is one opinion in two hats.
217 let ph: *i64 = sys_mmap(EV_P_SLOTS*8) as *i64
218 ph[EV_P_TTL] = 604800
219 ph[EV_P_MINCLASSES] = 2
220 ph[EV_P_REQHUMAN] = 1
221 ev_seed_good(r, now)
222 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_LLM
223 var t12: i64=0
224 if ev_verdict(r, ph, now)==EV_UNPROVEN { t12=1 }
225 ck(t12, "T12 mech+LLM under require_human -> UNPROVEN (an agent cannot certify its own work)" as *u8, fails)
226
227 // T12b: add the human row and the same record earns PROVEN -- the clause gates on the missing leg, it
228 // does not simply refuse everything.
229 ev_seed_good(r, now)
230 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_LLM + EV_CLASS_HUMAN
231 var t12b: i64=0
232 if ev_verdict(r, ph, now)==EV_PROVEN { t12b=1 }
233 ck(t12b, "T12b mech+LLM+human -> PROVEN (the third leg is what closes it)" as *u8, fails)
234
235 // T12c: the human leg does NOT excuse a missing mechanistic leg. Human+LLM is still two opinions.
236 ev_seed_good(r, now)
237 r[EV_R_CLASSMASK] = EV_CLASS_HUMAN + EV_CLASS_LLM
238 var t12c: i64=0
239 if ev_verdict(r, ph, now)==EV_UNPROVEN { t12c=1 }
240 ck(t12c, "T12c human+LLM without a mechanistic leg -> UNPROVEN (opinions are not measurements)" as *u8, fails)
241
242 w(" fails=" as *u8); wn(fails[0]); w("\n" as *u8)
243 // The rich domain line is KEPT and the canonical verdict is APPENDED after it, never instead of it:
244 // the shared judge anchors on the LAST line by position, so both readers are served and neither has to
245 // learn a second spelling of success.
246 if fails[0]==0 { w("VERDICT: verdict=GREEN (evidence law: quorum, expiry, provenance, non-vacuity, triangulation -- each negative-controlled)\n" as *u8) } else { w("VERDICT: verdict=RED\n" as *u8) }
247 return gv_verdict("evidence_law" as *u8, evg_ctr as *i64, "every clause of the shared evidence law negative-controlled, including that an ABSTENTION is not a dissent and that all-abstained is UNPROVEN rather than RED" as *u8)
248}