nx_gatelaw_gate.nx source
↩ module page · 595 lines · 32921 B
1// nx_gatelaw_gate.nx -- THE SESSION'S LAWS, MADE EXECUTABLE AND POINTED AT EVERY GATE IN THE ESTATE.
2//
3// WHY THIS EXISTS. Every law below was paid for with a real failure, written into a record, and then
4// RE-DERIVED days later because a record is something you have to remember to read. ★★★★★★ A LAW
5// THAT LIVES ONLY IN PROSE IS ADVICE, AND ADVICE IS ADOPTED AT ADVICE RATES; THE SAME LAW PLACED IN
6// THE PATH IS ADOPTED AT 100%. The estate already proved that with nx_memnew (a pre-flight that only
7// INFORMS survives; one that refuses gets disabled).
8//
9// So this is ADVISORY BY CONSTRUCTION: it names offenders, it does not block anyone. Its verdict is
10// bound to ITS OWN subject -- can it read the corpus -- and never to the fleet's condition, because a
11// permanent RED over thousands of legacy gates is noise, not a work order (the same call
12// nx_gatebuilt_gate made about stale_built).
13//
14// THE LAWS, each traceable to a measured failure:
15// L1 EXIT-CARRIES-VERDICT -- a gate that prints RED and returns 0 makes /api/gate_run report GREEN.
16// MEASURED 2026-08-07 on nx_dwline_roundtrip_gate: "passed 5/11
17// verdict=RED" served as exit_code=0 verdict=GREEN.
18// L2 HAS-NEGATIVE-CONTROL -- a suite of only positive teeth passes on a subject that does nothing.
19// MEASURED: nx_dwline_e2e_gate's no-g control is the only tooth that
20// would catch debug info becoming unconditional.
21// L3 INHERITS-BASE -- hand-rolled counters drift from the teeth that execute, producing
22// red-by-construction (passed 22/20) or silently-skipped teeth.
23// gv_check increments both, so declared == executed BY CONSTRUCTION.
24//
25// ★ MEASURED ON CODE, NOT ON PROSE: comments are STRIPPED before matching. A scanner that does not
26// skip comments measures the documentation -- that defect once made the whole estate inherit
27// "writer" from a comment in nx_syscalls.nx.
28//
29// ---------------------------------------------------------------------------------------------
30// 2026-08-07 CORRECTION -- L1 WAS MEASURING AN IDIOM AND CALLING IT A PROPERTY.
31//
32// The old predicate was a substring test for "return gv_verdict(" / "return gv_". A gate ending
33//
34// let rc: i64 = gv_verdict(name, ctr, note)
35// sys_exit(rc)
36//
37// carries the verdict to the process exit status MORE strongly than `return` does (sys_exit sets the
38// status unconditionally, and does not depend on what the runtime does with main's return value) --
39// and the old test called it an L1-VIOLATION. Measured: it falsely accused 13 gates written that
40// same day, whose author then read the offender list and believed it.
41// ★★★★★★ A DETECTOR NAMED FOR A SEMANTIC PROPERTY WHILE TESTING A SPELLING WILL ACCUSE THE
42// IDIOMS ITS AUTHOR DID NOT HAPPEN TO USE -- AND THOSE ACCUSATIONS READ EXACTLY LIKE FINDINGS.
43// A false accusation is strictly worse here than a miss: this organ's whole output is a worklist,
44// and a worklist with fabricated rows costs a reader the investigation of each one.
45//
46// L1 now resolves the ASSIGNED NAME at each `= gv_verdict(` site (stepping over the `: i64` type
47// annotation) and asks whether that exact name reaches `sys_exit(<name>)`. The two spellings are
48// counted SEPARATELY (l1_via_return / l1_via_sysexit) so the size of the correction is attributable
49// rather than folded silently into an improved-looking total.
50//
51// SECOND CORRECTION -- THE UNMEASURED MAJORITY IS NOW ITS OWN BUCKET. L1/L2 key on the gv_ pattern,
52// so they say NOTHING about gates that never inherit the base class. That was declared in prose here
53// and then misread anyway (as "3,125 gates exit 0 on RED"). It is now a printed counter,
54// hand_rolled_exit_UNMEASURED, with a partition check that it plus l3_ok equals scanned.
55// ★★★★★ UNKNOWN IS ITS OWN BUCKET -- AN UNMEASURED POPULATION FOLDED INTO A MEASURED ONE BECOMES
56// THE NUMBER SOMEBODY PLANS AGAINST.
57//
58// license_tier: ORIGINAL expect_exit: 0
59import "syscalls.nx"
60import "nx_gate_verdict.nx"
61
62const GL_SRC_CAP: i64 = 1048576
63const GL_MAXFILES: i64 = 4096
64const GL_NAMEBUF: i64 = 1048576
65const GL_MAXNAME: i64 = 256
66const GL_TMP: i64 = 4096
67
68func gl_read(path: *u8, buf: *u8, cap: i64) -> i64 {
69 let fd: i64 = sys_openat_rd(path)
70 if fd < 0 { return 0 - 1 }
71 var tot: i64 = 0
72 while tot < cap {
73 let n: i64 = sys_read(fd, (buf as i64 + tot) as *u8, cap - tot)
74 if n <= 0 { break }
75 tot = tot + n
76 }
77 sys_close(fd)
78 return tot
79}
80
81// Copy src->dst dropping // line comments. THE LOAD-BEARING STEP: without it this organ would report
82// on what gates SAY about themselves. Kept deliberately simple (no string-literal awareness) and that
83// limit is DECLARED: a "//" inside a string literal ends the line early, which can only ever cause a
84// FALSE MISS (under-reporting), never a false accusation. Failing toward silence is the right
85// direction for an advisory.
86func gl_strip(src: *u8, n: i64, dst: *u8) -> i64 {
87 var i: i64 = 0
88 var o: i64 = 0
89 while i < n {
90 if src[i] == (47 as u8) {
91 if i + 1 < n {
92 if src[i+1] == (47 as u8) {
93 while i < n { if src[i] == (10 as u8) { break } i = i + 1 }
94 }
95 }
96 }
97 if i < n { dst[o] = src[i]; o = o + 1; i = i + 1 }
98 }
99 return o
100}
101
102func gl_slen(p: *u8) -> i64 {
103 var m: i64 = 0
104 while p[m] != (0 as u8) { m = m + 1 }
105 return m
106}
107
108func gl_has(buf: *u8, n: i64, pat: *u8) -> i64 {
109 let m: i64 = gl_slen(pat)
110 if m == 0 { return 1 }
111 var i: i64 = 0
112 while i + m <= n {
113 var j: i64 = 0
114 var ok: i64 = 1
115 while j < m { if buf[i+j] != pat[j] { ok = 0; j = m } else { j = j + 1 } }
116 if ok == 1 { return 1 }
117 i = i + 1
118 }
119 return 0
120}
121
122func gl_find(buf: *u8, n: i64, pat: *u8, from: i64) -> i64 {
123 let m: i64 = gl_slen(pat)
124 if m == 0 { return 0 - 1 }
125 var i: i64 = from
126 while i + m <= n {
127 var j: i64 = 0
128 var ok: i64 = 1
129 while j < m { if buf[i+j] != pat[j] { ok = 0; j = m } else { j = j + 1 } }
130 if ok == 1 { return i }
131 i = i + 1
132 }
133 return 0 - 1
134}
135
136// Is `pat` present as CODE rather than as the contents of a string literal? Comment-stripping is not
137// enough: a scanner that searches source for "gv_verdict(" carries that exact text as a quoted
138// pattern, and a substring test then accuses the tool whose whole job is finding the thing.
139// MEASURED: nx_gatebuilt_gate was flagged by the first version of this very fix.
140// ★★★★★ A DETECTOR THAT SCANS SOURCE WILL FIND ITSELF, AND THEN FIND EVERY OTHER DETECTOR.
141// The test is deliberately one character wide -- a preceding double-quote -- because that is the
142// whole difference between a call and a mention, and a wider test would need a real parser.
143func gl_has_call(buf: *u8, n: i64, pat: *u8) -> i64 {
144 var from: i64 = 0
145 while from < n {
146 let at: i64 = gl_find(buf, n, pat, from)
147 if at < 0 { return 0 }
148 if at == 0 { return 1 }
149 if buf[at-1] != (34 as u8) { return 1 }
150 from = at + 1
151 }
152 return 0
153}
154
155func gl_is_ident(c: u8) -> i64 {
156 if c >= (48 as u8) { if c <= (57 as u8) { return 1 } }
157 if c >= (65 as u8) { if c <= (90 as u8) { return 1 } }
158 if c >= (97 as u8) { if c <= (122 as u8) { return 1 } }
159 if c == (95 as u8) { return 1 }
160 return 0
161}
162
163// Walk backwards over spaces and tabs. Returns the index of the first non-blank at or before k0,
164// or -1 if the scan ran off the front.
165func gl_bskip(code: *u8, k0: i64) -> i64 {
166 var k: i64 = k0
167 while k >= 0 {
168 if code[k] == (32 as u8) { k = k - 1 }
169 else { if code[k] == (9 as u8) { k = k - 1 } else { break } }
170 }
171 return k
172}
173
174// Does the verdict value reach the process exit status?
175// 0 = no
176// 1 = `return gv_verdict(...)` -- returned directly
177// 2 = `let X = gv_verdict(...)` then `return X` OR `sys_exit(X)` -- returned via a name
178// 3 = `sys_exit(gv_verdict(...))` -- nested, never named
179// Resolved by NAME, not by pattern: `sys_exit(0)` sitting beside a discarded gv_verdict() call must
180// NOT be credited, and the neg-control tooth below proves it is not.
181//
182// ⚠ THE FOUR SHAPES ABOVE WERE ENUMERATED FROM THE CORPUS, NOT IMAGINED. The first version of this
183// fix credited only `sys_exit(X)` because that was the idiom its author happened to write that day,
184// and it went on accusing 17 gates using `return X` and 3 using the nested form -- a SECOND round of
185// exactly the defect it was written to repair.
186// ★★★★★★ A RULER BUILT FROM THE IDIOMS YOU CAN RECALL MEASURES YOUR MEMORY, NOT THE POPULATION.
187// ENUMERATE WHAT IS ACTUALLY IN THE INPUT FIRST, AND THE SHAPE OF THE PREDICATE FALLS OUT OF IT.
188func gl_carries_verdict(code: *u8, cn: i64, tmp: *u8) -> i64 {
189 if gl_has(code, cn, "return gv_verdict(" as *u8) == 1 { return 1 }
190 if gl_has(code, cn, "return gv_" as *u8) == 1 { return 1 }
191 if gl_has(code, cn, "sys_exit(gv_verdict(" as *u8) == 1 { return 3 }
192
193 var pos: i64 = 0
194 while pos < cn {
195 let at: i64 = gl_find(code, cn, "gv_verdict(" as *u8, pos)
196 if at < 0 { break }
197 pos = at + 11
198
199 var k: i64 = gl_bskip(code, at - 1)
200 if k >= 0 {
201 if code[k] == (61 as u8) { // '='
202 k = gl_bskip(code, k - 1)
203 var e: i64 = k
204 while k >= 0 { if gl_is_ident(code[k]) == 1 { k = k - 1 } else { break } }
205 var s: i64 = k + 1
206
207 // `let rc: i64 = gv_verdict(...)` -- what we just read is the TYPE, and the name we
208 // want sits before the ':'. Without this step every site resolves to "i64" and the
209 // whole idiom goes uncredited, which is the original defect in a new costume.
210 let b: i64 = gl_bskip(code, k)
211 if b >= 0 {
212 if code[b] == (58 as u8) { // ':'
213 var k2: i64 = gl_bskip(code, b - 1)
214 e = k2
215 while k2 >= 0 { if gl_is_ident(code[k2]) == 1 { k2 = k2 - 1 } else { break } }
216 s = k2 + 1
217 }
218 }
219
220 if e >= s {
221 if (e - s) < (GL_TMP - 16) {
222 // Both consuming forms, because the corpus uses both: sys_exit(<name>) and
223 // return <name>. Checking only one is what produced the first false wave.
224 var form: i64 = 0
225 while form < 2 {
226 var pre: *u8 = "sys_exit(" as *u8
227 if form == 1 { pre = "return " as *u8 }
228 var o: i64 = 0
229 while pre[o] != (0 as u8) { tmp[o] = pre[o]; o = o + 1 }
230 var c2: i64 = s
231 while c2 <= e { tmp[o] = code[c2]; o = o + 1; c2 = c2 + 1 }
232 if form == 0 { tmp[o] = 41 as u8; o = o + 1 } // ')'
233 else { tmp[o] = 10 as u8; o = o + 1 } // newline: `return rc` ends its line
234 tmp[o] = 0 as u8
235 if gl_has(code, cn, tmp) == 1 { return 2 }
236 form = form + 1
237 }
238 }
239 }
240 }
241 }
242 }
243 return 0
244}
245
246// JOIN TWO FRAGMENTS INTO A NEEDLE THIS SOURCE NEVER SPELLS CONTIGUOUSLY.
247// The L4 axis below hunts for a call to the base class's value emitter. Spelling that needle as a plain
248// literal would make THIS FILE contain it, and the census would count itself -- measured on the day the
249// axis was written: L4 read 2 against a true population of 1. The comment stripper cannot save you, since
250// the needle would sit in code rather than in a comment. Joining two readable halves is deliberately
251// preferred over character codes: a literal spelled as numbers is the same defect in a disguise that no
252// human recognises and no grep finds.
253func gl_join2(dst: *u8, a: *u8, b: *u8) -> *u8 {
254 var i: i64 = 0
255 var p: i64 = 0
256 while a[i] != (0 as u8) { dst[p] = a[i]; p = p + 1; i = i + 1 }
257 i = 0
258 while b[i] != (0 as u8) { dst[p] = b[i]; p = p + 1; i = i + 1 }
259 dst[p] = 0 as u8
260 return dst
261}
262
263func gl_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } return p }
264// L5 POOL-EXIT (2026-09-17). A gate that creates a thread pool and ends with the raw thread exit never ends: the leader
265// retires, the workers stay parked in futex wait, the verdict is on disk and the process is a runaway nobody can stop
266// from any surface (two gates sat twenty minutes with fifteen threads each; seven shipping gates carried the shape).
267// The predicate reads the gate's OWN stripped source: pool = any pool-creating call present (nx_pool_submit, nf_pool,
268// mm_pool_i8, nsv_init), runaway = pool AND the raw exit present as a call. A pool created through an imported
269// library is invisible here, so the count is a FLOOR and says so. Returns 0 no pool, 1 pool and clean, 2 runaway.
270func gl_l5(code: *u8, cn: i64, np1: *u8, np2: *u8, np3: *u8, np4: *u8, nsx: *u8) -> i64 {
271 var pool: i64 = gl_has_call(code, cn, np1)
272 if pool == 0 { pool = gl_has_call(code, cn, np2) }
273 if pool == 0 { pool = gl_has_call(code, cn, np3) }
274 if pool == 0 { pool = gl_has_call(code, cn, np4) }
275 if pool == 0 { return 0 }
276 if gl_has_call(code, cn, nsx) == 1 { return 2 }
277 return 1
278}
279func gl_ends_gate_nx(nm: *u8, nl: i64) -> i64 {
280 // "<something>_gate.nx"
281 if nl < 12 { return 0 }
282 let suf: *u8 = "_gate.nx" as *u8
283 var k: i64 = 0
284 while k < 8 { if nm[nl-8+k] != suf[k] { return 0 } k = k + 1 }
285 return 1
286}
287
288func main(argc: i64, argv: *i64) -> i64 {
289 let ctr: *i64 = gv_ctr()
290 gv_head("=== NX-GATELAW -- are the estate's gates built the way its own failures taught? ===" as *u8)
291
292 sys_chdir("buildroot" as *u8)
293
294 var verbose: i64 = 0
295 if argc >= 2 { verbose = 1 }
296
297 let names: *u8 = sys_mmap(GL_NAMEBUF)
298 let noff: *i64 = sys_mmap(8 * (GL_MAXFILES + 8)) as *i64
299 var nfiles: i64 = 0
300 var npos: i64 = 0
301 var corpus_total: i64 = 0
302
303 // Both trees, because the build resolver probes runtime/_hdl_build FIRST and a census of only
304 // one of them would report on files the build may never read.
305 var dirn: i64 = 0
306 while dirn < 2 {
307 var dpath: *u8 = "runtime" as *u8
308 var pfx: *u8 = "runtime/" as *u8
309 var pfxlen: i64 = 8
310 if dirn == 1 { dpath = "runtime/_hdl_build" as *u8; pfx = "runtime/_hdl_build/" as *u8; pfxlen = 19 }
311 let dfd: i64 = __syscall(257, 0-100, dpath, 0x10000, 0, 0, 0)
312 if dfd >= 0 {
313 let dbuf: *u8 = sys_mmap(65536)
314 var go: i64 = 1
315 while go == 1 {
316 let nread: i64 = __syscall(217, dfd, dbuf, 65536, 0, 0, 0)
317 if nread <= 0 { go = 0 } else {
318 var pos: i64 = 0
319 while pos < nread {
320 let reclen: i64 = (dbuf[pos+16] as i64) | ((dbuf[pos+17] as i64) << 8)
321 var nl: i64 = 0
322 while dbuf[pos+19+nl] != (0 as u8) { nl = nl + 1 }
323 if gl_ends_gate_nx(((dbuf as i64) + pos + 19) as *u8, nl) == 1 {
324 corpus_total = corpus_total + 1
325 if nfiles < GL_MAXFILES {
326 if npos + nl + pfxlen + 4 < GL_NAMEBUF {
327 noff[nfiles] = npos
328 var c: i64 = 0
329 while c < pfxlen { names[npos] = pfx[c]; npos = npos + 1; c = c + 1 }
330 c = 0
331 while c < nl { names[npos] = dbuf[pos+19+c]; npos = npos + 1; c = c + 1 }
332 names[npos] = 0 as u8; npos = npos + 1
333 nfiles = nfiles + 1
334 }
335 }
336 }
337 if reclen <= 0 { pos = nread } else { pos = pos + reclen }
338 }
339 }
340 }
341 sys_close(dfd)
342 }
343 dirn = dirn + 1
344 }
345
346 let raw: *u8 = sys_mmap(GL_SRC_CAP)
347 let code: *u8 = sys_mmap(GL_SRC_CAP)
348 let tmp: *u8 = sys_mmap(GL_TMP)
349
350 // The L4 needles, assembled so this source never spells them contiguously (see gl_join2).
351 let nkv: *u8 = gl_join2(sys_mmap(64), "gv_" as *u8, "kv(" as *u8)
352 let nvh: *u8 = gl_join2(sys_mmap(64), "gv_values" as *u8, "_head(" as *u8)
353 // The asserting emitters count too: a tooth written with these publishes the number it tested, which
354 // is the whole point of the axis. Counting only the explicit printer would have made the cheapest and
355 // most reliable migration path invisible to the very census meant to drive it.
356 let nce: *u8 = gl_join2(sys_mmap(64), "gv_check" as *u8, "_eq(" as *u8)
357 let ncn: *u8 = gl_join2(sys_mmap(64), "gv_check" as *u8, "_near(" as *u8)
358 // The L5 needles, joined at runtime for the same reason: this file must not spell the raw exit or a pool call.
359 let np1: *u8 = gl_join2(sys_mmap(64), "nx_pool_" as *u8, "submit(" as *u8)
360 let np2: *u8 = gl_join2(sys_mmap(64), "nf_" as *u8, "pool(" as *u8)
361 let np3: *u8 = gl_join2(sys_mmap(64), "mm_pool_" as *u8, "i8(" as *u8)
362 let np4: *u8 = gl_join2(sys_mmap(64), "nsv_" as *u8, "init" as *u8)
363 let nsx: *u8 = gl_join2(sys_mmap(64), "sys_" as *u8, "exit(" as *u8)
364
365 var scanned: i64 = 0
366 var l1_ok: i64 = 0
367 var l1_ret: i64 = 0
368 var l1_via_name: i64 = 0
369 var l1_nested: i64 = 0
370 var discarded: i64 = 0
371 var l2_ok: i64 = 0
372 var l3_ok: i64 = 0
373 var all3: i64 = 0
374 var hand_rolled: i64 = 0
375 // L4 IS A SEPARATE AXIS AND IS DELIBERATELY NOT FOLDED INTO all3. A gate can satisfy all three older
376 // laws and still emit no number, so widening that conjunction would silently redefine a figure other
377 // lanes already act on. A new bucket that overlaps an existing partition gets declared separately.
378 var l4_ok: i64 = 0
379 var base_no_values: i64 = 0
380 // L5 IS A SEPARATE AXIS TOO: pool-creating gates, and those among them still ending with the raw thread exit.
381 var l5_pool: i64 = 0
382 var l5_runaway: i64 = 0
383
384 var fi: i64 = 0
385 while fi < nfiles {
386 let path: *u8 = ((names as i64) + noff[fi]) as *u8
387 let n: i64 = gl_read(path, raw, GL_SRC_CAP)
388 if n > 0 {
389 scanned = scanned + 1
390 let cn: i64 = gl_strip(raw, n, code)
391
392 // L3 first: it is the precondition for the other two being meaningful.
393 let base: i64 = gl_has(code, cn, "gv_check(" as *u8)
394 if base == 1 { l3_ok = l3_ok + 1 } else { hand_rolled = hand_rolled + 1 }
395
396 // L1: the verdict must REACH THE EXIT STATUS -- by return, by name, or nested in sys_exit.
397 let carry: i64 = gl_carries_verdict(code, cn, tmp)
398 var e1: i64 = 0
399 if carry > 0 { e1 = 1; l1_ok = l1_ok + 1 }
400 if carry == 1 { l1_ret = l1_ret + 1 }
401 if carry == 2 { l1_via_name = l1_via_name + 1 }
402 if carry == 3 { l1_nested = l1_nested + 1 }
403
404 // THE ACTIONABLE CLASS, and the only one worth a worklist row: the gate CALLS gv_verdict
405 // -- so it computed a verdict and printed it -- and then throws the value away. A gate
406 // with no gv_verdict call at all is simply outside L1's declared scope and must not be
407 // accused of anything; a scanner whose own source contains the literal "gv_verdict(" as a
408 // SEARCH PATTERN is the reason this is a call-shape test and not a substring test.
409 let calls_gv: i64 = gl_has_call(code, cn, "gv_verdict(" as *u8)
410 var discards: i64 = 0
411 if calls_gv == 1 { if carry == 0 { discards = 1; discarded = discarded + 1 } }
412
413 // L2: at least one tooth NAMED as a negative control. Naming is the honest proxy -- a
414 // machine cannot tell an assertion's polarity, but a gate author who wrote the word
415 // decided the tooth exists. REPORTED AS A NAMING CHECK, never as proof of coverage.
416 var e2: i64 = gl_has(code, cn, "neg-control" as *u8)
417 if e2 == 0 { e2 = gl_has(code, cn, "neg_control" as *u8) }
418 if e2 == 0 { e2 = gl_has(code, cn, "negative-control" as *u8) }
419 if e2 == 1 { l2_ok = l2_ok + 1 }
420
421 if base == 1 { if e1 == 1 { if e2 == 1 { all3 = all3 + 1 } } }
422
423 // L4: does this gate EMIT any measured value, or does it only assert PASS?
424 // A GATE THAT PRINTS ONLY PASS IS UNFALSIFIABLE FROM THE OUTSIDE. An arithmetic that cannot
425 // see a number can never contradict one, so a pass-only gate makes an independent SECOND
426 // METHOD CLASS structurally impossible -- and PROVEN requires two independent method classes.
427 // This axis measures the estate's exposure to that, which is how the whole fleet can read
428 // green while the estate-wide PROVEN ratio sits at zero.
429 var e4: i64 = gl_has(code, cn, nkv)
430 if e4 == 0 { e4 = gl_has(code, cn, nvh) }
431 if e4 == 0 { e4 = gl_has(code, cn, nce) }
432 if e4 == 0 { e4 = gl_has(code, cn, ncn) }
433 if e4 == 1 { l4_ok = l4_ok + 1 }
434 if base == 1 { if e4 == 0 { base_no_values = base_no_values + 1 } }
435 // L5: a gate that creates a pool must exit_group (gv_exit); the raw exit leaves its workers alive forever.
436 let e5: i64 = gl_l5(code, cn, np1, np2, np3, np4, nsx)
437 if e5 >= 1 { l5_pool = l5_pool + 1 }
438 if e5 == 2 {
439 l5_runaway = l5_runaway + 1
440 if verbose == 1 { gv_puts(" L5-VIOLATION pool-gate-ends-with-the-raw-thread-exit (gv_exit fixes it): " as *u8); gv_puts(path); gv_puts("\n" as *u8) }
441 }
442
443 if verbose == 1 {
444 // A COUNT WITHOUT A WORKLIST IS NOT ACTIONABLE. These gates are already on the base
445 // class, so one gv_kv call each is the whole remedy -- the cheap half of the exposure.
446 if base == 1 { if e4 == 0 {
447 gv_puts(" L4-VIOLATION emits-no-measured-value: " as *u8)
448 gv_puts(path); gv_puts("\n" as *u8)
449 } }
450 if discards == 1 {
451 gv_puts(" DISCARDS-VERDICT calls gv_verdict then returns a literal: " as *u8)
452 gv_puts(path); gv_puts("\n" as *u8)
453 }
454 }
455 }
456 fi = fi + 1
457 }
458
459 gv_puts("\n --- GATE-LAW CENSUS (whole corpus, both trees) ---\n" as *u8)
460 gv_puts(" gate_sources_found=" as *u8); gv_num(corpus_total)
461 gv_puts(" scanned=" as *u8); gv_num(scanned)
462 gv_puts(" declared_cap=" as *u8); gv_num(GL_MAXFILES); gv_puts("\n" as *u8)
463 gv_puts(" L3 inherits nx_gate_verdict (declared==executed by construction): " as *u8)
464 gv_num(l3_ok); gv_puts("\n" as *u8)
465 gv_puts(" L1 exit carries verdict: " as *u8)
466 gv_num(l1_ok); gv_puts(" [return gv_verdict " as *u8); gv_num(l1_ret)
467 gv_puts(" | via a name " as *u8); gv_num(l1_via_name)
468 gv_puts(" | nested in sys_exit " as *u8); gv_num(l1_nested); gv_puts("]\n" as *u8)
469 gv_puts(" DISCARDS-VERDICT (calls gv_verdict, throws the value away) -- THE WORKLIST: " as *u8)
470 gv_num(discarded); gv_puts("\n" as *u8)
471 gv_puts(" L2 names at least one negative control: " as *u8)
472 gv_num(l2_ok); gv_puts("\n" as *u8)
473 gv_puts(" ALL THREE: " as *u8)
474 gv_num(all3); gv_puts("\n" as *u8)
475 gv_puts(" hand_rolled_exit_UNMEASURED (no base class -- L1/L2 say NOTHING about these): " as *u8)
476 gv_num(hand_rolled); gv_puts("\n" as *u8)
477 gv_puts(" L4 emits at least one MEASURED VALUE (separate axis, NOT part of ALL THREE): " as *u8)
478 gv_num(l4_ok); gv_puts("\n" as *u8)
479 gv_puts(" L4 worklist -- on the base class and emitting nothing, one gv_kv call each (-v NAMES them): " as *u8)
480 gv_num(base_no_values); gv_puts("\n" as *u8)
481 gv_puts(" L5 creates a thread pool in its own source (a FLOOR: a pool made through an import is not seen): " as *u8)
482 gv_num(l5_pool); gv_puts("\n" as *u8)
483 gv_puts(" L5 worklist -- pool gates ending with the raw thread exit, runaways (-v NAMES them): " as *u8)
484 gv_num(l5_runaway); gv_puts("\n\n" as *u8)
485
486 // ---- BITE FIXTURES, assembled at runtime so this organ's own source cannot trip its scanner ----
487 // A green that never had a corresponding red is unverified, and the neg-control is the one that
488 // matters: crediting sys_exit(0) would make the fix worse than the defect it replaces.
489 let f_exit: *u8 = "let rc: i64 = gv_verdict(nm, ctr, note)\n sys_exit(rc)\n return rc\n" as *u8
490 let f_zero: *u8 = "let rc: i64 = gv_verdict(nm, ctr, note)\n sys_exit(0)\n return 0\n" as *u8
491 let f_ret: *u8 = " return gv_verdict(nm, ctr, note)\n" as *u8
492 let f_none: *u8 = " gv_num(passed)\n return 0\n" as *u8
493 let f_name: *u8 = "let rc: i64 = gv_verdict(nm, ctr, note)\n return rc\n" as *u8
494 let f_nest: *u8 = " sys_exit(gv_verdict(nm, ctr, note))\n return 0\n" as *u8
495 let f_disc: *u8 = " gv_verdict(nm, ctr, note)\n return 0\n" as *u8
496
497 let c_exit: i64 = gl_carries_verdict(f_exit, gl_slen(f_exit), tmp)
498 let c_zero: i64 = gl_carries_verdict(f_zero, gl_slen(f_zero), tmp)
499 let c_ret: i64 = gl_carries_verdict(f_ret, gl_slen(f_ret), tmp)
500 let c_none: i64 = gl_carries_verdict(f_none, gl_slen(f_none), tmp)
501 let c_name: i64 = gl_carries_verdict(f_name, gl_slen(f_name), tmp)
502 let c_nest: i64 = gl_carries_verdict(f_nest, gl_slen(f_nest), tmp)
503 let c_disc: i64 = gl_carries_verdict(f_disc, gl_slen(f_disc), tmp)
504 gv_puts(" fixtures: sys_exit(rc)=" as *u8); gv_num(c_exit)
505 gv_puts(" sys_exit(0)=" as *u8); gv_num(c_zero)
506 gv_puts(" return gv_verdict=" as *u8); gv_num(c_ret)
507 gv_puts(" neither=" as *u8); gv_num(c_none); gv_puts("\n" as *u8)
508
509 gv_check("sysexit-idiom-credited (this was a FALSE ACCUSATION before 2026-08-07)" as *u8,
510 (c_exit == 2) as i64, ctr)
511 gv_check("neg-control-sys_exit(0)-NOT-credited (the fix must not over-credit)" as *u8,
512 (c_zero == 0) as i64, ctr)
513 gv_check("incumbent-return-idiom-still-credited (no regression against the known good)" as *u8,
514 (c_ret == 1) as i64, ctr)
515 gv_check("neg-control-gate-with-neither-idiom-scores-zero" as *u8,
516 (c_none == 0) as i64, ctr)
517 gv_check("return-via-a-NAME credited (17 gates were falsely accused of exactly this)" as *u8,
518 (c_name == 2) as i64, ctr)
519 gv_check("nested sys_exit(gv_verdict(..)) credited (3 more falsely accused)" as *u8,
520 (c_nest == 3) as i64, ctr)
521 gv_check("neg-control-DISCARDED-verdict-STILL-caught (a fix that credits everything is worse)" as *u8,
522 (c_disc == 0) as i64, ctr)
523
524 // A quoted MENTION is not a CALL. Both directions, because this predicate decides whether a gate
525 // lands on the worklist, and the scanner-shaped gates are exactly the ones most likely to mention it.
526 let f_quoted: *u8 = " if gb_call_site(sbuf, sn, \"gv_verdict(\" as *u8) == 1 {\n" as *u8
527 let f_real: *u8 = " gv_verdict(nm, ctr, note)\n" as *u8
528 gv_check("neg-control-a-QUOTED-mention-of-gv_verdict-is-not-a-call" as *u8,
529 (gl_has_call(f_quoted, gl_slen(f_quoted), "gv_verdict(" as *u8) == 0) as i64, ctr)
530 gv_check("a real unquoted call IS still seen (the quote guard did not blind the check)" as *u8,
531 (gl_has_call(f_real, gl_slen(f_real), "gv_verdict(" as *u8) == 1) as i64, ctr)
532
533 // THE VERDICT IS ABOUT THIS ORGAN'S OWN SUBJECT, NOT THE FLEET'S CONDITION.
534 // A fleet-wide RED over legacy gates would be noise nobody can action; the CENSUS is the
535 // deliverable and the numbers above are the work order.
536 gv_check("corpus-enumerated-non-vacuously" as *u8, (scanned > 100) as i64, ctr)
537 gv_check("comment-stripper-shrinks-source" as *u8, (scanned > 0) as i64, ctr)
538 gv_check("neg-control-cap-not-silently-binding" as *u8, (corpus_total <= GL_MAXFILES) as i64, ctr)
539 gv_check("partition-sums: base-class + hand-rolled == scanned" as *u8,
540 ((l3_ok + hand_rolled) == scanned) as i64, ctr)
541
542 // ---- L4 FIXTURES, joined at runtime for the same reason the L1 fixtures are quoted ----
543 // The property that matters is that the needle matches a CONTIGUOUS occurrence only, so a file that
544 // merely mentions the two halves is never counted and a match can only come from a real call.
545 let fx: *u8 = sys_mmap(256)
546 let l4_joined: i64 = gl_has(gl_join2(fx, "xx " as *u8, "gv_kv( yy" as *u8), 12, nkv)
547 let l4_split: i64 = gl_has(gl_join2(fx, "xx gv_ " as *u8, "kv( yy" as *u8), 13, nkv)
548 gv_check("l4-needle-matches-a-contiguous-occurrence" as *u8, l4_joined, ctr)
549 gv_check("neg-control-l4-needle-is-SILENT-on-a-buffer-holding-only-the-split-halves" as *u8,
550 (l4_split == 0) as i64, ctr)
551 gv_check("neg-control-l4-detector-finds-a-real-emitter-so-a-zero-here-would-indict-the-scanner" as *u8,
552 (l4_ok >= 1) as i64, ctr)
553 gv_check("l4-worklist-is-a-subset-of-the-base-class-population" as *u8,
554 (base_no_values <= l3_ok) as i64, ctr)
555
556 // ---- L5 FIXTURES, joined at runtime: the predicate fires on a pool gate with the raw exit, stays silent on the
557 // exit_group form and on a raw exit with no pool, and a quoted mention of the raw exit is not a call ----
558 let f5: *u8 = sys_mmap(512)
559 var o5: i64 = 0
560 o5 = gl_cat(f5, o5, "let p = nf_" as *u8); o5 = gl_cat(f5, o5, "pool()\n let rc: i64 = gv_verdict(nm, ctr, note)\n sys_" as *u8); o5 = gl_cat(f5, o5, "exit(rc)\n" as *u8)
561 let l5_bad: i64 = gl_l5(f5, o5, np1, np2, np3, np4, nsx)
562 o5 = 0
563 o5 = gl_cat(f5, o5, "let p = nf_" as *u8); o5 = gl_cat(f5, o5, "pool()\n let rc: i64 = gv_verdict(nm, ctr, note)\n sys_" as *u8); o5 = gl_cat(f5, o5, "exit_group(rc)\n" as *u8)
564 let l5_good: i64 = gl_l5(f5, o5, np1, np2, np3, np4, nsx)
565 o5 = 0
566 o5 = gl_cat(f5, o5, "let rc: i64 = gv_verdict(nm, ctr, note)\n sys_" as *u8); o5 = gl_cat(f5, o5, "exit(rc)\n" as *u8)
567 let l5_nopool: i64 = gl_l5(f5, o5, np1, np2, np3, np4, nsx)
568 o5 = 0
569 o5 = gl_cat(f5, o5, "let p = nf_" as *u8); o5 = gl_cat(f5, o5, "pool()\n if gl_has(buf, n, \"sys_" as *u8); o5 = gl_cat(f5, o5, "exit(\" as *u8) == 1 { x = 1 }\n sys_" as *u8); o5 = gl_cat(f5, o5, "exit_group(rc)\n" as *u8)
570 let l5_quoted: i64 = gl_l5(f5, o5, np1, np2, np3, np4, nsx)
571 gv_check("l5-pool-gate-with-the-raw-exit-is-a-runaway" as *u8, (l5_bad == 2) as i64, ctr)
572 gv_check("neg-control-l5-pool-gate-with-exit_group-is-clean" as *u8, (l5_good == 1) as i64, ctr)
573 gv_check("neg-control-l5-raw-exit-without-a-pool-is-outside-the-axis" as *u8, (l5_nopool == 0) as i64, ctr)
574 gv_check("neg-control-l5-a-QUOTED-mention-of-the-raw-exit-is-not-a-call" as *u8, (l5_quoted == 1) as i64, ctr)
575 gv_check("l5-worklist-is-a-subset-of-the-pool-gates" as *u8, (l5_runaway <= l5_pool) as i64, ctr)
576 gv_check("neg-control-l5-detector-finds-a-real-pool-gate-so-a-zero-here-would-indict-the-scanner" as *u8, (l5_pool >= 1) as i64, ctr)
577
578 // EMIT THE CENSUS, because a census that only asserts PASS is exactly the defect L4 measures.
579 // Dogfooding is the point: this organ is the first consumer of the primitive it exists to count.
580 gv_values_head()
581 gv_kv("gate_sources_found" as *u8, corpus_total)
582 gv_kv("scanned" as *u8, scanned)
583 gv_kv("l3_inherits_base_class" as *u8, l3_ok)
584 gv_kv("l1_exit_carries_verdict" as *u8, l1_ok)
585 gv_kv("l2_names_a_negative_control" as *u8, l2_ok)
586 gv_kv("all_three" as *u8, all3)
587 gv_kv("hand_rolled_unmeasured" as *u8, hand_rolled)
588 gv_kv("l4_emits_a_measured_value" as *u8, l4_ok)
589 gv_kv("l4_worklist_base_class_but_silent" as *u8, base_no_values)
590 gv_kv("l5_pool_gates_floor" as *u8, l5_pool)
591 gv_kv("l5_runaway_exit_worklist" as *u8, l5_runaway)
592
593 return gv_verdict("nx_gatelaw_gate" as *u8, ctr,
594 "census only -- offenders are NAMED with -v and never blocked; a pre-flight that can refuse gets disabled, one that informs survives" as *u8)
595}