code wiki / _hdl_build / nx_boot_revive.nx
nx_boot_revive.nx
buildroot/runtime/_hdl_build/nx_boot_revive.nx
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
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
structs
| none |
consts
| 45 | const BR_MAGIC_65536: i64 = 65536 |
| 46 | const BR_MAGIC_1048592: i64 = 1048592 |
| 47 | const BR_MAGIC_1048576: i64 = 1048576 |
| 48 | const BR_MAGIC_16384: i64 = 16384 |
| 49 | const BR_MAGIC_65520: i64 = 65520 |
| 51 | const 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) |
| 52 | const BR_HB_THRESHOLD: i64 = 120 // liveness window (sec): a beat within this == in-flight at crash; older == stale |
| 53 | const BR_RESUME_MAXWS: i64 = 256 // ws-id range the replay state[] / scan ids[] can hold |
| 54 | const BR_RESUME_CAP: i64 = 256 // bounded resume-journal record size (matches WMS RECCAP) |
| 55 | const BR_TIMEOUT: i64 = 124 // GNU-timeout convention (nx_guarded_run idiom) |
| 56 | const BR_SPAWN_FAIL: i64 = 125 // wait4 error |
| 57 | const BR_SIGKILL: i64 = 9 // SIGTERM does not reap these hangs (2026-06-10 lesson) |
| 58 | const BR_POLL_MS: i64 = 50 // watchdog poll granularity |
| 59 | const BR_ARM_GRACE_MS: i64 = 200 // settle time between arming a daemon and recheck |
| 60 | const BR_BOOT_JITTER: i64 = 90 // now-uptime recomputation jitter window (same boot if within) |
functions
| 62 | func _p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 63 | func _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 } |
| 64 | func _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 } |
| 65 | func _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 } |
| 66 | func br_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 67 | func 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 } |
| 68 | func br_exists(path: *u8) -> i64 |
| 74 | func br_read_all(path: *u8, buf: *u8, cap: i64) -> i64 |
| 83 | func br_contains(hay: *u8, n: i64, pat: *u8) -> i64 |
| 97 | func br_last_num_after(hay: *u8, n: i64, pat: *u8) -> i64 |
| 119 | func br_is_pid(name: *u8) -> i64 called by 1: br_daemon_up |
| 130 | func br_organ_present(name: *u8) -> i64 |
| 143 | func br_source_present(name: *u8) -> i64 |
| 157 | func br_guarded(elf: *u8, a1: *u8, ms: i64) -> i64 |
| 193 | func br_uptime() -> i64 |
| 211 | func br_pid_match(nm: *u8, cmdl: *u8, ppath: *u8, sub: *u8) -> i64 |
| 227 | func br_daemon_up(sub: *u8) -> i64 |
| 258 | func br_find_in(buf: *u8, from: i64, to: i64, pat: *u8) -> i64 |
| 271 | func br_digits_at(buf: *u8, pos: i64, to: i64) -> i64 |
| 285 | func br_file_orphans(walpath: *u8, pmpath: *u8, boot_epoch: i64) -> i64 |
| 373 | func br_revive_one(en: *u8, lane: u8, budget: i64, c: *i64) -> i64 |
| 404 | func br_replay_resume(ledgerpath: *u8, hbpath: *u8, resumepath: *u8, |
| 471 | func main(argc: i64, argv: *i64) -> i64 |