code wiki / (root) / nx_lockwatch.nx

nx_lockwatch.nx

buildroot/runtime/nx_lockwatch.nx

14685 B329 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_lockwatch.nx -- WHO HOLDS THIS PLANE'S LOCK, AND WHAT ARE THEY DOING? WHY THIS EXISTS. On 2026-08-06 a gate went RED with an UNCHANGED binary. The cause was not in the diff at all: one worker sat in kernel state D, wchan=wait_for_commit -- a filesystem journal commit -- HOLDING a plane lock, while its siblings sat in wchan=locks_lock_inode_wait. Establishing that took reading /proc/locks by hand, mapping an inode back to a lock file, then reading /proc/<pid>/wchan and /proc/<pid>/fd for every candidate. Three separate investigations that day ran the same manual procedure, and ss_plane_lock's own BUSY message now TELLS an operator to do it: "check /proc/<pid>/wchan: locks_lock_inode_wait = queued, wait_for_commit = wedged on disk" ★TELLING SOMEONE TO RUN A PROCEDURE IS NOT THE SAME AS SHIPPING IT. A diagnostic that only exists in a message is a diagnostic nobody runs at 3am. This is that procedure, as an organ. AND THE DISTINCTION IT DRAWS IS THE WHOLE POINT -- these look identical from outside and need OPPOSITE responses: QUEUED (wchan=locks_lock_inode_wait) -- healthy contention. Someone is working; wait. WEDGED (state D, wchan=wait_for_commit / io_schedule / similar) -- the holder is stuck in the kernel on I/O. Waiting will not help; the disk is the problem, and every writer behind it is now blocked for as long as that lasts. STALE -- a lock file whose recorded holder is GONE. flock releases on process death, so this should be impossible; if it ever prints, the assumption is wrong and that matters more than anything else on the report. READ-ONLY. Opens nothing but /proc and the lock files' metadata; writes nothing, locks nothing -- deliberately, because an instrument that took the lock it is diagnosing would be the defect. usage: nx_lockwatch [store-dir] default knowledge/store exit: 0 = no held plane locks, 1 = at least one held, 2 = usage/unreadable license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_lockwatch.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ lw_slurp sys_openat_rd sys_read sys_close lw_w sys_write ↻ sys_exit ↻ lw_at_flock lw_field_start lw_num_at lw_inode_of lw_num_at ↻ lw_n lw_w ↻ sys_mmap ↻ sys_write ↻ sys_openat_rd ↻ sys_getdents64 dirent_reclen dirent_name lw_ends lw_len sys_fstatat sys_close ↻

structs

none

consts

30const LW_STORE: *u8 = "knowledge/store"
31const LW_LOCKS: *u8 = "/proc/locks"
32const LW_DIRBUF: i64 = 262144
33const LW_LOCKBUF: i64 = 262144
34const LW_PATH: i64 = 512
35const LW_SMALL: i64 = 256
36const LW_STATBUF: i64 = 256
37const LW_OFF_INO: i64 = 8 // x86-64 struct stat: st_dev@0, st_ino@8 (st_size@48 is the
39const LW_MAXLOCKS: i64 = 4096
40const LW_ZERO: i64 = 48
41const LW_NINE: i64 = 57
42const LW_NL: i64 = 10
43const LW_COLON: i64 = 58
44const LW_SP: i64 = 32
45const LW_B10: i64 = 10
46const LW_EXIT_CLEAR: i64 = 0
47const LW_EXIT_HELD: i64 = 1
48const LW_EXIT_USAGE: i64 = 2

functions

50func lw_w(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 2: lw_nmain calls 1: sys_write
51func lw_n(v: i64) -> i64
called by 1: main calls 3: lw_wsys_mmapsys_write
61func lw_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: lw_ends
65func lw_slurp(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
83func lw_ends(nm: *u8, suf: *u8) -> i64
called by 1: main calls 1: lw_len
93func lw_num_at(buf: *u8, i: i64, n: i64) -> i64
called by 2: lw_inode_ofmain
113func lw_field_start(b: *u8, p: i64, stop: i64, idx: i64) -> i64
called by 1: main
135func lw_inode_of(b: *u8, fstart: i64, stop: i64) -> i64
called by 1: main calls 1: lw_num_at
151func lw_at_flock(b: *u8, i: i64) -> i64
called by 1: main
160func main(argc: i64, argv: *i64) -> i64