code wiki / _hdl_build / nx_pub_recover.nx

nx_pub_recover.nx

buildroot/runtime/_hdl_build/nx_pub_recover.nx

7809 B140 linesdepth 3pulls 4 transitivereach 20 importersview sourcekind tooltopic pub
docsdependenciesstructsconstsfunctions

about

nx_pub_recover.nx -- THE PUBLISHER'S DAEMON-RECOVERY rung (ops authority, not ad-hoc workstreams). Operator law: "the nishi publisher should be managing restarts and all this stuff." So recovery is a PUBLISHER responsibility, decided from the MONITOR'S signal -- never an ad-hoc workstream kill. The supervisor (nx_hostctl) already RESPAWNS dead/hung daemons + crash-loop-guards. The GAP it can't see: a WEDGE -- a daemon that still answers but SLOWLY (the :8791 reader at 20s/request passes the binary up/down probe). nx_apm_sweep measures real latency -> apm_metrics.tsv. This organ reads that signal, maps a slow endpoint to its daemon, and emits an IDEMPOTENT + SERIALIZED + LEDGERED recovery REQUEST (the control-plane consumer proc_kill_by_name's it -> the existing keeper respawns a fresh one). By construction: never-brick #26 (a recovery REQUEST is reversible metadata; the action is only a kill+supervised-respawn, never a destructive write); idempotent #10 (a daemon already PENDING is not re-requested); serialized (fl_acquire, one decision at a time); fail-safe #14 (unmapped/healthy -> no-op). pr_recover(metricspath, queuepath, wedge_ms) -> number of recovery requests emitted license_tier: ORIGINAL

dependencies 3 imports · 3 importers

nx_syscalls.nx nx_arbiter.nx nx_framed_append.nx nx_pub_recover.nx nx_hostop.nx nx_pub_recover_exec.nx nx_pub_recover_gate.nx

imports: nx_syscalls.nxnx_arbiter.nxnx_framed_append.nx

imported by: nx_hostop.nxnx_pub_recover_exec.nxnx_pub_recover_gate.nx

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

main pr_atoi pr_uw sys_write pr_slen pr_wn sys_mmap pr_n sys_mmap ↻ sys_write ↻ pr_recover sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close pr_field pr_atoi ↻ pr_slen ↻ pr_daemon_for pr_has pr_slen ↻ pr_s fl_acquire fl_try fl_mkdir sys_mmap ↻ fl_path sys_openat_wr sys_flock sys_close ↻ fl_nap sys_mmap ↻ pr_already_pending sys_mmap ↻ sys_read_file ↻ pr_field ↻ pr_streq

structs

none

consts

20const PR_MAGIC_100000: i64 = 100000
22const PR_WEDGE_MS_DEFAULT: i64 = 5000
23const PR_METRICS: *u8 = "knowledge/status/apm_metrics.tsv"
24const PR_QUEUE: *u8 = "knowledge/publish/recovery_queue.tsv"
25const PR_LOCK: *u8 = "publish_recover"
26const PR_REC_CAP: i64 = 1024

functions

28func pr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
29func pr_uw(fd: i64, s: *u8) -> i64 { sys_write(fd, s, pr_slen(s)); return 0 }
called by 1: main calls 2: sys_writepr_slen
30func pr_n(buf: *u8, off: i64, v: i64) -> i64
39func pr_s(buf: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { buf[o] = s[i]; o = o + 1; i = i + 1 } return o }
40func pr_wn(fd: i64, v: i64) -> i64 { let b: *u8 = sys_mmap(24); let e: i64 = pr_n(b, 0, v); sys_write(fd, b, e); return 0 }
called by 1: main calls 3: sys_mmappr_nsys_write
42func pr_has(hay: *u8, n: i64, needle: *u8) -> i64
called by 1: pr_daemon_for calls 1: pr_slen
49func pr_field(line: *u8, linelen: i64, idx: i64, out: *u8) -> i64
59func pr_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v*10 + (c-48) } } i = i + 1 } return v }
called by 2: pr_recovermain
61func pr_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 }
called by 1: pr_already_pending
64func pr_daemon_for(url: *u8, urllen: i64, out: *u8) -> i64
called by 1: pr_recover calls 2: pr_haspr_s
73func pr_already_pending(queuepath: *u8, daemon: *u8) -> i64
94func pr_recover(metricspath: *u8, queuepath: *u8, wedge_ms: i64) -> i64
132func main(argc: i64, argv: *i64) -> i64