nx_watch.nx
buildroot/runtime/nx_watch.nx
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
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
structs
| none |
consts
| 18 | const NW_MAGIC_2000: i64 = 2000 |
| 20 | const NW_STALE_MS: i64 = 120000 // a RUNNING/BEAT job silent > 2min = STALLED (data-driven default) |
| 22 | const NW_GREEN: i64 = 0 |
| 23 | const NW_RED: i64 = 1 |
| 24 | const NW_RUNNING: i64 = 2 |
| 25 | const NW_STALLED: i64 = 3 |
| 26 | const NW_ABSENT: i64 = 4 |
functions
| 28 | func nw_prefix(ns: *u8, out: *u8) -> i64 |
| 45 | func nw_class(word: *u8, wl: i64) -> i64 |
| 64 | func nw_verdict(cls: i64, age_ms: i64, stale_ms: i64) -> i64 |
| 75 | func nw_mark(ns: *u8, id: *u8, state: *u8) -> i64 called by 8: cc_registercc_beatcc_releasedl_registerdl_walkmain+2 calls 4: nw_prefixsys_now_usstd_itoasov_put_str |
| 91 | func nw_read(ns: *u8, id: *u8, wordout: *u8, ageout: *i64) -> i64 called by 6: cc_checkcc_walkdl_walknw_statusnw_waitmain calls 4: nw_prefixsov_get_copysys_now_usnw_class |
| 115 | func nw_status(ns: *u8, id: *u8) -> i64 |
| 141 | func nw_wait(ns: *u8, id: *u8, max_ms: i64, poll_ms: i64) -> i64 |
| 156 | func main(argc: i64, argv: *i64) -> i64 |