code wiki / (root) / nx_watch.nx

nx_watch.nx

buildroot/runtime/nx_watch.nx

8104 B208 linesdepth 4pulls 5 transitivereach 7 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_watch.nx -- SOVEREIGN JOB / LIVENESS MONITOR (operator 2026-07-16: "our monitors are garbage -- WSL-polling Claude-Code Monitor flakes; build a STATE-OF-THE-ART Nishi monitor as MCP + RACI + API + workstream capability"). ROOT CAUSE of the flake: watching = polling WSL for "is it done" through fragile shell `until` conditions (screen-noise, exit-code weirdness, compound tests). THE SOVEREIGN FIX: a job writes ITS OWN terminal state into the sovereign store; nx_watch reports it DETERMINISTICALLY from the store -- zero polling, zero WSL dependence, works cross-session. mark <ns> <id> <state> job records its state (RUNNING at start, GREEN/RED/DONE at end) + ts beat <ns> <id> heartbeat for a long job (liveness; staleness = crash signal) status <ns> <id> print state + age_ms; EXIT CODE = verdict (0 GREEN/DONE, 1 RED, 2 RUNNING, 3 STALLED[running+stale], 4 ABSENT) -- scriptable, no grep wait <ns> <id> <max_ms> block until terminal (GREEN/RED/DONE) or timeout; sovereign sleep poll Store = seg_store via nx_sov_ledger (knowledge/store/watch_<ns>, key=id -> "STATE|us"). The staleness verdict is PURE (stored ts vs now) = gate-testable without a real clock race. RACI: supervisor|monitor (owns this). MCP: status/list = read verbs (broad-expose tier). license_tier: ORIGINAL

dependencies 2 imports · 4 importers

nx_sov_ledger.nx nx_lib_std.nx nx_watch.nx nx_claim_core.nx nx_deploy_leash.nx nx_watch_gate.nx nx_watch_read_probe.nx

imports: nx_sov_ledger.nxnx_lib_std.nx

imported by: nx_claim_core.nxnx_deploy_leash.nxnx_watch_gate.nxnx_watch_read_probe.nx

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

main std_putln std_puts std_slen sys_write std_streq nw_mark nw_prefix sys_now_us sys_mmap sys_clock_gettime_mono std_itoa sys_mmap ↻ sov_put_str sov_put ss_begin ss_begin_cap sys_mmap ↻ ss_add ss_add2 ss_w32 ss_len ss_commit ss_segid_ok sys_mmap ↻ ss_cat ss_catn sys_mmap ↻ sys_write ↻ ss_write_seg ss_segid_ok ↻ sys_mmap ↻ ss_cat ↻ ss_catn ↻ sys_write ↻ ss_segname ss_writefile sys_renameat ss_build_keys ss_build_terms

structs

none

consts

18const NW_MAGIC_2000: i64 = 2000
20const NW_STALE_MS: i64 = 120000 // a RUNNING/BEAT job silent > 2min = STALLED (data-driven default)
22const NW_GREEN: i64 = 0
23const NW_RED: i64 = 1
24const NW_RUNNING: i64 = 2
25const NW_STALLED: i64 = 3
26const NW_ABSENT: i64 = 4

functions

28func nw_prefix(ns: *u8, out: *u8) -> i64
called by 3: nw_marknw_readmain
45func nw_class(word: *u8, wl: i64) -> i64
called by 2: nw_readmain
64func nw_verdict(cls: i64, age_ms: i64, stale_ms: i64) -> i64
called by 2: nw_statusmain
75func nw_mark(ns: *u8, id: *u8, state: *u8) -> i64
91func nw_read(ns: *u8, id: *u8, wordout: *u8, ageout: *i64) -> i64
115func nw_status(ns: *u8, id: *u8) -> i64
141func nw_wait(ns: *u8, id: *u8, max_ms: i64, poll_ms: i64) -> i64
called by 1: main calls 3: nw_readsys_sleep_msnw_status
156func main(argc: i64, argv: *i64) -> i64