code wiki / (root) / nx_restage.nx

nx_restage.nx

buildroot/runtime/nx_restage.nx

8731 B132 linesdepth 5pulls 5 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_restage.nx -- EAT THE DEPLOY-TOOLING DEBT (operator 2026-07-17 "eat the debt and build the tools"): the missing primitive that restages a freshly-built elf into a build tree's _offc/. Without it, buildroot/_offc generators go STALE vs runtime source (the F-004 stale-binary class: e.g. the compare @verdict directive existed in nx_swcompare_sota.nx source but the staged _offc elf predated it, so the SSOT verdict silently fell back to a hardcoded string). nx_fs_write refuses _offc (text + deny), nx_shelltool is read-only, /api/build stages to nishihost not _offc -- so this closed gap blocked EVERY generator refresh. nx_restage <target> [broot] broot default "buildroot" ("." = in-place / local test) -> chdir broot; if the PROMOTED twin ../<target>.elf exists, COPY IT (2026-09-05, see WHY below); else fork _offc/nx_sov_build_run.elf <target> --build-only (=> _build/<target>.sov.elf) -> binary-safe copy to _offc/<target>.elf.new; VERIFY ELF magic + nonzero; atomic rename over _offc/<target>.elf -> emits {"action":"RESTAGED","target":..,"path":..,"source":"PROMOTED ../<t>.elf"|"BUILT _build/<t>.sov.elf","bytes":N} WHY PROMOTED-FIRST (2026-09-05): nx_compare_regen's fork-freshness check SHA-256s _offc/<gen>.elf against the PROMOTED ../<gen>.elf and names "nx_restage <gen>" as the remedy. A REBUILD here runs the sovereign lane, which is byte-different from the /api/build lane on identical source (measured: nx_swcompare_matrix restaged 332,217 B against the promoted 368,016 B -- FORK-STALE by construction, a THIRD digest). Copying the promoted bytes is the only refresh that can ever read FRESH; the rebuild stays as the fallback for a target that has never been promoted. The destination is opened 0755, so an inert twin cannot be produced. target sanitized [A-Za-z0-9_] (no path escape). Exit 0 restaged | 1 build/copy fail | 2 usage/bad-target. license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 1 imports · 1 importers

nx_tool_run.nx nx_restage.nx nx_restage_gate.nx

imports: nx_tool_run.nx

imported by: nx_restage_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main rpe r_san r_cat tr_run_capture 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 ↻ sys_pipe2 sys_fork sys_close sys_dup3 sys_execve_clean sys_close_inherited sys_close_inherited_proc sys_openat_rd sys_mmap ↻ sys_getdents64 dirent_reclen sys_close ↻ sys_munmap sys_execve tr_exec_failed sys_write ↻ sys_exit ↻ sys_read sys_wait4 wait_status_rc

structs

none

consts

21const K_MAGIC_262144: i64 = 262144
22const K_MAGIC_65536: i64 = 65536

functions

24func rp(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 1: main
25func rpe(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 1: main
26func rn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);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; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main
28func r_cat(dst: *u8, off: i64, src: *u8) -> i64 { var o: i64=off; var j: i64=0; while src[j]!=(0 as u8){dst[o]=src[j];o=o+1;j=j+1} return o }
called by 1: main
30func r_san(name: *u8) -> i64
called by 2: mainmain
47func main(argc: i64, argv: *i64) -> i64