nx_firstbyte_gate.nx source
↩ module page · 277 lines · 16210 B
1// nx_firstbyte_gate.nx -- the first-byte-up analysis is DERIVED, its cap axis is MEASURED, its
2// unsound links are RANKED BY ACTIONABILITY, it DISCRIMINATES, and it declares the axis it cannot see.
3//
4// Subject: ./nx_firstbyte.elf (the serving-root binary; e2e fork, never an in-process re-derive).
5//
6// PRE-DECLARED ACCEPT RULE: would this instrument have surfaced the five foundation defects of
7// 2026-08-23 BEFORE the lane above hit them? Known ground truth, so a real validation set. Re-scored
8// after the ranking landed -- published honestly, INCLUDING WHAT DID NOT MOVE:
9// D2 nx_gsplat 512x384 CAUGHT, and now ATTRIBUTED. The splat rungs read NOT-READY with
10// first_unsound=nx_gsplat.nx classed OWN -- the rung's own module, the
11// lane that owns the rung owns the fix.
12// D1 nx_skeleton SK_MAXB=32 MOVED: was CAUGHT-BUT-MASKED, now the mask is GONE and for the right
13// reason -- nx_skeleton.nx reads verdict=CLEAN (capacity_population=0)
14// since the rig-floor lane derived that bound away. It still sits in
15// three chains, and it is named in NONE of them. The tooth below asserts
16// exactly that consistency: A LINK THE CENSUS CALLS CLEAN MUST NEVER BE
17// NAMED AS UNSOUND. (If the skeleton lane re-introduces a picked bound
18// this tooth goes RED -- that is a foundation regression, and it SHOULD
19// be visible here. Named so the next reader knows why.)
20// D3 PF_NB=48 MISS, structural and UNCHANGED: a DATA prior read at runtime is not an
21// import. AN IMPORT GRAPH CANNOT SEE A DATA DEPENDENCY. Asserted.
22// D4 no vector types MISS, UNCHANGED: a LANGUAGE gap has no module to point at.
23// D5 no mesh->skeleton binder MISS, UNCHANGED: no row declared it. EMPTY-CHAIN is the nearest
24// observable proxy and is checked as its own bucket, even at zero.
25//
26// WHY THE RANKING NEEDED ITS OWN TEETH: ranking is a claim about ORDER, and an order can be wrong
27// while every count is right. The load-bearing tooth parses EVERY ranked list and asserts class order
28// (own, then rare, then ubiquitous) with ascending fan-in inside a class -- because the whole point is
29// that A CAP IN A LEAF EVERYONE SHARES MUST NEVER OUTRANK A CAP IN YOUR OWN MODULE. It also counts
30// what it parsed, so a run that parsed nothing cannot pass as a run that found nothing out of order.
31// license_tier: ORIGINAL Read-only. No hw writes (Rule 26).
32import "nx_syscalls.nx"
33import "nx_gate_verdict.nx"
34import "nx_gatekit_lib.nx"
35
36const FBG_ELF: *u8 = "./nx_firstbyte.elf" as *u8
37// PROTECTIVE and NAMED for that purpose: a subprocess's output length is unknowable in advance. A
38// tooth FAILS if the capture reaches it, so truncation ANNOUNCES rather than silently shortening the
39// evidence every other tooth reads.
40const FBG_CAPTURE_BUDGET: i64 = 262144
41const FBG_RANKED_TAG: *u8 = "|ranked=" as *u8
42const FBG_RANKED_TAGLEN: i64 = 8
43const FBG_FANIN_TAGLEN: i64 = 6
44
45static fbg_lists: i64
46static fbg_entries: i64
47
48func fbg_find_from(b: *u8, n: i64, pat: *u8, start: i64) -> i64 {
49 var plen: i64 = 0
50 while pat[plen] != (0 as u8) { plen = plen + 1 }
51 if plen == 0 { return 0 - 1 }
52 var i: i64 = start
53 while i + plen <= n {
54 var k: i64 = 0
55 var ok: i64 = 1
56 while k < plen {
57 if b[i + k] != pat[k] { ok = 0; k = plen }
58 else { k = k + 1 }
59 }
60 if ok == 1 { return i }
61 i = i + 1
62 }
63 return 0 - 1
64}
65
66func fbg_find(b: *u8, n: i64, pat: *u8) -> i64 { return fbg_find_from(b, n, pat, 0) }
67
68func fbg_has(b: *u8, n: i64, pat: *u8) -> i64 {
69 if fbg_find(b, n, pat) >= 0 { return 1 }
70 return 0
71}
72
73func fbg_digits_at(b: *u8, n: i64, start: i64) -> i64 {
74 var k: i64 = start
75 var v: i64 = 0
76 var got: i64 = 0
77 var done: i64 = 0
78 while done == 0 {
79 if k >= n { done = 1 }
80 else {
81 let c: i64 = b[k] as i64
82 var isdig: i64 = 0
83 if c >= 48 { if c <= 57 { isdig = 1 } }
84 if isdig == 1 { v = v * 10 + (c - 48); got = 1; k = k + 1 }
85 else { done = 1 }
86 }
87 }
88 if got == 0 { return 0 - 1 }
89 return v
90}
91
92func fbg_num_after(b: *u8, n: i64, key: *u8) -> i64 {
93 let at: i64 = fbg_find(b, n, key)
94 if at < 0 { return 0 - 1 }
95 var klen: i64 = 0
96 while key[klen] != (0 as u8) { klen = klen + 1 }
97 return fbg_digits_at(b, n, at + klen)
98}
99
100// THE RANKING IS AN ORDER CLAIM, SO IT IS CHECKED AS AN ORDER. For every `|ranked=` list: class rank
101// must be non-decreasing (OWN 0, RARE 1, UBIQ 2) and, within one class, fan-in must be non-decreasing
102// so the rarest -- the most targeted fix -- comes first. Returns 1 if every list is well ordered.
103// fbg_lists / fbg_entries record how much was actually examined: A CHECKER THAT PARSED NOTHING MUST
104// NOT BE READ AS A CHECKER THAT FOUND NOTHING WRONG.
105func fbg_rank_order_ok(b: *u8, n: i64) -> i64 {
106 fbg_lists = 0
107 fbg_entries = 0
108 var bad: i64 = 0
109 var at: i64 = fbg_find_from(b, n, FBG_RANKED_TAG, 0)
110 while at >= 0 {
111 fbg_lists = fbg_lists + 1
112 var eol: i64 = at
113 var d0: i64 = 0
114 while d0 == 0 {
115 if eol >= n { d0 = 1 }
116 else { if b[eol] == (10 as u8) { d0 = 1 } else { eol = eol + 1 } }
117 }
118 var i: i64 = at + FBG_RANKED_TAGLEN
119 var lastc: i64 = 0 - 1
120 var lastf: i64 = 0 - 1
121 var done: i64 = 0
122 while done == 0 {
123 if i >= eol { done = 1 }
124 else {
125 if b[i] == (40 as u8) {
126 var c: i64 = 0 - 1
127 if i + 1 < eol {
128 let ch: i64 = b[i + 1] as i64
129 if ch == 79 { c = 0 }
130 if ch == 82 { c = 1 }
131 if ch == 85 { c = 2 }
132 }
133 if c >= 0 {
134 fbg_entries = fbg_entries + 1
135 var f: i64 = 0 - 1
136 let fat: i64 = fbg_find_from(b, eol, "fanin=" as *u8, i)
137 if fat >= 0 { f = fbg_digits_at(b, eol, fat + FBG_FANIN_TAGLEN) }
138 if c < lastc { bad = 1 }
139 if c == lastc { if f < lastf { bad = 1 } }
140 lastc = c
141 lastf = f
142 }
143 }
144 i = i + 1
145 }
146 }
147 at = fbg_find_from(b, n, FBG_RANKED_TAG, at + FBG_RANKED_TAGLEN)
148 }
149 if bad == 1 { return 0 }
150 return 1
151}
152
153func main(argc: i64, argv: *i64) -> i64 {
154 let ctr: *i64 = gv_ctr()
155 gv_puts("nx_firstbyte_gate -- derived chain, MEASURED cap axis, RANKED unsound links, declared blind spot\n\n" as *u8)
156
157 let buf: *u8 = sys_mmap(FBG_CAPTURE_BUDGET)
158 var blen: i64 = 0
159 let rc: i64 = gk_run_capture(FBG_ELF, "chain" as *u8, "graphics" as *u8, 0 as *u8, 0 as *u8, buf, FBG_CAPTURE_BUDGET, &blen)
160
161 gv_puts(" subject rc=" as *u8); gv_num(rc); gv_puts(" bytes=" as *u8); gv_num(blen); gv_puts("\n" as *u8)
162 gv_check("subject-ran-and-produced-output (a silent subject proves nothing)" as *u8, blen > 0, ctr)
163 gv_check("capture-did-not-reach-its-PROTECTIVE-budget (truncation would shorten every tooth below)" as *u8, blen < FBG_CAPTURE_BUDGET, ctr)
164
165 let nodes: i64 = fbg_num_after(buf, blen, "graph nodes=" as *u8)
166 let rows: i64 = fbg_num_after(buf, blen, " rows=" as *u8)
167 let ready: i64 = fbg_num_after(buf, blen, "ready=" as *u8)
168 let capped: i64 = fbg_num_after(buf, blen, "capped=" as *u8)
169 let unobs: i64 = fbg_num_after(buf, blen, "unobservable=" as *u8)
170 let place: i64 = fbg_num_after(buf, blen, "placeholder=" as *u8)
171 let absent: i64 = fbg_num_after(buf, blen, "absent=" as *u8)
172 let empty: i64 = fbg_num_after(buf, blen, "empty_chain=" as *u8)
173 let unknown: i64 = fbg_num_after(buf, blen, "unknown=" as *u8)
174 let acap: i64 = fbg_num_after(buf, blen, "ancestors_cap=" as *u8)
175 let links: i64 = fbg_num_after(buf, blen, "chain_links_total=" as *u8)
176 let forks: i64 = fbg_num_after(buf, blen, "census_forks=" as *u8)
177 let nres: i64 = fbg_num_after(buf, blen, "resolved_chains=" as *u8)
178 let c_own: i64 = fbg_num_after(buf, blen, "capped_links_own=" as *u8)
179 let c_rare: i64 = fbg_num_after(buf, blen, "capped_links_rare=" as *u8)
180 let c_ubiq: i64 = fbg_num_after(buf, blen, "capped_links_ubiquitous=" as *u8)
181
182 gv_puts(" nodes=" as *u8); gv_num(nodes)
183 gv_puts(" rows=" as *u8); gv_num(rows)
184 gv_puts(" ready=" as *u8); gv_num(ready)
185 gv_puts(" capped=" as *u8); gv_num(capped)
186 gv_puts(" unobs=" as *u8); gv_num(unobs)
187 gv_puts(" placeholder=" as *u8); gv_num(place)
188 gv_puts(" absent=" as *u8); gv_num(absent)
189 gv_puts(" empty=" as *u8); gv_num(empty)
190 gv_puts(" links=" as *u8); gv_num(links)
191 gv_puts(" census_forks=" as *u8); gv_num(forks); gv_puts("\n" as *u8)
192 gv_puts(" resolved_chains=" as *u8); gv_num(nres)
193 gv_puts(" capped_links own=" as *u8); gv_num(c_own)
194 gv_puts(" rare=" as *u8); gv_num(c_rare)
195 gv_puts(" ubiq=" as *u8); gv_num(c_ubiq); gv_puts("\n" as *u8)
196
197 gv_check("graph-loaded-with-nodes (a zero-node graph makes every other tooth vacuous)" as *u8, nodes > 0, ctr)
198 gv_check("board-has-rows-AND-chains-were-walked (empty set cannot pass)" as *u8, rows > 0, ctr)
199 gv_check("chain-links-were-actually-walked (links>0, not a graph that resolved nothing)" as *u8, links > 0, ctr)
200
201 // THE CAP AXIS WAS ACTUALLY EXERCISED. Without this, an organ that skipped every census query
202 // would report a clean-looking board and no tooth above would notice.
203 gv_check("cap-axis-WAS-EXERCISED (census_forks>0; a skipped query would look identical to a clean one)" as *u8, forks > 0, ctr)
204 gv_check("cap-axis-DECLARED-MEASURED (was UNOBSERVABLE until the census shipped its per-module query)" as *u8, fbg_has(buf, blen, "capped_axis=MEASURED" as *u8), ctr)
205 gv_check("forks-are-DEDUPED-per-distinct-module (fewer forks than link occurrences)" as *u8, forks <= links + rows, ctr)
206
207 // PARTITION: every bucket counted. A partition tooth that omits a bucket is the very defect it
208 // exists to catch.
209 var partok: i64 = 0
210 if rows > 0 { if ready + capped + unobs + place + absent + empty + unknown == rows { partok = 1 } }
211 gv_check("partition-SUMS-with-EVERY-bucket (computed here, not taken on the organ's word)" as *u8, partok, ctr)
212 gv_check("organ-publishes-its-own-partition-sum" as *u8, fbg_has(buf, blen, "SUMS=1" as *u8), ctr)
213 gv_check("empty-chain-is-its-OWN-reported-bucket (undeclared-dependency is a DIFFERENT question from unsound)" as *u8, empty >= 0, ctr)
214
215 // ANTI-VACUITY: an analysis that puts EVERY row in ONE bucket has measured nothing. This is
216 // deliberately NOT "ready>0" -- ready is legitimately 0 today, because with only 2.56% of estate
217 // bounds DERIVED almost every chain carries a picked bound. Discrimination is what must hold.
218 var disc: i64 = 0
219 if capped > 0 { if place > 0 { disc = 1 } }
220 gv_check("anti-vacuity-DISCRIMINATES (two buckets populated; everything-in-one-bucket FAILS)" as *u8, disc, ctr)
221
222 // ABSTENTION INHERITED: an unreadable link must never be counted as clean.
223 gv_check("no-rung-reads-READY-on-an-UNREADABLE-link (abstention inherited from the census)" as *u8, 1 - fbg_has(buf, blen, "cap=UNOBSERVABLE|state=READY" as *u8), ctr)
224
225 // NO PHONY CAP: the closure bound is the node count itself.
226 var capok: i64 = 0
227 if acap == nodes { if nodes > 0 { capok = 1 } }
228 gv_check("ancestors-cap-EQUALS-node-count (DERIVED; a closure is a subset so it cannot truncate)" as *u8, capok, ctr)
229
230 // ---- THE RANKING. An order claim, checked as an order.
231 let ordok: i64 = fbg_rank_order_ok(buf, blen)
232 gv_puts(" ranked lists parsed=" as *u8); gv_num(fbg_lists)
233 gv_puts(" entries=" as *u8); gv_num(fbg_entries); gv_puts("\n" as *u8)
234 var rankexer: i64 = 0
235 if fbg_lists > 0 { if fbg_entries > fbg_lists { rankexer = 1 } }
236 gv_check("ranking-WAS-EXERCISED (lists parsed, with more entries than lists; a parser that read nothing cannot pass as one that found nothing wrong)" as *u8, rankexer, ctr)
237 gv_check("ranking-ORDER-HOLDS-own-then-rare-then-ubiquitous-ascending-fanin-within-a-class" as *u8, ordok, ctr)
238 var three: i64 = 0
239 if c_own > 0 { if c_rare > 0 { if c_ubiq > 0 { three = 1 } } }
240 gv_check("ranking-DISCRIMINATES-all-THREE-classes-populated (everything-in-one-class would rank nothing)" as *u8, three, ctr)
241 gv_check("ubiquitous-boundary-DERIVED-from-this-board (resolved_chains published; no threshold picked)" as *u8, nres > 0, ctr)
242 // EVERY capped link is reported, not just the winner: the classified total must exceed the number
243 // of capped rungs, or the organ is still publishing one finding per rung.
244 var allrep: i64 = 0
245 if capped > 0 { if c_own + c_rare + c_ubiq > capped { allrep = 1 } }
246 gv_check("ALL-capped-links-reported-not-just-the-winner (classified total exceeds capped rung count)" as *u8, allrep, ctr)
247 // A UBIQUITOUS LEAF MUST NEVER BE A RUNG'S HEADLINE WHILE THAT RUNG HAS ITS OWN CAP. This is the
248 // masking defect stated as a property: the ranked list is sorted, so a rung with own>=1 has an OWN
249 // entry first, and nx_syscalls -- the most shared leaf in the estate -- can never lead one.
250 gv_check("UBIQUITOUS-leaf-never-leads-a-ranked-list-that-has-an-OWN-cap (the masking defect, as a property)" as *u8, 1 - fbg_has(buf, blen, "|ranked=nx_syscalls.nx(UBIQ" as *u8), ctr)
251
252 // THE ERROR TERM TRAVELS WITH THE VERDICT. The census disclosed a false positive in its own
253 // classifier (CE_C_SHOWMAX=12, a counter INDEX flagged for containing "MAX"), so a CAPPED verdict
254 // is a measurement with a known error term, never a certainty.
255 gv_check("CAPPED-verdicts-carry-their-known-ERROR-TERM (an INDEX can wear a cap-shaped name)" as *u8, fbg_has(buf, blen, "capped_error_term=" as *u8), ctr)
256
257 // THE REMAINING BLIND SPOT DECLARES ITSELF.
258 gv_check("data-edges-DECLARED-NOT-DERIVED (an import graph cannot see a DATA dependency)" as *u8, fbg_has(buf, blen, "data_edges=NOT-DERIVED" as *u8), ctr)
259
260 // FIVE-DEFECT VALIDATION, measured on real board data, re-scored after the ranking.
261 gv_check("D2-CAUGHT-nx_gsplat-NAMED-as-the-unsound-link-of-its-own-rung (512x384 viewport)" as *u8, fbg_has(buf, blen, "first_unsound=nx_gsplat.nx" as *u8), ctr)
262 gv_check("D2-ATTRIBUTED-nx_gsplat-classed-OWN-so-the-rung-owner-owns-the-fix" as *u8, fbg_has(buf, blen, "nx_gsplat.nx(OWN" as *u8), ctr)
263 gv_check("D1-nx_skeleton-LOCATABLE-in-a-rung-chain" as *u8, fbg_has(buf, blen, "nx_skeleton.nx" as *u8), ctr)
264 gv_check("D1-MASK-LIFTED-a-link-the-census-calls-CLEAN-is-NEVER-named-as-unsound (nx_skeleton in no ranked list)" as *u8, 1 - fbg_has(buf, blen, "nx_skeleton.nx(" as *u8), ctr)
265 gv_check("D3-declared-MISS-a-DATA-prior-is-invisible-to-an-IMPORT-graph (nx_profile_fit absent)" as *u8, 1 - fbg_has(buf, blen, "nx_profile_fit.nx" as *u8), ctr)
266
267 // NEG-CONTROL: a domain with no matrix must REFUSE, not silently report an empty healthy board.
268 let buf2: *u8 = sys_mmap(FBG_CAPTURE_BUDGET)
269 var blen2: i64 = 0
270 let rc2: i64 = gk_run_capture(FBG_ELF, "chain" as *u8, "a_domain_that_does_not_exist" as *u8, 0 as *u8, 0 as *u8, buf2, FBG_CAPTURE_BUDGET, &blen2)
271 gv_puts(" neg-control rc=" as *u8); gv_num(rc2); gv_puts("\n" as *u8)
272 var negfired: i64 = 0
273 if rc2 == 4 { negfired = fbg_has(buf2, blen2, "matrix UNREADABLE" as *u8) }
274 gv_bite("neg-control-absent-matrix-REFUSES-BY-NAME-never-an-empty-healthy-board" as *u8, negfired, rc == 4, ctr)
275
276 return gv_verdict("NX-FIRSTBYTE-GATE" as *u8, ctr, "the chain is derived from the estate's own import graph, the cap axis is measured per module, every unsound link is ranked by who can act on it, and the blind spot that remains declares itself" as *u8)
277}