nx_lockwatch.nx
buildroot/runtime/nx_lockwatch.nx
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
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
structs
| none |
consts
| 30 | const LW_STORE: *u8 = "knowledge/store" |
| 31 | const LW_LOCKS: *u8 = "/proc/locks" |
| 32 | const LW_DIRBUF: i64 = 262144 |
| 33 | const LW_LOCKBUF: i64 = 262144 |
| 34 | const LW_PATH: i64 = 512 |
| 35 | const LW_SMALL: i64 = 256 |
| 36 | const LW_STATBUF: i64 = 256 |
| 37 | const LW_OFF_INO: i64 = 8 // x86-64 struct stat: st_dev@0, st_ino@8 (st_size@48 is the |
| 39 | const LW_MAXLOCKS: i64 = 4096 |
| 40 | const LW_ZERO: i64 = 48 |
| 41 | const LW_NINE: i64 = 57 |
| 42 | const LW_NL: i64 = 10 |
| 43 | const LW_COLON: i64 = 58 |
| 44 | const LW_SP: i64 = 32 |
| 45 | const LW_B10: i64 = 10 |
| 46 | const LW_EXIT_CLEAR: i64 = 0 |
| 47 | const LW_EXIT_HELD: i64 = 1 |
| 48 | const LW_EXIT_USAGE: i64 = 2 |
functions
| 50 | func 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 } |
| 51 | func lw_n(v: i64) -> i64 |
| 61 | func 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 |
| 65 | func lw_slurp(path: *u8, buf: *u8, cap: i64) -> i64 |
| 83 | func lw_ends(nm: *u8, suf: *u8) -> i64 |
| 93 | func lw_num_at(buf: *u8, i: i64, n: i64) -> i64 |
| 113 | func lw_field_start(b: *u8, p: i64, stop: i64, idx: i64) -> i64 called by 1: main |
| 135 | func lw_inode_of(b: *u8, fstart: i64, stop: i64) -> i64 |
| 151 | func lw_at_flock(b: *u8, i: i64) -> i64 called by 1: main |
| 160 | func main(argc: i64, argv: *i64) -> i64 |