nx_debt.nx
buildroot/runtime/nx_debt.nx
about
nx_debt.nx -- debt-store intake CLI (autonomous-loop design-of-record 2026-07-18, R1).
knowledge/store/debt- rows appended by judges/sessions; nx_ws_cycle REFUSES to emit WORK while
an open row exists (eat-debt-first mechanized). Row: <epoch>\t<sev1-9>\t<scope>\t<open|eaten>\t<desc>
nx_debt add <sev> <scope> <desc> [prefix]
nx_debt eat <epoch-id-or-index> [prefix] (epoch col0 exact-match FIRST, index fallback; echoes the row; idempotent)
nx_debt show <epoch-id-or-index> [prefix] (read-before-eat: echo one row, no mutation)
nx_debt page <offset> <limit> [prefix] (64KB-safe paged list w/ declared envelope)
nx_debt list [prefix]
nx_debt dedup [apply] [prefix] (CONSOLIDATE byte-identical OPEN rows: DRY-RUN by default, `apply`
commits; keeps the EARLIEST row of each group and only flips the rest open->eaten -- rule 13
soft-delete, no row is ever removed. ONE sts_seed per run, not one per closure.)
Fail-closed: bad sev / out-of-range seq commit NOTHING. flock on <prefix>plock.
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 3 imports · 0 importers
imports: nx_store_seed_lib.nxnx_seg_store.nxnx_syscalls.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
| 17 | const DB_MAGIC_1469598103934665603: i64 = 1469598103934665603 |
| 18 | const DB_MAGIC_1099511628211: i64 = 1099511628211 |
| 20 | const DB_CAP: i64 = 33554432 // 2026-08-06: was 4 MiB and THE PLANE CROSSED IT -- measured 4,217,666B / 3,326 rows via nx_plane_check while nx_debt page reported total=3311 and show could not find the ~15 NEWEST rows. The 07-29 note predicted the next ceiling was "weeks out"; it arrived in EIGHT DAYS. ***AN APPEND-ONLY PLANE PAST A PREFIX CAP LOSES ITS NEWEST ROWS FIRST, SO THE READER DEGRADES EXACTLY AS NEW WORK ARRIVES*** -- and add/page disagreed by one on `open` (2305 vs 2304) because they read different amounts of the same file. 32 MiB is ~8x current at ~500 rows/wk. ⚠THIS IS THE THIRD RAISE, NOT A FIX: the structural answer is to compare DB_CAP against the actual plane size and REFUSE LOUDLY (or tail-anchor the read) instead of silently returning a prefix -- a cap that can be crossed in silence will be crossed again. Detector now exists: nx_capcliff scan. |
| 21 | const DB_TAB: i64 = 9 |
| 22 | const DB_NL: i64 = 10 |
| 23 | const DB_STDERR: i64 = 2 |
| 24 | const DB_LOCK_EX: i64 = 2 |
| 25 | const DB_MODE: i64 = 420 |
| 26 | const DB_SPAN: i64 = 16 |
| 27 | const DB_ROWMAX: i64 = 131072 // 2026-08-06: per-row index capacity for the `dedup` verb (~39x the live |
| 30 | const DB_PATHCAP: i64 = 256 |
| 31 | const DB_MSGCAP: i64 = 512 |
| 32 | const DB_DESCCAP: i64 = 262144 // 2026-08-06: buffer for the CANONICAL desc (the exact bytes the row will |
| 40 | const DB_RACE_REREAD_MS: i64 = 250 |
| 58 | const DB_ID_MAXPROBE: i64 = 4096 |
| 110 | const DB_EXIT_USAGE: i64 = 2 |
functions
| 64 | func db_count_rows(buf: *u8, n: i64) -> i64 called by 1: db_load_guarded |
| 71 | func db_load_guarded(prefix: *u8, q: *u8, dbf: *i64) -> i64 |
| 112 | func db_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 113 | func db_werr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(DB_STDERR, s, n); return 0 } |
| 116 | func db_werrn(v: i64) -> i64 { let t: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 } 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 } let b: *u8 = sys_mmap(28); var i: i64 = 0; while i < k { b[i] = t[k-1-i]; i = i + 1 } sys_write(DB_STDERR, b, k); sys_munmap(t, 28); sys_munmap(b, 28); return 0 } |
| 117 | func db_vlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 118 | func db_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o] = s[i]; o = o + 1; i = i + 1 } return o } |
| 119 | func db_catn(d: *u8, o: i64, v: i64) -> i64 { let t: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { d[o] = 45 as u8; o = o + 1; m = 0 - m } 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; while i < k { d[o] = t[k-1-i]; o = o + 1; i = i + 1 } return o } |
| 120 | func db_atoi(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 } called by 1: main |
| 121 | func db_le(q: *u8, i: i64, n: i64) -> i64 { var e: i64 = i; var s: i64 = 1; while s == 1 { if e >= n { s = 0 } else { if q[e] == (DB_NL as u8) { s = 0 } else { e = e + 1 } } } return e } |
| 122 | func db_col(q: *u8, ls: i64, le: i64, c: i64, out: *i64) -> i64 |
| 138 | func db_span_lit(q: *u8, s: i64, e: i64, lit: *u8) -> i64 |
| 145 | func db_tail_eq(q: *u8, s: i64, e: i64, lit: *u8) -> i64 |
| 155 | func db_prefix_ok(a: *u8) -> i64 |
| 175 | func db_take_prefix(a: *u8) -> *u8 |
| 181 | func db_lock(prefix: *u8) -> i64 |
| 210 | func db_find_sub(h: *u8, n: i64, s: *u8) -> i64 called by 1: main |
| 226 | func db_open_count(q: *u8, n: i64) -> i64 |
| 237 | func main(argc: i64, argv: *i64) -> i64 |