code wiki / (root) / nx_swarm_heal.nx

nx_swarm_heal.nx

buildroot/runtime/nx_swarm_heal.nx

14525 B264 linesdepth 3pulls 5 transitivereach 0 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_heal.nx -- HUB-SIDE swarm endpoint self-heal (2026-08-12, residue debt 1786545237 item 4). THE GAP: knowledge/swarm_nodes.conf is the resolver SSOT (nx_swarm_endpoint_lib), re-read per call, but its ROW goes stale when the GPU node roams (DHCP/adapter flap: .192 -> .146 -> off-LAN). The gen orchestrator then dispatches to a dead addr. Beat telemetry can't fix it: the NODE beacon row is positional CPU/mem and carries no address, and a spoke reporting over the public edge cannot convey its LAN address anyway. So the hub REPAIRS BY VERIFIED REACHABILITY, never by a claim: check <role> [conf] -- probe the CURRENT conf addr for <role>; report FRESH/DOWN. No write. heal <role> <candidates.conf> [conf] [apply] -- if the current addr is DOWN, probe each candidate host:port; rewrite the row's addr field ONLY to the UNIQUE reachable one. 0 reachable -> LEFT (fail-closed); >1 -> AMBIGUOUS (never guess). Writes only with the literal `apply`; else DRY. selftest -- positive+negative probe controls + a conf-rewrite round-trip. SAFETY: a prober wrong in the ADOPT direction rewrites the SSOT to a dead endpoint -- the exact outage the conf's own law forbids ("a wrong endpoint is worse than none"). So adoption requires the STRONGEST evidence (getsockopt SO_ERROR==0, not merely poll-writable) AND uniqueness; anything short -> no write. PROBE PROVENANCE: go_probe_up is copied from nx_gen_worker.nx go_worker_up (the live multi-worker liveness selector). DUPLICATE-BY-NECESSITY: that func sits inside a daemon with a main() so it is not importable; both should move to a shared nx_netprobe_lib on the next nx_gen_worker touch (debt filed). license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_swarm_endpoint_lib.nx nx_gate_verdict.nx nx_netprobe_lib.nx nx_swarm_heal.nx

imports: nx_syscalls.nxnx_swarm_endpoint_lib.nxnx_gate_verdict.nxnx_netprobe_lib.nx

imported by: nobody (leaf or entry point)

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

main sh_streq sh_selftest gv_ctr 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 ↻ gv_head gv_puts sys_write ↻ sh_listen sys_socket sys_mmap ↻ sys_bind sys_close sys_listen gv_check gv_puts ↻ gv_bite gv_puts ↻ go_probe_up np_probe_up np_probe_up_to sys_socket ↻ sys_mmap ↻ sys_connect sys_poll sys_close ↻

structs

none

consts

25const SH_MAGIC_2048: i64 = 2048
26const SH_MAGIC_2000: i64 = 2000
27const SH_MAGIC_39271: i64 = 39271
28const SH_MAGIC_39272: i64 = 39272
30const SH_CONF: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/swarm_nodes.conf"
31const SH_CAP: i64 = 65536
32const SH_MODE_644: i64 = 420

functions

34func sh_p(s: *u8) -> i64 { sys_write(1, s, se_len(s)); return 0 }
called by 2: sh_healmain calls 2: sys_writese_len
35func sh_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); let t: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 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: sh_heal calls 2: sys_mmapsys_write
40func go_probe_up(ha: i64, hb: i64, hc: i64, hd: i64, port: i64) -> i64 { return np_probe_up(ha, hb, hc, hd, port) }
43func sh_parse_addr(s: *u8, n: i64, oct: *i64) -> i64
68func sh_addr_span(buf: *u8, n: i64, role: *u8, box: *i64) -> i64
89func sh_rewrite(conf: *u8, buf: *u8, n: i64, off: i64, len: i64, new_addr: *u8) -> i64
114func sh_probe_role(role: *u8) -> i64
124func sh_scan_candidates(path: *u8, winner: *u8) -> i64
158func sh_heal(role: *u8, candpath: *u8, conf: *u8, apply: i64) -> i64
184func sh_mkfile(path: *u8, content: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, SH_MODE_644); if fd < 0 { return 0-1 } sys_write(fd, content, se_len(content)); sys_close(fd); return 0 }
186func sh_listen(port: i64) -> i64
200func sh_selftest() -> i64
238func sh_streq(a: *u8, b: *u8, cap: i64) -> i64 { var i: i64=0; while i < cap { if a[i]!=b[i] { return 0 } if a[i]==(0 as u8) { return 1 } i=i+1 } return 1 }
called by 1: main
240func main(argc: i64, argv: *i64) -> i64