code wiki / _hdl_build / nx_capcliff.nx

nx_capcliff.nx

buildroot/runtime/_hdl_build/nx_capcliff.nx

39953 B619 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tool_run.nx nx_gate_verdict.nx nx_capcliff.nx

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

main cc_streq cc_selftest cc_exists sys_openat_rd sys_close sys_chdir sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ gv_ctr sys_mmap ↻ gv_head gv_puts sys_write ↻ cc_size sys_openat_rd ↻ sys_lseek sys_close ↻ gv_check gv_puts ↻ gv_kv gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap gv_check_eq

structs

none

consts

54const CC_MAGIC_4096: i64 = 4096
56const CC_CAP_DEFAULT: i64 = 4194304
57const CC_NEAR_PERMIL: i64 = 900
58const CC_MAXROWS: i64 = 256
59const CC_CONFCAP: i64 = 65536
60const CC_EXIT_NEAR: i64 = 4
61const CC_EXIT_OVER: i64 = 6
62const CC_EXIT_EMPTY: i64 = 5
63const CC_EXIT_UNMEASURED: i64 = 3
64const CC_SEEK_END: i64 = 2
65const CC_REMEDY_CONF: *u8 = "knowledge/capcliff_remedy.conf" as *u8
66const CC_SIZEGUARD: *u8 = "./nx_sizeguard.elf" as *u8
67const CC_SIZEGUARD_BUILT: *u8 = "_build/nx_sizeguard.sov.elf" as *u8
68const CC_GUARD_OUT: i64 = 4096
69const CC_LINE_CAP: i64 = 4096
70const CC_MODE_644: i64 = 420
71const CC_MODE_755: i64 = 493
72const CC_FIX_DIR: *u8 = "/tmp/nx_capcliff_recovery_20260912" as *u8
74const CC_ANCH_UNVERIFIED: i64 = 0
75const CC_ANCH_WHOLE: i64 = 1
76const CC_ANCH_TAIL: i64 = 2
77const CC_ANCH_HEAD: i64 = 3
79const CC_ST_UNGOVERNED: i64 = 0
80const CC_ST_GOVERNED: i64 = 1
81const CC_ST_BREACHED: i64 = 2
82const CC_ST_NOREADER: i64 = 3
83const CC_ST_UNREGISTERED: i64 = 4
84const CC_ST_UNMEASURED: i64 = 5
86const CC_GUARD_NONE: i64 = 0 - 1
87const CC_GUARD_NOELF: i64 = 0 - 2
88const CC_SG_GREEN: i64 = 0
89const CC_SG_AMBER: i64 = 1
90const CC_SG_RED: i64 = 2
92const CC_K_READERS: i64 = 0
93const CC_K_WHOLE: i64 = 1
94const CC_K_TAIL: i64 = 2
95const CC_K_HEAD: i64 = 3
96const CC_K_UNVER: i64 = 4
97const CC_K_WRITERS: i64 = 5
98const CC_K_WUNVER: i64 = 6
99const CC_K_GUARD: i64 = 7
100const CC_K_MENTIONS: i64 = 8
101const CC_K_N: i64 = 9

functions

103func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 3: cwncc_remedycc_scan calls 1: sys_write
104func cwe(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(2,s,n); return 0 }
called by 2: cc_scanmain calls 1: sys_write
105func 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 }
106func cwb(b: *u8, s: i64, e: i64) -> i64 { if e>s { sys_write(1, (b as i64 + s) as *u8, e-s) } return 0 }
called by 2: cc_remedycc_scan calls 1: sys_write
108func cc_streq(a: *u8, b: *u8) -> i64
called by 1: main
114func cc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
115func 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 }
116func cc_catn(d: *u8, o: i64, v: i64) -> i64
called by 1: cc_guard calls 1: sys_mmap
129func cc_span_has(buf: *u8, s: i64, e: i64, lit: *u8) -> i64
called by 2: cc_hascc_guard calls 1: cc_slen
142func cc_has(s: *u8, lit: *u8) -> i64 { return cc_span_has(s, 0, cc_slen(s), lit) }
143func 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 }
called by 1: cc_remedy calls 1: cc_slen
145func cc_atoi(s: *u8) -> i64
called by 1: main
152func cc_span_int(buf: *u8, s: i64, e: i64) -> i64
163func cc_size(path: *u8) -> i64
173func cc_copy(buf: *u8, s: i64, e: i64, dst: *u8) -> i64
181func cc_field(buf: *u8, rs: i64, re: i64, idx: i64, sp: *i64) -> i64
called by 1: cc_remedy
198func 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 }
202func cc_read_line(path: *u8, ln: i64, dst: *u8) -> i64
221func cc_anchor_class(line: *u8) -> i64
called by 1: cc_anchoring calls 1: cc_has
230func cc_anchor_name(c: i64) -> *u8
called by 1: cc_remedy
237func cc_split_site(spec: *u8, s: i64, e: i64, path: *u8) -> i64
246func cc_anchoring(spec: *u8, s: i64, e: i64, path: *u8, line: *u8) -> i64
252func cc_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
254func cc_guard(ledger: *u8, spec: *u8, s: i64, e: i64, out: *u8, olen: *i64) -> i64
283func cc_state_name(st: i64) -> *u8
called by 1: cc_remedy
293func cc_remedy(ledger: *u8, conf: *u8, counts: *i64, quiet: i64) -> i64
390func cc_scan(conf: *u8, cap: i64, remedy: *u8) -> i64
501func cc_wfile(path: *u8, s: *u8) -> i64
509func cc_selftest() -> i64
584func main(argc: i64, argv: *i64) -> i64