code wiki / (root) / nx_framed_append_gate.nx

nx_framed_append_gate.nx

buildroot/runtime/nx_framed_append_gate.nx

12238 B293 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_framed_append_gate.nx -- the REFEREE for WMS-R0 (atomic framed-append). Proves the nx_framed_append primitive defeats concurrent-appender tearing, AND proves the test can actually DETECT tearing (the mandatory negative control). GOOD lane: N workers fork concurrently, each emits NRECS records via the NEW single-write primitive fa_append(GOODPATH, ...). Expect ZERO torn lines and ALL N*NRECS lines present (nothing lost, nothing torn). BAD lane (NEGATIVE CONTROL): the SAME concurrency, but each record is emitted the OLD way -- a SEQUENCE of separate sys_write() calls per record. O_APPEND only makes ONE write atomic, not the sequence, so workers interleave -> torn lines MUST appear. bad_torn == 0 => the detector is worthless => RED (no false green). TAMPER: an oversized record (rec_len+1 > cap) must be REJECTED with -2, never silently written/torn. A line is WELL-FORMED iff it starts "FA w=" AND the bytes just before its '\n' are "END" AND it contains exactly one " END" token. Any interleaving violates one of those -> counted as torn. Output: rows -> stdout + the evidence log knowledge/status/framed_append_gate.log, then a final verdict line. Exit 0 on GREEN, 1 on RED. Sovereign: only nx_syscalls + nx_framed_append. license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_framed_append.nx nx_framed_append_gate.nx

imports: nx_syscalls.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 sys_openat_append gp sys_write gn sys_mmap sys_write ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real sys_openat_wr sys_close spawn_all sys_mmap ↻ sys_fork good_worker sys_mmap ↻ build_rec fa_cat fa_catn sys_mmap ↻ fa_append sys_mmap ↻ sys_openat_append ↻ sys_flock fa_write_all sys_write ↻ sys_close ↻ bad_worker sys_openat_append ↻ sys_mmap ↻ sys_write ↻ sys_close ↻ sys_exit sys_wait4 sys_mmap ↻ count_torn sys_mmap ↻ sys_read_file sys_openat_rd

structs

none

consts

26const NWORKERS: i64 = 16 // concurrency (raised so the neg-control tears robustly)
27const NRECS: i64 = 300 // records per worker
28const RECCAP: i64 = 256 // bounded record size for the primitive

functions

31func gp(logfd: i64, s: *u8) -> i64
called by 1: main calls 1: sys_write
38func gn(logfd: i64, v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
55func build_rec(buf: *u8, wid: i64, seq: i64, pid: i64) -> i64
called by 1: good_worker calls 2: fa_catfa_catn
68func good_worker(wid: i64) -> i64
84func bad_worker(wid: i64) -> i64
122func spawn_all(which: i64) -> i64
151func count_torn(path: *u8, outs: *i64) -> i64
called by 1: main calls 2: sys_mmapsys_read_file
220func main() -> i64