code wiki / _hdl_build / nx_dispatch_lease_gate.nx

nx_dispatch_lease_gate.nx

buildroot/runtime/_hdl_build/nx_dispatch_lease_gate.nx

12862 B243 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind gate/prooftopic dispatch
docsdependenciesstructsconstsfunctions

about

nx_dispatch_lease_gate.nx -- the REFEREE for WMS rung M4 (leasing dispatcher). module: nishi-core.autonomy.dispatch_lease_gate capability: GATE (prints a VERDICT computed from REAL checks; incl negative control) PROVES (the gate requirement, exactly): T1 picks-READY -- dl_pick_ready returns the highest-w READY rung, never blocked T2 dispatch-leases -- dl_dispatch leases that rung (fd>=0, id matches, lease file exists) T3 second-dispatch-DENIED -- a 2nd dl_try_lease on the SAME stream returns -1 (the collision proof: two workers cannot hold one stream) T3b keep-moving -- a fresh dl_dispatch while the top is leased returns the NEXT ready stream (not the blocked one, not a stall) T4 NEG CONTROL -- a deliberately BLOCKED stream (unmet dep) is NEVER dispatched: dl_ready==0 AND no dispatch ever returns its id T5 release-then-redispatch -- after dl_release the same stream leases again (fd>=0): proves it is a LEASE (releasable), not a permanent mark T6 TAMPER -- (a) fa_append oversize -> -2 (durability rejects, never torn) (b) a stale lease (epoch older than DL_STALE_SEC) is STOLEN (fd>=0) -- a dead worker's lease cannot wedge the machine VALIDITY (why the neg-control genuinely bites): if dl_pick_ready ignored an_deps_done it would return G-BLOCKED -> T1/T4 RED. If dl_try_lease used plain open not O_EXCL, T3 would return fd>=0 (collision) -> RED. If dl_release didn't unlink, T5 would stay -1 -> RED. HERMETIC: the gate WRITES its own scratch queue to /tmp/dlg_<ms>.tsv (9-field rows, same grammar) and uses a fresh scratch lease dir /tmp/dlg_<ms>/ -- it NEVER touches production. <ms> = sys_now_realtime_ms() so two concurrent gate runs never share lease state. WRITE DISCIPLINE: every evidence record (one buffer -> one locked fa_appendz) to knowledge/status/dispatch_lease_gate.log -- eating our own dogfood (the torn-line floor). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_dispatch_lease.nx nx_framed_append.nx nx_dispatch_lease_gate.nx

imports: nx_dispatch_lease.nxnx_framed_append.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_p sys_now_realtime_ms sys_mmap sys_clock_gettime_real g_scratch_paths fa_cat fa_catn sys_mmap ↻ g_uniq sys_now_us sys_mmap ↻ sys_clock_gettime_mono fa_cat ↻ fa_catn ↻ sys_mkdir g_write_fixture sys_openat_wr an_newcx sys_mmap ↻ an_find an_streq an_id_at dl_pick_ready an_pick an_deps_done an_deps_at sys_mmap ↻ an_find ↻ g_assert g_p ↻ g_n g_log fa_cat ↻ fa_catn ↻ fa_appendz fa_append sys_mmap ↻ sys_openat_append sys_flock

structs

none

consts

35const GLOG: *u8 = "knowledge/status/dispatch_lease_gate.log\x00" as *u8

functions

37func g_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: g_assertmain
38func g_n(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m; sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
called by 2: g_assertmain
41func g_catd(dst: *u8, off: i64, v: i64) -> i64
calls 1: fa_catn
48func g_log(name: *u8, pass: i64, detail: i64) -> i64
called by 1: g_assert calls 3: fa_catfa_catnfa_appendz
62func g_assert(name: *u8, pass: i64, detail: i64) -> i64
called by 1: main calls 3: g_pg_ng_log
73func g_uniq() -> i64
90func g_scratch_paths(ms: i64, qpath: *u8, ldir: *u8) -> i64
called by 1: main calls 3: fa_catfa_catng_uniq
116func g_write_fixture(path: *u8) -> i64
called by 1: main calls 1: sys_openat_wr
129func g_write_stale_lease(dir: *u8, id: *u8) -> i64
called by 1: main calls 2: dl_lease_pathsys_openat_wr
139func main() -> i64