code wiki / (root) / nx_swarm_queue.nx

nx_swarm_queue.nx

buildroot/runtime/nx_swarm_queue.nx

17507 B449 linesdepth 4pulls 6 transitivereach 4 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

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

nx_model_lane_core.nx nx_sov_ledger.nx nx_swarm_queue.nx nx_swarm_queue_gate.nx nx_swarm_tend.nx

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

main std_putln std_puts std_slen sys_write std_streq sq_release sys_now_us sys_mmap sys_clock_gettime_mono sq_mkrow std_itoa sys_mmap ↻ sq_put_state sq_pidkey std_itoa ↻ sov_put_str sov_put ss_begin ss_begin_cap ss_add ss_add2 ss_len ss_commit ss_segid_ok sys_mmap ↻ ss_cat ss_catn sys_write ↻ ss_write_seg ss_readall ss_writefile sys_renameat ss_syncdir sys_now_us ↻ sov_slen std_atoi sq_materialize sov_get_copy sys_mmap ↻

structs

none

consts

21const SQ_STORE: *u8 = "knowledge/store/swarm_sched"
22const SQ_LOCK: *u8 = "knowledge/status/swarm_sched.lock"
23const SQ_FLOOR_MB: i64 = 2048
24const SQ_MAXROW: i64 = 256
25const SQ_BACKFILL_MAX: i64 = 6000 // jobs <=6GB backfill idle capacity while a bigger job waits (data-driven default)

functions

33func sq_getpid() -> i64
called by 3: mainmainmain calls 1: sys_read
52func sq_pidkey(pid: i64, out: *u8) -> i64
called by 1: sq_put_state calls 1: std_itoa
62func sq_put_state(pid: i64, line: *u8) -> i64
71func sq_add_id(pid: i64) -> i64
111func sq_materialize(buf: *u8, cap: i64) -> i64
143func sq_ifield(buf: *u8, ls: i64, le: i64, k: i64) -> i64
163func sq_type(buf: *u8, ls: i64) -> i64
173func sq_scan(buf: *u8, n: i64, wp: *i64, wpr: *i64, we: *i64, out_nw: *i64) -> i64
223func sq_rank(wp: *i64, wpr: *i64, we: *i64, nw: i64, my_pid: i64, my_prio: i64, my_enq: i64) -> i64
called by 2: sq_try_grantmain
239func sq_should_admit(rank: i64, holders: i64, max_conc: i64, telem_ok: i64) -> i64
called by 1: main
247func sq_heavy_holders(buf: *u8, n: i64, threshold: i64) -> i64
294func sq_admit_v2(rank: i64, heavy_holders: i64, max_conc: i64, my_est: i64, backfill_max: i64, telem_ok: i64) -> i64
called by 2: sq_try_grantmain
302func sq_telem_ok(est_mb: i64) -> i64
312func sq_mkrow(ty: *u8, pid: i64, prio: i64, est: i64, us: i64, out: *u8) -> i64
328func sq_enqueue(pid: i64, prio: i64, est: i64) -> i64
337func sq_release(pid: i64) -> i64
346func sq_try_grant(pid: i64, prio: i64, est: i64, max_conc: i64, my_enq: i64) -> i64
376func sq_wait_admit(pid: i64, prio: i64, est: i64, max_conc: i64, max_wait_ms: i64, poll_ms: i64) -> i64
389func main(argc: i64, argv: *i64) -> i64