nx_swarm_job.nx
buildroot/runtime/nx_swarm_job.nx
about
nx_swarm_job.nx -- SWARM FABRIC job engine (SF-R3): decompose a chunky GEN job into independent
chunks and run them across opportunistic heterogeneous devices, straggler-proof + crash-safe.
The north-star compute substrate ("unified supercomputer for gen, any device") -- GREENFIELD from
OUR primitives, NOT a Ray/K3s clone.
THE DESIGN (durable-execution + speculative-execution fused, shared-nothing):
* DURABLE COMPLETION JOURNAL -- the ONLY thing that must survive a crash. A chunk is DONE iff a
"DONE <cid>" record exists (framed-append floor = flock'd, torn-write-proof). You never re-run
a completed chunk, ever.
* TRANSIENT O_EXCL LEASES -- a chunk is LEASED iff a fresh "<lockdir>/<job>.<cid>.lease" lockfile
exists (O_CREAT|O_EXCL = exactly one claimer wins, the dispatch_lease idiom). The lockfile is
stamped with a DEADLINE; a contender STEALS an expired lease (straggler / crashed holder). A
hub crash simply loses the lockfiles -> every in-flight chunk returns to PENDING = CORRECT.
* SPECULATIVE HARVEST -- whichever node completes a chunk FIRST wins; a duplicate complete of an
already-DONE chunk is IGNORED (idempotent). So a slow straggler racing its speculative re-lease
never corrupts the result and never stalls the job (ray.wait's "any finishes" -- but journaled).
COMPOSES (check-before-build 2026-07-15): the O_EXCL+stale-steal lease = the PROVEN nx_dispatch_lease
mechanism (generalized fixed DL_STALE_SEC -> per-lease deadline); the journal floor = nx_framed_append;
row/read/parse helpers = nx_swarm_lib. Placement (which node) = the SEPARATE nx_swarm_place organ,
composed by the DRIVER (rule 9 single-responsibility: this organ queues; place picks; a script wires).
submit <journal.log> <njobs> -- define the chunk universe 0..njobs-1
lease <journal.log> <lockdir> <job> <njobs> <ttl_s> -- claim the next PENDING/stale chunk (O_EXCL)
complete <journal.log> <lockdir> <job> <cid> <node> -- durable DONE (idempotent; dup -> IGNORED)
status <journal.log> <lockdir> <job> <njobs> -- done/leased/pending + COMPLETE verdict
harvest <journal.log> <lockdir> <job> <njobs> <ttl> <node> [maxiter] -- in-proc drain (sim exec)
[gate] -- self-gate, 8 tests incl liar-killers
PATH LAW: journal must pass sb_path_ok (.log); lockdir must be a bare name or under /tmp/.
license_tier: ORIGINAL expect_exit:0
dependencies 1 imports · 0 importers
imports: nx_swarm_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
| 32 | const SJ_MAGIC_1970: i64 = 1970 |
| 33 | const SJ_MAGIC_100000: i64 = 100000 |
| 35 | const SJ_OEXCL: i64 = 193 // O_CREAT|O_EXCL|O_WRONLY |
| 36 | const SJ_MODE: i64 = 420 // 0644 |
| 37 | const SJ_JBUF: i64 = 262144 |
| 38 | const SJ_REC: i64 = 256 |
functions
| 40 | func sj_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 } |
| 42 | func sj_eq(a: *u8, b: *u8) -> i64 called by 1: main |
| 50 | func sj_lockdir_ok(p: *u8) -> i64 |
| 71 | func sj_lease_path(lockdir: *u8, job: *u8, cid: i64, out: *u8) -> i64 |
| 83 | func sj_writeint_fd(fd: i64, v: i64) -> i64 |
| 96 | func sj_readint(path: *u8) -> i64 |
| 108 | func sj_unlink(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0, 0, 0, 0) } |
| 112 | func sj_lock_try(lockpath: *u8, deadline_sec: i64, now_sec: i64) -> i64 |
| 125 | func sj_lease_fresh(lockpath: *u8, now_sec: i64) -> i64 |
| 135 | func sj_derive_done(jbuf: *u8, jn: i64, njobs: i64, done: *i64) -> i64 |
| 161 | func sj_read_journal(journal: *u8, jbuf: *u8) -> i64 |
| 168 | func sj_submit(journal: *u8, njobs: i64) -> i64 |
| 180 | func sj_lease(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, ttl_sec: i64) -> i64 |
| 203 | func sj_complete(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, cid: i64, node: *u8) -> i64 called by 3: sj_harvestsj_gatemain calls 7: sj_read_journalsj_derive_donefa_catfa_catnfa_appendsj_lease_path+1 |
| 226 | func sj_status(journal: *u8, lockdir: *u8, job: *u8, njobs: i64) -> i64 |
| 262 | func sj_harvest(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, ttl_sec: i64, node: *u8, maxiter: i64) -> i64 |
| 288 | func sj_wfile_trunc(path: *u8) -> i64 called by 1: sj_gate |
| 295 | func sj_journal_count(journal: *u8, needle: *u8) -> i64 |
| 311 | func sj_gate() -> i64 |
| 410 | func main(argc: i64, argv: *i64) -> i64 |