code wiki / (root) / nx_jobcancel_lib.nx

nx_jobcancel_lib.nx

buildroot/runtime/nx_jobcancel_lib.nx

10634 B233 linesdepth 3pulls 3 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_jobcancel_lib.nx -- THE ONE cancel path for the jobs nx_job_run launched (engineshift ES29, 2026-09-15). WHY. MEASURED 2026-09-15: two cross-encoder one-shots launched through nx_job_run held the estate host at load 27 on 8 cpus for over 30 hours with 0 bytes of output, and admission correctly refused every build -- including the builds that would have replaced them. No sovereign surface could stop them: the launcher had no cancel verb, the resource governor's law forbids recycling a one-shot (never terminate what nothing will restart), and the /proc-walking diagnostics refuse to run above the very load the runaway causes. A RUNAWAY JOB THAT CANNOT BE CANCELLED IS A RESOURCE INCIDENT WITH NO REMEDY. This lib is the remedy, and it is BOUNDED BY CONSTRUCTION: * it cancels only a pid the launcher's own journal recorded for that out-file (REFUSED-ABSENT otherwise); * it signals only if /proc/<pid>/cmdline argv[0] is the elf the journal recorded (REFUSED-MISMATCH otherwise -- a recycled pid, a stranger, a daemon: never touched); * TERM first, a named grace (knowledge/jobrun.conf cancel_grace_ms, bootstrap default below), then KILL, then one more grace; every outcome is journaled beside the launch it cancels, so the record reads launch -> cancel -> outcome in one file. The journal row: <kind> TAB <epoch> TAB <pid> TAB <elf> TAB <out-file> TAB <name-or-outcome>, kind = launch | cancel. license_tier: ORIGINAL. No hw writes (Rule 26).

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_itoa_lib.nx nx_jobcancel_lib.nx nx_job_run.nx nx_jobcancel_gate.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nx_job_run.nxnx_jobcancel_gate.nx

structs

none

consts

20const JC_JRNL: *u8 = "knowledge/status/jobrun.jrnl"
21const JC_CONF: *u8 = "knowledge/jobrun.conf"
22const JC_CONF_KEY: *u8 = "cancel_grace_ms"
23const JC_GRACE_MS_DEFAULT: i64 = 3000 // bootstrap default (rule 17: env > svc-config > bootstrap > code); the conf row overrides
24const JC_POLL_MS: i64 = 100
25const JC_SIGTERM: i64 = 15
26const JC_SIGKILL: i64 = 9
27const JC_CMDLINE_CAP: i64 = 4096 // /proc/<pid>/cmdline has no size (lseek END reads 0), so ONE bounded read; only argv[0] is compared, a longer cmdline is compared on its prefix and that is announced by JC_CMDLINE_CAP in the receipt
28const JC_PATH_CAP: i64 = 128
29const JC_ROW_CAP: i64 = 2048
30const JC_MODE_644: i64 = 420
31const JC_TAB: i64 = 9
32const JC_LF: i64 = 10
33const JC_SPACE: i64 = 32
34const JC_CH_ZERO: i64 = 48
35const JC_CH_NINE: i64 = 57
36const JC_OK_TERM: i64 = 0
37const JC_OK_KILL: i64 = 1
38const JC_REFUSED_ABSENT: i64 = 2
39const JC_REFUSED_MISMATCH: i64 = 3
40const JC_ALREADY_GONE: i64 = 4
41const JC_STILL_ALIVE: i64 = 5
42const JC_F_KIND: i64 = 0
43const JC_F_EPOCH: i64 = 1
44const JC_F_PID: i64 = 2
45const JC_F_ELF: i64 = 3
46const JC_F_OUT: i64 = 4
47const JC_F_NAME: i64 = 5
48const JC_KIND_LAUNCH: *u8 = "launch"
49const JC_KIND_CANCEL: *u8 = "cancel"

functions

51func jc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
52func jc_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o + i] = s[i]; i = i + 1 } return o + i }
54func jc_eq_n(a: *u8, s: *u8, n: i64) -> i64
60func jc_streq(a: *u8, b: *u8) -> i64 { return jc_eq_n(a, b, jc_slen(b)) }
called by 1: main calls 2: jc_eq_njc_slen
61func jc_atoi_n(s: *u8, n: i64) -> i64
74func jc_field(line: *u8, n: i64, k: i64, off: *i64, len: *i64) -> i64
called by 2: g_count_rowsjc_find
90func jc_procpath(out: *u8, pid: i64, suffix: *u8) -> i64
99func jc_alive(pid: i64) -> i64
108func jc_cmdline(pid: i64, buf: *u8, cap: i64) -> i64
121func jc_verify(pid: i64, elf: *u8) -> i64
132func jc_find(jrnl: *u8, outfile: *u8, pidp: *i64, elfbuf: *u8, elfcap: i64) -> i64
165func jc_journal(jrnl: *u8, kind: *u8, epoch: i64, pid: i64, elf: *u8, outfile: *u8, tail: *u8) -> i64
180func jc_conf_grace(conf: *u8, dflt: i64) -> i64
199func jc_outcome_name(code: i64) -> *u8
called by 3: mainmainjc_cancel
208func jc_wait_gone(pid: i64, elf: *u8, grace_ms: i64, poll_ms: i64) -> i64
called by 1: jc_cancel calls 2: sys_sleep_msjc_verify
218func jc_cancel(jrnl: *u8, outfile: *u8, grace_ms: i64, poll_ms: i64, pidp: *i64) -> i64