nx_ws_ledger_gate.nx
buildroot/runtime/nx_ws_ledger_gate.nx
about
nx_ws_ledger_gate.nx -- the REFEREE for WMS-R2 (workstream transition ledger).
Proves the nx_ws_ledger reflog (a) survives concurrent writers with ZERO torn
entries AND ledger_replay reconstructs the correct final state, (b) FLAGS a
corrupted entry instead of silently skipping it, and (c) that the detector can
actually SEE failure (the mandatory negative control: the OLD multi-write path
tears). No-false-green: GREEN requires all lanes.
GOOD lane: NWORKERS fork concurrently; worker w writes NTRANS transitions
for ws-id=w via ledger_append (the R0 single-write primitive).
The terminal transition sets new = TERMINAL(w) deterministically.
Expect: total_lines == NWORKERS*NTRANS, flagged == 0, and
state[w] == TERMINAL(w) for every w (replay rebuilt final state).
TAMPER: a log of K good records PLUS one deliberately-broken raw record
(missing the " END" sentinel) -> ledger_replay MUST flag it
(flagged >= 1). flagged == 0 => corruption silently swallowed
=> RED.
NEG-CTRL: same concurrency as GOOD, but each transition emitted the OLD way
-- a SEQUENCE of separate sys_write() calls -> interleaving ->
torn entries. ledger_replay MUST flag > 0. flagged == 0 => the
detector is worthless => RED.
BOUND: an oversized record (rec_len+1 > cap) must be REJECTED with -2.
Output: rows -> stdout + knowledge/status/ws_ledger_gate.log, then a verdict.
Exit 0 GREEN, 1 RED. Sovereign: only nx_syscalls + nx_ws_ledger.
license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_ws_ledger.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
| 30 | const NWORKERS: i64 = 16 // concurrency (matches R0 gate) |
| 31 | const NTRANS: i64 = 300 // transitions per worker |
| 32 | const RECCAP: i64 = 256 // bounded record size |
| 33 | const MAXWS: i64 = 64 // state[] capacity (> NWORKERS) |
| 34 | const NSTATES: i64 = 5 // 0=TODO 1=WIP 2=VIEW 3=DONE 4=NOVEL |
functions
| 37 | func terminal(w: i64) -> i64 { return (w + 3) % NSTATES } |
| 40 | func gp(logfd: i64, s: *u8) -> i64 |
| 47 | func gn(logfd: i64, v: i64) -> i64 |
| 65 | func good_worker(w: i64) -> i64 |
| 80 | func bad_worker(w: i64) -> i64 |
| 134 | func spawn_all(which: i64) -> i64 |
| 156 | func main() -> i64 |