code wiki / _hdl_build / nx_gate_mutation_sweep.nx
nx_gate_mutation_sweep.nx source
↩ module page · 581 lines · 31636 B
1// nx_gate_mutation_sweep.nx -- BATCH mutation-scoring across the gate universe (the liar-killer worklist
2// engine for the sensor-gap program, [[project-nishi-sensor-gap-census-2026-07-14]]).
3//
4// usage: nx_gate_mutation_sweep <pair-budget> [mutants-per-pair] 0 = DRY RUN (list pairs only)
5//
6// DISCOVERY (mechanical, evidence-based -- the confirmed naming law): for every runtime/_hdl_build/
7// nx_X_gate.nx, the pair (subject=nx_X, gate=nx_X_gate) qualifies iff:
8// * subject nx_X.nx exists (in _hdl_build or runtime/)
9// * the gate actually IMPORTS the subject (runtime-built needle `import "nx_X.nx"`, quote bytes composed)
10// * the gate is not RISKY (listeners/network/bench markers), not build-only, not infra, not known-broken
11// (gatebase_*.tsv.refused marker)
12// For each qualifying pair (budget-bounded, resumable): fork the installed probe
13// _offc/nx_gate_mutation_probe.elf <subject> <gate> <mutants> -- it runs the identity control + evenly
14// spread ROR/AOR mutants and prints the mutation score. This sweep captures the probe output, parses the
15// LAST THREE ints (killed / total / survived), and BANKS:
16// knowledge/status/mutscore_<subject>.tsv subject \t gate \t killed \t total \t survived
17// knowledge/status/mutscore_<subject>.out the full probe transcript (survivor op+line = the worklist)
18// Ledger existence = resume-skip. SURVIVORS never fail the sweep -- they ARE the product (ranked
19// liar-killer worklist). Pipeline-RED pairs (identity fail etc.) are tallied as findings.
20// Never-brick: writes only mutscore_* ledgers/transcripts (+the probe's own archived copies).
21// Sovereign nx_cc->nxasm; CWD=nxc2 root. license_tier: ORIGINAL
22import "syscalls.nx"
23import "runtime.nx"
24import "nx_dirent.nx"
25import "nx_fcntl.nx"
26import "nx_handoff_gate.nx"
27import "nx_lease.nx" // singleton guard: concurrent sweeps corrupt each other via fixed scratch names
28import "nx_sov_ledger.nx"
29
30// The buildroot is the ONE directory that satisfies every dependency of this organ (the _offc build
31// runner, runtime/_hdl_build sources, and knowledge/{status,store,lease}). A NAMED const rather than an
32// inline literal, matching HC_CLOCK in nx_hostctl -- a bootstrap path cannot itself live in a config that
33// the bootstrap has to read in order to find its way.
34const MS_BUILDROOT: *u8 = "/volume1/homes/elderwesto/nishihost/buildroot" as *u8
35const K_MAGIC_3600: i64 = 3600
36const K_MAGIC_16384: i64 = 16384
37const K_MAGIC_1048576: i64 = 1048576
38const K_MAGIC_1024: i64 = 1024
39
40func ms_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
41
42func ms_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
43
44func ms_cat(dst: *u8, off: i64, s: *u8) -> i64 {
45 var i: i64 = 0
46 while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 }
47 return off + i
48}
49
50func ms_copyn(dst: *u8, src: *u8, n: i64) -> i64 {
51 var i: i64 = 0
52 while i < n { dst[i] = src[i]; i = i + 1 }
53 return 0
54}
55
56// render non-negative n into dst at off; returns new offset
57func ms_num(dst: *u8, off: i64, n: i64) -> i64 {
58 var m: i64 = n
59 if m < 0 { m = 0 }
60 let t: *u8 = sys_mmap(28)
61 var k: i64 = 0
62 if m == 0 { t[0] = 48 as u8; k = 1 }
63 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
64 var i: i64 = 0
65 while i < k { dst[off+i] = t[k-1-i]; i = i + 1 }
66 return off + k
67}
68
69// case-insensitive substring (needle lowercase)
70func ms_has_ci(buf: *u8, len: i64, ndl: *u8) -> i64 {
71 let nl: i64 = ms_slen(ndl)
72 if nl == 0 { return 1 }
73 var i: i64 = 0
74 while i + nl <= len {
75 var j: i64 = 0
76 var ok: i64 = 1
77 while j < nl {
78 if ms_lc(buf[i+j] as i64) != (ndl[j] as i64) { ok = 0; j = nl } else { j = j + 1 }
79 }
80 if ok == 1 { return 1 }
81 i = i + 1
82 }
83 return 0
84}
85
86// byte-exact find of NUL-terminated needle
87func ms_find(buf: *u8, len: i64, ndl: *u8) -> i64 {
88 let nl: i64 = ms_slen(ndl)
89 if nl == 0 { return 0 - 1 }
90 var i: i64 = 0
91 while i + nl <= len {
92 var j: i64 = 0
93 var ok: i64 = 1
94 while j < nl {
95 if buf[i+j] != ndl[j] { ok = 0; j = nl } else { j = j + 1 }
96 }
97 if ok == 1 { return i }
98 i = i + 1
99 }
100 return 0 - 1
101}
102
103func ms_read(path: *u8, buf: *u8, cap: i64) -> i64 {
104 let fd: i64 = sys_openat_rd(path)
105 if fd < 0 { return 0 - 1 }
106 var total: i64 = 0
107 var go: i64 = 1
108 while go == 1 {
109 go = 0
110 let tail: *u8 = ((buf as i64) + total) as *u8
111 let n: i64 = sys_read(fd, tail, cap - total)
112 if n > 0 { total = total + n; if total < cap { go = 1 } }
113 }
114 sys_close(fd)
115 return total
116}
117
118func ms_write(path: *u8, buf: *u8, len: i64) -> i64 {
119 let fd: i64 = sys_openat_wr(path, 0x1a4)
120 if fd < 0 { return 0 - 1 }
121 sys_write(fd, buf, len)
122 sys_close(fd)
123 return 0
124}
125
126// gate blind-run risk policy (same law as the baseline sweep)
127func ms_risky(name: *u8, nlen: i64, buf: *u8, len: i64) -> i64 {
128 if ms_has_ci(name, nlen, "daemon" as *u8) == 1 { return 1 }
129 if ms_has_ci(name, nlen, "serve" as *u8) == 1 { return 1 }
130 if ms_has_ci(name, nlen, "bench" as *u8) == 1 { return 1 }
131 if ms_has_ci(name, nlen, "monitor" as *u8) == 1 { return 1 }
132 if ms_has_ci(name, nlen, "watch" as *u8) == 1 { return 1 }
133 if ms_has_ci(buf, len, "sys_listen" as *u8) == 1 { return 1 }
134 if ms_has_ci(buf, len, "sys_bind" as *u8) == 1 { return 1 }
135 if ms_has_ci(buf, len, "sys_accept" as *u8) == 1 { return 1 }
136 if ms_has_ci(buf, len, "sys_connect" as *u8) == 1 { return 1 }
137 if ms_has_ci(buf, len, "https" as *u8) == 1 { return 1 }
138 if ms_has_ci(buf, len, "sys_sendto" as *u8) == 1 { return 1 }
139 if ms_has_ci(buf, len, "nxsecret" as *u8) == 1 { return 1 }
140 if ms_has_ci(buf, len, "--build-only" as *u8) == 1 { return 1 }
141 return 0
142}
143
144// fork the installed probe on one pair; probe stdout/err -> capture path; signal-aware rc
145func ms_run_probe(subject: *u8, gatename: *u8, mstr: *u8, capfile: *u8, envp: *i64) -> i64 {
146 let probe: *u8 = "_offc/nx_gate_mutation_probe.elf" as *u8
147 let ofd: i64 = sys_openat_wr(capfile, 0x1a4)
148 let av: *i64 = sys_mmap(8 * 6) as *i64
149 av[0] = probe as i64
150 av[1] = subject as i64
151 av[2] = gatename as i64
152 av[3] = mstr as i64
153 av[4] = 0
154 let pid: i64 = sys_fork()
155 if pid == 0 {
156 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) }
157 sys_execve(probe, av, envp)
158 sys_exit(127)
159 }
160 let st: *i64 = sys_mmap(16) as *i64
161 sys_wait4(pid, st, 0)
162 if ofd >= 0 { sys_close(ofd) }
163 let sig: i64 = st[0] & 0x7f
164 if sig != 0 { return 128 + sig }
165 return (st[0] >> 8) & 0xff
166}
167
168func main(argc: i64, argv: *i64) -> i64 {
169 // ---- SELF-LOCATE BEFORE ANYTHING ELSE (2026-08-01) ----
170 // Every path in this organ -- discovery, the forked probe at _offc/, the knowledge/ ledger AND the
171 // lease below -- resolves from cwd, and only buildroot/ satisfies all of them. That was fine while a
172 // human ran it by hand from the right directory, but it makes the organ UNSCHEDULABLE: the clock
173 // dispatches with argv[0]=path and no cwd control, from the nishihost root, where discovery finds
174 // zero pairs and this sweep (correctly) refuses. An organ that only works when launched by hand
175 // cannot be put on a beat, and a measurement nobody runs is not a measurement.
176 // So: locate our own root rather than depend on the caller's. Probe for runtime/_hdl_build and, if
177 // it is not here, chdir to the buildroot and re-probe. Fail-closed is preserved -- if neither works
178 // the existing [RED] refusal below still fires.
179 // ORDER IS LOAD-BEARING: this runs BEFORE ls_acquire, because the lease directory is itself
180 // cwd-relative (knowledge/lease/...). Acquiring first and chdir-ing after would take the lock in one
181 // directory and release it in another, leaking the lease for its full 3600s TTL.
182 // ⚠ THE DISCRIMINATOR MUST BE UNIQUE TO THE TARGET. My first attempt probed for runtime/_hdl_build
183 // and never fired, because that directory EXISTS AT BOTH the nishihost root and the buildroot -- my
184 // own dependency census had already recorded root: runtime=Y. Testing for something both candidates
185 // have answers no question. The runner is the one dependency ONLY buildroot carries (root's _offc/
186 // holds 261 files but not this one), which is exactly why buildroot is the correct cwd.
187 // LAW: A SELF-LOCATE PROBE MUST TEST FOR WHAT DISTINGUISHES THE TARGET, NOT MERELY FOR SOMETHING
188 // THE TARGET CONTAINS.
189 let sl_probe: i64 = nx_openat(NX_AT_FDCWD, "_offc/nx_sov_build_run.elf" as *u8, NX_O_RDONLY, 0)
190 if sl_probe < 0 {
191 sys_chdir(MS_BUILDROOT)
192 }
193 if sl_probe >= 0 { sys_close(sl_probe) }
194
195 // ---- SINGLETON LEASE (2026-08-01, debt 1785607895) ----
196 // I ran two of these concurrently by accident and they corrupted each other. The probe writes its
197 // mutants to FIXED filenames (runtime/_hdl_build/__mutprobe_lib.nx and __mutprobe_gate.nx), so two
198 // instances overwrite each other's mutant source in place and each may score a mutant the OTHER
199 // wrote. LAW: FIXED SCRATCH FILENAMES ARE A SINGLETON ASSERTION MADE SILENTLY -- writing to a
200 // constant path declares that only one instance may run, without saying so and without enforcing it.
201 // nx_lease already existed and nothing used it, the same unadopted primitive the clock ignores.
202 // ls_acquire returns 0 = ACQUIRED, 1 = held by another, -1 = error -- read from source, NOT assumed
203 // (it is the syscall convention, the inverse of the 1-means-success convention hc_promote_to uses).
204 // TTL is generous because a single pair can take minutes; a dead holder still frees the lane.
205 // OWNER MUST BE UNIQUE PER INSTANCE, NOT THE PROGRAM NAME. First attempt passed the constant
206 // "nx_gate_mutation_sweep" as owner; ls_acquire treats a lease held by the SAME owner as re-entrant,
207 // so the second concurrent sweep saw its own name on the lock and RE-ACQUIRED. The guard existed,
208 // created the lock dir, and let the duel through anyway.
209 // A NAME IS NOT AN IDENTITY -- the same law that made kill-by-name a noisy remedy and made the
210 // singleness gate miscount a forked keeper. Two processes of one program are two identities.
211 let ls_own: *u8 = sys_mmap(128)
212 var ls_oo: i64 = ls_cat(ls_own, 0, "mutsweep-" as *u8)
213 ls_oo = ls_catn(ls_own, ls_oo, ls_pid())
214 ls_own[ls_oo] = 0 as u8
215 let ls_hb: *u8 = sys_mmap(K_MAGIC_1024)
216 let ls_rc: i64 = ls_acquire("mutsweep" as *u8, ls_own, K_MAGIC_3600, ls_hb)
217 if ls_rc != 0 {
218 print("=== nx_gate_mutation_sweep: REFUSING -- another sweep holds the lease ===\n" as *u8)
219 print(" Two sweeps corrupt each other: the probe's scratch filenames are FIXED, so concurrent\n" as *u8)
220 print(" runs overwrite each other's mutant source and score mutants they did not write.\n" as *u8)
221 print(" Wait for the holder to finish, or release the lease if it is dead (TTL 3600s).\n" as *u8)
222 sys_exit(2)
223 return 2
224 }
225 var budget: i64 = 2
226 var mper: i64 = 4
227 if argc >= 2 {
228 let a: *u8 = argv[1] as *u8
229 var v: i64 = 0
230 var bi: i64 = 0
231 var sawdig: i64 = 0
232 while a[bi] != (0 as u8) {
233 let d: i64 = a[bi] as i64
234 if d >= 48 { if d <= 57 { v = v * 10 + (d - 48); sawdig = 1 } }
235 bi = bi + 1
236 }
237 if sawdig == 1 { budget = v }
238 }
239 if argc >= 3 {
240 let a2: *u8 = argv[2] as *u8
241 var v2: i64 = 0
242 var b2: i64 = 0
243 while a2[b2] != (0 as u8) {
244 let d2: i64 = a2[b2] as i64
245 if d2 >= 48 { if d2 <= 57 { v2 = v2 * 10 + (d2 - 48) } }
246 b2 = b2 + 1
247 }
248 if v2 > 0 { mper = v2 }
249 }
250 print("=== nx_gate_mutation_sweep: pair-budget=" as *u8)
251 print_i64(budget)
252 print(" mutants/pair=" as *u8)
253 print_i64(mper)
254 if budget == 0 { print(" (DRY RUN)" as *u8) }
255 print(" ===\n" as *u8)
256 // mutants-per-pair as string for probe argv
257 let mstr: *u8 = sys_mmap(16)
258 var mo: i64 = 0
259 var mm: i64 = mper
260 let mt: *u8 = sys_mmap(16)
261 var mk: i64 = 0
262 if mm == 0 { mt[0] = 48 as u8; mk = 1 }
263 while mm > 0 { mt[mk] = (48 + (mm % 10)) as u8; mm = mm / 10; mk = mk + 1 }
264 while mo < mk { mstr[mo] = mt[mk-1-mo]; mo = mo + 1 }
265 mstr[mo] = 0 as u8
266
267 let envp: *i64 = sys_mmap(8 * 4) as *i64
268 envp[0] = ("PATH=/usr/bin:/bin" as *u8) as i64
269 envp[1] = 0
270
271 // 2026-08-01 CWD, INVESTIGATED AND LEFT ALONE. I briefly rewrote these four paths to be
272 // ROOT-relative on the assumption that the root was the only cwd carrying knowledge/. THAT WAS
273 // WRONG and is reverted. Measured: buildroot/ carries ALL THREE dependencies -- _offc/nx_sov_build_run.elf
274 // (the root's _offc does NOT have it, despite holding 261 other files), runtime/_hdl_build, and
275 // knowledge/{status,store}. The root satisfies only two of the three. So BUILDROOT IS THE CORRECT
276 // CWD and this file was already self-consistent for it.
277 // The real defect was elsewhere: nx_offc_install wrote the forked probe into the ROOT's _offc/
278 // instead of buildroot/_offc/, so the sweep's fork got rc=127 NOT-FOUND and mislabelled it a
279 // PIPELINE-RED gate finding. Fix the INSTALL TARGET, not these paths.
280 // LAW: WHEN TWO COMPONENTS DISAGREE ON CWD, FIND WHICH DIRECTORY SATISFIES EVERY DEPENDENCY BEFORE
281 // REWRITING EITHER -- I changed the consumer when the producer was misplaced.
282 let dirp: *u8 = "runtime/_hdl_build" as *u8
283 let dfd: i64 = nx_openat(NX_AT_FDCWD, dirp, NX_O_RDONLY | NX_O_DIRECTORY, 0)
284 if dfd < 0 { print(" [RED] cannot open _hdl_build\n" as *u8); sys_exit(1); return 1 }
285 let dbuf: *u8 = sys_mmap(K_MAGIC_16384)
286 let dr_raw: *u8 = sys_mmap(NX_DIRENT_BYTES)
287 let dr: *NxDirent = dr_raw as *NxDirent
288
289 let cap: i64 = K_MAGIC_1048576
290 let gbuf: *u8 = sys_mmap(cap + 16)
291 let subject: *u8 = sys_mmap(256)
292 let gatename: *u8 = sys_mmap(256)
293 let path: *u8 = sys_mmap(K_MAGIC_1024)
294 let needle: *u8 = sys_mmap(512)
295 let ledger: *u8 = sys_mmap(K_MAGIC_1024)
296 let mkey: *u8 = sys_mmap(256)
297 let capfile: *u8 = "/tmp/mutsweep_probe.out" as *u8
298 let pcap: *u8 = sys_mmap(cap + 16)
299
300 var n_pairs: i64 = 0
301 var n_done: i64 = 0
302 var n_scored: i64 = 0
303 var n_pipefail: i64 = 0
304 var n_knownred: i64 = 0 // pairs skipped because a prior run banked them RED
305 let rkey_buf: *u8 = sys_mmap(256) // "red:<subject>" key into knowledge/store/mutred
306 var n_skip: i64 = 0
307 var n_remaining: i64 = 0
308 var tot_killed: i64 = 0
309 var tot_mut: i64 = 0
310 var tot_surv: i64 = 0
311 var att: i64 = 0
312 var shown_would: i64 = 0
313
314 var batch: i64 = nx_dirent_read(dfd, dbuf, K_MAGIC_16384)
315 while batch > 0 {
316 var off: i64 = 0
317 while off < batch {
318 let next_off: i64 = nx_dirent_iter(dbuf, off, batch, dr)
319 if next_off <= 0 { off = batch + 1 }
320 if off <= batch {
321 let nmlen: i64 = nx_dirent_name_len(dr)
322 // want names ending "_gate.nx" (8 chars)
323 var isg: i64 = 0
324 if nmlen > 8 {
325 let sfx: *u8 = "_gate.nx" as *u8
326 var si: i64 = 0
327 isg = 1
328 while si < 8 {
329 if dr.name[nmlen-8+si] != sfx[si] { isg = 0; si = 8 } else { si = si + 1 }
330 }
331 }
332 // ---- EXCLUDE THIS TOOL'S OWN SCRATCH (2026-08-01, debt 1785606069) ----
333 // nx_gate_mutation_probe writes its mutants as runtime/_hdl_build/__mutprobe_gate.nx,
334 // which ENDS IN _gate.nx and therefore matched the glob above. The probe was handing
335 // its own leftovers back to this sweep as a gate to score -- with whatever mutated
336 // content the previous run left behind. An instrument that writes into the directory
337 // it scans will eventually measure ITSELF.
338 // The probe's cleanup rename is the other defence, but it FAILED SILENTLY for months
339 // (its destination dir did not exist), so the two must be INDEPENDENT: prefix-skip here
340 // does not rely on cleanup working, and cleanup does not rely on this filter existing.
341 // Keying on the `__` PREFIX because the SUFFIX is what the glob matches -- naming the
342 // scratch with a leading __ was never enough on its own.
343 if nmlen > 2 {
344 if dr.name[0] == (95 as u8) {
345 if dr.name[1] == (95 as u8) { isg = 0 }
346 }
347 }
348 if isg == 1 {
349 // subject = name minus "_gate.nx"; gatename = name minus ".nx"
350 ms_copyn(subject, dr.name, nmlen - 8)
351 subject[nmlen-8] = 0 as u8
352 ms_copyn(gatename, dr.name, nmlen - 3)
353 gatename[nmlen-3] = 0 as u8
354
355 // subject source must exist (_hdl_build or runtime/)
356 var o: i64 = 0
357 o = ms_cat(path, o, "runtime/_hdl_build/" as *u8)
358 o = ms_cat(path, o, subject)
359 o = ms_cat(path, o, ".nx" as *u8)
360 path[o] = 0 as u8
361 var subj_ok: i64 = hg_evidence_file(path)
362 if subj_ok == 0 {
363 o = 0
364 o = ms_cat(path, o, "runtime/" as *u8)
365 o = ms_cat(path, o, subject)
366 o = ms_cat(path, o, ".nx" as *u8)
367 path[o] = 0 as u8
368 subj_ok = hg_evidence_file(path)
369 }
370 if subj_ok == 1 {
371 // read the GATE source for risk + import checks
372 o = 0
373 o = ms_cat(path, o, "runtime/_hdl_build/" as *u8)
374 o = ms_cat(path, o, gatename)
375 o = ms_cat(path, o, ".nx" as *u8)
376 path[o] = 0 as u8
377 let glen: i64 = ms_read(path, gbuf, cap)
378 if glen > 0 {
379 var skip: i64 = 0
380 if ms_risky(dr.name, nmlen, gbuf, glen) == 1 { skip = 1 }
381 // known-broken gate marker
382 if skip == 0 {
383 o = 0
384 o = ms_cat(ledger, o, "knowledge/status/gatebase_" as *u8)
385 o = ms_cat(ledger, o, gatename)
386 o = ms_cat(ledger, o, ".tsv.refused" as *u8)
387 ledger[o] = 0 as u8
388 if hg_evidence_file(ledger) == 1 { skip = 1 }
389 }
390 // gate must IMPORT the subject: needle import "<subject>.nx" (quote composed)
391 if skip == 0 {
392 o = 0
393 o = ms_cat(needle, o, "import " as *u8)
394 needle[o] = 34 as u8
395 o = o + 1
396 o = ms_cat(needle, o, subject)
397 o = ms_cat(needle, o, ".nx" as *u8)
398 needle[o] = 34 as u8
399 o = o + 1
400 needle[o] = 0 as u8
401 if ms_find(gbuf, glen, needle) < 0 { skip = 1 }
402 }
403 if skip == 1 { n_skip = n_skip + 1 }
404 if skip == 0 {
405 n_pairs = n_pairs + 1
406 // resume: SOVEREIGN mutscore record exists? (seg_store key mut:<subject>, NO tsv)
407 o = 0
408 o = ms_cat(mkey, o, "mut:" as *u8)
409 o = ms_cat(mkey, o, subject)
410 mkey[o] = 0 as u8
411 // ---- SKIP PAIRS ALREADY KNOWN UNSCOREABLE (2026-08-01) ----
412 // MEASURED DEFECT: scores were banked but PIPELINE-REDs were not, so every
413 // run re-attempted the same ~145 unscoreable pairs from the top of the
414 // alphabet and never reached new territory. A 30-round x 20-pair batch
415 // scored ZERO in 7 minutes -- it spent the whole time re-proving that
416 // nx_a11y_breadth through nx_aec still fail on correct code, which was
417 // already known and recorded.
418 // LAW: A RESUMABLE SWEEP MUST BANK ITS NEGATIVE RESULTS TOO. Remembering
419 // only successes means the unfinishable work is retried forever and the
420 // finishable work is never reached -- the sweep converges to a treadmill.
421 // Kept as a SEPARATE store from mutscore, deliberately: a pipeline-RED is
422 // NOT a score and must never be read as one. It also stays retryable --
423 // when the underlying gate is fixed and goes GREEN, delete its mutred row
424 // (or the store) and the pair re-enters the queue.
425 var rkey: i64 = 0
426 rkey = ms_cat(rkey_buf, 0, "red:" as *u8)
427 rkey = ms_cat(rkey_buf, rkey, subject)
428 rkey_buf[rkey] = 0 as u8
429 let have_red: i64 = sov_has("knowledge/store/mutred" as *u8, rkey_buf)
430 if have_red == 1 { n_knownred = n_knownred + 1 }
431
432 let have_mut: i64 = sov_has("knowledge/store/mutscore" as *u8, mkey)
433 if have_mut == 1 { n_done = n_done + 1 }
434 // Combined into ONE flag rather than nesting a second `if`, so the brace
435 // count of this block is UNCHANGED. Editing nested braces by hand in a
436 // 500-line function is how the D001 applier deleted a RED branch earlier
437 // today; the same caution applies to me.
438 var do_pair: i64 = 0
439 if have_mut == 0 { if have_red == 0 { do_pair = 1 } }
440 if do_pair == 1 {
441 if att < budget {
442 att = att + 1
443 print(" [pair " as *u8)
444 print_i64(att)
445 print("/" as *u8)
446 print_i64(budget)
447 print("] " as *u8)
448 print(subject)
449 print(" x " as *u8)
450 print(gatename)
451 print(" -> " as *u8)
452 let prc: i64 = ms_run_probe(subject, gatename, mstr, capfile, envp)
453 print("probe rc=" as *u8)
454 print_i64(prc)
455 let clen: i64 = ms_read(capfile, pcap, cap)
456 if prc != 0 {
457 n_pipefail = n_pipefail + 1
458 // BANK the negative result so the next run skips this pair
459 // instead of re-proving it. Value is the probe rc, which
460 // distinguishes a gate that FAILS on correct code (rc=1) from
461 // one that could not be built or run at all (rc=127).
462 let rv: *i64 = sys_mmap(16) as *i64
463 rv[0] = prc
464 sov_put_ints("knowledge/store/mutred" as *u8, rkey_buf, rv, 1)
465 print(" PIPELINE-RED (identity/needle) -> finding BANKED, no score\n" as *u8)
466 }
467 if prc == 0 {
468 // parse ALL ints; last three = killed / total / survived
469 let iv: *i64 = sys_mmap(8 * 256) as *i64
470 var nints: i64 = 0
471 if clen > 0 { nints = hg_parse_ints(pcap, clen, iv, 256) }
472 if nints >= 3 {
473 var st3: i64 = nints - 3
474 if nints > 256 { st3 = 256 - 3 }
475 let k: i64 = iv[st3]
476 let t: i64 = iv[st3+1]
477 let s: i64 = iv[st3+2]
478 tot_killed = tot_killed + k
479 tot_mut = tot_mut + t
480 tot_surv = tot_surv + s
481 n_scored = n_scored + 1
482 print("score " as *u8)
483 print_i64(k)
484 print("/" as *u8)
485 print_i64(t)
486 print(" survivors=" as *u8)
487 print_i64(s)
488 print("\n" as *u8)
489 // bank SOVEREIGN typed record [k,t,s] + transcript into seg_store (NO .tsv/.out side-car)
490 let kts: *i64 = sys_mmap(8 * 4) as *i64
491 kts[0] = k
492 kts[1] = t
493 kts[2] = s
494 sov_put_ints("knowledge/store/mutscore" as *u8, mkey, kts, 3)
495 if clen > 0 { sov_put("knowledge/store/mutscore_txt" as *u8, mkey, pcap, clen) }
496 if s > 0 { print(" *** SURVIVORS -> see transcript (liar-killer worklist)\n" as *u8) }
497 } else {
498 n_pipefail = n_pipefail + 1
499 print(" [unparseable probe output -> finding]\n" as *u8)
500 }
501 }
502 } else {
503 n_remaining = n_remaining + 1
504 if budget == 0 {
505 if shown_would < 20 {
506 print(" [pair] " as *u8)
507 print(subject)
508 print(" x " as *u8)
509 print(gatename)
510 print("\n" as *u8)
511 shown_would = shown_would + 1
512 }
513 }
514 }
515 }
516 }
517 }
518 }
519 }
520 off = next_off
521 }
522 }
523 batch = nx_dirent_read(dfd, dbuf, K_MAGIC_16384)
524 }
525 sys_close(dfd)
526
527 print("---- mutation-sweep tally ----\n" as *u8)
528 print(" qualifying pairs = " as *u8)
529 print_i64(n_pairs)
530 print(" (skipped risky/broken/no-import = " as *u8)
531 print_i64(n_skip)
532 print(")\n already scored = " as *u8)
533 print_i64(n_done)
534 print("\n known-RED (skipped) = " as *u8)
535 print_i64(n_knownred)
536 print(" (banked unscoreable; delete its knowledge/store/mutred row to retry after a fix)" as *u8)
537 print("\n scored this run = " as *u8)
538 print_i64(n_scored)
539 print(" (mutants " as *u8)
540 print_i64(tot_mut)
541 print(", killed " as *u8)
542 print_i64(tot_killed)
543 print(", SURVIVORS " as *u8)
544 print_i64(tot_surv)
545 print(")\n pipeline-RED pairs = " as *u8)
546 print_i64(n_pipefail)
547 print("\n remaining unscored = " as *u8)
548 print_i64(n_remaining)
549 // ---- NON-VACUITY TOOTH (2026-08-01): A SWEEP THAT SCANNED NOTHING IS NOT GREEN ----
550 // MEASURED DEFECT, not a hypothetical. Discovery walks runtime/_hdl_build/ CWD-RELATIVE. Run from
551 // the nishihost root -- where every other organ is launched -- it finds ZERO pairs and printed
552 // `verdict: GREEN` with sys_exit(0). Run from buildroot/ it finds hundreds. The fleet has 2192
553 // *_gate.nx under _hdl_build and 841 that import their subject by this tool's OWN documented rule,
554 // so "0 qualifying pairs" is never a true statement about the fleet -- it is the instrument
555 // reporting on its own cwd and calling it the world.
556 //
557 // This is the build-cwd-vs-run-cwd class that already cost a full redseen=0 investigation, and it
558 // FAILED OPEN: the one outcome that must never be silent is the one it chose.
559 // A sweep is only entitled to a verdict about the fleet if it SAW the fleet.
560 if n_pairs == 0 {
561 if n_done == 0 {
562 print("\n DISCOVERY FOUND ZERO PAIRS. This is almost certainly the CWD: discovery walks\n" as *u8)
563 print(" runtime/_hdl_build/ relative to the current directory, so it must be run from\n" as *u8)
564 print(" buildroot/ -- from the nishihost root it sees nothing.\n" as *u8)
565 print(" Reporting GREEN here would say 'no gate has a surviving mutant' when the truth is\n" as *u8)
566 print(" 'no gate was examined'. Those render identically to every rollup and mean opposite\n" as *u8)
567 print(" things, so this REFUSES instead.\n" as *u8)
568 print("=== verdict: RED (sweep measured NOTHING -- not a statement about the fleet) ===\n" as *u8)
569 ls_release("mutsweep" as *u8, ls_own)
570 sys_exit(3)
571 return 3
572 }
573 }
574 print("\n=== verdict: GREEN (sweep mechanics; survivors + pipeline-REDs above are FINDINGS) ===\n" as *u8)
575 // RELEASE ON EVERY EXIT. Acquire without release is HALF A FIX: the lease would survive its full
576 // 3600s TTL and refuse the next LEGITIMATE run for an hour. A guard that blocks correct work is a
577 // worse defect than the duel it prevents, and it would look exactly like the tool being broken.
578 ls_release("mutsweep" as *u8, ls_own)
579 sys_exit(0)
580 return 0
581}