nx_swarm_queue.nx
buildroot/runtime/nx_swarm_queue.nx
about
nx_swarm_queue.nx -- INTELLIGENT QUEUING + COORDINATION for the swarm admission plane (operator
2026-07-16: "dont just hard deny it should be intelligent queing and coordination"). Upgrades
nx_swarm_admit's terminal DENY into a K3s/Ray-class PENDING->SCHEDULED queue: a heavy launch that
can't run NOW ENQUEUES and WAITS; the scheduler admits it the moment resources free, ordered by
PRIORITY then FIFO (no monopoly, no starvation), telemetry-gated (never oversubscribes). All
sessions coordinate through ONE SOVEREIGN STORE (seg_store q:<pid> latest-wins; sys_flock
serializes the grant transition + q:ids index) so cross-session heavy launches SEQUENCE instead
of colliding. Per-pid state (knowledge/store/swarm_sched, key q:<pid>): W|pid|prio|est|us ·
H|pid|prio|est|us · D|pid|0|0|us -- latest-wins gives latest-state-per-pid natively (no log replay).
PURE gate-core: sq_rank (waiters ahead of me) + sq_should_admit (rank+holders<cap AND telem_ok).
wait-admit <pid> <prio> <est_mb> <max_conc> <max_wait_ms> · release <pid> · status
license_tier: ORIGINAL
dependencies 2 imports · 2 importers
imports: nx_model_lane_core.nxnx_sov_ledger.nx
imported by: nx_swarm_queue_gate.nxnx_swarm_tend.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 21 | const SQ_STORE: *u8 = "knowledge/store/swarm_sched" |
| 22 | const SQ_LOCK: *u8 = "knowledge/status/swarm_sched.lock" |
| 23 | const SQ_FLOOR_MB: i64 = 2048 |
| 24 | const SQ_MAXROW: i64 = 256 |
| 25 | const SQ_BACKFILL_MAX: i64 = 6000 // jobs <=6GB backfill idle capacity while a bigger job waits (data-driven default) |
functions
| 33 | func sq_getpid() -> i64 |
| 52 | func sq_pidkey(pid: i64, out: *u8) -> i64 |
| 62 | func sq_put_state(pid: i64, line: *u8) -> i64 |
| 71 | func sq_add_id(pid: i64) -> i64 |
| 111 | func sq_materialize(buf: *u8, cap: i64) -> i64 |
| 143 | func sq_ifield(buf: *u8, ls: i64, le: i64, k: i64) -> i64 |
| 163 | func sq_type(buf: *u8, ls: i64) -> i64 |
| 173 | func sq_scan(buf: *u8, n: i64, wp: *i64, wpr: *i64, we: *i64, out_nw: *i64) -> i64 |
| 223 | func sq_rank(wp: *i64, wpr: *i64, we: *i64, nw: i64, my_pid: i64, my_prio: i64, my_enq: i64) -> i64 |
| 239 | func sq_should_admit(rank: i64, holders: i64, max_conc: i64, telem_ok: i64) -> i64 called by 1: main |
| 247 | func sq_heavy_holders(buf: *u8, n: i64, threshold: i64) -> i64 |
| 294 | func sq_admit_v2(rank: i64, heavy_holders: i64, max_conc: i64, my_est: i64, backfill_max: i64, telem_ok: i64) -> i64 |
| 302 | func sq_telem_ok(est_mb: i64) -> i64 |
| 312 | func sq_mkrow(ty: *u8, pid: i64, prio: i64, est: i64, us: i64, out: *u8) -> i64 |
| 328 | func sq_enqueue(pid: i64, prio: i64, est: i64) -> i64 |
| 337 | func sq_release(pid: i64) -> i64 |
| 346 | func sq_try_grant(pid: i64, prio: i64, est: i64, max_conc: i64, my_enq: i64) -> i64 called by 1: sq_wait_admit calls 12: sys_openat_appendsys_flocksq_materializesq_scansq_ranksq_telem_ok+6 |
| 376 | func sq_wait_admit(pid: i64, prio: i64, est: i64, max_conc: i64, max_wait_ms: i64, poll_ms: i64) -> i64 |
| 389 | func main(argc: i64, argv: *i64) -> i64 |