code wiki / _hdl_build / nx_swapguard_beat.nx
nx_swapguard_beat.nx
buildroot/runtime/_hdl_build/nx_swapguard_beat.nx
about
nx_swapguard_beat.nx -- SWAP-EXHAUSTION TRIPWIRE (2026-07-29, seq1256 lineage). Today's mgmt_api
and tools_api wedges were both preceded by HOURS of exhausted swap (12-196kB free) with no alarm
anywhere -- long-running seg-store consumers leak into swap (seq905/947 class) and then park in
uninterruptible sleep. This beat reads /proc/meminfo SwapFree every scheduler cycle and, on breach,
(a) appends an evidence line and (b) files a sev8 debt row THROUGH nx_debt whose desc is CONSTANT --
nx_debt add is content-idempotent (banked law 07-20), so hourly re-alarms dedupe to ONE standing row
and the board (which gates nx_ws_cycle work-emission) becomes the alarm surface. ALARM-ONLY by
design: auto-recycle needs the sanctioned restart paths (seq1256) and graduates only after this
tripwire proves calibrated.
scheduler contract: jobs.tsv fork+execs with NO args. argv[1]=floor_kb override (testing).
floor default 2097152 kB = 2GiB, DERIVED: swap total ~24GiB; every observed wedge sat at <200kB
for hours, fresh-boot free is >20GiB -- 2GiB (~8%) alarms early while never false-firing on a
healthy host (rule-11: promote to conf when field-tuned).
trend line: <epoch>\tSwapFree=<kb>\t<OK|ALARM>\n -> knowledge/status/swapguard_trend.jsonl
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 healthy, 1 alarm
dependencies 4 imports · 0 importers
imports: nx_sovjson_lib.nxnx_syscalls.nxnx_tool_run.nxnx_gate_verdict.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
| 21 | const SG_FLOOR_KB: i64 = 2097152 |
| 22 | const SG_MODE: i64 = 420 |
| 23 | const SG_BUF: i64 = 8192 |
| 24 | const SG_HEALTHY_WITNESS_KB: i64 = 20000000 // ~19GiB: a comfortably-above-floor value for the gate's good-polarity witness |
functions
| 26 | func sg_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 27 | func sg_append(path: *u8, buf: *u8, n: i64) -> i64 |
| 36 | func sg_swapfree() -> i64 |
| 73 | func sg_breach(sf: i64, floor: i64) -> i64 |
| 78 | func sg_selftest() -> i64 |
| 88 | func main(argc: i64, argv: *i64) -> i64 |