nx_swarmadmit_tool_register.nx source
↩ module page · 24 lines · 2322 B
1// nx_swarmadmit_tool_register.nx -- register nx_swarm_admit (the general admission capability) into the
2// discovery registry -> mcp__nishi__nx_swarm_admit stub, so EVERY session/agent (including concurrent
3// siblings) can route heavy launches through admission instead of colliding on the host. Idempotent;
4// verifies by READBACK. expect_exit: 0 license_tier: ORIGINAL
5import "nx_tool_registry.nx"
6
7func sr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
8
9func main() -> i64 {
10 sr_puts("=== nx_swarmadmit_tool_register -- admission capability into the discovery registry ===\n" as *u8)
11 let w: i64 = tool_register("nx_swarm_admit" as *u8,
12 "General ecosystem ADMISSION capability (the swarm as cluster scheduler): call BEFORE any heavy launch (model decode, codec run, image-gen, training, big build) and obey the verdict, so the host never hits an oversubscription collision between uncoordinated workloads. VERB: admit <workstream> <kind> <est_mb> <held> <max_conc> -> one line 'SWARM-ADMIT ws=.. load1=../ncpu=.. avail_mb=.. -> GRANT|QUEUE|DENY-LOAD|DENY-RAM' computed from LIVE host telemetry (loadavg + MemAvailable): DENY-LOAD if load1>=ncpu; DENY-RAM if avail < est+floor; QUEUE if held>=max_conc; else GRANT. Pure verdict -- it never kills anything; the CALLER defers/queues. Proven in production: refused a real 1.5B forge claim while a sibling saturated the box." as *u8,
13 "over /mcp: tools/call name=nx_swarm_admit arguments={argv:[\"admit\",\"<workstream>\",\"<kind>\",\"<est_mb>\",\"<held>\",\"<max_conc>\"]}. e.g. {argv:[\"admit\",\"forge\",\"decode-1.5b\",\"11000\",\"0\",\"1\"]}. exit 0; verdict is in the output line." as *u8,
14 "GREEN (nx_swarm_admit_gate 3/3: DENY-LOAD at load>=ncpu, DENY-RAM at avail<est+floor, live-telemetry no-false-DENY; production DENY-RAM proven vs a real saturating sibling)" as *u8)
15 let p: *i64 = sys_mmap(8) as *i64
16 let l: *i64 = sys_mmap(8) as *i64
17 let g: i64 = tool_get("nx_swarm_admit" as *u8, p, l)
18 if w == 0 { if g == 1 { if l[0] > 0 {
19 sr_puts("verdict=GREEN (nx_swarm_admit discoverable -> mcp__nishi__nx_swarm_admit stub)\n" as *u8)
20 sys_exit(0); return 0
21 } } }
22 sr_puts("REGISTER FAILED\nverdict=RED\n" as *u8)
23 sys_exit(1); return 1
24}