code wiki / _hdl_build / nx_search_census.nx

nx_search_census.nx source

↩ module page · 534 lines · 30185 B

1// nx_search_census.nx -- G1: THE SEARCH CORPUS, THROUGHPUT AND DIVERSITY CENSUS. 2// /compare/search rung G1, contracts idx_corpus_census and wc_throughput_census. 3// 4// WHY IT EXISTS. On 2026-09-03 the operator could see that the index was not growing and the BOARD COULD 5// NOT. /compare/search carried four latency rows and a relevance row and NOTHING for corpus size, crawl 6// throughput or host diversity; the one row that touched scale had already withheld its Nishi figure as 7// "prose, never a measurement" and nobody had measured it since. Nothing else in the estate measured it 8// either -- knowledge/status/growth_series.log tracks the PM board, debts and maturity and carries no 9// corpus field at all -- so the one axis the operator was complaining about was invisible to every 10// consumer and therefore priced at zero by the ranker. 11// 12// WHAT IT REFUSES TO DO. It prints LEVELS and never a rate. A rate needs two samples in time and the 13// estate ALREADY has a time spine, nx_growth_series, whose report verb computes d/w/m deltas per axis. A 14// second spine here would be the duplicate-ruler defect, so this organ is a PRODUCER for that one: it 15// TRUNCATE-writes a canonical status file and lets the spine carry the trajectory. The throughput axis 16// is the DIFFERENCE between two spine rows, never a number this organ invents. 17// 18// EVERY COUNT CARRIES ITS COVERAGE, and that is not a slogan here. The key census is COMPLETE over the 19// manifest and says so, with its partition summed and the sum printed. The outcome partition is a 20// DECLARED TAIL WINDOW and says so. This organ was written in the same session a sibling validator was 21// caught reading the OLDEST 3.2 percent of a 129 MB log while printing "sampling newest-first" -- a 22// window published without its denominator reads as a population, and that is exactly how a three-week 23// old fossil became evidence about today. 24// 25// ONE FAIRNESS RULER. The fair verdict is wc_frontier_fair, imported from the ENFORCER itself, and the 26// host parser is the crawler's own wc_host. Re-deriving either here would be a second ruler that agrees 27// today and diverges silently on the next edit to one side. 28// 29// DECLARED GAPS, NAMED RATHER THAN HIDDEN. (1) doc= counts seg-store ENTRIES, which are append-only, so 30// it is an UPPER BOUND on distinct documents and the output says so on its own line; distinct-key dedup 31// is the named next rung. (2) The fr: pending-versus-done split is NOT reported: splitting it needs an 32// ss_hget per frontier key and the live shard holds millions, so the honest choices were a silent sample 33// or a named absence, and this takes the absence. 34// usage: nx_search_census [shard-prefix] [outcomes-log] 35// license_tier: ORIGINAL expect_exit: 0 36import "nx_web_crawl_step.nx" // wc_frontier_fair (shared fairness ruler) + wc_host (shared host parser) 37import "nx_intlog.nx" // cs_crossover (S1: the corpus-scale side of the published BM25 crossover) 38 39const SC_SHARD: *u8 = "knowledge/store/dp-web-pub-" 40const SC_LOG: *u8 = "knowledge/status/crawl_outcomes.log" 41const SC_STATUS: *u8 = "knowledge/status/search_census.status" 42// DECLARED window over the outcome log TAIL: how much recent crawl history one census reads. Printed 43// beside every figure derived from it, because a window without its denominator reads as a population. 44const SC_LOGCAP: i64 = 4194304 45// Open-addressed distinct-host set for the outcome window, sized well above any plausible host count in 46// one window so the load factor stays low. A genuine hash collision UNDERCOUNTS hosts, which is wrong in 47// the direction of reporting LESS diversity than there is -- the safe direction for a rung whose entire 48// claim is that diversity is too low. 49const SC_HOSTSLOTS: i64 = 65536 50const SC_HOSTBUF: i64 = 64 51const SC_URLBUF: i64 = 4096 52const SC_STATBUF: i64 = 4096 53const SC_HASH_MUL: i64 = 1000003 54const SC_TAB: i64 = 9 55const SC_NL: i64 = 10 56const SC_PERMIL: i64 = 1000 57 58func sc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 59func sc_n(v: i64) -> i64 { 60 let b: *u8 = sys_mmap(32); var x: i64 = v; var i: i64 = 31 61 if x < 0 { x = 0 - x } 62 if x == 0 { b[i] = 48 as u8; i = i - 1 } 63 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 64 if v < 0 { b[i] = 45 as u8; i = i - 1 } 65 sys_write(1, ((b as i64) + i + 1) as *u8, 31 - i); return 0 66} 67func sc_cat(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } return o } 68func sc_catn(out: *u8, o: i64, v: i64) -> i64 { 69 var m: i64 = v 70 if m < 0 { out[o] = 45 as u8; o = o + 1; m = 0 - m } 71 if m == 0 { out[o] = 48 as u8; return o + 1 } 72 var pw: i64 = 1 73 while m / pw >= 10 { pw = pw * 10 } 74 while pw > 0 { out[o] = (48 + (m / pw) % 10) as u8; o = o + 1; pw = pw / 10 } 75 return o 76} 77// Prefix test by LITERAL, never by character codes: a string spelled as char codes is the same defect as 78// a hand-counted length -- no reader recognises it and no grep finds it. 79func sc_lit_at(p: *u8, len: i64, lit: *u8) -> i64 { 80 var i: i64 = 0 81 while lit[i] != (0 as u8) { 82 if i >= len { return 0 } 83 if p[i] != lit[i] { return 0 } 84 i = i + 1 85 } 86 return 1 87} 88// Same test against a seg-store key entry, whose bytes start at eo+5. 89func sc_key_at(kb: *u8, eo: i64, kl: i64, lit: *u8) -> i64 { 90 let kp: *u8 = ((kb as i64) + eo + 5) as *u8 91 return sc_lit_at(kp, kl, lit) 92} 93// Multiply-accumulate hash. Deliberately no xor: this dialect's bitwise surface is not something a 94// census should be the first organ to depend on, and a collision here only undercounts hosts. 95// Parse the epoch field in place. Needed because a byte window is not a TIME window and only the 96// timestamps say which. 97func sc_atoi_at(p: *u8, s: i64, e: i64) -> i64 { 98 var v: i64 = 0 99 var i: i64 = s 100 while i < e { let c: i64 = p[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } 101 return v 102} 103func sc_hash(p: *u8, n: i64) -> i64 { 104 var h: i64 = 1 105 var i: i64 = 0 106 while i < n { h = h * SC_HASH_MUL + (p[i] as i64); if h < 0 { h = 0 - h } i = i + 1 } 107 if h <= 0 { h = 1 } 108 return h 109} 110// 1 when this host is NEWLY distinct in the set, 0 when already present or unusable. 111func sc_host_new(tbl: *i64, slots: i64, hp: *u8, hl: i64) -> i64 { 112 if hl <= 0 { return 0 } 113 let h: i64 = sc_hash(hp, hl) 114 var idx: i64 = h % slots 115 var guard: i64 = 0 116 while guard < slots { 117 if tbl[idx] == 0 { tbl[idx] = h; return 1 } 118 if tbl[idx] == h { return 0 } 119 idx = idx + 1 120 if idx >= slots { idx = 0 } 121 guard = guard + 1 122 } 123 return 0 124} 125 126// ---- THE TWO CONTRACT SYMBOLS. These are the names /compare/search watch rows measure, so they are the 127// REAL work and not wrappers shaped like it: a completion signal that keys on a name rewards writing the 128// name, so each of these must be the function that actually produces the number its row publishes. Both 129// are also the reason this organ is gateable -- a gate can drive them in-process with a fixture shard and 130// a fixture buffer, without forking anything or touching the live index. 131// 132// idx_corpus_census: out[0]=doc out[1]=url out[2]=frontier out[3]=priors out[4]=other out[5]=tombstones. 133// Returns TOTAL entries walked, so the caller can check the partition SUMS instead of trusting it. 134func idx_corpus_census(h: *i64, out: *i64) -> i64 { 135 var i: i64 = 0 136 while i < 6 { out[i] = 0; i = i + 1 } 137 if (h as i64) == 0 { return 0 - 1 } // UNOBSERVABLE, and -1 says so: an absent shard is not an empty one 138 let ns: i64 = h[0] 139 var all: i64 = 0 140 var s: i64 = 0 141 while s < ns { 142 let kb: *u8 = h[1 + 8 * s] as *u8 143 if h[2 + 8 * s] >= 8 { 144 let m: i64 = ss_r32(kb, 4) 145 var e: i64 = 0 146 while e < m { 147 let eo: i64 = 8 + 4 * m + ss_r32(kb, 8 + 4 * e) 148 let kl: i64 = ss_r32(kb, eo + 1) 149 all = all + 1 150 if (kb[eo] as i64) == 2 { out[5] = out[5] + 1 } else { 151 if sc_key_at(kb, eo, kl, "doc:" as *u8) == 1 { out[0] = out[0] + 1 } else { 152 if sc_key_at(kb, eo, kl, "url:" as *u8) == 1 { out[1] = out[1] + 1 } else { 153 if sc_key_at(kb, eo, kl, "fr:" as *u8) == 1 { out[2] = out[2] + 1 } else { 154 if sc_key_at(kb, eo, kl, "pr:" as *u8) == 1 { out[3] = out[3] + 1 } else { 155 out[4] = out[4] + 1 156 } } } } 157 } 158 e = e + 1 159 } 160 } 161 s = s + 1 162 } 163 return all 164} 165// wc_throughput_census: out[0]=hostcap out[1]=ok out[2]=thin out[3]=dup out[4]=robots out[5]=http 166// out[6]=other out[7]=distinct_hosts. Returns ROWS parsed, so the caller can check the class partition 167// SUMS to it. Buffers are passed IN, never allocated here: this runs once per row of a 4 MB window and 168// an allocation in a hot loop is how a census becomes the load it was measuring. 169// SLOTS IS A PARAMETER, NOT AN ASSUMPTION (2026-09-03, found by this organ's own gate on its FIRST run). 170// It previously took hosttbl from the caller and then indexed it with the hardcoded SC_HOSTSLOTS, so the 171// ALLOCATION and the INDEX BOUND lived in two places and any caller that sized its table differently got 172// a buffer overrun. The gate allocated 1024 slots, the callee indexed 65536, and it SIGSEGV'd -- which is 173// the good outcome, because the ship refused to promote a crashing gate. A callee that assumes the size 174// of a buffer it did not allocate is the same defect class as a hand-counted length beside a literal: 175// two copies of one number, drifting silently. Now there is one. 176func wc_throughput_census(buf: *u8, n: i64, out: *i64, hosttbl: *i64, slots: i64, hbuf: *u8, ubuf: *u8) -> i64 { 177 var i0: i64 = 0 178 while i0 < 10 { out[i0] = 0; i0 = i0 + 1 } 179 var rows: i64 = 0 180 var p: i64 = 0 181 while p < n { 182 // row extent is [p, re) -- a SEPARATE cursor, never the loop variable, so the scan can still say 183 // where it stopped instead of clobbering its own position in order to exit 184 var re: i64 = p 185 var f: i64 = 0 186 while f == 0 { if re >= n { f = 1 } else { if (buf[re] as i64) == SC_NL { f = 1 } else { re = re + 1 } } } 187 if re > p { 188 // row shape: <epoch> TAB <class> TAB <status> TAB <textlen> TAB <url> 189 var t1: i64 = 0 - 1 190 var t1e: i64 = 0 - 1 191 var t4: i64 = 0 - 1 192 var tabs: i64 = 0 193 var i: i64 = p 194 while i < re { 195 if (buf[i] as i64) == SC_TAB { 196 tabs = tabs + 1 197 if tabs == 1 { t1 = i + 1 } 198 if tabs == 2 { t1e = i } 199 if tabs == 4 { t4 = i + 1 } 200 } 201 i = i + 1 202 } 203 if t1 >= 0 { if t1e > t1 { 204 rows = rows + 1 205 // THE WINDOW'S TIME SPAN, not just its byte size. A byte window is NOT a time window, 206 // and only the timestamps say which hours it covers. Measured the day this was written: 207 // a 4 MB tail of the outcome log spans about 27 HOURS, so a permil computed over it 208 // averages a change made 2 hours ago into invisibility -- hostcap_defer_permil read 927 209 // while hand-sampled post-fix windows read ZERO, and both were correct about their own 210 // span. Declaring partial=1 was not enough; the SPAN is the envelope that matters. 211 let ep: i64 = sc_atoi_at(buf, p, t1 - 1) 212 if out[8] == 0 { out[8] = ep } 213 out[9] = ep 214 let cp: *u8 = ((buf as i64) + t1) as *u8 215 let clen: i64 = t1e - t1 216 // Prefix match on purpose: robots-cd belongs WITH robots, one class and not two. 217 if sc_lit_at(cp, clen, "hostcap" as *u8) == 1 { out[0] = out[0] + 1 } else { 218 if sc_lit_at(cp, clen, "robots" as *u8) == 1 { out[4] = out[4] + 1 } else { 219 if sc_lit_at(cp, clen, "thin" as *u8) == 1 { out[2] = out[2] + 1 } else { 220 if sc_lit_at(cp, clen, "dup" as *u8) == 1 { out[3] = out[3] + 1 } else { 221 if sc_lit_at(cp, clen, "http" as *u8) == 1 { out[5] = out[5] + 1 } else { 222 if sc_lit_at(cp, clen, "ok" as *u8) == 1 { out[1] = out[1] + 1 } else { 223 out[6] = out[6] + 1 224 } } } } } } 225 if t4 >= 0 { 226 let ul: i64 = re - t4 227 if ul > 0 { if ul < SC_URLBUF - 1 { 228 var y: i64 = 0 229 while y < ul { ubuf[y] = buf[t4 + y]; y = y + 1 } 230 ubuf[ul] = 0 as u8 231 let hl: i64 = wc_host(ubuf, hbuf) 232 if hl > 0 { out[7] = out[7] + sc_host_new(hosttbl, slots, hbuf, hl) } 233 } } 234 } 235 } } 236 } 237 p = re + 1 238 } 239 return rows 240} 241 242// ---- S1: CORPUS-SCALE SIDE OF THE PUBLISHED BM25 CROSSOVER. Indexed token occurrences are summed from every 243// live segment's NXQ1 positions sidecar: one varint run header per (term, doc) pair carries that pair's tf, so 244// the sum over every run is the exact count of token occurrences the tokenizer emitted into the index. A segment 245// without a readable sidecar contributes nothing and is COUNTED, so the figure is a LOWER BOUND whenever 246// pos_missing or pos_bad is above 0 -- and a lower bound already past the crossover still proves ABOVE, while a 247// lower bound under it proves nothing and says so. The crossover, its citation key and the study's own scope 248// caveat are DATA in knowledge/search_crossover.conf; the decision is nx_intlog's cs_crossover (the S1 symbol). 249const SC_CROSSOVER_CONF: *u8 = "knowledge/search_crossover.conf" 250const SC_POS_EXT: *u8 = ".pos" 251const SC_POS_MAGIC_N: i64 = 78 252const SC_POS_MAGIC_X: i64 = 88 253const SC_POS_MAGIC_Q: i64 = 81 254const SC_POS_MAGIC_1: i64 = 49 255const SC_POS_HDR: i64 = 8 256const SC_CONF_VALCAP: i64 = 2048 257const SC_INTBUF: i64 = 64 258const SC_SPACE: i64 = 32 259const SC_CR: i64 = 13 260// Sum every run's npos in one NXQ1 blob. outs[0]=tokens outs[1]=runs outs[2]=terms. 0 ok, -1 not an NXQ1 blob, 261// -2 a run cursor left the blob (truncated or corrupt): the partial sum is NOT trusted by the caller. 262func cs_pos_tokens(qb: *u8, qsz: i64, outs: *i64) -> i64 { 263 outs[0] = 0; outs[1] = 0; outs[2] = 0 264 if qsz < SC_POS_HDR { return 0 - 1 } 265 if (qb[0] as i64) != SC_POS_MAGIC_N { return 0 - 1 } 266 if (qb[1] as i64) != SC_POS_MAGIC_X { return 0 - 1 } 267 if (qb[2] as i64) != SC_POS_MAGIC_Q { return 0 - 1 } 268 if (qb[3] as i64) != SC_POS_MAGIC_1 { return 0 - 1 } 269 let nterms: i64 = ss_r32(qb, 4) 270 let qbase: i64 = SC_POS_HDR + 4 * nterms 271 if qbase > qsz { return 0 - 2 } 272 let cur: *i64 = sys_mmap(16) as *i64 273 var t: i64 = 0 274 while t < nterms { 275 var e: i64 = qsz 276 if t + 1 < nterms { e = qbase + ss_r32(qb, SC_POS_HDR + 4 * (t + 1)) } 277 if e > qsz { e = qsz } 278 cur[0] = qbase + ss_r32(qb, SC_POS_HDR + 4 * t) 279 while cur[0] < e { 280 let np: i64 = ss_vr(qb, cur) 281 var sk: i64 = 0 282 while sk < np { if cur[0] >= e { return 0 - 2 } ss_vr(qb, cur); sk = sk + 1 } 283 outs[0] = outs[0] + np 284 outs[1] = outs[1] + 1 285 } 286 if cur[0] > e { return 0 - 2 } 287 t = t + 1 288 } 289 outs[2] = nterms 290 return 0 291} 292// One key-value line of a conf: copies the value (to end of line, CR stripped) into out. Returns bytes copied, 293// 0 when the key has no line. A key must start its line and be followed by one space. 294func sc_conf_val(cf: *u8, n: i64, key: *u8, out: *u8, cap: i64) -> i64 { 295 var kl: i64 = 0 296 while key[kl] != (0 as u8) { kl = kl + 1 } 297 var i: i64 = 0 298 while i < n { 299 var e: i64 = i 300 var f: i64 = 0 301 while f == 0 { if e >= n { f = 1 } else { if (cf[e] as i64) == SC_NL { f = 1 } else { e = e + 1 } } } 302 if e - i > kl { if (cf[i + kl] as i64) == SC_SPACE { if sc_lit_at(((cf as i64) + i) as *u8, e - i, key) == 1 { 303 var o: i64 = 0 304 var j: i64 = i + kl + 1 305 while j < e { if (cf[j] as i64) != SC_CR { if o < cap - 1 { out[o] = cf[j]; o = o + 1 } } j = j + 1 } 306 out[o] = 0 as u8 307 return o 308 } } } 309 i = e + 1 310 } 311 out[0] = 0 as u8 312 return 0 313} 314func sc_conf_int(cf: *u8, n: i64, key: *u8) -> i64 { 315 let vb: *u8 = sys_mmap(SC_INTBUF) 316 let vn: i64 = sc_conf_val(cf, n, key, vb, SC_INTBUF) 317 if vn <= 0 { return 0 } 318 return sc_atoi_at(vb, 0, vn) 319} 320 321func main(argc: i64, argv: *i64) -> i64 { 322 var prefix: *u8 = SC_SHARD 323 if argc >= 2 { prefix = argv[1] as *u8 } 324 var logp: *u8 = SC_LOG 325 if argc >= 3 { logp = argv[2] as *u8 } 326 327 sc_w("=== NX-SEARCH-CENSUS -- LEVELS ONLY; the RATE is the difference between two nx_growth_series rows, never a number this organ invents ===\n" as *u8) 328 329 // ---- 1. THE KEY CENSUS, COMPLETE over the manifest: every segment, every entry. 330 // ss_open2(...,1) is the MMAP open. The read-all ss_open pulls the WHOLE multi-GB shard into anon 331 // RAM -- the OOM class the compactor was rewritten to kill. A census must never be why the box falls 332 // over, and a measurement that costs an outage is not a measurement anyone will keep running. 333 let h: *i64 = ss_open2(prefix, 1) 334 if (h as i64) == 0 { 335 sc_w("SHARD UNREADABLE prefix=" as *u8); sc_w(prefix) 336 sc_w("\n UNOBSERVABLE, not zero -- an absent shard and an empty shard are different facts and only one of them is a defect. An axis that cannot see must abstain, never acquit.\nverdict=SKIP\n" as *u8) 337 return 3 338 } 339 let ns: i64 = h[0] 340 // COMPOSE the contract function; main FORMATS and never re-implements. Two copies of this walk would 341 // be a duplicate ruler: they agree the day they are written and drift on the next edit to either one. 342 let kc: *i64 = sys_mmap(64) as *i64 343 let e_all: i64 = idx_corpus_census(h, kc) 344 let e_doc: i64 = kc[0] 345 let e_url: i64 = kc[1] 346 let e_fr: i64 = kc[2] 347 let e_pr: i64 = kc[3] 348 let e_other: i64 = kc[4] 349 let e_tomb: i64 = kc[5] 350 sc_w("SHARD prefix=" as *u8); sc_w(prefix); sc_w(" segments=" as *u8); sc_n(ns); sc_w("\n" as *u8) 351 sc_w("KEYS doc=" as *u8); sc_n(e_doc) 352 sc_w(" url=" as *u8); sc_n(e_url) 353 sc_w(" frontier=" as *u8); sc_n(e_fr) 354 sc_w(" priors=" as *u8); sc_n(e_pr) 355 sc_w(" other=" as *u8); sc_n(e_other) 356 sc_w(" tombstones=" as *u8); sc_n(e_tomb) 357 sc_w(" total=" as *u8); sc_n(e_all); sc_w("\n" as *u8) 358 // A PARTITION IS A CLAIM: CHECK THE PARTS SUM, AND PRINT THE CHECK. An unexplained residual is a leak; 359 // an explained one is a decision. Silence about it is neither. 360 let e_sum: i64 = e_doc + e_url + e_fr + e_pr + e_other + e_tomb 361 sc_w("PARTITION parts=" as *u8); sc_n(e_sum); sc_w(" total=" as *u8); sc_n(e_all) 362 if e_sum == e_all { sc_w(" SUMS=1 coverage_complete=1 corpus_complete=1 (every segment in the manifest, every entry in each)\n" as *u8) } else { sc_w(" SUMS=0 RESIDUAL -- do not trust these buckets\n" as *u8) } 363 sc_w("ENVELOPE doc= counts append-only ENTRIES, so it is an UPPER BOUND on distinct documents (a rewritten doc counts once per segment it lands in). NO consumer may publish doc= as a document count until the distinct-key dedup rung lands.\n" as *u8) 364 sc_w("ENVELOPE frontier= is likewise an upper bound on PENDING urls: the pending-versus-done split needs one value read per key and the shard holds millions, so it is a NAMED ABSENCE here rather than a silent sample.\n" as *u8) 365 366 // ---- 1b. S1: THE CORPUS-SCALE SIDE OF THE PUBLISHED BM25 CROSSOVER (composes cs_pos_tokens + cs_crossover). 367 let cxb: *i64 = sys_mmap(16) as *i64 368 cxb[0] = 0 369 let cxcf: *u8 = sys_read_file(SC_CROSSOVER_CONF, cxb) 370 var cx_tokens: i64 = 0 371 let cx_ref: *u8 = sys_mmap(SC_INTBUF) 372 let cx_cav: *u8 = sys_mmap(SC_CONF_VALCAP) 373 cx_ref[0] = 0 as u8 374 cx_cav[0] = 0 as u8 375 if (cxcf as i64) != 0 { 376 cx_tokens = sc_conf_int(cxcf, cxb[0], "crossover_tokens" as *u8) 377 sc_conf_val(cxcf, cxb[0], "ref" as *u8, cx_ref, SC_INTBUF) 378 sc_conf_val(cxcf, cxb[0], "caveat" as *u8, cx_cav, SC_CONF_VALCAP) 379 } 380 let pxs: *i64 = sys_mmap(16) as *i64 381 let pxo: *i64 = sys_mmap(32) as *i64 382 var tok_total: i64 = 0 383 var pos_runs: i64 = 0 384 var pos_ok: i64 = 0 385 var pos_missing: i64 = 0 386 var pos_bad: i64 = 0 387 let qp: *u8 = sys_mmap(SC_URLBUF) 388 var s2: i64 = 0 389 while s2 < ns { 390 let nm: *u8 = ss_open_segname(h, s2) 391 if (nm as i64) == 0 { pos_missing = pos_missing + 1 } else { 392 var qo: i64 = sc_cat(qp, 0, prefix) 393 qo = sc_cat(qp, qo, nm) 394 qo = sc_cat(qp, qo, SC_POS_EXT) 395 qp[qo] = 0 as u8 396 pxs[0] = 0 397 let qb: *u8 = ss_readall(qp, pxs) 398 if (qb as i64) == 0 { pos_missing = pos_missing + 1 } else { 399 let prc: i64 = cs_pos_tokens(qb, pxs[0], pxo) 400 if prc == 0 { tok_total = tok_total + pxo[0]; pos_runs = pos_runs + pxo[1]; pos_ok = pos_ok + 1 } else { pos_bad = pos_bad + 1 } 401 ss_freeall(qb, pxs[0]) // the paired free for ss_readall, released per segment: a census must never become the load it measures 402 } 403 } 404 s2 = s2 + 1 405 } 406 var cx_side: i64 = 0 - 1 407 var sidew: *u8 = "NO-CONF" as *u8 408 if cx_tokens > 0 { 409 let cxr: i64 = cs_crossover(tok_total, cx_tokens) 410 if cxr == CS_SIDE_ABOVE { cx_side = CS_SIDE_ABOVE; sidew = "ABOVE" as *u8 } 411 else { if cxr == CS_SIDE_UNMEASURED { sidew = "UNMEASURED" as *u8 } else { if pos_missing + pos_bad == 0 { cx_side = CS_SIDE_BELOW; sidew = "BELOW" as *u8 } else { sidew = "BELOW-OR-UNCOVERED" as *u8 } } } // zero indexed tokens is an UNMEASURED corpus, never a BELOW (the three-state contract) 412 } 413 sc_w("CROSSOVER indexed_tokens=" as *u8); sc_n(tok_total) 414 sc_w(" runs=" as *u8); sc_n(pos_runs) 415 sc_w(" segments_with_pos=" as *u8); sc_n(pos_ok) 416 sc_w(" pos_missing=" as *u8); sc_n(pos_missing) 417 sc_w(" pos_bad=" as *u8); sc_n(pos_bad) 418 sc_w(" crossover_tokens=" as *u8); sc_n(cx_tokens) 419 sc_w(" side=" as *u8); sc_w(sidew) 420 sc_w(" ref=" as *u8); sc_w(cx_ref) 421 sc_w(" scope=" as *u8); sc_w(cx_cav); sc_w("\n" as *u8) 422 sc_w("ENVELOPE indexed_tokens= counts the token OCCURRENCES the tokenizer emitted into the positions sidecars (unindexed bytes are not tokens here), summed over every segment whose sidecar was read whole; with pos_missing or pos_bad above 0 it is a LOWER BOUND, and ABOVE is still asserted from a lower bound because a bound already past the crossover proves the side, while BELOW is asserted only with every segment covered.\n" as *u8) 423 424 // ---- 2. THE OUTCOME PARTITION over a DECLARED TAIL WINDOW. 425 let buf: *u8 = sys_mmap(SC_LOGCAP) 426 let fd: i64 = sys_openat_rd(logp) 427 var flen: i64 = 0 428 var n: i64 = 0 429 var startoff: i64 = 0 430 if fd >= 0 { 431 flen = sys_lseek(fd, 0, 2) 432 if flen > SC_LOGCAP { startoff = flen - SC_LOGCAP } 433 sys_lseek(fd, startoff, 0) 434 var go: i64 = 1 435 while go == 1 { 436 let r: i64 = sys_read(fd, ((buf as i64) + n) as *u8, SC_LOGCAP - n) 437 if r <= 0 { go = 0 } else { n = n + r } 438 if n >= SC_LOGCAP { go = 0 } 439 } 440 sys_close(fd) 441 } 442 // A seeked window almost never lands on a row boundary: DROP the partial leading row rather than 443 // count half a record into a class. 444 if startoff > 0 { 445 var lead: i64 = 0 446 var q: i64 = 0 447 var fnd: i64 = 0 448 while fnd == 0 { if q >= n { fnd = 1 } else { if (buf[q] as i64) == SC_NL { lead = q + 1; fnd = 1 } else { q = q + 1 } } } 449 if lead > 0 { 450 var mv: i64 = 0 451 while mv < n - lead { buf[mv] = buf[mv + lead]; mv = mv + 1 } 452 n = n - lead 453 } 454 } 455 let hosttbl: *i64 = sys_mmap(SC_HOSTSLOTS * 8) as *i64 456 let hbuf: *u8 = sys_mmap(SC_HOSTBUF) 457 let ubuf: *u8 = sys_mmap(SC_URLBUF) // allocated ONCE: never allocate in a hot loop 458 // COMPOSE the contract function; main FORMATS and never re-implements. The buffers are passed IN so 459 // nothing allocates per row -- a census that allocates in its hot loop becomes the load it measures. 460 let tc: *i64 = sys_mmap(96) as *i64 461 let rows: i64 = wc_throughput_census(buf, n, tc, hosttbl, SC_HOSTSLOTS, hbuf, ubuf) 462 let c_hostcap: i64 = tc[0] 463 let c_ok: i64 = tc[1] 464 let c_thin: i64 = tc[2] 465 let c_dup: i64 = tc[3] 466 let c_robots: i64 = tc[4] 467 let c_http: i64 = tc[5] 468 let c_other: i64 = tc[6] 469 let hosts: i64 = tc[7] 470 var partial: i64 = 0 471 if startoff > 0 { partial = 1 } 472 sc_w("OUTCOMES log_bytes=" as *u8); sc_n(flen) 473 sc_w(" window_bytes=" as *u8); sc_n(n) 474 sc_w(" rows=" as *u8); sc_n(rows) 475 if partial == 1 { sc_w(" scope=TAIL partial=1 (older rows NOT scanned -- a DECLARED window, never the population)\n" as *u8) } else { sc_w(" scope=FULL partial=0\n" as *u8) } 476 let w_first: i64 = tc[8] 477 let w_last: i64 = tc[9] 478 sc_w("WINDOW_SPAN first_epoch=" as *u8); sc_n(w_first) 479 sc_w(" last_epoch=" as *u8); sc_n(w_last) 480 sc_w(" span_s=" as *u8); sc_n(w_last - w_first) 481 sc_w(" -- EVERY CLASS COUNT AND PERMIL BELOW IS AN AVERAGE OVER THIS SPAN. A change made more recently than the span is averaged toward invisibility: measured 2026-09-03, this window spanned 51763s (14.4h, and note the author had ESTIMATED 27h by extrapolating a growth rate -- the measurement beat the estimate by 2x, which is why this field exists at all) and reported hostcap_defer_permil=925 while hand-sampled post-fix windows read ZERO. Both readings were correct about their own span. AND A SECOND TRAP LIVES HERE: A PERMIL OVER ROWS IS NOT A PERMIL OVER TIME. Rows are not uniformly distributed in time -- a deferral costs no fetch and is emitted in bursts, while a successful fetch is slow -- so a period that DEFERS heavily contributes far more rows per second than one that FETCHES, and a row-weighted average over-weights it. With about 27 percent of this window post-fix BY TIME, a naive reading would predict ~730 permil; it reads 925 because the pre-fix rows are denser, not because the fix is failing. To judge a RECENT change, read the log tail directly or shrink SC_LOGCAP; do not reason from this permil alone.\n" as *u8) 482 sc_w("CLASSES hostcap=" as *u8); sc_n(c_hostcap) 483 sc_w(" ok=" as *u8); sc_n(c_ok) 484 sc_w(" thin=" as *u8); sc_n(c_thin) 485 sc_w(" dup=" as *u8); sc_n(c_dup) 486 sc_w(" robots=" as *u8); sc_n(c_robots) 487 sc_w(" http=" as *u8); sc_n(c_http) 488 sc_w(" other=" as *u8); sc_n(c_other); sc_w("\n" as *u8) 489 let c_sum: i64 = c_hostcap + c_ok + c_thin + c_dup + c_robots + c_http + c_other 490 sc_w("PARTITION classes=" as *u8); sc_n(c_sum); sc_w(" rows=" as *u8); sc_n(rows) 491 if c_sum == rows { sc_w(" SUMS=1\n" as *u8) } else { sc_w(" SUMS=0 RESIDUAL -- do not trust these class counts\n" as *u8) } 492 // THE TWO NUMBERS RUNG G0 IS GRADED ON. Splitting the classes matters and is not cosmetic: a thin or 493 // robots loss is the JS-render rung R1, not the host-diversity rung G0, and a single throughput 494 // figure would attribute one to the other and send the next reader at the wrong rung. 495 var defer_permil: i64 = 0 496 if rows > 0 { defer_permil = c_hostcap * SC_PERMIL / rows } 497 sc_w("DIVERSITY distinct_hosts=" as *u8); sc_n(hosts) 498 sc_w(" hostcap_defer_permil=" as *u8); sc_n(defer_permil) 499 sc_w(" window_quota=" as *u8); sc_n(WC_WINQ) 500 let fair: i64 = wc_frontier_fair(rows, hosts) 501 if fair == 1 { sc_w(" fair=1\n" as *u8) } else { sc_w(" fair=0 -- this many rows could not have been held to the quota across this few hosts\n" as *u8) } 502 503 // ---- 3. THE CANONICAL STATUS FILE: TRUNCATE-write, one state, verdict LAST so a positional reader 504 // (gv_last_line) is safe. Deliberately NOT append-only -- the trajectory belongs to nx_growth_series, 505 // and a second append-only spine here is precisely the defect this organ refuses to commit. 506 let sb: *u8 = sys_mmap(SC_STATBUF) 507 var o: i64 = 0 508 o = sc_cat(sb, o, "corpus_doc_entries " as *u8); o = sc_catn(sb, o, e_doc) 509 o = sc_cat(sb, o, "\ncorpus_url_entries " as *u8); o = sc_catn(sb, o, e_url) 510 o = sc_cat(sb, o, "\nfrontier_entries " as *u8); o = sc_catn(sb, o, e_fr) 511 o = sc_cat(sb, o, "\nshard_segments " as *u8); o = sc_catn(sb, o, ns) 512 o = sc_cat(sb, o, "\nshard_entries_total " as *u8); o = sc_catn(sb, o, e_all) 513 o = sc_cat(sb, o, "\noutcome_rows " as *u8); o = sc_catn(sb, o, rows) 514 o = sc_cat(sb, o, "\noutcome_window_partial " as *u8); o = sc_catn(sb, o, partial) 515 o = sc_cat(sb, o, "\noutcome_window_span_s " as *u8); o = sc_catn(sb, o, w_last - w_first) 516 o = sc_cat(sb, o, "\noutcome_window_first_epoch " as *u8); o = sc_catn(sb, o, w_first) 517 o = sc_cat(sb, o, "\noutcome_window_last_epoch " as *u8); o = sc_catn(sb, o, w_last) 518 o = sc_cat(sb, o, "\nhostcap_defer_permil " as *u8); o = sc_catn(sb, o, defer_permil) 519 o = sc_cat(sb, o, "\ndistinct_hosts " as *u8); o = sc_catn(sb, o, hosts) 520 o = sc_cat(sb, o, "\nfrontier_fair " as *u8); o = sc_catn(sb, o, fair) 521 o = sc_cat(sb, o, "\ncorpus_indexed_tokens " as *u8); o = sc_catn(sb, o, tok_total) 522 o = sc_cat(sb, o, "\ncorpus_pos_uncovered " as *u8); o = sc_catn(sb, o, pos_missing + pos_bad) 523 o = sc_cat(sb, o, "\ncrossover_tokens " as *u8); o = sc_catn(sb, o, cx_tokens) 524 o = sc_cat(sb, o, "\ncrossover_side " as *u8); o = sc_catn(sb, o, cx_side) 525 o = sc_cat(sb, o, "\nverdict=GREEN\n" as *u8) 526 if ss_writefile(SC_STATUS, sb, o) == 0 { 527 sc_w("STATUS wrote " as *u8); sc_n(o); sc_w(" bytes -> " as *u8); sc_w(SC_STATUS); sc_w("\n" as *u8) 528 } else { 529 sc_w("STATUS WRITE FAILED -- the census ran and published nothing, which from outside is indistinguishable from never running\n" as *u8) 530 } 531 532 sc_w("verdict=GREEN\n" as *u8) 533 return 0 534}