code wiki / _hdl_build / nx_rebuild_plan.nx
nx_rebuild_plan.nx
buildroot/runtime/_hdl_build/nx_rebuild_plan.nx
about
nx_rebuild_plan.nx -- DEPENDENCY-AWARE STALENESS: which deployed organs must be rebuilt, and WHY.
THE WOUND (measured 2026-07-30, debt 1785446507 sev8): 667 of 722 deployed organs run binaries older
than what their source+deps produce. Only 222 of those are stale by their OWN source. The other 445
are stale because a SHARED runtime moved underneath them -- `nx_syscalls.nx` is imported by 14,172
files, so one edit to it invalidates almost every statically linked elf in the ecosystem WITHOUT
touching a single line of their own .nx. Nothing in the ecosystem could compute that. The existing
instruments each answer a smaller question: `nx_stale_check <target>` rebuilds ONE target and
byte-compares (correct but O(one build) and says nothing about WHY), and an own-source mtime census
misses the dominant 445 entirely.
★★★THE POINT IS THE TRIGGER, NOT THE VERDICT. "stale" is useless on its own -- 667 rows of "stale"
is not a work order, it is noise. Naming the ONE file whose mtime invalidated each organ turns the
census into a plan: 445 organs all triggered by nx_syscalls.nx is a SINGLE decision (rebuild the
dependents of one file), not 445 investigations. A tool that reports a problem without naming its
cause makes the operator redo the diagnosis the tool already did.
METHOD: resolve each deployed <t>.elf to its source, walk the TRANSITIVE import closure (lazily, from
the deployed organs as roots -- never the whole 17.5k-file tree), memoise closure_max_mtime + argmax
per node, then compare against the deployed elf's mtime. Cycles are coloured and broken, so a cyclic
import cannot hang the walk or silently drop a subtree.
nx_rebuild_plan [elfdir] [srcroot] [maxrows]
-> per-organ rows {organ, verdict, trigger, age_min} + a summary keyed by TRIGGER
verdicts: CURRENT | STALE-BY-OWN | STALE-BY-DEP | STALE-BY-TOOLCHAIN | NOSOURCE
Exit 0 always (a census is not a gate; it reports, it does not refuse).
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.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
| 30 | const RP_AT_FDCWD: i64 = 0 - 100 |
| 31 | const RP_SYS_NEWFSTATAT: i64 = 262 |
| 32 | const RP_STATBUF: i64 = 256 |
| 33 | const RP_OFF_SIZE: i64 = 48 |
| 34 | const RP_OFF_MTIME: i64 = 88 |
| 37 | const RP_MAXN: i64 = 8192 |
| 38 | const RP_PATHCAP: i64 = 192 |
| 39 | const RP_MAXE: i64 = 131072 |
| 40 | const RP_MAXROOT: i64 = 4096 |
| 44 | const RP_HEAD: i64 = 32768 |
| 45 | const RP_DIRBUF: i64 = 262144 |
| 46 | const RP_SEC_PER_MIN: i64 = 60 |
| 49 | const RP_TOP_TRIGGERS: i64 = 12 |
functions
| 51 | func rp_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 56 | func rp_n(v: i64) -> i64 { nxi_out(v); return 0 } |
| 57 | func rp_eq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } called by 1: main |
| 58 | func rp_len(a: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { i = i + 1 } return i } |
| 59 | func rp_cpy(dst: *u8, src: *u8) -> i64 { var i: i64 = 0; while src[i] != (0 as u8) { dst[i] = src[i]; i = i + 1 } dst[i] = 0 as u8; return i } called by 1: main |
| 60 | func rp_cat(dst: *u8, o: i64, src: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while src[i] != (0 as u8) { dst[p] = src[i]; p = p + 1; i = i + 1 } dst[p] = 0 as u8; return p } called by 1: main |
| 62 | func rp_mtime(path: *u8) -> i64 |
| 69 | func rp_readhead(path: *u8, buf: *u8, cap: i64) -> i64 |
| 80 | func rp_is_elf(name: *u8) -> i64 |
| 91 | func rp_import_of(buf: *u8, i: i64, le: i64, dst: *u8, cap: i64) -> i64 called by 1: main |
| 115 | func main(argc: i64, argv: *i64) -> i64 |