code wiki / (root) / nx_fetchfail.nx

nx_fetchfail.nx source

↩ module page · 628 lines · 30146 B

1// nx_fetchfail.nx -- WIRES THE CONTENT AXIS TO A PLANE. It adds NO ruler of its own. 2// 3// WHY THIS EXISTS AND WHAT IT DELIBERATELY DOES NOT DO. On 2026-08-25 a sibling seat landed the content 4// classifier (mi_content_class, in nx_mirrorintegrity_lib.nx) which decides whether a stored mirror is 5// the DOCUMENT or merely a bot wall, a login gate, an error page or a JS shell. Measured the same hour: 6// that function had exactly ONE reference in the whole tree -- its own definition, over 23,234 files at 7// corpus_complete=1 -- and the conf it reads did not exist. It was BUILT + UNWIRED, and a classifier 8// nobody calls is a comment. So this organ is the wiring, not a second opinion: 9// A DUPLICATE RULER IS THE DEBT. EXTEND THE INCUMBENT, NEVER ADD A SECOND. 10// Every classification below comes from mi_content_class. If its verdict is wrong, it is fixed THERE. 11// 12// TWO VERBS, AND THE FIRST ONE EXISTS BECAUSE THE BAR HAD TO BE DERIVED RATHER THAN PICKED: 13// probe -- walk the corpus and print the PROSE-BYTE DISTRIBUTION. No plane write, no verdict. This 14// is the measurement from which prose-floor-bytes is chosen, and the lib's own comment 15// requires that the shipped bar carry the distribution it came from. A threshold picked by 16// taste is a magic number wearing a config key. 17// census -- classify with the conf bar and emit the plane. (default) 18// 19// THE PLANE: knowledge/store/fetchfail- (seg-store; sovereign rows, NO third-party format anywhere). 20// The prefix is spelled in FULL and never bare: a bare prefix resolves against CWD and makes a populated 21// plane answer EMPTY, which reads exactly like a plane that was never seeded. 22// Row key = the mirror path (stable, so a re-run UPDATES rather than duplicates: rule 10) 23// Row value = url|mirror|class|reason|remedy|prose|bytes|detected_at|state 24// state is OPEN while the body still classifies as a failure and flips to RESOLVED on the first run 25// after it is re-fetched clean -- AN AUTOFILED ROW WITH NO AUTO-CLOSE IS A LATCH, NOT A DETECTOR. 26// 27// nx_fetchfail [probe|census] [dir] default: census knowledge/fetched 28// license_tier: ORIGINAL expect_exit: 0 29import "nx_mirrorintegrity_lib.nx" 30import "nx_seg_store.nx" 31 32const FF_PLANE: *u8 = "knowledge/store/fetchfail-\x00" 33// THERE ARE TWO KNOWLEDGE TREES AND THE REFS LIVE IN EXACTLY ONE OF THEM. Measured 2026-08-25: 34// buildroot/knowledge/compare holds 63 .refs files in its first page; knowledge/compare holds ZERO. 35// A version of this organ pointed at the nishihost twin and would have emitted url=- for every single 36// row -- not an error, a CONFIDENT WRONG ANSWER, which is the worse failure. Worse still, which tree is 37// reachable depends on the CWD the organ is forked with, and that differs between the MCP surface and 38// the job runner. So the directory is RESOLVED at runtime against candidates and the winner is PRINTED, 39// rather than assumed: the same relative-then-absolute shape mi_prose_floor already uses in this lib. 40const FF_REFSDIR_A: *u8 = "buildroot/knowledge/compare\x00" 41const FF_REFSDIR_B: *u8 = "knowledge/compare\x00" 42const FF_REFSDIR_ABS: *u8 = "/volume1/homes/elderwesto/nishihost/buildroot/knowledge/compare\x00" 43const FF_REFSEXT: *u8 = ".refs\x00" 44const FF_ST_OPEN: *u8 = "OPEN\x00" 45const FF_ST_RES: *u8 = "RESOLVED\x00" 46const FF_URL_FIELD: i64 = 3 // refs row: ref|key|cite|url|mirror|pin|accessed|class|grounds 47const FF_MIR_FIELD: i64 = 4 48const FF_MAXREFS: i64 = 512 // declared: .refs files loaded; overflow ANNOUNCES, never silent 49const FF_MAXFIELD: i64 = 32 50const FF_ROWCAP: i64 = 4096 51const FF_KIND_LIVE: i64 = 1 // seg-store live-row kind (0 is a tombstone) 52const FF_DIRBUF: i64 = 131072 53const FF_PATHCAP: i64 = 4096 54const FF_MAXDEPTH: i64 = 8 55const FF_DT_DIR: i64 = 4 56const FF_WORKCAP: i64 = 1048576 57const FF_WORKFLUSH: i64 = 1047000 58const FF_BAR: i64 = 124 // '|' 59const FF_NL: i64 = 10 60// THE PLANE IS A ROW PLANE, KEYED q:<n>. A first cut of this organ keyed rows by the mirror PATH, 61// which committed real segments that the estate's standard reader then refused with 62// NOT-A-ROW-PLANE: "HAS segments but carries no q:n row index". The refusal was correct and it 63// carefully distinguished that state from an empty plane -- but a plane only THIS organ can list is 64// a plane nobody will read. Keys are therefore q:<n> and the mirror path is column 0 of the value, 65// which is the same id-in-column-0 shape comparewatch- and deployq- already use. 66const FF_QPFX: *u8 = "q:\x00" 67const FF_MAXPRIOR: i64 = 65536 // declared: prior rows loaded for auto-close; overflow ANNOUNCES 68const FF_PRIORBUF: i64 = 16777216 69 70// counts[] slots -- named, because a bare index is a magic number wearing an offset 71const FF_C_FILES: i64 = 0 72const FF_C_FLAG: i64 = 1 73const FF_C_OK: i64 = 2 74const FF_C_NOTHTML: i64 = 3 75const FF_C_RESOLV: i64 = 4 76const FF_C_UNREAD: i64 = 5 77 78// prose histogram buckets -- boundaries are powers of four so the shape of the distribution, not a 79// pre-chosen bar, is what the reader sees. 80const FF_NBUCK: i64 = 8 81const FF_B1: i64 = 1 82const FF_B2: i64 = 16 83const FF_B3: i64 = 64 84const FF_B4: i64 = 256 85const FF_B5: i64 = 1024 86const FF_B6: i64 = 4096 87const FF_B7: i64 = 16384 88 89func ff_streq(a: *u8, b: *u8) -> i64 { 90 var i: i64=0 91 var eq: i64=1 92 var go: i64=1 93 while go==1 { 94 let ca: i64 = a[i] as i64 95 let cb: i64 = b[i] as i64 96 if ca!=cb { eq=0; go=0 } else { if ca==0 { go=0 } else { i=i+1 } } 97 } 98 return eq 99} 100func ff_bucket(p: i64) -> i64 { 101 if p < FF_B1 { return 0 } 102 if p < FF_B2 { return 1 } 103 if p < FF_B3 { return 2 } 104 if p < FF_B4 { return 3 } 105 if p < FF_B5 { return 4 } 106 if p < FF_B6 { return 5 } 107 if p < FF_B7 { return 6 } 108 return 7 109} 110func ff_bucket_lo(i: i64) -> i64 { 111 if i==0 { return 0 } 112 if i==1 { return FF_B1 } 113 if i==2 { return FF_B2 } 114 if i==3 { return FF_B3 } 115 if i==4 { return FF_B4 } 116 if i==5 { return FF_B5 } 117 if i==6 { return FF_B6 } 118 return FF_B7 119} 120 121// ---------------------------------------------------------------- refs join 122// Load every knowledge/compare/*.refs body once so the url lookup is a memory scan rather than a 123// re-read per hit. ovf[0]=1 announces an overflowed table. 124func ff_refs_load_one(dir: *u8, ptrs: *i64, lens: *i64, ovf: *i64) -> i64 { 125 var n: i64 = 0 126 let fd: i64 = sys_openat_rd(dir) 127 if fd<0 { return 0 } 128 let dbuf: *u8 = sys_mmap(FF_DIRBUF) 129 let pb: *u8 = sys_mmap(FF_PATHCAP) 130 let lenp: *i64 = sys_mmap(16) as *i64 131 var go: i64 = 1 132 while go==1 { 133 let nr: i64 = sys_getdents64(fd, dbuf, FF_DIRBUF) 134 if nr<=0 { go=0 } else { 135 var off: i64 = 0 136 while off < nr { 137 let rec: *u8 = (dbuf as i64 + off) as *u8 138 let nm: *u8 = dirent_name(rec) 139 if mi_isdotdot(nm)==0 { 140 let nl: i64 = mi_slen(nm) 141 let el: i64 = mi_slen(FF_REFSEXT as *u8) 142 var isrefs: i64 = 0 143 if nl > el { 144 var k: i64 = 0 145 var same: i64 = 1 146 while k < el { 147 if nm[nl-el+k] != (FF_REFSEXT as *u8)[k] { same=0; k=el } else { k=k+1 } 148 } 149 isrefs = same 150 } 151 if isrefs==1 { 152 var a: i64 = mi_cat(pb, 0, dir) 153 a = mi_cat(pb, a, "/" as *u8) 154 a = mi_cat(pb, a, nm) 155 pb[a]=0 as u8 156 lenp[0]=0 157 let b: *u8 = sys_read_file(pb, lenp) 158 if (b as i64) != 0 { 159 if n >= FF_MAXREFS { ovf[0]=1 } else { 160 ptrs[n]=b as i64 161 lens[n]=lenp[0] 162 n=n+1 163 } 164 } 165 } 166 } 167 off = off + dirent_reclen(rec) 168 } 169 } 170 } 171 sys_close(fd) 172 return n 173} 174 175// Resolve the refs directory by TRYING each candidate and keeping the first that actually yields refs 176// files. which[0] receives the winning candidate pointer so the census can PRINT it -- a join that 177// silently found nothing is indistinguishable from a corpus with no citations, and only naming the 178// directory it actually read makes that difference visible to the reader. 179func ff_refs_load(ptrs: *i64, lens: *i64, ovf: *i64, which: *i64) -> i64 { 180 ovf[0]=0 181 which[0]=0 182 var n: i64 = ff_refs_load_one(FF_REFSDIR_A as *u8, ptrs, lens, ovf) 183 if n>0 { which[0]=FF_REFSDIR_A as i64; return n } 184 n = ff_refs_load_one(FF_REFSDIR_B as *u8, ptrs, lens, ovf) 185 if n>0 { which[0]=FF_REFSDIR_B as i64; return n } 186 n = ff_refs_load_one(FF_REFSDIR_ABS as *u8, ptrs, lens, ovf) 187 if n>0 { which[0]=FF_REFSDIR_ABS as i64; return n } 188 return 0 189} 190 191// Find the url whose refs row NAMES this mirror. Returns 1 and fills out, or 0. 192// A mirror with no refs row is NOT an error -- knowledge/fetched also holds bodies fetched by lanes 193// that never cited them -- so the caller records '-' rather than inventing a url. 194func ff_url_for(mirror: *u8, ptrs: *i64, lens: *i64, nrefs: i64, out: *u8) -> i64 { 195 let ml: i64 = mi_slen(mirror) 196 var r: i64 = 0 197 var got: i64 = 0 198 while r < nrefs { 199 let b: *u8 = ptrs[r] as *u8 200 let n: i64 = lens[r] 201 var p: i64 = 0 202 var go: i64 = 1 203 while go==1 { 204 let hit: i64 = mi_find(b, p, n, mirror) 205 if hit < 0 { go=0 } else { 206 var ls: i64 = hit 207 var f1: i64 = 0 208 while f1==0 { 209 if ls<=0 { f1=1 } else { 210 if (b[ls-1] as i64)==FF_NL { f1=1 } else { ls=ls-1 } 211 } 212 } 213 var le: i64 = hit 214 var f2: i64 = 0 215 while f2==0 { 216 if le>=n { f2=1 } else { 217 if (b[le] as i64)==FF_NL { f2=1 } else { le=le+1 } 218 } 219 } 220 let fs: *i64 = sys_mmap(8*FF_MAXFIELD) as *i64 221 var nf: i64 = 1 222 fs[0]=ls 223 var q: i64 = ls 224 while q < le { 225 if (b[q] as i64)==FF_BAR { 226 if nf < FF_MAXFIELD { fs[nf]=q+1 } 227 nf=nf+1 228 } 229 q=q+1 230 } 231 var advanced: i64 = 0 232 if nf > FF_MIR_FIELD { 233 var ms: i64 = fs[FF_MIR_FIELD] 234 var me: i64 = le 235 if FF_MIR_FIELD+1 < nf { me = fs[FF_MIR_FIELD+1]-1 } 236 var eq: i64 = 0 237 if me-ms == ml { 238 var t: i64 = 0 239 var s: i64 = 1 240 while t < ml { if b[ms+t]!=mirror[t] { s=0; t=ml } else { t=t+1 } } 241 eq = s 242 } 243 if eq==1 { 244 var us: i64 = fs[FF_URL_FIELD] 245 var ue: i64 = le 246 if FF_URL_FIELD+1 < nf { ue = fs[FF_URL_FIELD+1]-1 } 247 var o: i64 = 0 248 var t2: i64 = us 249 while t2 < ue { out[o]=b[t2]; o=o+1; t2=t2+1 } 250 out[o]=0 as u8 251 got=1 252 go=0 253 r=nrefs 254 advanced=1 255 } 256 } 257 if advanced==0 { p = hit+1 } 258 } 259 } 260 r=r+1 261 } 262 return got 263} 264 265func ff_qkey(buf: *u8, n: i64) -> i64 { 266 var a: i64 = mi_cat(buf, 0, FF_QPFX as *u8) 267 a = mi_catn(buf, a, n) 268 buf[a]=0 as u8 269 return a 270} 271 272// Load the PREVIOUS run's rows so a body that has since been re-fetched clean can be flipped to 273// RESOLVED. Without this the plane latches: AN AUTOFILED ROW WITH NO AUTO-CLOSE IS A LATCH, NOT A 274// DETECTOR, and it reads identically whether the fault cleared long ago or is firing right now. 275// paths[] point into blob; states[] is 1 when that row was OPEN. ovf[0]=1 announces an overflow. 276func ff_prior_load(h: *i64, paths: *i64, states: *i64, blob: *u8, ovf: *i64) -> i64 { 277 ovf[0]=0 278 if (h as i64)==0 { return 0 } 279 let kb: *u8 = sys_mmap(64) 280 let vp: *i64 = sys_mmap(16) as *i64 281 let vl: *i64 = sys_mmap(16) as *i64 282 var n: i64 = 0 283 var bo: i64 = 0 284 var i: i64 = 0 285 var go: i64 = 1 286 while go==1 { 287 ff_qkey(kb, i) 288 if ss_hget(h, kb, vp, vl)!=1 { go=0 } else { 289 let v: *u8 = vp[0] as *u8 290 let vn: i64 = vl[0] 291 if n >= FF_MAXPRIOR { ovf[0]=1; go=0 } else { 292 if bo + vn + 2 >= FF_PRIORBUF { ovf[0]=1; go=0 } else { 293 // column 0 is the mirror path 294 var e: i64 = 0 295 var f: i64 = 0 296 while f==0 { 297 if e>=vn { f=1 } else { if (v[e] as i64)==FF_BAR { f=1 } else { e=e+1 } } 298 } 299 paths[n]=(blob as i64)+bo 300 var t: i64 = 0 301 while t<e { blob[bo]=v[t]; bo=bo+1; t=t+1 } 302 blob[bo]=0 as u8; bo=bo+1 303 var st: i64 = 0 304 if mi_find(v, 0, vn, FF_ST_OPEN as *u8) >= 0 { st=1 } 305 states[n]=st 306 n=n+1 307 i=i+1 308 } 309 } 310 } 311 } 312 return n 313} 314func ff_prior_open(path: *u8, paths: *i64, states: *i64, n: i64) -> i64 { 315 var i: i64 = 0 316 var r: i64 = 0 317 while i < n { 318 if states[i]==1 { if ff_streq(paths[i] as *u8, path)==1 { r=1; i=n } else { i=i+1 } } else { i=i+1 } 319 } 320 return r 321} 322 323// ---------------------------------------------------------------- walk 324func ff_walk(p: *u8, pn: i64, depth: i64, mode: i64, floor: i64, 325 counts: *i64, ccnt: *i64, hist: *i64, w: *i64, qn: *i64, 326 ppaths: *i64, pstates: *i64, nprior: i64, 327 ptrs: *i64, lens: *i64, nrefs: i64, work: *u8, wo: *i64) -> i64 { 328 if depth > FF_MAXDEPTH { return 0 } 329 if pn > FF_PATHCAP-256 { return 0 } 330 p[pn]=0 as u8 331 let fd: i64 = sys_openat_rd(p) 332 if fd<0 { return 0 } 333 let dbuf: *u8 = sys_mmap(FF_DIRBUF) 334 let prose: *i64 = sys_mmap(16) as *i64 335 let hbp: *i64 = sys_mmap(16) as *i64 336 let row: *u8 = sys_mmap(FF_ROWCAP) 337 let urlb: *u8 = sys_mmap(FF_ROWCAP) 338 let kbuf: *u8 = sys_mmap(64) 339 var go: i64 = 1 340 while go==1 { 341 let nr: i64 = sys_getdents64(fd, dbuf, FF_DIRBUF) 342 if nr<=0 { go=0 } else { 343 var off: i64 = 0 344 while off < nr { 345 let rec: *u8 = (dbuf as i64 + off) as *u8 346 let ty: i64 = dirent_type(rec) 347 let nm: *u8 = dirent_name(rec) 348 if mi_isdotdot(nm)==0 { 349 let cs: i64 = mi_join(p, pn, nm) 350 p[cs]=0 as u8 351 if ty==FF_DT_DIR { 352 ff_walk(p, cs, depth+1, mode, floor, counts, ccnt, hist, w, qn, ppaths, pstates, nprior, ptrs, lens, nrefs, work, wo) 353 } else { 354 let cls: i64 = mi_content_class(p, floor, prose, hbp) 355 counts[FF_C_FILES]=counts[FF_C_FILES]+1 356 ccnt[cls]=ccnt[cls]+1 357 if hbp[0]<=0 { counts[FF_C_UNREAD]=counts[FF_C_UNREAD]+1 } 358 // the histogram is over JUDGEABLE bodies only: a non-HTML body has no prose 359 // measurement at all (prose=-1) and folding it in as a zero would manufacture 360 // a spike at the very bucket the floor is chosen from. 361 if prose[0] >= 0 { hist[ff_bucket(prose[0])] = hist[ff_bucket(prose[0])] + 1 } 362 if cls==MC_NOT_HTML { counts[FF_C_NOTHTML]=counts[FF_C_NOTHTML]+1 } else { 363 if cls==MC_OK { 364 counts[FF_C_OK]=counts[FF_C_OK]+1 365 if mode==1 { 366 if ff_prior_open(p, ppaths, pstates, nprior)==1 { 367 var a: i64 = 0 368 a = mi_cat(row, a, p) 369 row[a]=FF_BAR as u8; a=a+1 370 a = mi_cat(row, a, "-" as *u8) 371 row[a]=FF_BAR as u8; a=a+1 372 a = mi_catn(row, a, cls) 373 row[a]=FF_BAR as u8; a=a+1 374 a = mi_cat(row, a, mi_content_reason(cls)) 375 row[a]=FF_BAR as u8; a=a+1 376 a = mi_cat(row, a, "none\x00" as *u8) 377 row[a]=FF_BAR as u8; a=a+1 378 a = mi_catn(row, a, prose[0]) 379 row[a]=FF_BAR as u8; a=a+1 380 a = mi_catn(row, a, hbp[0]) 381 row[a]=FF_BAR as u8; a=a+1 382 a = mi_catn(row, a, sys_now_realtime_sec()) 383 row[a]=FF_BAR as u8; a=a+1 384 a = mi_cat(row, a, FF_ST_RES as *u8) 385 ff_qkey(kbuf, qn[0]) 386 ss_add(w, FF_KIND_LIVE, kbuf, row, a) 387 qn[0]=qn[0]+1 388 counts[FF_C_RESOLV]=counts[FF_C_RESOLV]+1 389 } 390 } 391 } else { 392 counts[FF_C_FLAG]=counts[FF_C_FLAG]+1 393 urlb[0]=45 as u8 394 urlb[1]=0 as u8 395 if mode==1 { ff_url_for(p, ptrs, lens, nrefs, urlb) } 396 if mode==1 { 397 var a: i64 = 0 398 a = mi_cat(row, a, p) 399 row[a]=FF_BAR as u8; a=a+1 400 a = mi_cat(row, a, urlb) 401 row[a]=FF_BAR as u8; a=a+1 402 a = mi_catn(row, a, cls) 403 row[a]=FF_BAR as u8; a=a+1 404 a = mi_cat(row, a, mi_content_reason(cls)) 405 row[a]=FF_BAR as u8; a=a+1 406 a = mi_cat(row, a, mi_content_remedy(cls)) 407 row[a]=FF_BAR as u8; a=a+1 408 a = mi_catn(row, a, prose[0]) 409 row[a]=FF_BAR as u8; a=a+1 410 a = mi_catn(row, a, hbp[0]) 411 row[a]=FF_BAR as u8; a=a+1 412 a = mi_catn(row, a, sys_now_realtime_sec()) 413 row[a]=FF_BAR as u8; a=a+1 414 a = mi_cat(row, a, FF_ST_OPEN as *u8) 415 ff_qkey(kbuf, qn[0]) 416 ss_add(w, FF_KIND_LIVE, kbuf, row, a) 417 qn[0]=qn[0]+1 418 } 419 if wo[0] < FF_WORKFLUSH { 420 var b: i64 = wo[0] 421 b = mi_cat(work, b, " " as *u8) 422 b = mi_cat(work, b, mi_content_reason(cls)) 423 b = mi_cat(work, b, " remedy=" as *u8) 424 b = mi_cat(work, b, mi_content_remedy(cls)) 425 b = mi_cat(work, b, " prose=" as *u8) 426 b = mi_catn(work, b, prose[0]) 427 b = mi_cat(work, b, " bytes=" as *u8) 428 b = mi_catn(work, b, hbp[0]) 429 b = mi_cat(work, b, " url=" as *u8) 430 b = mi_cat(work, b, urlb) 431 b = mi_cat(work, b, " " as *u8) 432 b = mi_cat(work, b, p) 433 work[b]=FF_NL as u8; b=b+1 434 wo[0]=b 435 } 436 } 437 } 438 } 439 } 440 off = off + dirent_reclen(rec) 441 } 442 } 443 } 444 sys_close(fd) 445 return 0 446} 447 448func main(argc: i64, argv: *i64) -> i64 { 449 var mode: i64 = 1 // 1=census, 0=probe 450 var dir: *u8 = MI_DEF_DIR as *u8 451 var ai: i64 = 1 452 if argc>=2 { 453 let a1: *u8 = argv[1] as *u8 454 if ff_streq(a1, "probe\x00" as *u8)==1 { mode=0; ai=2 } 455 else { if ff_streq(a1, "census\x00" as *u8)==1 { mode=1; ai=2 } } 456 } 457 if argc>ai { dir = argv[ai] as *u8 } 458 459 let floor: i64 = mi_prose_floor() 460 461 mi_w("=== NX-FETCHFAIL -- a WHOLE body is not the same claim as the RIGHT body ===\n" as *u8) 462 mi_w(" subject dir: " as *u8); mi_w(dir) 463 if mode==0 { mi_w(" mode: PROBE (distribution only -- no plane write, no verdict)\n" as *u8) } 464 else { mi_w(" mode: CENSUS\n" as *u8) } 465 466 let counts: *i64 = sys_mmap(128) as *i64 467 var z: i64 = 0 468 while z<8 { counts[z]=0; z=z+1 } 469 let ccnt: *i64 = sys_mmap(128) as *i64 470 z=0 471 while z<8 { ccnt[z]=0; z=z+1 } 472 let hist: *i64 = sys_mmap(8*FF_NBUCK) as *i64 473 z=0 474 while z<FF_NBUCK { hist[z]=0; z=z+1 } 475 476 let refp: *i64 = sys_mmap(8*FF_MAXREFS) as *i64 477 let refl: *i64 = sys_mmap(8*FF_MAXREFS) as *i64 478 let rovf: *i64 = sys_mmap(16) as *i64 479 rovf[0]=0 480 let rwhich: *i64 = sys_mmap(16) as *i64 481 rwhich[0]=0 482 var nrefs: i64 = 0 483 if mode==1 { nrefs = ff_refs_load(refp, refl, rovf, rwhich) } 484 485 let work: *u8 = sys_mmap(FF_WORKCAP) 486 let wo: *i64 = sys_mmap(16) as *i64 487 wo[0]=0 488 let pbuf: *u8 = sys_mmap(FF_PATHCAP) 489 var dn: i64 = 0 490 while dir[dn]!=(0 as u8) { pbuf[dn]=dir[dn]; dn=dn+1 } 491 492 let w: *i64 = ss_begin_cap(SS_MAGIC_1048576) 493 let qn: *i64 = sys_mmap(16) as *i64 494 qn[0]=0 495 // Load the previous run's rows BEFORE walking, then close the handle: the walk writes a fresh 496 // full generation of rows, so holding a reader open across it would only invite reading rows this 497 // very run is replacing. 498 let ppaths: *i64 = sys_mmap(8*FF_MAXPRIOR) as *i64 499 let pstates: *i64 = sys_mmap(8*FF_MAXPRIOR) as *i64 500 let povf: *i64 = sys_mmap(16) as *i64 501 povf[0]=0 502 var nprior: i64 = 0 503 if mode==1 { 504 let pblob: *u8 = sys_mmap(FF_PRIORBUF) 505 let h: *i64 = ss_open(FF_PLANE as *u8) 506 nprior = ff_prior_load(h, ppaths, pstates, pblob, povf) 507 if (h as i64) != 0 { ss_close(h) } 508 } 509 510 ff_walk(pbuf, dn, 0, mode, floor, counts, ccnt, hist, w, qn, ppaths, pstates, nprior, refp, refl, nrefs, work, wo) 511 512 let ob: *u8 = sys_mmap(16384) 513 var a: i64 = 0 514 515 if mode==0 { 516 a = mi_cat(ob, a, "\n-- PROSE-BYTE DISTRIBUTION over JUDGEABLE (HTML) bodies --\n" as *u8) 517 a = mi_cat(ob, a, " This is the evidence prose-floor-bytes is chosen FROM. A bar picked without it\n" as *u8) 518 a = mi_cat(ob, a, " is a magic number wearing a config key.\n" as *u8) 519 var i: i64 = 0 520 var tot: i64 = 0 521 while i < FF_NBUCK { tot=tot+hist[i]; i=i+1 } 522 i=0 523 while i < FF_NBUCK { 524 a = mi_cat(ob, a, " prose>=" as *u8) 525 a = mi_catn(ob, a, ff_bucket_lo(i)) 526 a = mi_cat(ob, a, " count=" as *u8) 527 a = mi_catn(ob, a, hist[i]) 528 ob[a]=FF_NL as u8; a=a+1 529 i=i+1 530 } 531 a = mi_cat(ob, a, " judgeable_total=" as *u8); a = mi_catn(ob, a, tot) 532 a = mi_cat(ob, a, " not-html=" as *u8); a = mi_catn(ob, a, counts[FF_C_NOTHTML]) 533 a = mi_cat(ob, a, " files=" as *u8); a = mi_catn(ob, a, counts[FF_C_FILES]) 534 let psum: i64 = tot + counts[FF_C_NOTHTML] 535 a = mi_cat(ob, a, "\n sum=" as *u8); a = mi_catn(ob, a, psum) 536 if psum==counts[FF_C_FILES] { a = mi_cat(ob, a, " partition=RECONCILES\n" as *u8) } 537 else { a = mi_cat(ob, a, " partition=LEAK\n" as *u8) } 538 ob[a]=0 as u8 539 mi_w(ob) 540 let vb0: *u8 = sys_mmap(512) 541 var v0: i64 = 0 542 v0 = mi_cat(vb0, v0, "\nNX-FETCHFAIL mode=probe files=" as *u8); v0 = mi_catn(vb0, v0, counts[FF_C_FILES]) 543 v0 = mi_cat(vb0, v0, " judgeable=" as *u8); v0 = mi_catn(vb0, v0, counts[FF_C_FILES]-counts[FF_C_NOTHTML]) 544 v0 = mi_cat(vb0, v0, " floor_in_force=" as *u8); v0 = mi_catn(vb0, v0, floor) 545 v0 = mi_cat(vb0, v0, " verdict=GREEN\n" as *u8) 546 vb0[v0]=0 as u8 547 mi_w(vb0) 548 sys_exit(0) 549 return 0 550 } 551 552 mi_w("\n-- WORKLIST (every flagged body, with the REMEDY LANE that clears it) --\n" as *u8) 553 if wo[0]==0 { mi_w(" (none -- every judgeable body carried prose above the floor)\n" as *u8) } 554 else { work[wo[0]]=0 as u8; mi_w(work) } 555 if wo[0] >= FF_WORKFLUSH { mi_w(" <== THIS LIST IS A PREFIX OF ITS OWN COUNT (worklist buffer filled)\n" as *u8) } 556 557 a = mi_cat(ob, a, "\n-- BY CLASS (the ruler is mi_content_class; these are its measured firings) --\n" as *u8) 558 var k: i64 = 0 559 while k <= MC_NOT_HTML { 560 a = mi_cat(ob, a, " count=" as *u8) 561 a = mi_catn(ob, a, ccnt[k]) 562 a = mi_cat(ob, a, " " as *u8) 563 a = mi_cat(ob, a, mi_content_reason(k)) 564 a = mi_cat(ob, a, " remedy=" as *u8) 565 a = mi_cat(ob, a, mi_content_remedy(k)) 566 ob[a]=FF_NL as u8; a=a+1 567 k=k+1 568 } 569 a = mi_cat(ob, a, "\n-- PARTITION (must sum to files) --\n FLAGGED=" as *u8) 570 a = mi_catn(ob, a, counts[FF_C_FLAG]) 571 a = mi_cat(ob, a, " CONTENT-PRESENT=" as *u8); a = mi_catn(ob, a, counts[FF_C_OK]) 572 a = mi_cat(ob, a, " NOT-HTML(unjudgeable)=" as *u8); a = mi_catn(ob, a, counts[FF_C_NOTHTML]) 573 a = mi_cat(ob, a, "\n files=" as *u8); a = mi_catn(ob, a, counts[FF_C_FILES]) 574 let sum: i64 = counts[FF_C_FLAG]+counts[FF_C_OK]+counts[FF_C_NOTHTML] 575 a = mi_cat(ob, a, " sum=" as *u8); a = mi_catn(ob, a, sum) 576 if sum==counts[FF_C_FILES] { a = mi_cat(ob, a, " partition=RECONCILES\n" as *u8) } 577 else { a = mi_cat(ob, a, " partition=LEAK\n" as *u8) } 578 a = mi_cat(ob, a, "\n-- SEPARATE AXES (NOT partition members) --\n unreadable-or-empty=" as *u8) 579 a = mi_catn(ob, a, counts[FF_C_UNREAD]) 580 a = mi_cat(ob, a, "\n auto-closed-this-run=" as *u8); a = mi_catn(ob, a, counts[FF_C_RESOLV]) 581 a = mi_cat(ob, a, "\n refs_files_loaded=" as *u8); a = mi_catn(ob, a, nrefs) 582 if rovf[0]==1 { a = mi_cat(ob, a, " <== REFS TABLE OVERFLOWED: the url join used a PREFIX\n" as *u8) } 583 a = mi_cat(ob, a, "\n prose-floor-bytes in force=" as *u8); a = mi_catn(ob, a, floor) 584 a = mi_cat(ob, a, "\n\n-- SCOPE, STATED SO NOBODY READS THIS AS A CLEAN BILL --\n" as *u8) 585 a = mi_cat(ob, a, " NOT-HTML is NOT clean: a PDF or image cannot be judged on this axis at all and is\n" as *u8) 586 a = mi_cat(ob, a, " counted apart rather than acquitted. FLAGGED is a FLOOR on damage -- a fetch failure\n" as *u8) 587 a = mi_cat(ob, a, " that renders prose above the floor is not detected here. Completeness is a SEPARATE\n" as *u8) 588 a = mi_cat(ob, a, " question answered by nx_mirrorintegrity: a body can be COMPLETE-PROVEN and still be a\n" as *u8) 589 a = mi_cat(ob, a, " bot wall, and neither census alone is a certificate.\n" as *u8) 590 ob[a]=0 as u8 591 mi_w(ob) 592 593 var committed: i64 = 0 594 if w[1] > 0 { 595 // THE ROW-COUNT KEY IS PART OF THE ROW-PLANE CONTRACT, NOT AN EXTRA. sts_load -- the loader 596 // behind every standard reader, `nx_store_put <prefix> load` included -- reads "q:n" FIRST and 597 // returns ZERO ROWS when it is absent, which surfaces to the caller as NOT-A-ROW-PLANE. So 598 // writing q:0..q:n-1 WITHOUT q:n produces a plane that is fully populated and still unreadable 599 // by anything except its own author: the exact defect the q: rewrite existed to end, reproduced 600 // one key short of the finish line. Measured 2026-08-25: rows=135, plane_committed=1, and the 601 // standard reader still answered NOT-A-ROW-PLANE until this key was written. 602 // It also makes a SHRINKING generation correct: rows from an older, longer segment still 603 // resolve, and only the count decides how many are read. 604 let cb: *u8 = sys_mmap(64) 605 let cl: i64 = mi_catn(cb, 0, qn[0]) 606 ss_add(w, FF_KIND_LIVE, "q:n\x00" as *u8, cb, cl) 607 let seg: i64 = ss_next_segid(FF_PLANE as *u8) 608 if ss_commit(FF_PLANE as *u8, w, seg)==0 { committed=1 } 609 } 610 611 let vb: *u8 = sys_mmap(1024) 612 var v: i64 = 0 613 v = mi_cat(vb, v, "\nNX-FETCHFAIL files=" as *u8); v = mi_catn(vb, v, counts[FF_C_FILES]) 614 v = mi_cat(vb, v, " flagged=" as *u8); v = mi_catn(vb, v, counts[FF_C_FLAG]) 615 v = mi_cat(vb, v, " content_present=" as *u8); v = mi_catn(vb, v, counts[FF_C_OK]) 616 v = mi_cat(vb, v, " not_html=" as *u8); v = mi_catn(vb, v, counts[FF_C_NOTHTML]) 617 v = mi_cat(vb, v, " resolved=" as *u8); v = mi_catn(vb, v, counts[FF_C_RESOLV]) 618 v = mi_cat(vb, v, " floor=" as *u8); v = mi_catn(vb, v, floor) 619 v = mi_cat(vb, v, " rows=" as *u8); v = mi_catn(vb, v, qn[0]) 620 v = mi_cat(vb, v, " plane_committed=" as *u8); v = mi_catn(vb, v, committed) 621 if counts[FF_C_FLAG] > 0 { v = mi_cat(vb, v, " verdict=RED\n" as *u8) } 622 else { v = mi_cat(vb, v, " verdict=GREEN\n" as *u8) } 623 vb[v]=0 as u8 624 mi_w(vb) 625 if counts[FF_C_FLAG] > 0 { sys_exit(1); return 1 } 626 sys_exit(0) 627 return 0 628}