code wiki / _hdl_build / nx_dispatch_lease_gate.nx
nx_dispatch_lease_gate.nx
buildroot/runtime/_hdl_build/nx_dispatch_lease_gate.nx
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
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
structs
| none |
consts
| 35 | const GLOG: *u8 = "knowledge/status/dispatch_lease_gate.log\x00" as *u8 |
functions
| 37 | func 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 } |
| 38 | func 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 } |
| 41 | func g_catd(dst: *u8, off: i64, v: i64) -> i64 calls 1: fa_catn |
| 48 | func g_log(name: *u8, pass: i64, detail: i64) -> i64 |
| 62 | func g_assert(name: *u8, pass: i64, detail: i64) -> i64 |
| 73 | func g_uniq() -> i64 |
| 90 | func g_scratch_paths(ms: i64, qpath: *u8, ldir: *u8) -> i64 |
| 116 | func g_write_fixture(path: *u8) -> i64 |
| 129 | func g_write_stale_lease(dir: *u8, id: *u8) -> i64 |
| 139 | func main() -> i64 |