code wiki / _hdl_build / nx_capcliff.nx
nx_capcliff.nx
buildroot/runtime/_hdl_build/nx_capcliff.nx
about
nx_capcliff.nx -- READER-CAP CLIFF DETECTOR for append-only ledgers, WITH THE REMEDY CENSUS (DI13).
WHY THIS EXISTS (measured 2026-08-06). Several estate readers capture a ledger into a BOUNDED
buffer -- 4 MiB is the recurring number (nx_debt_view declares capture_cap=4194304; nx_catalog
reports actlog 4194304B exactly). When the ledger grows PAST that cap the reader keeps working and
silently returns a TRUNCATED PREFIX. Two were already over on the day this was written:
knowledge/status/actlog.jrnl -- read at offset 4194304 returns bytes and 'more remains', while
nx_catalog reports exactly 4194304B. The boundary row is epoch 1785966081 (~21h before), so
EVERY INVOCATION SINCE THEN IS INVISIBLE and nx_catalog calls freshly-run organs
REGISTERED-DARK (S4) 'callable, authorised, NEVER RUN'. The estate's headline ADOPTION signal
was being manufactured by a truncated buffer.
knowledge/store/debt- -- nx_plane_check says rows=3326 GREEN bytes=4217666, while nx_debt page
reports total=3311 and nx_debt show cannot find the ~15 newest rows.
***BECAUSE THESE LEDGERS ARE APPEND-ONLY, A PREFIX CAP ALWAYS EATS THE NEWEST ROWS FIRST.*** The
instrument therefore degrades exactly as new work arrives, and every downstream metric drifts
toward 'nothing happened lately'. That is the worst possible failure direction for an adoption or
debt gauge, and nothing announced it.
This organ makes the cliff PREDICTABLE instead of discovered: it measures each rostered ledger
against the cap and reports headroom, so a crossing is forecast rather than found by accident.
THE REMEDY CENSUS (DI13, 2026-09-06). An OVER row is a SIZE fact, not a proven reader defect: a
TAIL-anchored or whole-file reader loses nothing, a HEAD-anchored one loses the newest rows. So every
OVER ledger is now judged against knowledge/capcliff_remedy.conf, rows `ledger|kind|target|note`:
reader target = <file:line> of the consumer's READ SITE. The organ READS THAT LINE and classifies
it -- WHOLE (sys_read_file), TAIL (SEEK_END or a *_tail( helper), HEAD (a bare sys_read),
UNVERIFIED (none of those: a declaration that did not point at a read). The conf declares
WHERE to look; the classification is measured, never copied from the row.
writer target = <file:line> of the appender (verified: the line must append).
guard target = sizeguard:<byte-cliff>:<line-cliff>; nx_sizeguard is FORKED on the ledger with that
budget and its exit code is the guard's verdict (0 GREEN 1 AMBER 2 RED 3 UNMEASURED).
mention target = a file that names the ledger without reading it (comment, fixture); declared, not judged.
Remedy states describe the DECLARED ROSTER, not a complete semantic census of all source consumers.
GOVERNED: declared readers are WHOLE/TAIL or guarded GREEN/AMBER; BREACHED: a declared guard reads RED;
UNGOVERNED: a declared HEAD/UNVERIFIED reader has no working guard. UNREGISTERED: a readable conf has
no matching ledger rows. UNMEASURED: conf unreadable or zero declared readers, including writer-only rows.
Zero declared readers cannot prove no actual readers. The legacy NO-READER state code/name is retained
for compatibility but no current evidence contract establishes it. Output carries the roster truth scope
and semantic_coverage=UNMEASURED. Unknown coverage abstains with exit 3 in remedy and OVER-ledger scan;
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_tool_run.nxnx_gate_verdict.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 54 | const CC_MAGIC_4096: i64 = 4096 |
| 56 | const CC_CAP_DEFAULT: i64 = 4194304 |
| 57 | const CC_NEAR_PERMIL: i64 = 900 |
| 58 | const CC_MAXROWS: i64 = 256 |
| 59 | const CC_CONFCAP: i64 = 65536 |
| 60 | const CC_EXIT_NEAR: i64 = 4 |
| 61 | const CC_EXIT_OVER: i64 = 6 |
| 62 | const CC_EXIT_EMPTY: i64 = 5 |
| 63 | const CC_EXIT_UNMEASURED: i64 = 3 |
| 64 | const CC_SEEK_END: i64 = 2 |
| 65 | const CC_REMEDY_CONF: *u8 = "knowledge/capcliff_remedy.conf" as *u8 |
| 66 | const CC_SIZEGUARD: *u8 = "./nx_sizeguard.elf" as *u8 |
| 67 | const CC_SIZEGUARD_BUILT: *u8 = "_build/nx_sizeguard.sov.elf" as *u8 |
| 68 | const CC_GUARD_OUT: i64 = 4096 |
| 69 | const CC_LINE_CAP: i64 = 4096 |
| 70 | const CC_MODE_644: i64 = 420 |
| 71 | const CC_MODE_755: i64 = 493 |
| 72 | const CC_FIX_DIR: *u8 = "/tmp/nx_capcliff_recovery_20260912" as *u8 |
| 74 | const CC_ANCH_UNVERIFIED: i64 = 0 |
| 75 | const CC_ANCH_WHOLE: i64 = 1 |
| 76 | const CC_ANCH_TAIL: i64 = 2 |
| 77 | const CC_ANCH_HEAD: i64 = 3 |
| 79 | const CC_ST_UNGOVERNED: i64 = 0 |
| 80 | const CC_ST_GOVERNED: i64 = 1 |
| 81 | const CC_ST_BREACHED: i64 = 2 |
| 82 | const CC_ST_NOREADER: i64 = 3 |
| 83 | const CC_ST_UNREGISTERED: i64 = 4 |
| 84 | const CC_ST_UNMEASURED: i64 = 5 |
| 86 | const CC_GUARD_NONE: i64 = 0 - 1 |
| 87 | const CC_GUARD_NOELF: i64 = 0 - 2 |
| 88 | const CC_SG_GREEN: i64 = 0 |
| 89 | const CC_SG_AMBER: i64 = 1 |
| 90 | const CC_SG_RED: i64 = 2 |
| 92 | const CC_K_READERS: i64 = 0 |
| 93 | const CC_K_WHOLE: i64 = 1 |
| 94 | const CC_K_TAIL: i64 = 2 |
| 95 | const CC_K_HEAD: i64 = 3 |
| 96 | const CC_K_UNVER: i64 = 4 |
| 97 | const CC_K_WRITERS: i64 = 5 |
| 98 | const CC_K_WUNVER: i64 = 6 |
| 99 | const CC_K_GUARD: i64 = 7 |
| 100 | const CC_K_MENTIONS: i64 = 8 |
| 101 | const CC_K_N: i64 = 9 |
functions
| 103 | func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 104 | func cwe(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(2,s,n); return 0 } |
| 105 | func cwn(v: i64) -> i64 { var m: i64=v; if m<0{cw("-" as *u8);m=0-m} let t:*u8=sys_mmap(28); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(28); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); sys_munmap(t,28); sys_munmap(o,28); return 0 } |
| 106 | func cwb(b: *u8, s: i64, e: i64) -> i64 { if e>s { sys_write(1, (b as i64 + s) as *u8, e-s) } return 0 } |
| 108 | func cc_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 114 | func cc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 115 | func cc_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 } |
| 116 | func cc_catn(d: *u8, o: i64, v: i64) -> i64 |
| 129 | func cc_span_has(buf: *u8, s: i64, e: i64, lit: *u8) -> i64 |
| 142 | func cc_has(s: *u8, lit: *u8) -> i64 { return cc_span_has(s, 0, cc_slen(s), lit) } |
| 143 | func cc_span_eq(buf: *u8, s: i64, e: i64, lit: *u8) -> i64 { let ll: i64 = cc_slen(lit); if e - s != ll { return 0 } var i: i64 = 0; while i < ll { if buf[s + i] != lit[i] { return 0 } i = i + 1 } return 1 } |
| 145 | func cc_atoi(s: *u8) -> i64 called by 1: main |
| 152 | func cc_span_int(buf: *u8, s: i64, e: i64) -> i64 |
| 163 | func cc_size(path: *u8) -> i64 |
| 173 | func cc_copy(buf: *u8, s: i64, e: i64, dst: *u8) -> i64 |
| 181 | func cc_field(buf: *u8, rs: i64, re: i64, idx: i64, sp: *i64) -> i64 called by 1: cc_remedy |
| 198 | func cc_line_end(buf: *u8, n: i64, p: i64) -> i64 { var i: i64 = p; var go: i64 = 1; while go == 1 { if i >= n { go = 0 } else { if buf[i] == (10 as u8) { go = 0 } else { i = i + 1 } } } return i } |
| 202 | func cc_read_line(path: *u8, ln: i64, dst: *u8) -> i64 |
| 221 | func cc_anchor_class(line: *u8) -> i64 |
| 230 | func cc_anchor_name(c: i64) -> *u8 called by 1: cc_remedy |
| 237 | func cc_split_site(spec: *u8, s: i64, e: i64, path: *u8) -> i64 |
| 246 | func cc_anchoring(spec: *u8, s: i64, e: i64, path: *u8, line: *u8) -> i64 |
| 252 | func cc_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } |
| 254 | func cc_guard(ledger: *u8, spec: *u8, s: i64, e: i64, out: *u8, olen: *i64) -> i64 |
| 283 | func cc_state_name(st: i64) -> *u8 called by 1: cc_remedy |
| 293 | func cc_remedy(ledger: *u8, conf: *u8, counts: *i64, quiet: i64) -> i64 called by 3: cc_scancc_selftestmain calls 15: sys_mmapsys_read_filecc_line_endcc_fieldcc_span_eqcc_anchoring+9 |
| 390 | func cc_scan(conf: *u8, cap: i64, remedy: *u8) -> i64 |
| 501 | func cc_wfile(path: *u8, s: *u8) -> i64 |
| 509 | func cc_selftest() -> i64 |
| 584 | func main(argc: i64, argv: *i64) -> i64 |