nx_swarm_job_evidence_t67.nx
buildroot/runtime/nx_swarm_job_evidence_t67.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 2 imports · 1 importers
imports: nx_swarm_lib.nxnx_readcap_lib.nx
imported by: nx_swarm_journal_evidence_gate_t67.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 33 | const SJ_EVIDENCE_IO:i64=0-20 |
| 34 | const SJ_EVIDENCE_TRUNCATED:i64=0-21 |
| 35 | const SJ_EVIDENCE_FRAME:i64=0-22 |
| 36 | const SJ_EVIDENCE_RECORD:i64=0-23 |
| 37 | const SJ_DECIMAL_MAX:i64=9223372036854775807 |
| 38 | const SJ_MAGIC_1970: i64 = 1970 |
| 39 | const SJ_MAGIC_100000: i64 = 100000 |
| 41 | const SJ_OEXCL: i64 = 193 // O_CREAT|O_EXCL|O_WRONLY |
| 42 | const SJ_MODE: i64 = 420 // 0644 |
| 43 | const SJ_JBUF: i64 = 262144 |
| 44 | const SJ_REC: i64 = 256 |
functions
| 46 | func sj_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 } |
| 48 | func sj_eq(a: *u8, b: *u8) -> i64 called by 1: main |
| 56 | func sj_lockdir_ok(p: *u8) -> i64 called by 1: main |
| 77 | func sj_lease_path(lockdir: *u8, job: *u8, cid: i64, out: *u8) -> i64 |
| 89 | func sj_writeint_fd(fd: i64, v: i64) -> i64 |
| 102 | func sj_readint(path: *u8) -> i64 |
| 114 | func sj_unlink(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0, 0, 0, 0) } |
| 118 | func sj_lock_try(lockpath: *u8, deadline_sec: i64, now_sec: i64) -> i64 |
| 131 | func sj_lease_fresh(lockpath: *u8, now_sec: i64) -> i64 |
| 141 | func sj_done_record(buf:*u8,start:i64,end:i64)->i64 called by 1: sj_derive_done |
| 159 | func sj_derive_done(jbuf:*u8,jn:i64,njobs:i64,done:*i64)->i64 |
| 175 | func sj_evidence_refused(code:i64)->i64 |
| 179 | func sj_read_journal(journal:*u8,jbuf:*u8)->i64 called by 6: sj_leasesj_completesj_statussj_journal_countsj_gatemain calls 2: rc_fill_filerc_complete |
| 191 | func sj_submit(journal: *u8, njobs: i64) -> i64 |
| 203 | func sj_lease(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, ttl_sec: i64) -> i64 |
| 228 | func sj_complete(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, cid: i64, node: *u8) -> i64 called by 4: sj_harvestsj_gatemainmain calls 8: sj_read_journalsj_evidence_refusedsj_derive_donefa_catfa_catnfa_append+2 |
| 253 | func sj_status(journal: *u8, lockdir: *u8, job: *u8, njobs: i64) -> i64 |
| 291 | func sj_harvest(journal: *u8, lockdir: *u8, job: *u8, njobs: i64, ttl_sec: i64, node: *u8, maxiter: i64) -> i64 |
| 317 | func sj_wfile_trunc(path: *u8) -> i64 called by 1: sj_gate |
| 324 | func sj_journal_count(journal: *u8, needle: *u8) -> i64 |
| 340 | func sj_gate() -> i64 |
| 439 | func main(argc: i64, argv: *i64) -> i64 |