code wiki / _hdl_build / nx_swapguard_beat.nx

nx_swapguard_beat.nx

buildroot/runtime/_hdl_build/nx_swapguard_beat.nx

6770 B130 linesdepth 3pulls 5 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_sovjson_lib.nx nx_syscalls.nx nx_tool_run.nx nx_gate_verdict.nx nx_swapguard_beat.nx

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

main sj_lit_eq sj_vlen sg_selftest gv_ctr sys_mmap gv_head gv_puts sys_write gv_bite gv_puts ↻ sg_breach gv_verdict gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap gv_journal sys_openat_append sys_mmap ↻ gv_catn sys_mmap ↻ sys_munmap ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real gv_cat sys_write ↻ sys_close sys_munmap ↻ sys_exit sj_atoi_z sg_swapfree sys_mmap ↻ sys_openat_rd sys_read sys_close ↻ sj_vlen ↻ sys_now_realtime_sec ↻

structs

none

consts

21const SG_FLOOR_KB: i64 = 2097152
22const SG_MODE: i64 = 420
23const SG_BUF: i64 = 8192
24const SG_HEALTHY_WITNESS_KB: i64 = 20000000 // ~19GiB: a comfortably-above-floor value for the gate's good-polarity witness

functions

26func 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 }
called by 1: main calls 1: sys_write
27func sg_append(path: *u8, buf: *u8, n: i64) -> i64
36func sg_swapfree() -> i64
73func sg_breach(sf: i64, floor: i64) -> i64
called by 2: sg_selftestmain
78func sg_selftest() -> i64
88func main(argc: i64, argv: *i64) -> i64