nx_swarm_heal.nx
buildroot/runtime/nx_swarm_heal.nx
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
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
structs
| none |
consts
| 25 | const SH_MAGIC_2048: i64 = 2048 |
| 26 | const SH_MAGIC_2000: i64 = 2000 |
| 27 | const SH_MAGIC_39271: i64 = 39271 |
| 28 | const SH_MAGIC_39272: i64 = 39272 |
| 30 | const SH_CONF: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/swarm_nodes.conf" |
| 31 | const SH_CAP: i64 = 65536 |
| 32 | const SH_MODE_644: i64 = 420 |
functions
| 34 | func sh_p(s: *u8) -> i64 { sys_write(1, s, se_len(s)); return 0 } |
| 35 | func 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 } |
| 40 | func go_probe_up(ha: i64, hb: i64, hc: i64, hd: i64, port: i64) -> i64 { return np_probe_up(ha, hb, hc, hd, port) } |
| 43 | func sh_parse_addr(s: *u8, n: i64, oct: *i64) -> i64 |
| 68 | func sh_addr_span(buf: *u8, n: i64, role: *u8, box: *i64) -> i64 |
| 89 | func sh_rewrite(conf: *u8, buf: *u8, n: i64, off: i64, len: i64, new_addr: *u8) -> i64 |
| 114 | func sh_probe_role(role: *u8) -> i64 |
| 124 | func sh_scan_candidates(path: *u8, winner: *u8) -> i64 |
| 158 | func sh_heal(role: *u8, candpath: *u8, conf: *u8, apply: i64) -> i64 |
| 184 | func 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 } |
| 186 | func sh_listen(port: i64) -> i64 |
| 200 | func sh_selftest() -> i64 |
| 238 | func 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 |
| 240 | func main(argc: i64, argv: *i64) -> i64 |