nx_heal_lib.nx
buildroot/runtime/nx_heal_lib.nx
about
nx_heal_lib.nx -- CONSOLIDATED heal-plane tool, LIBRARY half (importable: no main; the CLI is
nx_heal.nx, the gate nx_heal_gate.nx asserts on these functions' RETURN VALUES directly).
Tool #11 of the 15-tool architecture: one verb-router, composing what exists, ONE MCP stub.
READ-ONLY first increment: surfaces the supervision +
self-heal + remediation state of the NAS plane so an operator or workstream can SEE/MONITOR over
MCP what tonight's prevention layer is doing (tools_selfheal / edge_selfheal / supervisor snap).
Verbs:
status -> one rollup: supervisor snapshot (UP/DOWN counts + every non-UP line),
selfheal_status.tsv, last self-heal log line + remediation count per plane
log tools|edge -> tail of that plane's self-heal log
remediations -> per-plane remediation event counts + most recent epochs
All verbs take an optional basedir (default "." = ~/nishihost on the NAS); the gate points it at a
fixture dir. Mutating verbs (reconcile/reap) are a LATER increment behind a separate cap -- this
increment is honestly read-only (schema ro=1). license_tier: ORIGINAL
dependencies 6 imports · 2 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnx_connect.nxnx_seg_store.nxnx_vsz_watchdog_core.nxnx_os_proc.nx
imported by: nx_heal.nxnx_heal_gate.nx
structs
| none |
consts
| 22 | const NH_BUF_CAP: i64 = 262144 // max bytes considered per surfaced file (logs stay small by design) |
| 23 | const NH_TAIL_LINES: i64 = 20 // `log` verb: lines of tail shown |
| 24 | const NH_RECENT_EVTS: i64 = 5 // `remediations`: most recent epochs echoed |
| 25 | const NH_PATH_CAP: i64 = 512 |
| 26 | const NH_ASCII_0: i64 = 48 // '0' (decimal print) |
| 212 | const NH_OLD_SECS: i64 = 600 // a pid older than this = stable long-lived parent |
| 213 | const NH_RECENT_WIN: i64 = 3600 // remediation recency window (matches selfheal's per-hour accounting) |
| 214 | const NH_MAX_PIDS: i64 = 64 // matched-pid table cap |
| 215 | const NH_ALLPID_CAP: i64 = 4096 // max live pids enumerated per scan (via the nx_os_proc seam) |
| 216 | const NH_CL_CAP: i64 = 4096 // argv0 read cap |
| 217 | const NH_SUP_CAP: i64 = 262144 // supervisor-log read cap |
| 219 | const NH_V_DOWN: i64 = 0 // no live process |
| 220 | const NH_V_STABLE: i64 = 1 // long-lived parent; pid churn = worker children (monitor false-positive) |
| 221 | const NH_V_LOOP_HEAL: i64 = 2 // young processes + recent heal-plane remediations = selfheal is bouncing it |
| 222 | const NH_V_LOOP_UNTRACKED: i64 = 3 // young processes, NO heal remediations = something ELSE restarts it |
| 364 | const NH_FETCH_CAP: i64 = 32768 |
functions
| 28 | func nh_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 33 | func nh_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 34 | func nh_streq(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 } |
| 35 | func nh_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 } called by 1: nh_path |
| 37 | func nh_path(out: *u8, base: *u8, name: *u8) -> i64 |
| 45 | func nh_read(base: *u8, name: *u8, bufp: *i64) -> i64 |
| 57 | func nh_tail(buf: *u8, n: i64, want: i64) -> i64 |
| 75 | func nh_lastline(buf: *u8, n: i64) -> i64 |
| 87 | func nh_lines(buf: *u8, n: i64) -> i64 |
| 94 | func nh_match(buf: *u8, i: i64, end: i64, lit: *u8) -> i64 |
| 104 | func nh_line_has_up(buf: *u8, ls: i64, le: i64) -> i64 |
| 112 | func nh_is_svc(buf: *u8, ls: i64, le: i64) -> i64 |
| 117 | func nh_status(base: *u8) -> i64 |
| 194 | func nh_log(base: *u8, plane: *u8) -> i64 |
| 224 | func nh_str_eq(a: *u8, b: *u8) -> i64 { return nh_streq(a, b) } |
| 226 | func nh_wallclock() -> i64 |
| 234 | func nh_scan(daemon: *u8, pids: *i64, ages: *i64, ppids: *i64) -> i64 |
| 263 | func nh_recent_epochs(buf: *u8, n: i64, now: i64, win: i64) -> i64 |
| 283 | func nh_classify(npids: i64, oldest_age: i64, recent_remed: i64) -> i64 |
| 292 | func nh_diagnose(daemon: *u8, plane: *u8, base: *u8) -> i64 |
| 365 | func nh_organ_body(port: i64) -> i64 called by 1: main calls 10: sys_socketnh_putssys_set_socket_timeoutsys_mmapnx_connect_boundedsys_close+4 |
| 407 | func nh_remediations(base: *u8) -> i64 |