code wiki / _hdl_build / nx_boot_revive.nx

nx_boot_revive.nx

buildroot/runtime/_hdl_build/nx_boot_revive.nx

32680 B661 linesdepth 5pulls 5 transitivereach 1 importersview sourcekind tooltopic boot
docsdependenciesstructsconstsfunctions

about

nx_boot_revive.nx -- the DOCTOR's boot-resurrection organ (verb: HEAL). CR1 of the crash-recovery ladder (knowledge/specs/2026-06-10-crash-recovery-ladder.md). WHY: the 2026-06-10 Windows reboot proved recovery REQUIRED a live session: /tmp organs were gone (4/16 present), the pulse daemon was dead, and the team self-healed only LAZILY (tp_run heals the 11 pulse steps when a pulse happens to run) and only because a session restarted the daemon by hand. This organ makes recovery a single durable unit a boot hook fires with ZERO sessions: (1) BOOT DETECT -- boot_epoch = now - /proc/uptime; one BOOT row per boot appended to knowledge/status/boot_journal.log incl. dark_gap = boot_epoch - last DAEMON-BEAT (how long the substrate was DOWN -- the crash is measured, not inferred). (2) ORGAN REVIVE -- every E row of triage_expected.conf absent-but-recoverable is rebuilt NOW via _offc/nx_sov_build_run.elf, each under a hard watchdog deadline (conf B row, seconds; WNOHANG poll + SIGKILL reap, nx_guarded_run idiom -- a hung build/run becomes a counted TIMEOUT, never a wedged boot). (3) DAEMON REVIVE -- every D row not found in /proc is re-armed via the same runner (the daemon's own pidfile dup-guard makes re-arming idempotent). Durable REVIVE line -> knowledge/status/boot_revive.log. Verdict GREEN only if all expected organs are present and daemons running and nothing timed out; W-lane and no-source absences stay LOUD (named debts, never silently skipped). (4) ORPHANED INTENTS (CR4) -- scan the intent WAL (knowledge/status/intent_wal.log, INTENT-START/INTENT-DONE rows written by self-journaling work units like nx_team_pulse): any START from BEFORE this boot with no DONE = work the crash interrupted mid-flight; it is auto-FILED as a pm_plan row (owner=Conductor) and marked INTENT-FILED in the WAL so re-runs never refile (idempotent). STARTs from THIS boot are in-flight, never filed. argv[1]=conf override, argv[2]=log override, argv[3]=journal override, argv[4]=intent-WAL override, argv[5]=pm-plan override (gate fixtures). Sovereign (syscalls only, no .sh). Run from nxc2 root. license_tier: ORIGINAL (1c) REPLAY + RESUME (M6, crash-recovery capstone) -- on boot, REPLAY the WMS-R2 transition reflog (nx_ws_ledger.ledger_replay) to reconstruct the AUTHORITATIVE current state of every workstream, then check WMS-M1 heartbeats (nx_heartbeat_monitor.hbm_scan) to find streams that were IN-FLIGHT at the crash (recently beating == HB_ALIVE) AND not marked DONE -> resume EXACTLY those. Completed streams (state==BR_WS_DONE) are ignored; stale streams (HB_STALLED / HB_UNKNOWN) are reported but NOT resumed (not in-flight at the crash boundary). Each resume = ONE framed record via fa_appendz to a resume journal. The crash that started this whole arc becomes a non-event. Purely ADDITIVE: existing boot-detect / orphan-revive / organ-revive / daemon-revive are byte-identical. argv[6]=ledger override, argv[7]=heartbeat override, argv[8]=resume-journal override,

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_ws_ledger.nx nx_heartbeat_monitor.nx nx_boot_revive.nx nx_boot_revive_m6_gate.nx

imports: nx_syscalls.nxnx_ws_ledger.nxnx_heartbeat_monitor.nx

imported by: nx_boot_revive_m6_gate.nx

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

main _p sys_write sys_mmap br_read_all sys_openat_rd sys_read sys_close sys_exit sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real br_uptime sys_mmap ↻ br_read_all ↻ br_last_num_after br_len sys_openat_append _fp sys_write ↻ _fn sys_mmap ↻ sys_write ↻ sys_close ↻ _pn sys_mmap ↻ sys_write ↻ br_file_orphans sys_mmap ↻ br_read_all ↻ br_find_in br_len ↻ br_digits_at _p ↻ _pn ↻ sys_openat_append ↻ _fp ↻ _fn ↻ sys_close ↻ sys_now_realtime_sec ↻

structs

none

consts

45const BR_MAGIC_65536: i64 = 65536
46const BR_MAGIC_1048592: i64 = 1048592
47const BR_MAGIC_1048576: i64 = 1048576
48const BR_MAGIC_16384: i64 = 16384
49const BR_MAGIC_65520: i64 = 65520
51const BR_WS_DONE: i64 = 3 // ledger DONE state code (ws_ledger gate: 0=TODO 1=WIP 2=VIEW 3=DONE 4=NOVEL; data-driven, Cardinal 11)
52const BR_HB_THRESHOLD: i64 = 120 // liveness window (sec): a beat within this == in-flight at crash; older == stale
53const BR_RESUME_MAXWS: i64 = 256 // ws-id range the replay state[] / scan ids[] can hold
54const BR_RESUME_CAP: i64 = 256 // bounded resume-journal record size (matches WMS RECCAP)
55const BR_TIMEOUT: i64 = 124 // GNU-timeout convention (nx_guarded_run idiom)
56const BR_SPAWN_FAIL: i64 = 125 // wait4 error
57const BR_SIGKILL: i64 = 9 // SIGTERM does not reap these hangs (2026-06-10 lesson)
58const BR_POLL_MS: i64 = 50 // watchdog poll granularity
59const BR_ARM_GRACE_MS: i64 = 200 // settle time between arming a daemon and recheck
60const BR_BOOT_JITTER: i64 = 90 // now-uptime recomputation jitter window (same boot if within)

functions

62func _p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
63func _pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
64func _fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 2: br_file_orphansmain calls 1: sys_write
65func _fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
66func br_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
67func br_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
68func br_exists(path: *u8) -> i64
74func br_read_all(path: *u8, buf: *u8, cap: i64) -> i64
83func br_contains(hay: *u8, n: i64, pat: *u8) -> i64
called by 1: br_pid_match calls 1: br_len
97func br_last_num_after(hay: *u8, n: i64, pat: *u8) -> i64
called by 1: main calls 1: br_len
119func br_is_pid(name: *u8) -> i64
called by 1: br_daemon_up
130func br_organ_present(name: *u8) -> i64
143func br_source_present(name: *u8) -> i64
157func br_guarded(elf: *u8, a1: *u8, ms: i64) -> i64
193func br_uptime() -> i64
called by 1: main calls 2: sys_mmapbr_read_all
211func br_pid_match(nm: *u8, cmdl: *u8, ppath: *u8, sub: *u8) -> i64
227func br_daemon_up(sub: *u8) -> i64
258func br_find_in(buf: *u8, from: i64, to: i64, pat: *u8) -> i64
called by 1: br_file_orphans calls 1: br_len
271func br_digits_at(buf: *u8, pos: i64, to: i64) -> i64
called by 2: br_file_orphansmain
285func br_file_orphans(walpath: *u8, pmpath: *u8, boot_epoch: i64) -> i64
373func br_revive_one(en: *u8, lane: u8, budget: i64, c: *i64) -> i64
404func br_replay_resume(ledgerpath: *u8, hbpath: *u8, resumepath: *u8,
471func main(argc: i64, argv: *i64) -> i64