code wiki / (root) / nx_compare_rank_refresh_test_20260907.nx

nx_compare_rank_refresh_test_20260907.nx source

↩ module page · 1257 lines · 85097 B

1// nx_compare_rank.nx -- THE ROADMAP RANKER: priority computed from the boards, never chosen by a seat. 2// 3// Operator 2026-08-18: "we need sota best of breed prioritization and ranking from the foundation first 4// bit up in our compares to drive our roadmaps ... it needs to push back on your random doing of low 5// priorities" and "we cant keep having you do random shit and say its effective". A seat picking rungs 6// by whatever is cheapest with parts in-tree is the defect; this organ makes the compare COMPUTE the 7// order from data the boards already carry and PUBLISH it where every seat, MCP caller and RACI row 8// reads it. It decides nothing itself: the math is nx_dr_ocm (DR-6 opportunity-cost ranker, 9// Priority=(V*M)/C, integer deterministic -- REGISTERED-DARK until today, adopted here) and the plane 10// write is nx_store_put; this organ only DERIVES the three inputs per open rung, all from data: 11// 12// THE MATHEMATICS (v5, 2026-08-18 -- operator: "a full mathematical system on opportunity cost, 13// clustering, foundation-up capabilities, best-of-breed research as of August 2026", not a seat's 14// coefficients). Every term is COUNTED or a RATIO of board data; the only chosen constant left is 15// RANK_COST_UNKNOWN and it fires only on a plan row that declared no cost (a labeled data defect). 16// value v = deficit + CoD + option + enables (all from matrix codes + dep rows) 17// deficit = sum of rival codes on the rung's row (2 leads, 1 present, 0 absent): value at stake 18// CoD = deficit x (rivals LEADING / rivals total): WSJF cost-of-delay -- the fraction of the 19// field already ahead is the time-criticality; every unit open, that many rivals widen it 20// option = 1, ONLY when every rival is absent: the lead itself, held by nobody -- its unlocking 21// value is already the enables leg below (one leg each; a v5 draft double-charged it) 22// enables = number of OTHER open rungs whose transitive dependency closure contains this rung: 23// the foundation-first / opportunity-enablement leg (WSJF) and the compound-option leg 24// (real-options portfolio theory), counted from dep rows 25// momentum m = 1 + declared dependencies already MEASURED present (substrate landed; never 0 because 26// nx_dr_ocm multiplies and a zero would hide the rung) 27// cost c = the plan's own est u in tenths, DIVIDED by the rung's cluster size (open rungs sharing 28// the same organ file share substrate: read once, one build lane, one gate to extend -- 29// graph clustering on the organ column, measured never labelled); unestimated -> labeled 30// sponsor = the operator's sponsor- plane coefficient (PR6), applied to value, every firing row named 31// priority = nx_dr_ocm( v x sponsor, m, c ) = (V x M x 1000)/C with forgone-best-alternative and 32// budget-aware greedy selection (DR-6, integer deterministic) 33// critical path: the FIRST unmet product version's milestone rungs + transitive open deps rank 34// before everything else (ver| rows) -- staged delivery 0.1 -> 1.0 -> 2.0. 35// Provenance: WSJF/cost-of-delay (SAFe LPM), real-options R&D portfolio valuation with project 36// interdependencies (Blau et al.; OptFolio-class DSS), integer-programming portfolio selection under 37// budget (knapsack form -- dr_ocm's greedy is the bounded-effort stand-in), dependency-graph enablement. 38// pmdash.refs carries the citations. What is NOT here, honestly: uncertainty distributions (PTRS-style 39// success probabilities per rung) -- the estate has no measured per-rung success rate yet; PR7's 40// actuals-write-back is the data that makes that term possible, and it will be added when the data 41// exists rather than invented now. 42// 43// The output is the PRINTED TABLE (every rung's full derivation, v/m/c and where each came from, so the 44// number can be argued from its inputs) plus ONE PLANE ROW per domain in comparerank-<domain>: 45// id=<domain>, title=the #1 rung, status=its priority, scope=the #1 rung id, note=the ordered queue. 46// One row = one segment commit; a per-rung row was measured stalling the fleet in D-state on 47// 2026-08-18 (syscalls per unit of output, §F). Whole population per domain, no sampling. 48// 49// usage: nx_compare_rank <domain> [budget_tenths] (runs from nishihost cwd; reads 50// buildroot/knowledge/compare/<domain>.plan + .matrix; forks ./nx_dr_ocm_cli.elf and ./nx_store_put.elf) 51// exit: 0 ranked+published | 2 usage | 3 plan/matrix unreadable | 4 ranker fork failed | 5 BAR-STALE (a declared bar 52// older than the current month with no this-month barscan attestation: the board refuses to hand out work) 53// | 6 LADDER-PARTIAL (a declared ladder to SOTA left half-declared: an undated target or a rung with no role) 54// license_tier: ORIGINAL No hw writes (Rule 26). 55import "nx_syscalls.nx" 56import "nx_tool_run.nx" 57import "nx_rank_refresh_lib.nx" 58// CE2 (2026-08-23): the estate's adoption ladder -- ONE classifier shared with nx_catalog and the page 59import "nx_catalog_lib.nx" 60import "nx_symdecl_lib.nx" 61// BAR FRESHNESS (2026-09-06): the one ruler for bar age, composed here so a stale bar refuses the work queue 62import "nx_barfresh_lib.nx" 63// LADDER TO SOTA (2026-09-06): the one ruler for dated best-in-class and frontier targets and a role on every rung 64import "nx_ladder_lib.nx" 65const RANK_EXIT_REFRESH_IO: i64 = 7 66const RANK_EXIT_DISPATCH: i64 = 8 67const RANK_INPUT_METADATA_BYTES: i64 = 256 // two SHA256 hex strings, sizes and labels 68const RANK_EXIT_BAR_STALE: i64 = 5 // a declared bar older than the current month with no this-month attestation: the board hands out no work 69const RANK_EXIT_LADDER_PARTIAL: i64 = 6 // a declared ladder to SOTA left half-declared (an undated target, a rung with no role): refused the same way 70 71// POPULATION CAPS REMOVED 2026-08-23 (lane F): the former RANK_MAX_RUNGS=64 / RANK_MAX_ROWS=64 / 72// RANK_FIELD_MAX=24 / RANK_FILE_CAP=262144 / RANK_SRC_CAP=524288 / RANK_QUEUE_CAP=8192 were SILENT 73// caps -- browser.matrix carries 76 rows, so every row past 64 was invisible and its rung read 74// UNMAPPED (measured: BR20 bpd_download, whose watch row exists). Every population bound is now 75// DERIVED from the data it bounds: files are read whole by sys_read_file (sized from the file, cannot 76// short-read), row/rung/field arrays are sized from the line and pipe census of the loaded bytes, and 77// every buffer that holds a composed string is sized from the lengths of what it composes. The only 78// bounds that remain are fork CAPTURES (a pipe has no knowable size): each is named for its one 79// purpose, sized from the population that produces it, and ANNOUNCES when it fills. 80const RK_DEC_MAX: i64 = 20 // max decimal digits of an i64 (19) plus a sign: the width of one 81 // rk_catn/rk_pn number, the unit every composed-string bound counts in 82const RK_NUMBUF: i64 = RK_DEC_MAX + 4 // one number rendered to text + NUL + slack for the '-' and terminator 83// (RANK_EXCEED_BONUS retired 2026-08-18: the exceed lane is now valued as a REAL OPTION -- one plus the 84// downstream rungs it enables -- derived from the dependency graph instead of a chosen constant.) 85const RANK_COST_UNKNOWN: i64 = 100 // 10.0 u: an unestimated rung is treated as EXPENSIVE, labeled -- 86 // the ONE remaining chosen constant, and it only ever affects rungs 87 // whose plan row failed to declare a cost (a labeled data defect) 88const RANK_DEFAULT_BUDGET: i64 = 300 // 30.0 u -- above every plan's full-parity figure, so the greedy 89 // selection reports the whole ordering (budget filtering is the 90 // caller's lever via argv[2]) 91const RANK_STORE_FIELDS: i64 = 8 92// ONE RUNG NOTE is literals + numbers + plane-sourced text. The constants below are COUNTED from this 93// source (scratchpad count_lits.py over every `rk_cat(nb, ...)` / `rk_catn(nb, ...)` site, 2026-08-23): 94// RK_NOTE_LITERALS = 531 the summed source length of the 26 literal appends (a source-length bound) 95// RK_NOTE_NUMS = 13 rk_catn sites on the note path, each at most RK_DEC_MAX bytes 96// RK_SPONSOR_ROW_LITERALS = 11 the literal bytes ONE applying sponsor row adds (" sponsor[" ":" "]"); the 97// row's own id and weight come from the plane, so the plane's length bounds them 98// The caller sizes a note as literals + nums*RK_DEC_MAX + splen + rows*RK_SPONSOR_ROW_LITERALS + the 99// dom/id/sym/organ strings it echoes. Re-count when a note literal is added; the count is the contract. 100const RK_NOTE_LITERALS: i64 = 531 101const RK_NOTE_NUMS: i64 = 13 102const RK_SPONSOR_ROW_LITERALS: i64 = 11 103const RANK_FORK_CAP: i64 = 4096 // captured stdout of one nx_store_put / nx_pm_intake fork: their 104 // receipts are one line; a fill is ANNOUNCED (CAPTURE-FULL) not dropped 105// the ranker's JSON: one object per open rung -- 8 keys (89 literal bytes incl. braces and the separating 106// comma) plus 8 numbers -- and a fixed header/footer (195 literal bytes plus 5 numbers); COUNTED from 107// nx_dr_ocm_cli's emitter (scratchpad count_ocm.py, 2026-08-23). The capture is sized from nopen, and a 108// fill is REFUSED loudly (a ranking read as a prefix is worse than no ranking). 109const RK_OCM_OBJ_BYTES: i64 = 89 + 8 * RK_DEC_MAX 110const RK_OCM_HDR_BYTES: i64 = 195 + 5 * RK_DEC_MAX + 16 111// CE2/CE6 (2026-08-23): a rung whose symbol is PRESENT but whose organ is short of full adoption (built and 112// never promoted, promoted and never registered, a lib imported only by its gate) used to count DONE here -- 113// the board could not see a partial deploy at all. Such rungs now also print as FINISH rows (state + remedy) 114// ahead of the ranked queue, land in the plane note as F[state]ID, and in the stamped artefact 115// buildroot/knowledge/compare/<dom>.rank that the page renders as "Do this next". NO coefficient changed: 116// v/m/c, the critical path and the order of open rungs are untouched; FINISH is a separate, cheaper class. 117const RANK_FIX_PER_RUNG: i64 = 64 + 10 * RK_DEC_MAX // row skeleton: kind, pipes, numbers, newline 118// One persisted `unmapped|<id>|<sym>|<reason>` row: the literal bytes only. The two VARIABLE parts, 119// id and sym, are added as measured rk_slen terms at the cap loop rather than being guessed here -- 120// the same shape the rest of that loop already uses, so this cannot under-size on a long symbol. 121// Measured literal: "unmapped|" 9 + "|" 1 + "|" 1 + "no-matrix-row-carries-this-symbol" 33 + LF 1 = 45. 122const RANK_UNMAPPED_ROW: i64 = 48 123// RAISED 256 -> 512 (2026-09-01) to carry the one-line unmapped COUNT header that now precedes the 124// stamp. The tail is fixed-size text, so this is arithmetic, not a guess: the count line is ~110 bytes 125// plus a rendered integer, and 256 had no room for it beside the stamp it was sized for. 126const RANK_FIX_TAIL: i64 = 512 // the stamped last line + the unmapped count line 127const RANK_PM_TOP: i64 = 3 // critical rungs filed into pm intake per run: enough to drive 128 // the next sessions, few enough that intake stays a queue not a dump 129 130func rk_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 131func rk_puts(s: *u8) -> i64 { sys_write(1, s, rk_slen(s)); return 0 } 132func rk_pn(v: i64) -> i64 { 133 let t: *u8 = sys_mmap(RK_NUMBUF) as *u8 134 var m: i64 = v; var w: i64 = 0 135 if m < 0 { t[w] = 45 as u8; w = w + 1; m = 0 - m } 136 if m == 0 { t[w] = 48 as u8; sys_write(1, t, w + 1); return 0 } 137 let d: *u8 = sys_mmap(RK_NUMBUF) as *u8 138 var k: i64 = 0 139 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 140 var j: i64 = 0 141 while j < k { t[w] = d[k-1-j]; w = w + 1; j = j + 1 } 142 sys_write(1, t, w); return 0 143} 144func rk_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var oo: i64 = o; while s[i] != (0 as u8) { d[oo] = s[i]; oo = oo + 1; i = i + 1 } d[oo] = 0 as u8; return oo } 145func rk_catn(d: *u8, o: i64, v: i64) -> i64 { 146 let t: *u8 = sys_mmap(RK_NUMBUF) as *u8 147 var m: i64 = v; var k: i64 = 0; var oo: i64 = o 148 if m < 0 { d[oo] = 45 as u8; oo = oo + 1; m = 0 - m } 149 if m == 0 { d[oo] = 48 as u8; oo = oo + 1; d[oo] = 0 as u8; return oo } 150 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 151 while k > 0 { k = k - 1; d[oo] = t[k]; oo = oo + 1 } 152 d[oo] = 0 as u8 153 return oo 154} 155func rk_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] == b[i] { if a[i] == (0 as u8) { return 1 } i = i + 1 } return 0 } 156func rk_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } 157// WHOLE-FILE READ, sized from the file (sys_read_file: lseek END, cannot short-read; +16 slack so the 158// in-place NUL-splitting below may write one past the last byte). Returns the byte count, -1 if 159// unreadable, and hands the buffer back through outb. The former rk_read took a caller CAP and 160// stopped there in silence -- a 262144-byte plan or a 524288-byte organ source read as a PREFIX. 161func rk_read_all(path: *u8, outb: *i64) -> i64 { 162 let lenp: *i64 = sys_mmap(16) as *i64 163 let b: *u8 = sys_read_file(path, lenp) 164 outb[0] = b as i64 165 if (b as i64) == 0 { return 0 - 1 } 166 return lenp[0] 167} 168// line census of a loaded buffer: newlines + 1 -- an upper bound on rows/rungs/ms/ver rows, DERIVED 169func rk_lines(b: *u8, n: i64) -> i64 { 170 var c: i64 = 1 171 var i: i64 = 0 172 while i < n { if b[i] == (10 as u8) { c = c + 1 } i = i + 1 } 173 return c 174} 175// pipe census: the most '|' on any one line + 2 -- the field-slot bound for rk_split, DERIVED 176func rk_max_pipes(b: *u8, n: i64) -> i64 { 177 var best: i64 = 0 178 var cur: i64 = 0 179 var i: i64 = 0 180 while i < n { 181 if b[i] == (10 as u8) { if cur > best { best = cur } cur = 0 } else { if b[i] == (124 as u8) { cur = cur + 1 } } 182 i = i + 1 183 } 184 if cur > best { best = cur } 185 return best + 2 186} 187// split a NUL-terminated line on '|' IN PLACE (same contract as the compare generator's splitpipe) 188func rk_split(s: *u8, fld: *i64, maxf: i64) -> i64 { 189 var c: i64 = 1; fld[0] = s as i64; var i: i64 = 0 190 while s[i] != (0 as u8) { if s[i] == (124 as u8) { s[i] = 0 as u8; if c < maxf { fld[c] = (s as i64) + i + 1; c = c + 1 } } i = i + 1 } 191 return c 192} 193// "1.5" -> 15, "2" -> 20, "-" -> -1 (tenths of a unit; one decimal is all the plans use) 194func rk_tenths(s: *u8) -> i64 { 195 if s[0] == (45 as u8) { return 0 - 1 } 196 var v: i64 = 0; var i: i64 = 0; var any: i64 = 0; var frac: i64 = 0 - 1 197 while s[i] != (0 as u8) { 198 let c: i64 = s[i] as i64 199 if c >= 48 { if c <= 57 { if frac < 0 { v = v * 10 + (c - 48) } else { if frac == 0 { v = v * 10 + (c - 48); frac = 1 } } any = 1 } } 200 if c == 46 { frac = 0 } 201 i = i + 1 202 } 203 if any == 0 { return 0 - 1 } 204 if frac < 0 { v = v * 10 } 205 if frac == 0 { v = v * 10 } 206 return v 207} 208func rk_int(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v } 209// symbol match: the matrix row's symbol is either "<sym>" (present) or "_ABSENT_:<sym>" (watched) 210func rk_sym_is(rowsym: *u8, sym: *u8) -> i64 { 211 if rk_streq(rowsym, sym) == 1 { return 1 } 212 if rk_starts(rowsym, "_ABSENT_:" as *u8) == 1 { if rk_streq((rowsym as i64 + 9) as *u8, sym) == 1 { return 1 } } 213 return 0 214} 215 216// presence measured EXACTLY as the emitter measures it: the symbol exists as a top-level function 217// declaration in the organ's source. The matrix DATA keeps its _ABSENT_ watch spelling forever -- 218// the flip is a MEASUREMENT at emit -- so a ranker that reads the data state calls every landed rung 219// open (measured on first run: done=0 of 22 with ig_room_solve, gp_collect2 and ntb_bake_pbr all 220// live). Re-measure, never trust the spelling. 221func rk_measure(org: *u8, sym: *u8) -> i64 { 222 let pb: *u8 = sys_mmap(rk_slen(org) + 16) // "buildroot/" (10) + org + NUL 223 var o: i64 = rk_cat(pb, 0, "buildroot/" as *u8) 224 o = rk_cat(pb, o, org) 225 // ONE RULER (2026-08-23, lane L): the declaration test lives in nx_symdecl_lib and is the SAME 226 // function the matrix generator, the sota watch section and the regen's comparewatch plane call. 227 // The claim above ("EXACTLY as the emitter measures it") was measured FALSE on lang LN8 -- the 228 // emitter used a substring -- and is now true by construction rather than by assertion. 229 let rl: *i64 = sys_mmap(16) as *i64 230 if sd_present(pb, sym, rl) == 1 { return 1 } 231 return 0 232} 233// DARK CONTRACT (2026-09-06, operator: a permanent fix, we do not build and lose capability to darkness): the organ 234// the row names EXISTS and was read, but does not declare the symbol under a rule that can judge -- something shipped 235// there under another name. The SAME arithmetic the matrix generator (cell state dk) and the regen's comparewatch 236// plane (state DARK) use: sd_present returns -1 unreadable / 0 read-and-absent / 1 present, and the JS rule's 237// abstention is folded to 0, so a JSDECL rule is excluded -- a rung the ruler cannot judge is open, never dark. 238func rk_dark(org: *u8, sym: *u8) -> i64 { 239 let pb: *u8 = sys_mmap(rk_slen(org) + 16) 240 var o: i64 = rk_cat(pb, 0, "buildroot/" as *u8) 241 o = rk_cat(pb, o, org) 242 let rl: *i64 = sys_mmap(16) as *i64 243 let st: i64 = sd_present(pb, sym, rl) 244 if st != 0 { return 0 } 245 if rl[0] == SD_RULE_JSDECL { return 0 } 246 return 1 247} 248// rk_sponsor_term -- PR6: the operator's SPONSORSHIP as a ranker coefficient (feedback law 249// 2026-08-18: a verdict that is not a row is a verdict the next ranking ignores). Reads the sponsor- 250// plane through nx_store_put load (the CLI lane; the MCP load verb reads planes empty), each row 251// id<TAB>title<TAB>sev<TAB>weight<TAB>actor<TAB>scope<TAB>note. A row APPLIES to a rung when its scope 252// is this domain or "all" AND (its note or title names the rung's id, its symbol, or its domain). 253// Weights are the coarse vocabulary plus2/plus1/minus1/minus2 (a coefficient, not a science; a fine 254// scale would invite tuning theater). Multiplier = SPONSOR_BASE + sum(weights) in units of 255// SPONSOR_BASE, floored at 1 so a minus can demote but never zero a value (a zeroed value hides the 256// rung from the ranker -- demotion must stay visible). Returns the multiplier x SPONSOR_BASE; the 257// caller applies v = v * m / SPONSOR_BASE and prints m so the coefficient is arguable from its rows. 258const SPONSOR_BASE: i64 = 4 // plus2 = +50%, plus1 = +25%, minus1 = -25%, minus2 = -50% 259const SPONSOR_PLANE_CAP: i64 = 262144 260func rk_has(hay: *u8, needle: *u8) -> i64 { 261 let nl: i64 = rk_slen(needle) 262 if nl == 0 { return 0 } 263 var i: i64 = 0 264 while hay[i] != (0 as u8) { 265 var k: i64 = 0 266 var same: i64 = 1 267 while k < nl { if hay[i+k] != needle[k] { same = 0; k = nl } else { if hay[i+k] == (0 as u8) { same = 0; k = nl } } k = k + 1 } 268 if same == 1 { return 1 } 269 i = i + 1 270 } 271 return 0 272} 273func rk_sponsor_term(plane: *u8, plen: i64, dom: *u8, rid1: *u8, sym: *u8, nb: *u8, no0: i64, noOut: *i64) -> i64 { 274 var mult: i64 = SPONSOR_BASE 275 var no: i64 = no0 276 var applied: i64 = 0 277 var p: i64 = 0 278 while p < plen { 279 var e: i64 = p 280 while e < plen { if plane[e] == (10 as u8) { break } e = e + 1 } 281 plane[e] = 0 as u8 282 let ln: *u8 = (plane as i64 + p) as *u8 283 p = e + 1 284 if ln[0] != (0 as u8) { 285 // split on TAB 286 let f: *i64 = sys_mmap(16 * 8) as *i64 287 var c: i64 = 1; f[0] = ln as i64; var i: i64 = 0 288 while ln[i] != (0 as u8) { if ln[i] == (9 as u8) { ln[i] = 0 as u8; if c < 16 { f[c] = (ln as i64) + i + 1; c = c + 1 } } i = i + 1 } 289 if c >= 7 { 290 let scope: *u8 = f[5] as *u8 291 var inscope: i64 = 0 292 if rk_streq(scope, dom) == 1 { inscope = 1 } 293 if rk_streq(scope, "all" as *u8) == 1 { inscope = 1 } 294 if inscope == 1 { 295 var names: i64 = 0 296 if rk_has(f[6] as *u8, rid1) == 1 { names = 1 } 297 if rk_has(f[6] as *u8, sym) == 1 { names = 1 } 298 if rk_has(f[1] as *u8, sym) == 1 { names = 1 } 299 // a domain-scoped row with no rung name applies to the whole domain 300 if rk_streq(scope, dom) == 1 { names = 1 } 301 if names == 1 { 302 var w: i64 = 0 303 let ws: *u8 = f[3] as *u8 304 if rk_streq(ws, "plus2" as *u8) == 1 { w = 2 } 305 if rk_streq(ws, "plus1" as *u8) == 1 { w = 1 } 306 if rk_streq(ws, "minus1" as *u8) == 1 { w = 0 - 1 } 307 if rk_streq(ws, "minus2" as *u8) == 1 { w = 0 - 2 } 308 mult = mult + w 309 applied = applied + 1 310 no = rk_cat(nb, no, " sponsor[" as *u8); no = rk_cat(nb, no, f[0] as *u8); no = rk_cat(nb, no, ":" as *u8); no = rk_cat(nb, no, ws); no = rk_cat(nb, no, "]" as *u8) 311 } 312 } 313 } 314 } 315 } 316 if mult < 1 { mult = 1 } 317 if applied == 0 { no = rk_cat(nb, no, " sponsor=none" as *u8) } else { no = rk_cat(nb, no, " sponsor_mult_x4=" as *u8); no = rk_catn(nb, no, mult) } 318 noOut[0] = no 319 return mult 320} 321// ---- PR11: THE SELF-SUFFICIENCY TERM ------------------------------------------------------------ 322// Operator 2026-08-20: "where would be the best investment that drives the most self sufficiency 323// down". Recorded interpretation (feedback-foundation-and-autonomous-frontier-2026-08-20): drive 324// outside DEPENDENCY down / sovereignty UP. A rung whose organ stands on outside dependency delivers 325// a capability that does not survive the internet going away, or that only exists while a seat drives 326// it -- and rule 1 of that same memo says such a rung is MISPRICED, not merely noted. So the price 327// changes here, in the ranker, rather than on a separate board nobody consults. 328// 329// Input: nx_selfsuff's ledger (knowledge/status/selfsuff.ledger, or argv[3]), rows 330// dep|domain|organ|outside_dep|seat_only|seat_freq|claude_loop|hosts 331// Only TWO of those columns feed the coefficient, and the exclusion is measured, not stylistic: 332// outside_dep -- distinct non-sovereign hosts the organ dials in string literals, plus distinct 333// carriers it touches at ONE HOP. Sparse, RE-MEASURED 2026-08-20 against the fixed 334// census (the 90-of-556 figure this line used to carry came from a build that no 335// longer exists): 33 of 560 with-source organs carry ANY measured dependency -- 336// 26 outside_dep units + 18 claude_loop organs = 44 dependency units. 337// ⚠ The ledger also now carries a TRANSITIVE net_dep column (0 none / 1 direct / 338// 2 via-helper). It is DELIBERATELY NOT read here: it answers "what breaks with no 339// internet", which is a different question from "how much outside dependency does 340// this rung stand on", and folding it in would re-price every rung in the estate 341// off the back of a measurement change rather than a decision. 342// claude_loop -- seat_only AND a WITNESS frame in the action record. Evidence-positive. 343// seat_only -- DELIBERATELY NOT USED. Measured at 92% of subjects, and A SIGNAL THAT FIRES ON 344// EVERYTHING DISCRIMINATES NOTHING; as a penalty it would demote nearly every rung 345// by the same amount, which is a no-op on ordering wearing the costume of rigour. 346// 347// THERE ARE NO CHOSEN WEIGHTS, on purpose -- there is no number here for a later seat to tune toward 348// a nicer answer: 349// SELFSUFF_BASE = SPONSOR_BASE's quarter vocabulary. ONE coefficient scale in this organ, not two. 350// SELFSUFF_FLOOR = the sponsor term's floor, for the sponsor term's reason: a zeroed value HIDES a 351// rung from the ranking, and a demotion must stay VISIBLE. 352// SELFSUFF_PEN_CAP = SELFSUFF_BASE - SELFSUFF_FLOOR. Not a knob: any larger value is unreachable 353// because the floor clamps first, and any smaller one would make the floor 354// unreachable, silently capping the term below its own vocabulary. 355// 356// d == 0 => multiplier == SELFSUFF_BASE => the value is UNCHANGED. That is the POSITIVE CONTROL, and 357// it is the tooth that matters: A TERM THAT PENALISES EVERYTHING PASSES EVERY NEGATIVE TEST. 358const SELFSUFF_BASE: i64 = 4 359const SELFSUFF_FLOOR: i64 = 1 360const SELFSUFF_PEN_CAP: i64 = SELFSUFF_BASE - SELFSUFF_FLOOR 361// (SELFSUFF_LEDGER_CAP=4194304 retired 2026-08-23: the ledger is a FILE and is read whole by rk_read_all) 362// compare b[s..e) against a NUL-terminated literal WITHOUT writing into the buffer -- the ledger is 363// read once and shared by every rung, so a parser that NUL-splits in place would corrupt the next 364// lookup (the sponsor term hands out copies for exactly this reason; not needing copies is cheaper). 365func rk_ss_eqf(b: *u8, s: i64, e: i64, lit: *u8) -> i64 { 366 var i: i64 = 0 367 var p: i64 = s 368 while p < e { 369 if lit[i] == (0 as u8) { return 0 } 370 if b[p] != lit[i] { return 0 } 371 p = p + 1 372 i = i + 1 373 } 374 if lit[i] == (0 as u8) { return 1 } 375 return 0 376} 377func rk_ss_atoi(b: *u8, s: i64, e: i64) -> i64 { 378 var v: i64 = 0 379 var neg: i64 = 0 380 var p: i64 = s 381 while p < e { 382 let c: i64 = b[p] as i64 383 if c == 45 { neg = 1 } else { if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } } 384 p = p + 1 385 } 386 if neg == 1 { return 0 - v } 387 return v 388} 389// Returns the multiplier in units of SELFSUFF_BASE; the caller applies v = v * m / SELFSUFF_BASE. 390// Every row that fired is printed BY ID (domain/organ) beside the number, so the coefficient is 391// arguable from its evidence rather than taken on trust -- the sponsor term's contract, kept. 392func rk_selfsuff_term(led: *u8, ln: i64, dom: *u8, org: *u8, nb: *u8, no0: i64, noOut: *i64) -> i64 { 393 var no: i64 = no0 394 if ln <= 0 { 395 no = rk_cat(nb, no, " selfsuff=UNOBSERVED(no ledger -- run nx_selfsuff census)" as *u8) 396 noOut[0] = no 397 return SELFSUFF_BASE 398 } 399 let fs: *i64 = sys_mmap(16 * 8) as *i64 400 var found: i64 = 0 401 var outd: i64 = 0 402 var loopd: i64 = 0 403 var p: i64 = 0 404 while p < ln { 405 var e: i64 = p 406 var fnd: i64 = 0 407 while fnd == 0 { if e >= ln { fnd = 1 } else { if led[e] == (10 as u8) { fnd = 1 } else { e = e + 1 } } } 408 if found == 0 { if rk_starts((led as i64 + p) as *u8, "dep|" as *u8) == 1 { 409 var nf: i64 = 1 410 fs[0] = p 411 var q: i64 = p 412 while q < e { if led[q] == (124 as u8) { if nf < 16 { fs[nf] = q + 1; nf = nf + 1 } } q = q + 1 } 413 if nf >= 8 { 414 if rk_ss_eqf(led, fs[1], fs[2] - 1, dom) == 1 { if rk_ss_eqf(led, fs[2], fs[3] - 1, org) == 1 { 415 outd = rk_ss_atoi(led, fs[3], fs[4] - 1) 416 loopd = rk_ss_atoi(led, fs[6], fs[7] - 1) 417 found = 1 418 } } 419 } 420 } } 421 p = e + 1 422 } 423 if found == 0 { 424 // NOT the same state as a missing ledger, and NOT the same as zero dependency: this organ was 425 // never in the census population. Say which, and do not price what was not measured. 426 no = rk_cat(nb, no, " selfsuff=NO-LEDGER-ROW(organ absent from the census population)" as *u8) 427 noOut[0] = no 428 return SELFSUFF_BASE 429 } 430 var dep: i64 = outd + loopd 431 if dep < 0 { dep = 0 } 432 var pen: i64 = dep 433 if pen > SELFSUFF_PEN_CAP { pen = SELFSUFF_PEN_CAP } 434 var mult: i64 = SELFSUFF_BASE - pen 435 if mult < SELFSUFF_FLOOR { mult = SELFSUFF_FLOOR } 436 no = rk_cat(nb, no, " selfsuff[row=" as *u8); no = rk_cat(nb, no, dom); no = rk_cat(nb, no, "/" as *u8); no = rk_cat(nb, no, org) 437 no = rk_cat(nb, no, " outside_dep=" as *u8); no = rk_catn(nb, no, outd) 438 no = rk_cat(nb, no, " claude_loop=" as *u8); no = rk_catn(nb, no, loopd) 439 no = rk_cat(nb, no, " pen=min(dep,base-floor)=" as *u8); no = rk_catn(nb, no, pen) 440 no = rk_cat(nb, no, " mult_x4=" as *u8); no = rk_catn(nb, no, mult) 441 if dep == 0 { no = rk_cat(nb, no, " SOVEREIGN-NO-PENALTY" as *u8) } 442 no = rk_cat(nb, no, "]" as *u8) 443 noOut[0] = no 444 return mult 445} 446// walk one comma-separated rung-id token: resolve to a rung index; return 1 if that rung is OPEN 447// (not measured present); mode 1 additionally marks it on the critical path. 448func rk_list_one(idstr: *u8, mode: i64, rid: *i64, nr: i64, rdone: *i64, crit: *i64) -> i64 { 449 if idstr[0] == (0 as u8) { return 0 } 450 if idstr[0] == (45 as u8) { return 0 } 451 var r: i64 = 0 452 while r < nr { 453 if rk_streq(rid[r] as *u8, idstr) == 1 { 454 if rdone[r] == 0 { if mode == 1 { crit[r] = 1 } return 1 } 455 return 0 456 } 457 r = r + 1 458 } 459 return 0 460} 461// walk a whole comma list; returns how many listed rungs are OPEN (mode 1 also marks them critical) 462func rk_list_scan(ls: *u8, mode: i64, rid: *i64, nr: i64, rdone: *i64, crit: *i64) -> i64 { 463 let tmp: *u8 = sys_mmap(rk_slen(ls) + 2) // one token is never longer than the whole list 464 var di: i64 = 0 465 var dj: i64 = 0 466 var any: i64 = 0 467 var go: i64 = 1 468 while go == 1 { 469 let c: i64 = ls[di] as i64 470 if c == 44 { tmp[dj] = 0 as u8; any = any + rk_list_one(tmp, mode, rid, nr, rdone, crit); dj = 0 } 471 else { if c == 0 { tmp[dj] = 0 as u8; any = any + rk_list_one(tmp, mode, rid, nr, rdone, crit); go = 0 } 472 else { if c != 32 { tmp[dj] = ls[di]; dj = dj + 1 } } } 473 di = di + 1 474 } 475 return any 476} 477 478// the longest ver| label: the stage text one queue entry can carry ("later" is 5; a label may be longer) 479// ---- CE6: THE ORDER, AS AN ARTEFACT A PAGE CAN READ (2026-08-23) ---- 480// One truncate-write per run (tmp + fsync + rename: a reader never sees a half file), canonical last line 481// = the stamp, so a consumer anchors by POSITION and never greps an append-only journal (the 482// nx_deploy_ready lesson). Path is the generator's tree: buildroot/knowledge/compare/<dom>.rank. 483func rk_write_rank_unlocked(dom: *u8, buf: *u8, n0: i64, nr: i64, ndone: i64, nopen: i64, nfinish: i64, tgt: i64, vlab: *i64) -> i64 { 484 var n: i64 = n0 485 n = rk_cat(buf, n, "# asof=" as *u8); n = rk_catn(buf, n, sys_now_realtime_sec()) 486 n = rk_cat(buf, n, " domain=" as *u8); n = rk_cat(buf, n, dom) 487 n = rk_cat(buf, n, " target_version=" as *u8) 488 if tgt >= 0 { n = rk_cat(buf, n, vlab[tgt] as *u8) } else { n = rk_cat(buf, n, "-" as *u8) } 489 n = rk_cat(buf, n, " rungs=" as *u8); n = rk_catn(buf, n, nr) 490 n = rk_cat(buf, n, " done=" as *u8); n = rk_catn(buf, n, ndone) 491 n = rk_cat(buf, n, " open=" as *u8); n = rk_catn(buf, n, nopen) 492 n = rk_cat(buf, n, " finish=" as *u8); n = rk_catn(buf, n, nfinish) 493 n = rk_cat(buf, n, " ranker=nx_dr_ocm\n" as *u8) 494 let dl: i64 = rk_slen(dom) 495 let outp: *u8 = sys_mmap(dl + 48) 496 var oo: i64 = rk_cat(outp, 0, "buildroot/knowledge/compare/" as *u8); oo = rk_cat(outp, oo, dom); oo = rk_cat(outp, oo, ".rank" as *u8) 497 let tmp: *u8 = sys_mmap(dl + 56) 498 var to: i64 = rk_cat(tmp, 0, outp); to = rk_cat(tmp, to, ".tmp" as *u8) 499 let fd: i64 = sys_openat_wr(tmp, MODE_0644) 500 if fd < 0 { rk_puts("RANK ARTEFACT WRITE-FAILED: cannot open " as *u8); rk_puts(tmp); rk_puts("\n" as *u8); return 0 - 1 } 501 var w: i64 = 0 502 while w < n { 503 let r: i64 = sys_write(fd, ((buf as i64) + w) as *u8, n - w) 504 if r <= 0 { sys_close(fd); rk_puts("RANK ARTEFACT WRITE-FAILED: short write\n" as *u8); return 0 - 1 } 505 w = w + r 506 } 507 if sys_fsync(fd) != 0 { sys_close(fd); rk_puts("RANK ARTEFACT WRITE-FAILED: fsync before rename\n" as *u8); return 0 - 1 } 508 if sys_close(fd) != 0 { rk_puts("RANK ARTEFACT WRITE-FAILED: close before rename\n" as *u8); return 0 - 1 } 509 if rrf_file_equal(tmp, buf, n) != 1 { rk_puts("RANK ARTEFACT WRITE-FAILED: temporary readback mismatch\n" as *u8); return 0 - 1 } 510 if sys_renameat(tmp, outp) != 0 { rk_puts("RANK ARTEFACT WRITE-FAILED: rename\n" as *u8); return 0 - 1 } 511 let dirfd: i64 = sys_openat_rd("buildroot/knowledge/compare" as *u8) 512 if dirfd < 0 { rk_puts("RANK ARTEFACT UNCERTAIN: renamed but directory unavailable for fsync\n" as *u8); return 0 - 1 } 513 let drc: i64 = sys_fsync(dirfd) 514 let crc: i64 = sys_close(dirfd) 515 if drc != 0 { rk_puts("RANK ARTEFACT UNCERTAIN: renamed but directory fsync failed\n" as *u8); return 0 - 1 } 516 if crc != 0 { rk_puts("RANK ARTEFACT UNCERTAIN: directory close failed\n" as *u8); return 0 - 1 } 517 if rrf_file_equal(outp, buf, n) != 1 { rk_puts("RANK ARTEFACT UNCERTAIN: committed path readback mismatch\n" as *u8); return 0 - 1 } 518 rk_puts("RANK artefact wrote=" as *u8); rk_pn(n); rk_puts(" of=" as *u8); rk_puts(outp); rk_puts(" finish=" as *u8); rk_pn(nfinish); rk_puts("\n" as *u8) 519 return 0 520} 521// Serialize cooperating refreshes while the fixed temporary path is written and verified. 522func rk_write_rank(dom: *u8, buf: *u8, n0: i64, nr: i64, ndone: i64, nopen: i64, nfinish: i64, tgt: i64, vlab: *i64) -> i64 { 523 let lp: *u8 = sys_mmap(rk_slen(dom) + 64) 524 var o: i64 = rk_cat(lp, 0, "buildroot/knowledge/compare/" as *u8) 525 o = rk_cat(lp, o, dom); o = rk_cat(lp, o, ".rank.lock" as *u8) 526 let fd: i64 = sys_openat_rdwr(lp, MODE_0644) 527 if fd < 0 { rk_puts("RANK ARTEFACT REFUSED: lock open failed\n" as *u8); return 0 - 1 } 528 if sys_flock(fd, SYS_LOCK_EX | SYS_LOCK_NB) != 0 { sys_close(fd); rk_puts("RANK ARTEFACT REFUSED: writer lock unavailable\n" as *u8); return 0 - 1 } 529 let rc: i64 = rk_write_rank_unlocked(dom, buf, n0, nr, ndone, nopen, nfinish, tgt, vlab) 530 let closed: i64 = sys_close(fd) 531 if closed != 0 { return 0 - 1 } 532 return rc 533} 534 535func qcap_stage_max(vlab: *i64, nver: i64) -> i64 { 536 var best: i64 = 5 537 var k: i64 = 0 538 while k < nver { let l: i64 = rk_slen(vlab[k] as *u8); if l > best { best = l } k = k + 1 } 539 return best 540} 541 542func main(argc: i64, argv: *i64) -> i64 { 543 if argc < 2 { rk_puts("usage: nx_compare_rank <domain> [budget_tenths] [selfsuff_ledger] [--artifact-only]\n" as *u8); return 2 } 544 let dom: *u8 = argv[1] as *u8 545 var argn: i64 = argc 546 var artifact_only: i64 = 0 547 if argc > 2 { if rk_streq(argv[argc - 1] as *u8, "--artifact-only" as *u8) == 1 { artifact_only = 1; argn = argc - 1 } } 548 if artifact_only == 1 { rk_puts("RANK mode=artifact-only PM-and-plane-dispatch=disabled\n" as *u8) } 549 var budget: i64 = RANK_DEFAULT_BUDGET 550 if argn > 2 { budget = rk_int(argv[2] as *u8) } 551 // ---- read the plan ---- 552 let dlen: i64 = rk_slen(dom) 553 let pp: *u8 = sys_mmap(dlen + 48) // "buildroot/knowledge/compare/" (28) + dom + ".matrix" (7) + NUL 554 var po: i64 = rk_cat(pp, 0, "buildroot/knowledge/compare/" as *u8); po = rk_cat(pp, po, dom); po = rk_cat(pp, po, ".plan" as *u8) 555 let pbp: *i64 = sys_mmap(16) as *i64 556 let pn: i64 = rk_read_all(pp, pbp) 557 let pbuf: *u8 = pbp[0] as *u8 558 if pn <= 0 { rk_puts("RANK REFUSED: no plan at " as *u8); rk_puts(pp); rk_puts("\n" as *u8); return 3 } 559 // ---- read the matrix ---- 560 let mp: *u8 = sys_mmap(dlen + 48) 561 var mo: i64 = rk_cat(mp, 0, "buildroot/knowledge/compare/" as *u8); mo = rk_cat(mp, mo, dom); mo = rk_cat(mp, mo, ".matrix" as *u8) 562 let mbp: *i64 = sys_mmap(16) as *i64 563 let mn: i64 = rk_read_all(mp, mbp) 564 let mbuf: *u8 = mbp[0] as *u8 565 if mn <= 0 { rk_puts("RANK REFUSED: no matrix at " as *u8); rk_puts(mp); rk_puts("\n" as *u8); return 3 } 566 let plan_sha: *u8 = sys_mmap(RRF_HEX_BYTES + RRF_NUL_BYTES) 567 let matrix_sha: *u8 = sys_mmap(RRF_HEX_BYTES + RRF_NUL_BYTES) 568 if rrf_hash(pbuf, pn, plan_sha) != 0 { return RANK_EXIT_REFRESH_IO } 569 if rrf_hash(mbuf, mn, matrix_sha) != 0 { return RANK_EXIT_REFRESH_IO } 570 // ---- DERIVED population bounds: rows <= lines of the matrix, rungs/ms/ver <= lines of the plan, 571 // fields per row <= pipes on the widest line -- counted from the loaded bytes, never a constant ---- 572 let max_rows: i64 = rk_lines(mbuf, mn) 573 let max_rungs: i64 = rk_lines(pbuf, pn) 574 var max_fields: i64 = rk_max_pipes(mbuf, mn) 575 let pf: i64 = rk_max_pipes(pbuf, pn) 576 if pf > max_fields { max_fields = pf } 577 // ---- index matrix rows: symbol -> (present, sum of rival codes, all-absent) ---- 578 let msym: *i64 = sys_mmap(max_rows * 8) as *i64 579 let morg: *i64 = sys_mmap(max_rows * 8) as *i64 580 let mdef: *i64 = sys_mmap(max_rows * 8) as *i64 581 let mall0: *i64 = sys_mmap(max_rows * 8) as *i64 582 let mlead: *i64 = sys_mmap(max_rows * 8) as *i64 583 let mpres: *i64 = sys_mmap(max_rows * 8) as *i64 584 var mrows: i64 = 0 585 var ncol: i64 = 0 586 let fld: *i64 = sys_mmap(max_fields * 8) as *i64 587 var p: i64 = 0 588 while p < mn { 589 var e: i64 = p 590 while e < mn { if mbuf[e] == (10 as u8) { break } e = e + 1 } 591 mbuf[e] = 0 as u8 592 let line: *u8 = (mbuf as i64 + p) as *u8 593 p = e + 1 594 if line[0] == (64 as u8) { if rk_starts(line, "@cols " as *u8) == 1 { let cf: *i64 = sys_mmap(max_fields * 8) as *i64; ncol = rk_split((line as i64 + 6) as *u8, cf, max_fields) } } 595 else { if line[0] != (0 as u8) { if line[0] != (35 as u8) { 596 let cnt: i64 = rk_split(line, fld, max_fields) 597 if cnt >= 5 + ncol { if mrows < max_rows { 598 msym[mrows] = fld[2] 599 morg[mrows] = fld[1] 600 var dsum: i64 = 0 601 var allz: i64 = 1 602 var nlead: i64 = 0 603 var cj: i64 = 0 604 while cj < ncol { let cv: i64 = rk_int(fld[4 + cj] as *u8); dsum = dsum + cv; if cv > 0 { allz = 0 } if cv >= 2 { nlead = nlead + 1 } cj = cj + 1 } 605 mdef[mrows] = dsum 606 mall0[mrows] = allz 607 mlead[mrows] = nlead 608 mpres[mrows] = 1 609 if rk_starts(fld[2] as *u8, "_ABSENT_" as *u8) == 1 { mpres[mrows] = 0 } 610 mrows = mrows + 1 611 } } 612 } } } 613 } 614 // ---- walk plan rungs: collect id/title/sym/exec/est/deps ---- 615 let vlab: *i64 = sys_mmap(max_rungs * 8) as *i64 616 let vms: *i64 = sys_mmap(max_rungs * 8) as *i64 617 var nver: i64 = 0 618 let msid: *i64 = sys_mmap(max_rungs * 8) as *i64 619 let msrungs: *i64 = sys_mmap(max_rungs * 8) as *i64 620 var nms: i64 = 0 621 let rid: *i64 = sys_mmap(max_rungs * 8) as *i64 622 let rtitle: *i64 = sys_mmap(max_rungs * 8) as *i64 623 let rsym: *i64 = sys_mmap(max_rungs * 8) as *i64 624 let rexec: *i64 = sys_mmap(max_rungs * 8) as *i64 625 let rest: *i64 = sys_mmap(max_rungs * 8) as *i64 626 let rdeps: *i64 = sys_mmap(max_rungs * 8) as *i64 627 var nr: i64 = 0 628 // THE BAR AND LADDER RULERS READ A PRISTINE COPY. rk_split in the rung walk below NUL-terminates every FIELD of every 629 // rung| row in place, so once that loop has run pbuf no longer spells "rung|" anywhere: a ruler handed pbuf counts zero 630 // rungs and reports every rungrole| row as an orphan. MEASURED live 2026-09-06 on a fully declared board: targets=3 631 // rungs=0 orphans=34 verdict=PARTIAL, a false refusal from the hook that exists to refuse half-declared ladders. The copy 632 // is taken BEFORE the walk; sotabar|, sotatarget| and rungrole| rows were never mutated, which is why the bar hook 633 // happened to read correctly and the ladder hook did not -- the same buffer, two answers, decided by which rows the 634 // ranker itself parses. 635 let prist: *u8 = sys_mmap(pn + 1) 636 var pci: i64 = 0 637 while pci < pn { prist[pci] = pbuf[pci]; pci = pci + 1 } 638 prist[pn] = 0 as u8 639 p = 0 640 while p < pn { 641 var e2: i64 = p 642 while e2 < pn { if pbuf[e2] == (10 as u8) { break } e2 = e2 + 1 } 643 pbuf[e2] = 0 as u8 644 let ln: *u8 = (pbuf as i64 + p) as *u8 645 p = e2 + 1 646 if rk_starts(ln, "rung|" as *u8) == 1 { if nr < max_rungs { 647 let c2: i64 = rk_split(ln, fld, max_fields) 648 if c2 >= 8 { 649 rid[nr] = fld[1]; rtitle[nr] = fld[2]; rsym[nr] = fld[3]; rexec[nr] = fld[5] 650 rest[nr] = rk_tenths(fld[6] as *u8) 651 rdeps[nr] = fld[7] 652 nr = nr + 1 653 } 654 } } 655 // ver|<label>|<ms-id>: the PRODUCT VERSION ladder (operator 2026-08-18: critical paths to 0.1 656 // then 1.0 then 2.0 drive delivery, digital and physical). Order in the file IS the ladder. 657 if rk_starts(ln, "ver|" as *u8) == 1 { if nver < max_rungs { 658 let c3: i64 = rk_split(ln, fld, max_fields) 659 if c3 >= 3 { vlab[nver] = fld[1]; vms[nver] = fld[2]; nver = nver + 1 } 660 } } 661 // ms|<id>|<label>|<cum>|<rung,rung,...> 662 if rk_starts(ln, "ms|" as *u8) == 1 { if nms < max_rungs { 663 let c4: i64 = rk_split(ln, fld, max_fields) 664 if c4 >= 5 { msid[nms] = fld[1]; msrungs[nms] = fld[4]; nms = nms + 1 } 665 } } 666 } 667 if nr == 0 { rk_puts("RANK REFUSED: plan has no rung rows\n" as *u8); return 3 } 668 // BAR FRESHNESS -- THE HARD FAIL (operator 2026-09-06: "make sure its a hard fail to use anything less than current 669 // month unless there is nothing current month" and "this needs to become the way that the logic forces you from the 670 // /compare domain"). The plan's sotabar| rows carry their source month and its barscan| rows attest what THIS month's 671 // listing returned; nx_barfresh_lib is the one ruler. A domain that declared bars and let them go stale gets NO ranking 672 // and NO pm filing: the board refuses to hand out work until the bar is the current month's or its fallback is attested 673 // this month. A domain with no bar rows is LABELED, never refused -- it opts in by declaring its first bar (a fleet-wide 674 // refusal on day one would be the permanently-red detector everyone learns to ignore). prist is the pristine copy taken 675 // before the rung walk (rk_split NUL-terminates every field in place); the ruler reads both line endings. 676 let bfc: *i64 = sys_mmap(BF_C_N * 8) as *i64 677 let bfnb: i64 = bf_count_rows(prist, pn, BF_BAR_TAG) 678 let bfoff: *i64 = sys_mmap((bfnb + 1) * 8) as *i64 679 let bfym: *i64 = sys_mmap((bfnb + 1) * 8) as *i64 680 let bfst: *i64 = sys_mmap((bfnb + 1) * 8) as *i64 681 let bfseen: *i64 = sys_mmap((bfnb + 1) * 8) as *i64 682 let bfcur: i64 = bf_now_ym() 683 bf_classify(prist, pn, bfcur, bfoff, bfym, bfst, bfseen, bfc) 684 let bfv: i64 = bf_verdict(bfc) 685 rk_puts("BARFRESH bars=" as *u8); rk_pn(bfc[BF_C_BARS]); rk_puts(" fresh=" as *u8); rk_pn(bfc[BF_C_FRESH]); rk_puts(" attested=" as *u8); rk_pn(bfc[BF_C_ATTESTED]); rk_puts(" stale=" as *u8); rk_pn(bfc[BF_C_STALE]); rk_puts(" unattested=" as *u8); rk_pn(bfc[BF_C_UNATTESTED]); rk_puts(" malformed=" as *u8); rk_pn(bfc[BF_C_MALFORMED]); rk_puts(" sum=" as *u8); rk_pn(bf_partition_sum(bfc)); rk_puts(" scans_this_month=" as *u8); rk_pn(bfc[BF_C_SCANS_CUR]); rk_puts(" verdict=" as *u8); rk_puts(bf_verdict_name(bfv)); rk_puts("\n" as *u8) 686 if bfv == BF_EXIT_NOBAR { rk_puts("BARFRESH NO-BAR: this plan declares no sotabar| row, so its bars are UNMEASURED -- LABELED, ranking proceeds; declare the field's current-month bar (sotabar|<id>|<YYYY-MM>|<subject>|<what it says>|<ref>|<note>) to opt into the hard fail\n" as *u8) } 687 if bfv == BF_EXIT_STALE { 688 rk_puts("RANK REFUSED: BAR-STALE -- a bar on this board is older than the current month and no barscan| row dated this month attests that the current month has nothing newer for its listing. The board hands out no work on a stale bar: run nx_barfresh " as *u8); rk_puts(dom); rk_puts(" for the per-bar states, fetch and READ the current month's listing (nx_research_fetch, pinned as a .refs row), then land a current sotabar| row or a barscan|<today>|<ref>|newest=<month> attestation\n" as *u8) 689 return RANK_EXIT_BAR_STALE 690 } 691 // LADDER TO SOTA (operator 2026-09-06: "how you framed it here is how all the /compare domains should be emitting with 692 // clarity on what dependencies from the first byte up all grow us each rung up to sota with a clear target on what is 693 // best in class and what is frontier"). sotatarget| rows name the dated targets and rungrole| rows give every rung its 694 // role toward one; nx_ladder_lib is the one ruler. A board that declared its ladder and left it half-declared (an 695 // undated target, a rung with no role, a role or class outside the vocabulary) is refused like a stale bar; a board with 696 // no ladder is LABELED and ranked -- it opts in by declaring its first target. 697 let ldnt: i64 = bf_count_rows(prist, pn, LD_TARGET_TAG) 698 let ldnr: i64 = bf_count_rows(prist, pn, LD_RUNG_TAG) 699 let ldc: *i64 = sys_mmap(LD_N_COUNT * 8) as *i64 700 let ldtoff: *i64 = sys_mmap((ldnt + 1) * 8) as *i64 701 let ldtcls: *i64 = sys_mmap((ldnt + 1) * 8) as *i64 702 let ldtst: *i64 = sys_mmap((ldnt + 1) * 8) as *i64 703 let ldroff: *i64 = sys_mmap((ldnr + 1) * 8) as *i64 704 let ldrrole: *i64 = sys_mmap((ldnr + 1) * 8) as *i64 705 let ldrtgt: *i64 = sys_mmap((ldnr + 1) * 8) as *i64 706 let ldrst: *i64 = sys_mmap((ldnr + 1) * 8) as *i64 707 ld_classify(prist, pn, ldtoff, ldtcls, ldtst, ldroff, ldrrole, ldrtgt, ldrst, ldc) 708 let ldv: i64 = ld_verdict(ldc) 709 rk_puts("LADDER targets=" as *u8); rk_pn(ldc[LD_N_TARGETS]); rk_puts(" best_in_class=" as *u8); rk_pn(ldc[LD_N_BIC]); rk_puts(" frontier=" as *u8); rk_pn(ldc[LD_N_FRONTIER]); rk_puts(" undated=" as *u8); rk_pn(ldc[LD_N_UNDATED]); rk_puts(" badclass=" as *u8); rk_pn(ldc[LD_N_BADCLASS]); rk_puts(" rungs=" as *u8); rk_pn(ldc[LD_N_RUNGS]); rk_puts(" placed=" as *u8); rk_pn(ldc[LD_N_PLACED]); rk_puts(" unplaced=" as *u8); rk_pn(ldc[LD_N_UNPLACED]); rk_puts(" badrole=" as *u8); rk_pn(ldc[LD_N_BADROLE]); rk_puts(" badtarget=" as *u8); rk_pn(ldc[LD_N_BADTARGET]); rk_puts(" sum=" as *u8); rk_pn(ld_partition_sum(ldc)); rk_puts(" substrate=" as *u8); rk_pn(ldc[LD_N_SUBSTRATE]); rk_puts(" arm=" as *u8); rk_pn(ldc[LD_N_ARM]); rk_puts(" contender=" as *u8); rk_pn(ldc[LD_N_CONTENDER]); rk_puts(" superseded=" as *u8); rk_pn(ldc[LD_N_SUPERSEDED]); rk_puts(" orphans=" as *u8); rk_pn(ldc[LD_N_ORPHANS]); rk_puts(" verdict=" as *u8); rk_puts(ld_verdict_name(ldv)); rk_puts("\n" as *u8) 710 if ldv == LD_EXIT_NOLADDER { rk_puts("LADDER NO-LADDER: this plan names no sotatarget| row, so what best-in-class and the frontier ARE is UNDECLARED -- LABELED, ranking proceeds; declare a dated best-in-class and a dated frontier target (sotatarget|<id>|<class>|<sotabar id>|<statement>|<ref>) and a rungrole|<rung>|<role>|<target>|<why> row per rung to opt into the hard fail\n" as *u8) } 711 if ldv == LD_EXIT_PARTIAL { 712 rk_puts("RANK REFUSED: LADDER-PARTIAL -- this board declared its ladder to SOTA and left it half-declared: a target without a sotabar row, a class or role outside the vocabulary, a rung with no rungrole row, or a rungrole row naming no rung or no target. The board hands out no work on a half-declared ladder: run nx_ladder " as *u8); rk_puts(dom); rk_puts(" for the per-target and per-rung states and complete the declaration\n" as *u8) 713 return RANK_EXIT_LADDER_PARTIAL 714 } 715 // ---- derive v/m/c per OPEN rung (a rung whose symbol is measured PRESENT is done: skipped, counted) ---- 716 let ov: *i64 = sys_mmap(nr * 8) as *i64 717 let om: *i64 = sys_mmap(nr * 8) as *i64 718 let oc: *i64 = sys_mmap(nr * 8) as *i64 719 let oidx: *i64 = sys_mmap(nr * 8) as *i64 720 let onote: *i64 = sys_mmap(nr * 8) as *i64 721 let rdone: *i64 = sys_mmap(nr * 8) as *i64 722 let rmi: *i64 = sys_mmap(nr * 8) as *i64 723 // DARK CONTRACT per rung (2026-09-06, operator: a permanent fix, we do not build and lose capability to darkness): 724 // 1 when the rung's matrix row names an organ that EXISTS and was read but does not declare the contracted 725 // symbol -- something shipped under another name; printed on the rung line so the repoint is priced as work. 726 let rdark_r: *i64 = sys_mmap(nr * 8) as *i64 727 var nopen: i64 = 0 728 var ndone: i64 = 0 729 // PASS A: measure every rung's presence first, so the momentum pass can read ANY dependency's 730 // state regardless of declaration order. 731 var i: i64 = 0 732 while i < nr { 733 var mi: i64 = 0 - 1 734 var q: i64 = 0 735 while q < mrows { if rk_sym_is(msym[q] as *u8, rsym[i] as *u8) == 1 { mi = q; q = mrows } q = q + 1 } 736 var done: i64 = 0 737 if mi >= 0 { 738 if mpres[mi] == 1 { done = 1 } 739 else { 740 var symp: *u8 = msym[mi] as *u8 741 if rk_starts(symp, "_ABSENT_:" as *u8) == 1 { symp = (symp as i64 + 9) as *u8 } 742 done = rk_measure(morg[mi] as *u8, symp) 743 if done == 0 { rdark_r[i] = rk_dark(morg[mi] as *u8, symp) } 744 } 745 } 746 rdone[i] = done 747 rmi[i] = mi 748 if done == 1 { ndone = ndone + 1 } 749 i = i + 1 750 } 751 // ---- CE2: ADOPTION of every DONE rung (present by symbol) -- FULL or PARTIAL, judged by the shared 752 // classifier (program ladder / library importer reach / gate execution surfaces), memoised per organ ---- 753 let ads: *i64 = sys_mmap(CLB_N * 8) as *i64 754 clb_load(ads) 755 let rfin: *i64 = sys_mmap(nr * 8) as *i64 756 let rtok: *i64 = sys_mmap(nr * 8) as *i64 757 let rrem: *i64 = sys_mmap(nr * 8) as *i64 758 let mname: *i64 = sys_mmap(nr * 8) as *i64 759 let mtok: *i64 = sys_mmap(nr * 8) as *i64 760 let mful: *i64 = sys_mmap(nr * 8) as *i64 761 let mrem: *i64 = sys_mmap(nr * 8) as *i64 762 var mc: i64 = 0 763 var nfinish: i64 = 0 764 var fi: i64 = 0 765 while fi < nr { 766 rfin[fi] = 0 767 rtok[fi] = "" as *u8 as i64 768 rrem[fi] = "" as *u8 as i64 769 if rdone[fi] == 1 { if rmi[fi] >= 0 { 770 let oname: *u8 = sys_mmap(CLB_TOK_CAP) 771 cl_name_of_path(morg[rmi[fi]] as *u8, oname, CLB_TOK_CAP) 772 var hit: i64 = 0 - 1 773 var mk: i64 = 0 774 while mk < mc { if rk_streq(mname[mk] as *u8, oname) == 1 { hit = mk; mk = mc } mk = mk + 1 } 775 if hit < 0 { 776 let tokb: *u8 = sys_mmap(CLB_TOK_CAP) 777 let remp: *i64 = sys_mmap(8) as *i64 778 let ful: i64 = clb_classify(oname, ads, tokb, remp) 779 mname[mc] = oname as i64; mtok[mc] = tokb as i64; mful[mc] = ful; mrem[mc] = remp[0] 780 hit = mc 781 mc = mc + 1 782 } 783 rtok[fi] = mtok[hit] 784 rrem[fi] = mrem[hit] 785 if mful[hit] != CLB_FULL { rfin[fi] = 1; nfinish = nfinish + 1 } 786 } } 787 fi = fi + 1 788 } 789 // the stamped artefact: sized from the rows it will hold, never a cap 790 var rkcap: i64 = RANK_FIX_TAIL + RANK_INPUT_METADATA_BYTES + rk_slen(dom) + 64 791 var rkz: i64 = 0 792 // + RANK_UNMAPPED_ROW and a SECOND id/sym pair per rung (2026-09-01): every rung can now also emit 793 // an `unmapped|<id>|<sym>|...` row, and id and sym appear in BOTH that row and its rank| row. Budget 794 // for the worst case -- every rung unmapped -- because a cap that assumes some rungs are carried 795 // would under-size exactly on the board that most needs this row. 796 while rkz < nr { rkcap = rkcap + RANK_FIX_PER_RUNG + RANK_UNMAPPED_ROW + rk_slen(rid[rkz] as *u8) + rk_slen(rid[rkz] as *u8) + rk_slen(rtitle[rkz] as *u8) + rk_slen(rsym[rkz] as *u8) + rk_slen(rsym[rkz] as *u8) + rk_slen(rtok[rkz] as *u8) + rk_slen(rrem[rkz] as *u8); rkz = rkz + 1 } 797 let rkbuf: *u8 = sys_mmap(rkcap) 798 var rko: i64 = rk_cat(rkbuf, 0, "# " as *u8); rko = rk_cat(rkbuf, rko, dom); rko = rk_cat(rkbuf, rko, ".rank -- NX-DERIVED: regenerated artefact, not authored memory (nx_compare_rank). rows: finish|id|title|sym|state|remedy . rank|n|stage|id|priority|v|m|c|title|sym . unmapped-count|n|why . unmapped|id|sym|reason (a rung NO matrix row carries: priced at zero, so the dimension is invisible to every consumer -- the count is emitted even when it is 0, because a declared zero proves the check ran and silence does not) . last line = stamp\n" as *u8) 799 rko = rk_cat(rkbuf, rko, "# inputs_v=1 plan_sha256=" as *u8); rko = rk_cat(rkbuf, rko, plan_sha) 800 rko = rk_cat(rkbuf, rko, " plan_bytes=" as *u8); rko = rk_catn(rkbuf, rko, pn) 801 rko = rk_cat(rkbuf, rko, " matrix_sha256=" as *u8); rko = rk_cat(rkbuf, rko, matrix_sha) 802 rko = rk_cat(rkbuf, rko, " matrix_bytes=" as *u8); rko = rk_catn(rkbuf, rko, mn) 803 rko = rk_cat(rkbuf, rko, "\n" as *u8) 804 var fp: i64 = 0 805 while fp < nr { 806 if rfin[fp] == 1 { 807 rk_puts(" F [FINISH] " as *u8); rk_puts(rid[fp] as *u8); rk_puts(" state=" as *u8); rk_puts(rtok[fp] as *u8); rk_puts(" | " as *u8); rk_puts(rtitle[fp] as *u8); rk_puts(" [" as *u8); rk_puts(rsym[fp] as *u8); rk_puts("] " as *u8); rk_puts(rrem[fp] as *u8); rk_puts("\n" as *u8) 808 rko = rk_cat(rkbuf, rko, "finish|" as *u8); rko = rk_cat(rkbuf, rko, rid[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtitle[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rsym[fp] as *u8) 809 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtok[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rrem[fp] as *u8); rko = rk_cat(rkbuf, rko, "\n" as *u8) 810 } 811 fp = fp + 1 812 } 813 // sponsor plane, loaded ONCE through the CLI lane (a fork per rung would be N forks for one read) 814 let spav: *i64 = sys_mmap(8 * 8) as *i64 815 spav[0] = "./nx_store_put.elf" as *u8 as i64 816 spav[1] = "sponsor-" as *u8 as i64 817 spav[2] = "load" as *u8 as i64 818 spav[3] = 0 819 let splane: *u8 = sys_mmap(SPONSOR_PLANE_CAP) 820 let splen: *i64 = sys_mmap(16) as *i64 821 splen[0] = 0 822 tr_run_capture("./nx_store_put.elf" as *u8, spav, splane, SPONSOR_PLANE_CAP - 1, splen) 823 let splines: i64 = rk_lines(splane, splen[0]) // the most rows any note could name: every row of the plane 824 // a capture that fills its pipe budget is a PREFIX: say so (the plane is a fork, its size unknowable) 825 if splen[0] >= SPONSOR_PLANE_CAP - 1 { rk_puts("SPONSOR plane CAPTURE-FULL at SPONSOR_PLANE_CAP -- rows past the cap are NOT applied, LABELED\n" as *u8) } 826 // a plane that failed to load is UNOBSERVED, not empty: say so once, rank without the term 827 if splen[0] <= 0 { rk_puts("SPONSOR plane UNOBSERVED (load returned nothing) -- ranking without the sponsorship term, LABELED\n" as *u8) } 828 // PR11: the self-sufficiency ledger, read ONCE. A plain file read, not a plane fork: the ledger is 829 // a derived artefact with ONE writer (nx_selfsuff census), so it needs neither a segment commit nor 830 // a fork per rung, and under the load this estate actually runs at that difference is the whole 831 // cost of the term. 832 var ssledp: *u8 = "knowledge/status/selfsuff.ledger" as *u8 833 if argn > 3 { ssledp = argv[3] as *u8 } 834 let ssbp: *i64 = sys_mmap(16) as *i64 835 var ssn: i64 = rk_read_all(ssledp, ssbp) // the WHOLE ledger (a file, sized from itself) 836 let ssbuf: *u8 = ssbp[0] as *u8 837 if ssn < 0 { ssn = 0 } 838 if ssn <= 0 { rk_puts("SELFSUFF ledger UNOBSERVED (nothing at " as *u8); rk_puts(ssledp); rk_puts(") -- ranking without the self-sufficiency term, LABELED per rung\n" as *u8) } 839 else { rk_puts("SELFSUFF ledger " as *u8); rk_puts(ssledp); rk_puts(" bytes=" as *u8); rk_pn(ssn); rk_puts("\n" as *u8) } 840 // ---- ENABLEMENT (foundation-first, from the dependency graph): for each open rung, how many OTHER 841 // open rungs have it in their transitive dependency closure. A rung that unblocks five others is 842 // worth five downstream deliveries -- this is the WSJF "opportunity enablement" leg and the real- 843 // options "compound option" value, both COUNTED from dep rows, never chosen. O(n^2) closure walk 844 // over nr rungs (nr is the plan's own count; the former "<=64" was the cap this lane removed). 845 let enab: *i64 = sys_mmap(nr * 8) as *i64 846 var ez: i64 = 0 847 while ez < nr { enab[ez] = 0; ez = ez + 1 } 848 var a6: i64 = 0 849 while a6 < nr { 850 if rdone[a6] == 0 { 851 // closure of a6's deps: mark reachable open rungs 852 let reach: *i64 = sys_mmap(nr * 8) as *i64 853 var z6: i64 = 0 854 while z6 < nr { reach[z6] = 0; z6 = z6 + 1 } 855 rk_list_scan(rdeps[a6] as *u8, 1, rid, nr, rdone, reach) 856 var it6: i64 = 0 857 while it6 < nr { 858 var grew: i64 = 0 859 var b6: i64 = 0 860 while b6 < nr { 861 if reach[b6] == 1 { 862 var pre6: i64 = 0; var q6: i64 = 0 863 while q6 < nr { pre6 = pre6 + reach[q6]; q6 = q6 + 1 } 864 rk_list_scan(rdeps[b6] as *u8, 1, rid, nr, rdone, reach) 865 var post6: i64 = 0; q6 = 0 866 while q6 < nr { post6 = post6 + reach[q6]; q6 = q6 + 1 } 867 if post6 > pre6 { grew = 1 } 868 } 869 b6 = b6 + 1 870 } 871 if grew == 0 { it6 = nr } 872 it6 = it6 + 1 873 } 874 // every rung in a6's closure enables a6: credit each 875 var c6: i64 = 0 876 while c6 < nr { if reach[c6] == 1 { enab[c6] = enab[c6] + 1 } c6 = c6 + 1 } 877 } 878 a6 = a6 + 1 879 } 880 // ---- rival total for the cost-of-delay ratio (from @cols) ---- 881 var nriv: i64 = ncol 882 if nriv < 1 { nriv = 1 } 883 // PASS B: derive v/m/c for the open rungs 884 i = 0 885 while i < nr { 886 let mi: i64 = rmi[i] 887 if rdone[i] == 1 { } else { 888 var v: i64 = 0 889 // the note is literals + numbers + (sponsor rows named verbatim, bounded by the plane's own 890 // length) + (the organ path the selfsuff term echoes): sized from those parts, never a cap 891 var nbcap: i64 = RK_NOTE_LITERALS + RK_NOTE_NUMS * RK_DEC_MAX + splen[0] + splines * RK_SPONSOR_ROW_LITERALS + rk_slen(dom) + rk_slen(rid[i] as *u8) + rk_slen(rsym[i] as *u8) + 16 892 if mi >= 0 { nbcap = nbcap + rk_slen(morg[mi] as *u8) } 893 let nb: *u8 = sys_mmap(nbcap) 894 var no: i64 = 0 895 if mi >= 0 { 896 // COST OF DELAY (WSJF): the deficit is the value at stake; the fraction of rivals already 897 // LEADING (code 2) on this row is the time-criticality -- every day open, that many rivals 898 // widen the gap. CoD = deficit x leading / rivals, in the same integer units as deficit, 899 // plus the deficit itself as the base value. Both from the matrix codes. 900 let lead: i64 = mlead[mi] 901 let cod: i64 = mdef[mi] * lead / nriv 902 v = mdef[mi] + cod 903 if rdark_r[i] == 1 { no = rk_cat(nb, no, "DARK-CONTRACT(organ exists, symbol undeclared: repoint the rung AND its row to the real entry point, or rename the function) " as *u8) } 904 no = rk_cat(nb, no, "deficit=" as *u8); no = rk_catn(nb, no, mdef[mi]) 905 no = rk_cat(nb, no, " cod=deficit*leading/rivals=" as *u8); no = rk_catn(nb, no, cod) 906 // REAL-OPTION VALUE (exceed lane): a row NO rival has is an option on a lead; its value 907 // is what it unlocks -- the enablement count in deficit units, plus one for the lead 908 // itself. DERIVED, replacing the former constant bonus. 909 // the option is the LEAD itself (1) on top of the enablement every rung already carries 910 // below -- counting enables inside the option AND as its own leg double-charged exceed 911 // rows (measured 2026-08-18: R14 printed option=1+enables=8 AND +enables=7). One leg each. 912 if mall0[mi] == 1 { v = v + 1; no = rk_cat(nb, no, " +option(all rivals absent: a lead nobody holds)=1" as *u8) } 913 } else { no = rk_cat(nb, no, "UNMAPPED(no matrix row carries this symbol) value=0" as *u8) } 914 // ENABLEMENT: downstream open rungs this one unblocks (foundation-first, from dep rows) 915 v = v + enab[i] 916 no = rk_cat(nb, no, " +enables=" as *u8); no = rk_catn(nb, no, enab[i]) 917 // momentum: 1 + deps measured present 918 var mom: i64 = 1 919 let ds: *u8 = rdeps[i] as *u8 920 if ds[0] != (45 as u8) { 921 // deps are comma-separated rung ids; resolve each to its symbol, then to matrix presence 922 let dtmp: *u8 = sys_mmap(rk_slen(ds) + 2) 923 var di: i64 = 0; var dj: i64 = 0 924 var run: i64 = 1 925 while run == 1 { 926 if ds[di] == (44 as u8) { dtmp[dj] = 0 as u8; dj = 0 927 var r2: i64 = 0; while r2 < nr { if rk_streq(rid[r2] as *u8, dtmp) == 1 { if rdone[r2] == 1 { mom = mom + 1 } r2 = nr } r2 = r2 + 1 } 928 } else { if ds[di] == (0 as u8) { dtmp[dj] = 0 as u8; run = 0 929 var r3: i64 = 0; while r3 < nr { if rk_streq(rid[r3] as *u8, dtmp) == 1 { if rdone[r3] == 1 { mom = mom + 1 } r3 = nr } r3 = r3 + 1 } 930 } else { dtmp[dj] = ds[di]; dj = dj + 1 } } 931 di = di + 1 932 } 933 } 934 no = rk_cat(nb, no, " momentum=1+deps-present=" as *u8); no = rk_catn(nb, no, mom) 935 var cst: i64 = rest[i] 936 if cst <= 0 { cst = RANK_COST_UNKNOWN; no = rk_cat(nb, no, " cost=UNESTIMATED->" as *u8); no = rk_catn(nb, no, RANK_COST_UNKNOWN) } else { no = rk_cat(nb, no, " cost_tenths=" as *u8); no = rk_catn(nb, no, cst) } 937 // CLUSTER COHERENCE: open rungs whose matrix rows name the SAME organ file share substrate 938 // (one read of the code, one build lane, one gate to extend). Cost is divided by the cluster 939 // size for every member -- adjacent scheduling pays the shared setup once. Measured from the 940 // organ column, never labelled by hand; a singleton cluster divides by 1. 941 if mi >= 0 { 942 var clu: i64 = 0 943 var k7: i64 = 0 944 while k7 < nr { if rdone[k7] == 0 { if rmi[k7] >= 0 { if rk_streq(morg[rmi[k7]] as *u8, morg[mi] as *u8) == 1 { clu = clu + 1 } } } k7 = k7 + 1 } 945 if clu > 1 { cst = cst / clu; if cst < 1 { cst = 1 } no = rk_cat(nb, no, " cluster=" as *u8); no = rk_catn(nb, no, clu); no = rk_cat(nb, no, "->cost/cluster=" as *u8); no = rk_catn(nb, no, cst) } 946 } 947 if v <= 0 { v = 0 } 948 // PR6: sponsorship coefficient (x4 fixed-point), applied to VALUE so a standing order moves 949 // the ordering the way the operator meant, and every row that fired is printed by id 950 if splen[0] > 0 { 951 let noo: *i64 = sys_mmap(16) as *i64 952 // the term NUL-splits its buffer in place: hand it a COPY so the plane stays intact for 953 // the next rung (one load, N cheap copies -- never N forks, never a corrupted re-read) 954 let scopy: *u8 = sys_mmap(splen[0] + 16) 955 var cz: i64 = 0 956 while cz < splen[0] { scopy[cz] = splane[cz]; cz = cz + 1 } 957 scopy[splen[0]] = 0 as u8 958 let sm: i64 = rk_sponsor_term(scopy, splen[0], dom, rid[i] as *u8, rsym[i] as *u8, nb, no, noo) 959 no = noo[0] 960 v = v * sm / SPONSOR_BASE 961 } 962 // PR11: the self-sufficiency coefficient (x4 fixed-point), applied to VALUE so a rung that 963 // ships a capability standing on outside dependency is priced for what it actually 964 // delivers. Floored at SELFSUFF_FLOOR: it DEMOTES, it never hides. A rung whose organ has 965 // zero measured dependency comes back at SELFSUFF_BASE and its value is untouched. 966 if mi >= 0 { 967 let noo2: *i64 = sys_mmap(16) as *i64 968 let ssm: i64 = rk_selfsuff_term(ssbuf, ssn, dom, morg[mi] as *u8, nb, no, noo2) 969 no = noo2[0] 970 v = v * ssm / SELFSUFF_BASE 971 } else { no = rk_cat(nb, no, " selfsuff=NO-MATRIX-ROW(no organ to look up)" as *u8) } 972 ov[nopen] = v; om[nopen] = mom; oc[nopen] = cst; oidx[nopen] = i; onote[nopen] = nb as i64 973 nopen = nopen + 1 974 } 975 i = i + 1 976 } 977 // ---- CRITICAL PATH: the first version whose milestone rungs are not all measured present is the 978 // TARGET; its open rungs plus their transitive open dependencies are the path. Everything else is 979 // real work for a LATER version and ranks after -- the version ladder, not a seat's taste, decides. 980 let crit: *i64 = sys_mmap(nr * 8) as *i64 981 var cz: i64 = 0 982 while cz < nr { crit[cz] = 0; cz = cz + 1 } 983 var tgt: i64 = 0 - 1 984 var vv: i64 = 0 985 while vv < nver { 986 var mm: i64 = 0 - 1 987 var s5: i64 = 0 988 while s5 < nms { if rk_streq(msid[s5] as *u8, vms[vv] as *u8) == 1 { mm = s5; s5 = nms } s5 = s5 + 1 } 989 if mm >= 0 { if tgt < 0 { 990 let unmet: i64 = rk_list_scan(msrungs[mm] as *u8, 0, rid, nr, rdone, crit) 991 if unmet > 0 { tgt = vv; rk_list_scan(msrungs[mm] as *u8, 1, rid, nr, rdone, crit) } 992 } } 993 vv = vv + 1 994 } 995 // transitive closure over declared deps (only OPEN deps join the path) 996 var itc: i64 = 0 997 while itc < nr { 998 var ch: i64 = 0 999 var a5: i64 = 0 1000 while a5 < nr { 1001 if crit[a5] == 1 { 1002 let before: i64 = rk_list_scan(rdeps[a5] as *u8, 0, rid, nr, rdone, crit) 1003 if before > 0 { 1004 // count marks added by mode 1: re-scan marking; ch set if any newly marked 1005 var b5: i64 = 0 1006 var pre: i64 = 0 1007 while b5 < nr { pre = pre + crit[b5]; b5 = b5 + 1 } 1008 rk_list_scan(rdeps[a5] as *u8, 1, rid, nr, rdone, crit) 1009 var post: i64 = 0 1010 b5 = 0 1011 while b5 < nr { post = post + crit[b5]; b5 = b5 + 1 } 1012 if post > pre { ch = 1 } 1013 } 1014 } 1015 a5 = a5 + 1 1016 } 1017 if ch == 0 { itc = nr } 1018 itc = itc + 1 1019 } 1020 rk_puts("=== NX-COMPARE-RANK domain=" as *u8); rk_puts(dom); rk_puts(" rungs=" as *u8); rk_pn(nr); rk_puts(" done=" as *u8); rk_pn(ndone); rk_puts(" open=" as *u8); rk_pn(nopen); rk_puts(" finish(done-but-partially-adopted)=" as *u8); rk_pn(nfinish); rk_puts(" (partition sums: done+open=rungs; finish is a subset of done) matrix_rows=" as *u8); rk_pn(mrows); rk_puts(" fields_max=" as *u8); rk_pn(max_fields); rk_puts(" (derived bounds: rows<=matrix lines, rungs<=plan lines -- no cap)\n" as *u8) 1021 if tgt >= 0 { rk_puts("TARGET VERSION " as *u8); rk_puts(vlab[tgt] as *u8); rk_puts(" (milestone " as *u8); rk_puts(vms[tgt] as *u8); rk_puts(") -- critical-path rungs rank FIRST; the rest are staged later\n" as *u8) } 1022 else { if nver > 0 { rk_puts("ALL DECLARED VERSIONS MET -- ranking by value alone\n" as *u8) } else { rk_puts("NO ver| ladder in the plan -- add ver rows to stage the roadmap; ranking by value alone (LABELED)\n" as *u8) } } 1023 if nopen == 0 { 1024 rk_puts("RANK: nothing open -- every rung's symbol is measured present\n" as *u8) 1025 if rrf_file_hash_matches(pp, plan_sha) != 1 { return RANK_EXIT_REFRESH_IO } 1026 if rrf_file_hash_matches(mp, matrix_sha) != 1 { return RANK_EXIT_REFRESH_IO } 1027 if rk_write_rank(dom, rkbuf, rko, nr, ndone, nopen, nfinish, tgt, vlab) != 0 { return RANK_EXIT_REFRESH_IO } 1028 return 0 1029 } 1030 // ---- fork nx_dr_ocm with the triples ---- 1031 let av: *i64 = sys_mmap(8 * (4 + 3 * nopen + 2)) as *i64 // argv0, budget, 3 per open rung, NULL 1032 av[0] = "./nx_dr_ocm_cli.elf" as *u8 as i64 1033 let bs: *u8 = sys_mmap(RK_NUMBUF); rk_catn(bs, 0, budget) 1034 av[1] = bs as i64 1035 var ai: i64 = 2 1036 var k: i64 = 0 1037 while k < nopen { 1038 let sv: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sv, 0, ov[k]); av[ai] = sv as i64; ai = ai + 1 1039 let sm: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sm, 0, om[k]); av[ai] = sm as i64; ai = ai + 1 1040 let sc: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sc, 0, oc[k]); av[ai] = sc as i64; ai = ai + 1 1041 k = k + 1 1042 } 1043 av[ai] = 0 1044 // capture sized from the population: one JSON object per open rung + header/footer (see the consts) 1045 let out_cap: i64 = RK_OCM_HDR_BYTES + nopen * RK_OCM_OBJ_BYTES 1046 let out: *u8 = sys_mmap(out_cap) 1047 let olen: *i64 = sys_mmap(16) as *i64 1048 let scorer_rc: i64 = tr_run_capture("./nx_dr_ocm_cli.elf" as *u8, av, out, out_cap - 1, olen) 1049 if scorer_rc != 0 { rk_puts("RANK REFUSED: scorer exit=" as *u8); rk_pn(scorer_rc); rk_puts("\n" as *u8); return 4 } 1050 if olen[0] <= 0 { rk_puts("RANK REFUSED: nx_dr_ocm returned nothing\n" as *u8); return 4 } 1051 if olen[0] >= out_cap - 1 { rk_puts("RANK REFUSED: nx_dr_ocm output FILLED its derived capture (RK_OCM_OBJ_BYTES/HDR undersized for this emitter -- the ranking would be a prefix)\n" as *u8); return 4 } 1052 // ---- parse the ranking: sequence of {"rank":R,"id":I,...,"priority":P,...} objects, in rank order ---- 1053 // walk "\"id\":" occurrences; the object's rank and priority follow/precede in a fixed field order 1054 let rank_of: *i64 = sys_mmap(nopen * 8) as *i64 1055 let pri_of: *i64 = sys_mmap(nopen * 8) as *i64 1056 var z: i64 = 0 1057 while z < nopen { rank_of[z] = 0; pri_of[z] = 0; z = z + 1 } 1058 var oi: i64 = 0 1059 var currank: i64 = 0 1060 while oi + 8 < olen[0] { 1061 if out[oi] == (34 as u8) { if out[oi+1] == (114 as u8) { if out[oi+2] == (97 as u8) { if out[oi+3] == (110 as u8) { if out[oi+4] == (107 as u8) { if out[oi+5] == (34 as u8) { if out[oi+6] == (58 as u8) { 1062 var jj: i64 = oi + 7; var rv: i64 = 0 1063 var gj: i64 = 1 1064 while gj == 1 { if jj < olen[0] { if out[jj] >= (48 as u8) { if out[jj] <= (57 as u8) { rv = rv * 10 + ((out[jj] as i64) - 48); jj = jj + 1 } else { gj = 0 } } else { gj = 0 } } else { gj = 0 } } 1065 currank = rv 1066 } } } } } } } 1067 if out[oi] == (34 as u8) { if out[oi+1] == (105 as u8) { if out[oi+2] == (100 as u8) { if out[oi+3] == (34 as u8) { if out[oi+4] == (58 as u8) { 1068 var jj2: i64 = oi + 5; var idv: i64 = 0 1069 var gj2: i64 = 1 1070 while gj2 == 1 { if jj2 < olen[0] { if out[jj2] >= (48 as u8) { if out[jj2] <= (57 as u8) { idv = idv * 10 + ((out[jj2] as i64) - 48); jj2 = jj2 + 1 } else { gj2 = 0 } } else { gj2 = 0 } } else { gj2 = 0 } } 1071 if idv < nopen { rank_of[idv] = currank } 1072 } } } } } 1073 if out[oi] == (34 as u8) { if rk_starts((out as i64 + oi) as *u8, "\"priority\":" as *u8) == 1 { 1074 var jj3: i64 = oi + 11; var pv: i64 = 0 1075 var gj3: i64 = 1 1076 while gj3 == 1 { if jj3 < olen[0] { if out[jj3] >= (48 as u8) { if out[jj3] <= (57 as u8) { pv = pv * 10 + ((out[jj3] as i64) - 48); jj3 = jj3 + 1 } else { gj3 = 0 } } else { gj3 = 0 } } else { gj3 = 0 } } 1077 // the id for this object was the last id seen: attribute priority to it 1078 var lastid: i64 = 0 - 1 1079 var back: i64 = oi 1080 while back > 0 { if out[back] == (34 as u8) { if rk_starts((out as i64 + back) as *u8, "\"id\":" as *u8) == 1 { var jb: i64 = back + 5; var iv: i64 = 0; var gb: i64 = 1; while gb == 1 { if jb < olen[0] { if out[jb] >= (48 as u8) { if out[jb] <= (57 as u8) { iv = iv * 10 + ((out[jb] as i64) - 48); jb = jb + 1 } else { gb = 0 } } else { gb = 0 } } else { gb = 0 } } lastid = iv; back = 0 } } back = back - 1 } 1081 if lastid >= 0 { if lastid < nopen { pri_of[lastid] = pv } } 1082 } } 1083 oi = oi + 1 1084 } 1085 if rrf_file_hash_matches(pp, plan_sha) != 1 { rk_puts("RANK REFUSED: plan changed during computation\n" as *u8); return RANK_EXIT_REFRESH_IO } 1086 if rrf_file_hash_matches(mp, matrix_sha) != 1 { rk_puts("RANK REFUSED: matrix changed during computation\n" as *u8); return RANK_EXIT_REFRESH_IO } 1087 // ---- print in rank order + publish the plane ---- 1088 // THE PREFIX IS A PATH AND MUST BE SPELLED IN FULL. Measured 2026-08-23: the bare "comparerank-<dom>" 1089 // resolved against the CWD, so every published order landed at the nishihost ROOT (segments beside the 1090 // binaries), knowledge/store/comparerank-* read EMPTY, and a seat concluded the ranker committed nothing. 1091 let pfx: *u8 = sys_mmap(dlen + 48) // "knowledge/store/comparerank-" (28) + dom + NUL 1092 var pfo: i64 = rk_cat(pfx, 0, "knowledge/store/comparerank-" as *u8); pfo = rk_cat(pfx, pfo, dom) 1093 // ---- two-pass order: critical-path rungs first (in ranker order), then the rest ---- 1094 let ord: *i64 = sys_mmap(nopen * 8) as *i64 1095 var no2: i64 = 0 1096 var pass2: i64 = 0 1097 while pass2 < 2 { 1098 var rr2: i64 = 1 1099 while rr2 <= nopen { 1100 var f2: i64 = 0 1101 while f2 < nopen { 1102 if rank_of[f2] == rr2 { 1103 var isc: i64 = crit[oidx[f2]] 1104 if pass2 == 0 { if isc == 1 { ord[no2] = f2; no2 = no2 + 1 } } 1105 else { if isc == 0 { ord[no2] = f2; no2 = no2 + 1 } } 1106 f2 = nopen 1107 } 1108 f2 = f2 + 1 1109 } 1110 rr2 = rr2 + 1 1111 } 1112 pass2 = pass2 + 1 1113 } 1114 var r: i64 = 1 1115 var published: i64 = 0 1116 var pmfiled: i64 = 0 1117 // the queue note holds one entry per open rung: "#" r "[" stage "]" id "=" pri " " -- sized from the 1118 // ids and stage labels it will actually hold (RK_DEC_MAX per number), so it cannot fill and the 1119 // former ...TRUNCATED-AT-CAP suffix has no path to fire: the row IS the whole order now 1120 var qcap: i64 = 16 1121 var qk: i64 = 0 1122 while qk < nver { qcap = qcap + rk_slen(vlab[qk] as *u8); qk = qk + 1 } // the longest stage label <= sum of labels 1123 var qk2: i64 = 0 1124 while qk2 < nopen { qcap = qcap + 8 + 2 * RK_DEC_MAX + rk_slen(rid[oidx[qk2]] as *u8) + qcap_stage_max(vlab, nver); qk2 = qk2 + 1 } 1125 var qk3: i64 = 0 1126 while qk3 < nr { if rfin[qk3] == 1 { qcap = qcap + 4 + rk_slen(rid[qk3] as *u8) + rk_slen(rtok[qk3] as *u8) } qk3 = qk3 + 1 } 1127 let qbuf: *u8 = sys_mmap(qcap) 1128 var qlen: i64 = 0 1129 var qf: i64 = 0 1130 while qf < nr { if rfin[qf] == 1 { qlen = rk_cat(qbuf, qlen, "F[" as *u8); qlen = rk_cat(qbuf, qlen, rtok[qf] as *u8); qlen = rk_cat(qbuf, qlen, "]" as *u8); qlen = rk_cat(qbuf, qlen, rid[qf] as *u8); qlen = rk_cat(qbuf, qlen, " " as *u8) } qf = qf + 1 } 1131 var qtop: i64 = "-" as *u8 as i64 1132 var qtoptitle: i64 = "-" as *u8 as i64 1133 var qtoppri: i64 = 0 1134 while r <= no2 { 1135 let found: i64 = ord[r - 1] 1136 if found >= 0 { 1137 let ri: i64 = oidx[found] 1138 var stg: *u8 = "later" as *u8 1139 if crit[ri] == 1 { if tgt >= 0 { stg = vlab[tgt] as *u8 } } 1140 rk_puts(" #" as *u8); rk_pn(r); rk_puts(" [" as *u8); rk_puts(stg); rk_puts("] " as *u8); rk_puts(rid[ri] as *u8); rk_puts(" priority=" as *u8); rk_pn(pri_of[found]) 1141 rk_puts(" v=" as *u8); rk_pn(ov[found]); rk_puts(" m=" as *u8); rk_pn(om[found]); rk_puts(" c=" as *u8); rk_pn(oc[found]) 1142 rk_puts(" | " as *u8); rk_puts(rtitle[ri] as *u8); rk_puts(" [" as *u8); rk_puts(rsym[ri] as *u8); rk_puts("] " as *u8); rk_puts(onote[found] as *u8); rk_puts("\n" as *u8) 1143 rko = rk_cat(rkbuf, rko, "rank|" as *u8); rko = rk_catn(rkbuf, rko, r); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, stg); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rid[ri] as *u8) 1144 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, pri_of[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, ov[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, om[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, oc[found]) 1145 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtitle[ri] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rsym[ri] as *u8); rko = rk_cat(rkbuf, rko, "\n" as *u8) 1146 // ONE PLANE ROW PER DOMAIN, accumulated here and committed ONCE after the loop. The v5 draft 1147 // committed one row PER RUNG -- 19 fsync'd segment commits per domain, x7 domains, x the gate's 1148 // fixture -- and on 2026-08-18 that serialised into D-state store puts (wait_on_page_bit) that 1149 // stalled the fleet, the gate and the ship loop for an hour on a saturated array. Count the 1150 // syscalls per unit of output (§F): the printed table already carries every derivation, pm 1151 // intake carries the top rows; the plane needs the ORDER, and the order is one row. 1152 let qo0: i64 = qlen 1153 qlen = rk_cat(qbuf, qlen, "#" as *u8); qlen = rk_catn(qbuf, qlen, r); qlen = rk_cat(qbuf, qlen, "[" as *u8); qlen = rk_cat(qbuf, qlen, stg); qlen = rk_cat(qbuf, qlen, "]" as *u8); qlen = rk_cat(qbuf, qlen, rid[ri] as *u8); qlen = rk_cat(qbuf, qlen, "=" as *u8); qlen = rk_catn(qbuf, qlen, pri_of[found]); qlen = rk_cat(qbuf, qlen, " " as *u8) 1154 if r == 1 { qtop = rid[ri]; qtoptitle = rtitle[ri]; qtoppri = pri_of[found] } 1155 // NISHI PM DRIVES (operator 2026-08-18): the top RANK_PM_TOP critical-path rungs are FILED 1156 // into the pm intake journal, so the work queue every seat reads starts from the ranking, 1157 // not from a seat's taste. Idempotence is the journal's triage lane's problem by design -- 1158 // re-ranking re-asserts the same ask, which is a re-prioritisation signal, not noise. 1159 if artifact_only == 0 { if r <= RANK_PM_TOP { if crit[ri] == 1 { 1160 let pav: *i64 = sys_mmap(8 * 8) as *i64 1161 // dom + " rank#" r + " stage=" stg + " " id + " " title + " priority=" pri + " sym=" sym 1162 let pt: *u8 = sys_mmap(rk_slen(dom) + rk_slen(stg) + rk_slen(rid[ri] as *u8) + rk_slen(rtitle[ri] as *u8) + rk_slen(rsym[ri] as *u8) + 2 * RK_DEC_MAX + 48) 1163 var pto: i64 = rk_cat(pt, 0, dom); pto = rk_cat(pt, pto, " rank#" as *u8); pto = rk_catn(pt, pto, r) 1164 pto = rk_cat(pt, pto, " stage=" as *u8); pto = rk_cat(pt, pto, stg) 1165 pto = rk_cat(pt, pto, " " as *u8); pto = rk_cat(pt, pto, rid[ri] as *u8) 1166 pto = rk_cat(pt, pto, " " as *u8); pto = rk_cat(pt, pto, rtitle[ri] as *u8) 1167 pto = rk_cat(pt, pto, " priority=" as *u8); pto = rk_catn(pt, pto, pri_of[found]) 1168 pto = rk_cat(pt, pto, " sym=" as *u8); pto = rk_cat(pt, pto, rsym[ri] as *u8) 1169 pav[0] = "./nx_pm_intake.elf" as *u8 as i64 1170 pav[1] = "ask" as *u8 as i64 1171 pav[2] = "knowledge/status/pm_intake.jrnl" as *u8 as i64 1172 pav[3] = "nx_compare_rank" as *u8 as i64 1173 pav[4] = pt as i64 1174 pav[5] = 0 1175 let pout: *u8 = sys_mmap(RANK_FORK_CAP) 1176 let polen: *i64 = sys_mmap(16) as *i64 1177 let pmrc: i64 = tr_run_capture("./nx_pm_intake.elf" as *u8, pav, pout, RANK_FORK_CAP - 1, polen) 1178 if pmrc != 0 { rk_puts("RANK DISPATCH-UNCERTAIN: PM child failed; inspect journal before retry\n" as *u8); return RANK_EXIT_DISPATCH } 1179 if polen[0] <= 0 { rk_puts("RANK DISPATCH-UNCERTAIN: PM receipt empty\n" as *u8); return RANK_EXIT_DISPATCH } 1180 if polen[0] >= RANK_FORK_CAP - 1 { rk_puts("RANK DISPATCH-UNCERTAIN: PM receipt truncated\n" as *u8); return RANK_EXIT_DISPATCH } 1181 pmfiled = pmfiled + 1 1182 } } } 1183 } 1184 r = r + 1 1185 } 1186 rk_puts("PM filed=" as *u8); rk_pn(pmfiled); rk_puts(" of top " as *u8); rk_pn(RANK_PM_TOP); rk_puts(" critical rungs into knowledge/status/pm_intake.jrnl\n" as *u8) 1187 // the ONE plane commit: id=<domain>, title=the #1 rung, sev=1, status=its priority, note=the ordered 1188 // queue "#r[stage]RUNG=priority ..." -- the whole order in one row, one segment commit 1189 if artifact_only == 0 { if no2 > 0 { 1190 let sav: *i64 = sys_mmap(8 * 16) as *i64 1191 let spr: *u8 = sys_mmap(RK_NUMBUF); rk_catn(spr, 0, qtoppri) 1192 var sncap: i64 = 6 + qlen + 16 + 2 // "queue=" + the queue + " target_version=" + NUL 1193 if tgt >= 0 { sncap = sncap + rk_slen(vlab[tgt] as *u8) } 1194 let sn: *u8 = sys_mmap(sncap) 1195 var sno: i64 = rk_cat(sn, 0, "queue=" as *u8); sno = rk_cat(sn, sno, qbuf) 1196 if tgt >= 0 { sno = rk_cat(sn, sno, " target_version=" as *u8); sno = rk_cat(sn, sno, vlab[tgt] as *u8) } 1197 sav[0] = "./nx_store_put.elf" as *u8 as i64 1198 sav[1] = pfx as i64 1199 sav[2] = "put" as *u8 as i64 1200 sav[3] = "nx_compare_rank" as *u8 as i64 1201 sav[4] = dom as i64 1202 sav[5] = qtoptitle 1203 sav[6] = "1" as *u8 as i64 1204 sav[7] = spr as i64 1205 sav[8] = "pm" as *u8 as i64 1206 sav[9] = qtop 1207 sav[10] = sn as i64 1208 sav[11] = 0 1209 let sout: *u8 = sys_mmap(RANK_FORK_CAP) 1210 let solen: *i64 = sys_mmap(16) as *i64 1211 let putrc: i64 = tr_run_capture("./nx_store_put.elf" as *u8, sav, sout, RANK_FORK_CAP - 1, solen) 1212 if putrc != 0 { rk_puts("RANK DISPATCH-UNCERTAIN: plane child failed; inspect committed state before retry\n" as *u8); return RANK_EXIT_DISPATCH } 1213 if solen[0] <= 0 { rk_puts("RANK DISPATCH-UNCERTAIN: plane receipt empty\n" as *u8); return RANK_EXIT_DISPATCH } 1214 if solen[0] >= RANK_FORK_CAP - 1 { rk_puts("RANK DISPATCH-UNCERTAIN: plane receipt truncated\n" as *u8); return RANK_EXIT_DISPATCH } 1215 published = 1 1216 } } 1217 // PERSIST THE UNCARRIED-DIMENSION FINDING (2026-09-01) -- the ranker already KNEW this and threw it away. 1218 // A rung whose symbol no matrix row carries takes the UNMAPPED branch above and is priced at ZERO, but 1219 // it said so only on stdout: the .rank ARTIFACT had no field for it. So the one signal that names the 1220 // "measured, but carried by no column" defect died with whatever terminal ran the ranker -- for all 96 1221 // domains, on every run. 1222 // WHY THIS OUTRANKS THE ROWS IT PRINTS: that defect is exactly how /compare/search carried NO latency 1223 // row at all while its own declared 3000ms consumer bar (knowledge/uat_journeys.conf: search-query) 1224 // FAILED 41 consecutive hourly runs. The published critical path was computed on input that omitted 1225 // the only axis that was failing, and a seat had to NOTICE. Persisting it makes the artifact say so. 1226 // ★AN INSTRUMENT THAT PRINTS A FINDING BUT DOES NOT PERSIST IT HAS NOT PUBLISHED IT. 1227 // THE COUNT IS EMITTED EVEN WHEN ZERO: a declared zero is evidence the check RAN, while silence is 1228 // indistinguishable from the check being absent -- the estate's own abstain-never-acquit law. And the 1229 // count carries a NAMED WORKLIST, one row per offender, because a count without a worklist is not 1230 // actionable. 1231 // STRICTLY ADDITIVE, AND THE STAMP STAYS LAST: these rows are appended BEFORE rk_write_rank writes the 1232 // stamp, so every positional reader that takes the final line is unaffected, and no rank| row changes, 1233 // so a consumer parsing only rank| rows cannot even notice this. 1234 var unm: i64 = 0 1235 var uq: i64 = 0 1236 while uq < nr { if rmi[uq] < 0 { unm = unm + 1 } uq = uq + 1 } 1237 rko = rk_cat(rkbuf, rko, "unmapped-count|" as *u8) 1238 rko = rk_catn(rkbuf, rko, unm) 1239 rko = rk_cat(rkbuf, rko, "|rungs whose symbol NO matrix row carries: priced at zero, invisible to consumers\n" as *u8) 1240 uq = 0 1241 while uq < nr { 1242 if rmi[uq] < 0 { 1243 rko = rk_cat(rkbuf, rko, "unmapped|" as *u8) 1244 rko = rk_cat(rkbuf, rko, rid[uq] as *u8) 1245 rko = rk_cat(rkbuf, rko, "|" as *u8) 1246 rko = rk_cat(rkbuf, rko, rsym[uq] as *u8) 1247 rko = rk_cat(rkbuf, rko, "|no-matrix-row-carries-this-symbol\n" as *u8) 1248 } 1249 uq = uq + 1 1250 } 1251 rk_puts("RANK unmapped=" as *u8); rk_pn(unm); rk_puts(" rung(s) no matrix row carries -- pending artifact commit\n" as *u8) 1252 if rrf_file_hash_matches(pp, plan_sha) != 1 { rk_puts("RANK REFRESH-FAILED: plan changed before write\n" as *u8); return RANK_EXIT_REFRESH_IO } 1253 if rrf_file_hash_matches(mp, matrix_sha) != 1 { rk_puts("RANK REFRESH-FAILED: matrix changed before write\n" as *u8); return RANK_EXIT_REFRESH_IO } 1254 if rk_write_rank(dom, rkbuf, rko, nr, ndone, nopen, nfinish, tgt, vlab) != 0 { return RANK_EXIT_REFRESH_IO } 1255 rk_puts("RANK published=" as *u8); rk_pn(published); rk_puts(" row(s) (one per domain, the whole order in its note) plane=" as *u8); rk_puts(pfx); rk_puts(" ranker=nx_dr_ocm rule=(deficit+CoD+option+enables)*sponsor*selfsuff*(1+deps-landed)/(est_tenths/cluster) provenance=WSJF+real-options+dep-graph+sovereignty-ledger (header + pmdash.refs)\n" as *u8) 1256 return 0 1257}