code wiki / _hdl_build / nx_compare_rank_gate.nx
nx_compare_rank_gate.nx source
↩ module page · 489 lines · 27438 B
1// nx_compare_rank_gate.nx -- THE LIAR-KILLER ON THE RANKER (operator 2026-08-18: "validate it ... if some
2// stupid shit like your made up magic numbers come into the system or any other stupid blockers happen
3// the team can overcome the blocker ... a liar killer extraordinaire ... not allowing you to build shitty
4// clay and polish it and call it sota").
5//
6// A ranker that cannot be refused is another authoritative number nobody audits. This gate makes every
7// failure class the operator named UNPASSABLE in silence, and every RED prints the UNBLOCK ACTION so a
8// team member acts without the seat that caused it:
9// T1 NO CHOSEN COEFFICIENTS: nx_law_warden countfile on the ranker's own source must be 0 inline
10// magic. A seat that smuggles a constant back in turns this RED before the ranking is trusted.
11// T2 GRAPHICS VALIDATION: on the REAL graphics board the top critical-path rung must be the referee
12// panel (cjc_panel) -- the pre-declared Phase-0 gate: nothing above it is measurable without it.
13// A wrong first pick means the mathematics regressed. (Runs the live ranker on the live board.)
14// T3 CLAY-POLISH REFUSAL: on the fixture, a rung whose row shows EVERY rival LEADING (the field is
15// lapping us -- catch-up gap) must rank ABOVE an equal-cost rung nobody has (the exceed lane) --
16// polishing a lead while the field laps you on fundamentals is the clay-polish failure by name.
17// (CoD makes this true: leading/rivals=1 doubles the value.)
18// T4 DERIVATION FIRES: fixture rungs with est=- print UNESTIMATED; two rungs on one organ print
19// cluster=2; enablement counts a dependency root ABOVE its dependents. Anti-vacuity: the derivation
20// is proven to move numbers, not just to print names.
21// T5 SPONSOR BITES BOTH WAYS: a minus2 sponsor row on the fixture domain LOWERS the affected rung's
22// priority versus the run without it, and the run names the row -- a plane write that cannot move
23// the number means the term is dead. neg-control-sponsor-absent = the run without the row.
24// T6 THE RANKER COUNTS ITSELF: done + open == rungs on the summary line (partition sums), else RED.
25// T7 SUMMARY CARRIES THE RULE: the published rule line names WSJF+real-options+dep-graph -- a
26// ranker whose printed rule drifts from its header is a lie with a trusted byline.
27// Fixture is assembled at RUNTIME (never checked in: a detector that scans source would find its own
28// fixture). The ranker reads buildroot/knowledge/compare/<dom>.* by construction, so the fixture domain
29// `rankgatefx` is written THERE and REMOVED at the end -- and it is harmless on any early-exit path:
30// no regen.list row names it, so no page can ever emit it, and the fixture sponsor row is closed.
31// license_tier: ORIGINAL No hw writes (Rule 26).
32import "nx_syscalls.nx"
33import "nx_tool_run.nx"
34import "nx_gate_verdict.nx"
35
36const RG_CAP: i64 = 262144
37const RG_TIMEOUT_MS: i64 = 240000
38const RG_FX_DOM: *u8 = "rankgatefx"
39const RG_FX_PLAN: *u8 = "buildroot/knowledge/compare/rankgatefx.plan"
40const RG_FX_MATRIX: *u8 = "buildroot/knowledge/compare/rankgatefx.matrix"
41const RG_RANKER: *u8 = "./nx_compare_rank.elf"
42const RG_RANKER_BUILD: *u8 = "./buildroot/_build/nx_compare_rank.sov.elf"
43const RG_RANKER_STAGED: *u8 = "./nx_compare_rank.sov.elf.new"
44static rg_announced: i64 = 0
45const RG_MODE_RW: i64 = 420
46
47func rg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
48func rg_has(hay: *u8, hlen: i64, needle: *u8) -> i64 {
49 let nl: i64 = rg_slen(needle)
50 if nl == 0 { return 0 }
51 var i: i64 = 0
52 while i + nl <= hlen {
53 var k: i64 = 0
54 var same: i64 = 1
55 while k < nl { if hay[i+k] != needle[k] { same = 0; k = nl } k = k + 1 }
56 if same == 1 { return 1 }
57 i = i + 1
58 }
59 return 0
60}
61// position of needle in hay, or -1
62func rg_find(hay: *u8, hlen: i64, needle: *u8, from: i64) -> i64 {
63 let nl: i64 = rg_slen(needle)
64 var i: i64 = from
65 while i + nl <= hlen {
66 var k: i64 = 0
67 var same: i64 = 1
68 while k < nl { if hay[i+k] != needle[k] { same = 0; k = nl } k = k + 1 }
69 if same == 1 { return i }
70 i = i + 1
71 }
72 return 0 - 1
73}
74// integer immediately after needle's first occurrence, or -1
75func rg_int_after(hay: *u8, hlen: i64, needle: *u8) -> i64 {
76 let p: i64 = rg_find(hay, hlen, needle, 0)
77 if p < 0 { return 0 - 1 }
78 var j: i64 = p + rg_slen(needle)
79 var v: i64 = 0
80 var any: i64 = 0
81 var go: i64 = 1
82 while go == 1 { if j < hlen { let c: i64 = hay[j] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); any = 1; j = j + 1 } else { go = 0 } } else { go = 0 } } else { go = 0 } }
83 if any == 0 { return 0 - 1 }
84 return v
85}
86// priority printed for a rung id: find " <id> priority=" and read the number
87func rg_pri_of(out: *u8, olen: i64, rid: *u8) -> i64 {
88 let key: *u8 = sys_mmap(128)
89 var o: i64 = 0
90 key[o] = 32 as u8; o = o + 1
91 var i: i64 = 0
92 while rid[i] != (0 as u8) { key[o] = rid[i]; o = o + 1; i = i + 1 }
93 let sfx: *u8 = " priority=" as *u8
94 i = 0
95 while sfx[i] != (0 as u8) { key[o] = sfx[i]; o = o + 1; i = i + 1 }
96 key[o] = 0 as u8
97 return rg_int_after(out, olen, key)
98}
99// rank position (#N) of a rung id, or -1
100func rg_rank_of(out: *u8, olen: i64, rid: *u8) -> i64 {
101 let key: *u8 = sys_mmap(128)
102 var o: i64 = 0
103 key[o] = 32 as u8; o = o + 1
104 var i: i64 = 0
105 while rid[i] != (0 as u8) { key[o] = rid[i]; o = o + 1; i = i + 1 }
106 let sfx: *u8 = " priority=" as *u8
107 i = 0
108 while sfx[i] != (0 as u8) { key[o] = sfx[i]; o = o + 1; i = i + 1 }
109 key[o] = 0 as u8
110 let p: i64 = rg_find(out, olen, key, 0)
111 if p < 0 { return 0 - 1 }
112 // walk back to "#"
113 var b: i64 = p
114 while b > 0 { if out[b] == (35 as u8) { break } b = b - 1 }
115 if out[b] != (35 as u8) { return 0 - 1 }
116 var j: i64 = b + 1
117 var v: i64 = 0
118 var go: i64 = 1
119 while go == 1 { if j < olen { let c: i64 = out[j] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); j = j + 1 } else { go = 0 } } else { go = 0 } } else { go = 0 } }
120 return v
121}
122func rg_write(path: *u8, body: *u8) -> i64 {
123 let fd: i64 = sys_openat_wr(path, RG_MODE_RW)
124 if fd < 0 { return 0 - 1 }
125 sys_write(fd, body, rg_slen(body))
126 sys_close(fd)
127 return 0
128}
129func rg_run(dom: *u8, out: *u8, olen: *i64) -> i64 {
130 let av: *i64 = sys_mmap(8 * 4) as *i64
131 av[0] = RG_RANKER as i64
132 av[1] = dom as i64
133 av[2] = 0
134 olen[0] = 0
135 // PROVE THE CANDIDATE, NOT THE INCUMBENT (measured 2026-08-18: the ship loop staged a fixed ranker,
136 // this gate ran the LIVE one, T7 read the old rule line and refused the promote that would have
137 // fixed it -- a gate that tests the incumbent can never approve the change that repairs it).
138 // Order: staged .new (what /api/promote will install) > _build twin > promoted. Announced once.
139 var pick: *u8 = RG_RANKER_STAGED
140 var pr: i64 = sys_openat_rd(pick)
141 if pr >= 0 { sys_close(pr) } else {
142 pick = RG_RANKER_BUILD; pr = sys_openat_rd(pick)
143 if pr >= 0 { sys_close(pr) } else { pick = RG_RANKER }
144 }
145 if rg_announced == 0 { gv_puts(" subject=" as *u8); gv_puts(pick); gv_puts(" (staged > _build > promoted)\n" as *u8); rg_announced = 1 }
146 av[0] = pick as i64
147 tr_run_capture_to(pick, av, out, RG_CAP - 1, olen, RG_TIMEOUT_MS)
148 return olen[0]
149}
150
151
152// ---- T9 FLEET RUNG-ID UNIQUENESS (added 2026-09-03 after the defect was committed by a seat) ----
153// A .plan may carry two rungs with the SAME id and nothing refuses it: the board accepts the append, and
154// the ranker -- which resolves a rung by scanning until it matches -- reads WHICHEVER COMES FIRST. That is
155// the coin-flip-wearing-a-schema defect organ_kind.conf was caught with, arriving on the board the whole
156// estate plans against. MEASURED: a seat appended rung LN37 while another lane's LN37 (the f64 ordered
157// compare) had landed the same day, and four log rows under LN36 while LN36 belonged to the decimal-exponent
158// rung; both were accepted in silence and found only by grepping afterwards.
159// SCOPE IS WITHIN A FILE, deliberately: two domains may reuse a number (LN1 and GR1 are different rungs),
160// but two rungs in ONE plan sharing an id is unambiguously wrong and is what the ranker cannot resolve.
161// It NAMES every offender -- a count without a worklist is not actionable -- and RATCHETS against a
162// self-baselining floor, so introducing it cannot turn the estate's headline board red on day one.
163const RGD_DIR: *u8 = "buildroot/knowledge/compare"
164const RGD_BASE: *u8 = "knowledge/status/rungid_dup.conf"
165const RGD_DBUF: i64 = 65536
166const RGD_MAXID: i64 = 1024
167const RGD_IDLEN: i64 = 24
168const RGD_DENT_NAME_OFF: i64 = 19 // getdents64: d_ino 8 + d_off 8 + d_reclen 2 + d_type 1
169const RGD_DENT_RECLEN_OFF: i64 = 16
170
171func rgd_slen(a: *u8) -> i64 { var n: i64 = 0; while a[n] != (0 as u8) { n = n + 1 } return n }
172func rgd_cat(d: *u8, p: i64, src: *u8) -> i64 { var i: i64 = 0; while src[i] != (0 as u8) { d[p + i] = src[i]; i = i + 1 } d[p + i] = 0 as u8; return p + i }
173func rgd_ends_plan(nm: *u8) -> i64 {
174 let n: i64 = rgd_slen(nm)
175 if n < 5 { return 0 }
176 if nm[n-5] != (46 as u8) { return 0 }
177 if nm[n-4] != (112 as u8) { return 0 }
178 if nm[n-3] != (108 as u8) { return 0 }
179 if nm[n-2] != (97 as u8) { return 0 }
180 if nm[n-1] != (110 as u8) { return 0 }
181 return 1
182}
183// ids are stored fixed-width so a compare is a byte loop with no allocation
184func rgd_id_eq(tbl: *u8, k: i64, id: *u8, idn: i64) -> i64 {
185 let base: i64 = k * RGD_IDLEN
186 var i: i64 = 0
187 while i < idn { if tbl[base + i] != id[i] { return 0 } i = i + 1 }
188 if idn < RGD_IDLEN { if tbl[base + idn] != (0 as u8) { return 0 } }
189 return 1
190}
191// scan ONE plan; appends " DUP <file> <id>" lines to rep and returns the number of duplicate ids found
192func rgd_scan_plan(dirp: *u8, nm: *u8, rep: *u8, repos: *i64, repcap: i64) -> i64 {
193 let path: *u8 = sys_mmap(1024)
194 var po: i64 = rgd_cat(path, 0, dirp)
195 po = rgd_cat(path, po, "/" as *u8)
196 po = rgd_cat(path, po, nm)
197 path[po] = 0 as u8
198 let lp: *i64 = sys_mmap(16) as *i64
199 let buf: *u8 = sys_read_file(path, lp)
200 if (buf as i64) == 0 { return 0 }
201 let n: i64 = lp[0]
202 let tbl: *u8 = sys_mmap(RGD_MAXID * RGD_IDLEN)
203 var nid: i64 = 0
204 var dups: i64 = 0
205 var i: i64 = 0
206 while i < n {
207 // a rung row starts a line with "rung|"
208 var at_line: i64 = 0
209 if i == 0 { at_line = 1 }
210 if i > 0 { if buf[i-1] == (10 as u8) { at_line = 1 } }
211 if at_line == 1 {
212 var isr: i64 = 0
213 if i + 5 <= n {
214 if buf[i] == (114 as u8) { if buf[i+1] == (117 as u8) { if buf[i+2] == (110 as u8) { if buf[i+3] == (103 as u8) { if buf[i+4] == (124 as u8) { isr = 1 } } } } }
215 }
216 if isr == 1 {
217 // field 2 is the id: from i+5 to the next '|'
218 var e: i64 = i + 5
219 while e < n { if buf[e] == (124 as u8) { e = n + e } else { if buf[e] == (10 as u8) { e = n + e } else { e = e + 1 } } }
220 if e > n { e = e - n }
221 var idn: i64 = e - (i + 5)
222 if idn > 0 { if idn < RGD_IDLEN {
223 let idp: *u8 = ((buf as i64) + i + 5) as *u8
224 var seen: i64 = 0
225 var k: i64 = 0
226 while k < nid { if rgd_id_eq(tbl, k, idp, idn) == 1 { seen = 1; k = nid } k = k + 1 }
227 if seen == 1 {
228 dups = dups + 1
229 if repos[0] + 96 < repcap {
230 repos[0] = rgd_cat(rep, repos[0], " DUP " as *u8)
231 repos[0] = rgd_cat(rep, repos[0], nm)
232 repos[0] = rgd_cat(rep, repos[0], " rung id " as *u8)
233 var c: i64 = 0
234 while c < idn { rep[repos[0]] = idp[c]; repos[0] = repos[0] + 1; c = c + 1 }
235 repos[0] = rgd_cat(rep, repos[0], " appears twice -- the ranker resolves whichever it matches first
236" as *u8)
237 rep[repos[0]] = 0 as u8
238 }
239 }
240 if seen == 0 { if nid < RGD_MAXID {
241 let bs: i64 = nid * RGD_IDLEN
242 var c2: i64 = 0
243 while c2 < idn { tbl[bs + c2] = idp[c2]; c2 = c2 + 1 }
244 if idn < RGD_IDLEN { tbl[bs + idn] = 0 as u8 }
245 nid = nid + 1
246 } }
247 } }
248 }
249 }
250 i = i + 1
251 }
252 return dups
253}
254// walk every .plan in the compare dir. Returns the duplicate total; files[0] gets the count SCANNED, so a
255// zero-duplicate verdict over zero files can never read as clean (the gate-passes-on-the-empty-set defect).
256func rgd_fleet(rep: *u8, repcap: i64, files: *i64) -> i64 { return rgd_fleet_in(RGD_DIR, rep, repcap, files) }
257// the dir is a PARAMETER so the census can be bite-proven on a fixture tree rather than only asserted
258// against the live board -- a detector that has only ever seen the real corpus has not been shown to fire.
259func rgd_fleet_in(dirp: *u8, rep: *u8, repcap: i64, files: *i64) -> i64 {
260 files[0] = 0
261 let fd: i64 = sys_openat_rd(dirp)
262 if fd < 0 { return 0 - 1 }
263 let dbuf: *u8 = sys_mmap(RGD_DBUF)
264 let repos: *i64 = sys_mmap(16) as *i64
265 repos[0] = 0
266 rep[0] = 0 as u8
267 var total: i64 = 0
268 var go: i64 = 1
269 while go == 1 {
270 // ★ONE getdents64 CALL IS NOT A DIRECTORY LISTING -- loop until it returns 0, or a big directory is
271 // silently read as a prefix and its total published as fact.
272 let got: i64 = sys_getdents64(fd, dbuf, RGD_DBUF)
273 if got <= 0 { go = 0 }
274 if got > 0 {
275 var off: i64 = 0
276 while off < got {
277 let reclen: i64 = (dbuf[off + RGD_DENT_RECLEN_OFF] as i64) + ((dbuf[off + RGD_DENT_RECLEN_OFF + 1] as i64) << 8)
278 if reclen <= 0 { off = got } else {
279 let nm: *u8 = ((dbuf as i64) + off + RGD_DENT_NAME_OFF) as *u8
280 if rgd_ends_plan(nm) == 1 {
281 files[0] = files[0] + 1
282 total = total + rgd_scan_plan(dirp, nm, rep, repos, repcap)
283 }
284 off = off + reclen
285 }
286 }
287 }
288 }
289 sys_close(fd)
290 return total
291}
292
293func main(argc: i64, argv: *i64) -> i64 {
294 let ctr: *i64 = gv_ctr()
295 gv_puts("=== NX-COMPARE-RANK-GATE (the liar-killer on the ranking mathematics) ===\n" as *u8)
296
297 // T1 -- no chosen coefficients in the ranker
298 let wav: *i64 = sys_mmap(8 * 4) as *i64
299 wav[0] = "./nx_law_warden.elf" as *u8 as i64
300 wav[1] = "countfile" as *u8 as i64
301 wav[2] = "buildroot/runtime/nx_compare_rank.nx" as *u8 as i64
302 wav[3] = 0
303 let wout: *u8 = sys_mmap(4096)
304 let wlen: *i64 = sys_mmap(16) as *i64
305 tr_run_capture_to("./nx_law_warden.elf" as *u8, wav, wout, 4095, wlen, RG_TIMEOUT_MS)
306 let magic: i64 = rg_int_after(wout, wlen[0], "\"magic\":" as *u8)
307 gv_need("T1-precondition warden answered" as *u8, magic >= 0, ctr)
308 gv_check("T1 no-chosen-coefficients: ranker source inline-magic==0" as *u8, magic == 0, ctr)
309 if magic > 0 { gv_puts(" UNBLOCK: nx_magic map buildroot/runtime/nx_compare_rank.nx -> hoist to a DERIVED value or a named const with its derivation in the comment; the ranking is untrusted until this is 0\n" as *u8) }
310
311 // T2 -- graphics validation on the LIVE board
312 let gout: *u8 = sys_mmap(RG_CAP)
313 let glen: *i64 = sys_mmap(16) as *i64
314 rg_run("graphics" as *u8, gout, glen)
315 gv_need("T2-precondition ranker ran on graphics" as *u8, glen[0] > 0, ctr)
316 let gr1: i64 = rg_rank_of(gout, glen[0], "GR1" as *u8)
317 gv_check("T2 graphics: referee panel (GR1/cjc_panel) is rank #1 on the critical path" as *u8, gr1 == 1, ctr)
318 if gr1 != 1 { gv_puts(" UNBLOCK: the referee is Phase-0 by declared law (nothing above it is measurable); if the board changed so another rung honestly outranks it, update this tooth WITH the board diff -- otherwise the mathematics regressed: diff nx_compare_rank.nx against its last GREEN\n" as *u8) }
319 // T6 -- the ranker counts itself (partition sums) on the live graphics run
320 let rungs: i64 = rg_int_after(gout, glen[0], "rungs=" as *u8)
321 let done: i64 = rg_int_after(gout, glen[0], "done=" as *u8)
322 let open: i64 = rg_int_after(gout, glen[0], "open=" as *u8)
323 var t6ok: i64 = 0
324 if rungs > 0 { if done + open == rungs { t6ok = 1 } }
325 gv_check("T6 partition sums: done+open==rungs on the live summary" as *u8, t6ok, ctr)
326 if done + open != rungs { gv_puts(" UNBLOCK: the ranker miscounts its own population -- a rung is being double-counted or dropped in PASS A; fix before trusting any ordering\n" as *u8) }
327 // T7 -- the printed rule names its provenance
328 gv_check("T7 rule line names WSJF+real-options+dep-graph" as *u8, rg_has(gout, glen[0], "WSJF+real-options+dep-graph" as *u8), ctr)
329 if rg_has(gout, glen[0], "WSJF+real-options+dep-graph" as *u8) == 0 { gv_puts(" UNBLOCK: the summary rule drifted from the header mathematics -- re-sync the RANK published line to the header, one truth\n" as *u8) }
330
331 // ---- fixture domain (assembled at runtime, removed at the end) ----
332 // matrix: two rivals; FX1 = every rival LEADING (catch-up gap, cost 10); FX2 = nobody has it (exceed
333 // lane, cost 10); FX3 = depends on FX1 (so FX1 enables 1); FX4 = same organ as FX2 (cluster 2)
334 let mx: *u8 = "@title rank gate fixture\n@cols RivalA|RivalB\nFX one: catch-up gap|runtime/rgfx_a.nx|_ABSENT_:rgfx_one|0|2|2|catch-up\nFX two: exceed lane|runtime/rgfx_b.nx|_ABSENT_:rgfx_two|0|0|0|exceed\nFX three: downstream of one|runtime/rgfx_c.nx|_ABSENT_:rgfx_three|0|1|1|dep\nFX four: sibling of two|runtime/rgfx_b.nx|_ABSENT_:rgfx_four|0|1|1|cluster\n" as *u8
335 let pl: *u8 = "ver|0.1|F0\nrung|FX1|catch-up gap|rgfx_one|d|Organ|1|-\nrung|FX2|exceed lane|rgfx_two|d|Organ|1|-\nrung|FX3|downstream|rgfx_three|d|Organ|-|FX1\nrung|FX4|sibling|rgfx_four|d|Organ|1|-\nms|F0|all|4|FX1,FX2,FX3,FX4\n" as *u8
336 // IDEMPOTENT SETUP: a prior run killed mid-flight leaves its fixture behind (measured 2026-08-18 --
337 // both files survived a kill). Remove first, then write; a gate that is not idempotent reports on
338 // its first run and lies about every run after (§28).
339 sys_unlinkat(RG_FX_MATRIX)
340 sys_unlinkat(RG_FX_PLAN)
341 rg_write(RG_FX_MATRIX, mx)
342 rg_write(RG_FX_PLAN, pl)
343 let fout: *u8 = sys_mmap(RG_CAP)
344 let flen: *i64 = sys_mmap(16) as *i64
345 rg_run(RG_FX_DOM, fout, flen)
346 gv_need("T3-precondition ranker ran on the fixture" as *u8, flen[0] > 0, ctr)
347 // T3 clay-polish refusal: FX1 (all rivals leading) must outrank FX2 (nobody has it) at equal cost
348 let p1: i64 = rg_pri_of(fout, flen[0], "FX1" as *u8)
349 let p2: i64 = rg_pri_of(fout, flen[0], "FX2" as *u8)
350 var t3ok: i64 = 0
351 if p1 > 0 { if p1 > p2 { t3ok = 1 } }
352 gv_check("T3 clay-polish refusal: all-rivals-leading gap outranks equal-cost exceed lane" as *u8, t3ok, ctr)
353 if t3ok == 0 { gv_puts(" UNBLOCK: CoD (deficit*leading/rivals) must dominate the option term when the field is lapping us; check the CoD leg was not dropped from value\n" as *u8) }
354 // T4 derivation fires
355 let t4a: i64 = rg_has(fout, flen[0], "cost=UNESTIMATED" as *u8)
356 gv_check("T4a UNESTIMATED is labeled (FX3 est=-)" as *u8, t4a, ctr)
357 if t4a == 0 {
358 // A FAILING TOOTH CARRIES ITS EVIDENCE: print the FX3 line the ranker actually produced, so the
359 // reader sees what was derived instead of guessing (measured 2026-08-18: this tooth failed on
360 // its first run and the fixture line was the only thing that could say why).
361 let p3: i64 = rg_find(fout, flen[0], " FX3 " as *u8, 0)
362 gv_puts(" EVIDENCE FX3 line: " as *u8)
363 if p3 >= 0 { var e3: i64 = p3; while e3 < flen[0] { if fout[e3] == (10 as u8) { break } e3 = e3 + 1 } sys_write(1, (fout as i64 + p3) as *u8, e3 - p3) } else { gv_puts("(FX3 not ranked -- was it measured DONE? rgfx_c.nx must not exist under buildroot/runtime/)" as *u8) }
364 gv_puts("\n UNBLOCK: rk_tenths must return <0 for '-' and the cost branch must label on <=0; check the fixture plan row has 8 fields with est at index 6\n" as *u8)
365 }
366 gv_check("T4b cluster measured (FX2+FX4 share rgfx_b.nx -> cluster=2)" as *u8, rg_has(fout, flen[0], "cluster=2" as *u8), ctr)
367 gv_check("T4c enablement counted (FX1 enables FX3 -> +enables=1)" as *u8, rg_has(fout, flen[0], "+enables=1" as *u8), ctr)
368 if rg_has(fout, flen[0], "+enables=1" as *u8) == 0 { gv_puts(" UNBLOCK: the dependency-closure enablement walk did not credit FX1 for FX3; check rk_list_scan resolves the dep id and the closure loop terminates only when no marks were added\n" as *u8) }
369 // T5 sponsor bites both ways: write a minus2 row scoped to the fixture domain naming FX1, re-run,
370 // FX1's priority must DROP; then remove the row (a fixture row must not survive the gate)
371 let sav: *i64 = sys_mmap(8 * 16) as *i64
372 sav[0] = "./nx_store_put.elf" as *u8 as i64
373 sav[1] = "sponsor-" as *u8 as i64
374 sav[2] = "put" as *u8 as i64
375 sav[3] = "nx_compare_rank_gate" as *u8 as i64
376 sav[4] = "rankgate-fixture-minus" as *u8 as i64
377 sav[5] = "gate fixture: demote FX1" as *u8 as i64
378 sav[6] = "1" as *u8 as i64
379 sav[7] = "minus2" as *u8 as i64
380 sav[8] = "gate" as *u8 as i64
381 sav[9] = RG_FX_DOM as i64
382 sav[10] = "gate fixture row naming FX1 rgfx_one -- REMOVED by the gate at the end of its run" as *u8 as i64
383 sav[11] = 0
384 let sout: *u8 = sys_mmap(4096)
385 let slen: *i64 = sys_mmap(16) as *i64
386 tr_run_capture_to("./nx_store_put.elf" as *u8, sav, sout, 4095, slen, RG_TIMEOUT_MS)
387 let f2out: *u8 = sys_mmap(RG_CAP)
388 let f2len: *i64 = sys_mmap(16) as *i64
389 rg_run(RG_FX_DOM, f2out, f2len)
390 let p1b: i64 = rg_pri_of(f2out, f2len[0], "FX1" as *u8)
391 let named: i64 = rg_has(f2out, f2len[0], "sponsor[rankgate-fixture-minus:minus2]" as *u8)
392 var t5bite: i64 = 0
393 if p1b >= 0 { if p1b < p1 { if named == 1 { t5bite = 1 } } }
394 gv_bite("T5 sponsor minus2 lowers FX1 (bite) / neg-control-sponsor-absent leaves it (silent)" as *u8, t5bite, 0, ctr)
395 var t5ok: i64 = 0
396 if p1b >= 0 { if p1b < p1 { t5ok = 1 } }
397 if t5ok == 0 { gv_puts(" UNBLOCK: the sponsor term did not move the number -- check nx_store_put load returns the row (CLI lane), the scope matches the domain, and the row note names the rung id\n" as *u8) }
398 // ---- T9a: the census FIRES on a planted duplicate before it is believed on the real board ----
399 // Assembled at RUNTIME under /tmp so no source scanner mistakes it for a real plan, and so the gate
400 // never shares a fixture with a production beat.
401 sys_mkdir("/tmp/nx_rankgate_dup" as *u8, 493)
402 let fx1: i64 = sys_openat_wr("/tmp/nx_rankgate_dup/clean.plan" as *u8, 420)
403 if fx1 >= 0 { sys_write(fx1, "rung|ZZ1|a|s|n
404rung|ZZ2|b|s|n
405log|1|ZZ1|land|x
406" as *u8, 46); sys_close(fx1) }
407 let fx2: i64 = sys_openat_wr("/tmp/nx_rankgate_dup/dirty.plan" as *u8, 420)
408 if fx2 >= 0 { sys_write(fx2, "rung|YY1|a|s|n
409rung|YY2|b|s|n
410rung|YY1|c|s|n
411" as *u8, 45); sys_close(fx2) }
412 let brep: *u8 = sys_mmap(8192)
413 let bfiles: *i64 = sys_mmap(16) as *i64
414 let bn: i64 = rgd_fleet_in("/tmp/nx_rankgate_dup" as *u8, brep, 8191, bfiles)
415 gv_puts("T9a fixture: plans=" as *u8); gv_num(bfiles[0]); gv_puts(" dups=" as *u8); gv_num(bn); gv_puts("
416" as *u8)
417 gv_check("T9a the census FINDS a planted duplicate rung id" as *u8, (bfiles[0] == 2) * (bn == 1), ctr)
418 gv_check("T9a neg-control the census does NOT flag the clean plan beside it" as *u8, rg_has(brep, 8191, "clean.plan" as *u8) == 0, ctr)
419 gv_check("T9a the report NAMES the offending file and id" as *u8, (rg_has(brep, 8191, "dirty.plan" as *u8) == 1) * (rg_has(brep, 8191, "YY1" as *u8) == 1), ctr)
420 sys_unlinkat("/tmp/nx_rankgate_dup/clean.plan" as *u8)
421 sys_unlinkat("/tmp/nx_rankgate_dup/dirty.plan" as *u8)
422
423 // ---- T9: no plan on the fleet carries two rungs with one id --------------------------------
424 let rgd_rep: *u8 = sys_mmap(65536)
425 let rgd_files: *i64 = sys_mmap(16) as *i64
426 let rgd_n: i64 = rgd_fleet(rgd_rep, 65535, rgd_files)
427 gv_puts("T9 rung-id uniqueness: plans scanned=" as *u8); gv_num(rgd_files[0])
428 gv_puts(" duplicate ids=" as *u8); gv_num(rgd_n); gv_puts("
429" as *u8)
430 if rgd_n > 0 { gv_puts(rgd_rep) }
431 gv_check("T9 the fleet scan actually examined plans -- a zero over zero files is not a clean board" as *u8, rgd_files[0] > 0, ctr)
432 // SELF-BASELINING RATCHET: the floor is whatever the fleet reads the first time this runs, so shipping
433 // the detector cannot turn the board red on day one; every later run must be <= that floor. A rise
434 // NAMES the offending plan and id above.
435 let rgd_lp: *i64 = sys_mmap(16) as *i64
436 let rgd_bb: *u8 = sys_read_file(RGD_BASE, rgd_lp)
437 var rgd_floor: i64 = 0 - 1
438 if (rgd_bb as i64) != 0 { if rgd_lp[0] > 0 {
439 var q: i64 = 0
440 var v: i64 = 0
441 var seen: i64 = 0
442 while q < rgd_lp[0] {
443 let c: i64 = rgd_bb[q] as i64
444 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); seen = 1 } }
445 q = q + 1
446 }
447 if seen == 1 { rgd_floor = v }
448 } }
449 if rgd_floor < 0 {
450 let bfd: i64 = sys_openat_wr(RGD_BASE, 420)
451 if bfd >= 0 {
452 let nb: *u8 = sys_mmap(64)
453 var bo: i64 = rgd_cat(nb, 0, "" as *u8)
454 gv_puts("T9 self-baselining on first sight at " as *u8); gv_num(rgd_n); gv_puts("
455" as *u8)
456 bo = 0
457 var vv: i64 = rgd_n
458 if vv == 0 { nb[bo] = 48 as u8; bo = bo + 1 }
459 if vv > 0 {
460 let tmpb: *u8 = sys_mmap(32)
461 var td: i64 = 0
462 while vv > 0 { tmpb[td] = (48 + vv - (vv/10)*10) as u8; vv = vv / 10; td = td + 1 }
463 while td > 0 { td = td - 1; nb[bo] = tmpb[td]; bo = bo + 1 }
464 }
465 nb[bo] = 10 as u8; bo = bo + 1
466 sys_write(bfd, nb, bo)
467 sys_close(bfd)
468 }
469 rgd_floor = rgd_n
470 }
471 gv_puts("T9 floor=" as *u8); gv_num(rgd_floor); gv_puts("
472" as *u8)
473 gv_check("T9 no plan gained a duplicate rung id -- the ranker resolves an id by first match, so two rungs sharing one is a coin flip" as *u8, rgd_n <= rgd_floor, ctr)
474
475 // remove the fixture sponsor row: close it. nx_store_put close rewrites col3 (the sponsor WEIGHT
476 // field) to "closed", which parses as no weight in rk_sponsor_term -- inert by construction, and
477 // scoped to a domain no page emits besides.
478 sav[2] = "close" as *u8 as i64
479 sav[3] = "nx_compare_rank_gate" as *u8 as i64
480 sav[4] = "rankgate-fixture-minus" as *u8 as i64
481 sav[5] = "gate run complete; fixture row retired" as *u8 as i64
482 sav[6] = 0
483 tr_run_capture_to("./nx_store_put.elf" as *u8, sav, sout, 4095, slen, RG_TIMEOUT_MS)
484 // remove the fixture domain files
485 sys_unlinkat(RG_FX_MATRIX)
486 sys_unlinkat(RG_FX_PLAN)
487
488 return gv_verdict("nx_compare_rank_gate" as *u8, ctr, "the ranking is trusted only while every tooth here is GREEN; a RED names its unblock" as *u8)
489}