nx_jobcancel_lib.nx
buildroot/runtime/nx_jobcancel_lib.nx
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
imports: nx_syscalls.nxnx_itoa_lib.nx
imported by: nx_job_run.nxnx_jobcancel_gate.nx
structs
| none |
consts
| 20 | const JC_JRNL: *u8 = "knowledge/status/jobrun.jrnl" |
| 21 | const JC_CONF: *u8 = "knowledge/jobrun.conf" |
| 22 | const JC_CONF_KEY: *u8 = "cancel_grace_ms" |
| 23 | const JC_GRACE_MS_DEFAULT: i64 = 3000 // bootstrap default (rule 17: env > svc-config > bootstrap > code); the conf row overrides |
| 24 | const JC_POLL_MS: i64 = 100 |
| 25 | const JC_SIGTERM: i64 = 15 |
| 26 | const JC_SIGKILL: i64 = 9 |
| 27 | const 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 |
| 28 | const JC_PATH_CAP: i64 = 128 |
| 29 | const JC_ROW_CAP: i64 = 2048 |
| 30 | const JC_MODE_644: i64 = 420 |
| 31 | const JC_TAB: i64 = 9 |
| 32 | const JC_LF: i64 = 10 |
| 33 | const JC_SPACE: i64 = 32 |
| 34 | const JC_CH_ZERO: i64 = 48 |
| 35 | const JC_CH_NINE: i64 = 57 |
| 36 | const JC_OK_TERM: i64 = 0 |
| 37 | const JC_OK_KILL: i64 = 1 |
| 38 | const JC_REFUSED_ABSENT: i64 = 2 |
| 39 | const JC_REFUSED_MISMATCH: i64 = 3 |
| 40 | const JC_ALREADY_GONE: i64 = 4 |
| 41 | const JC_STILL_ALIVE: i64 = 5 |
| 42 | const JC_F_KIND: i64 = 0 |
| 43 | const JC_F_EPOCH: i64 = 1 |
| 44 | const JC_F_PID: i64 = 2 |
| 45 | const JC_F_ELF: i64 = 3 |
| 46 | const JC_F_OUT: i64 = 4 |
| 47 | const JC_F_NAME: i64 = 5 |
| 48 | const JC_KIND_LAUNCH: *u8 = "launch" |
| 49 | const JC_KIND_CANCEL: *u8 = "cancel" |
functions
| 51 | func jc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 52 | func 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 } |
| 54 | func jc_eq_n(a: *u8, s: *u8, n: i64) -> i64 |
| 60 | func jc_streq(a: *u8, b: *u8) -> i64 { return jc_eq_n(a, b, jc_slen(b)) } |
| 61 | func jc_atoi_n(s: *u8, n: i64) -> i64 |
| 74 | func jc_field(line: *u8, n: i64, k: i64, off: *i64, len: *i64) -> i64 |
| 90 | func jc_procpath(out: *u8, pid: i64, suffix: *u8) -> i64 |
| 99 | func jc_alive(pid: i64) -> i64 |
| 108 | func jc_cmdline(pid: i64, buf: *u8, cap: i64) -> i64 |
| 121 | func jc_verify(pid: i64, elf: *u8) -> i64 |
| 132 | func jc_find(jrnl: *u8, outfile: *u8, pidp: *i64, elfbuf: *u8, elfcap: i64) -> i64 |
| 165 | func jc_journal(jrnl: *u8, kind: *u8, epoch: i64, pid: i64, elf: *u8, outfile: *u8, tail: *u8) -> i64 called by 3: mainmainjc_cancel calls 6: sys_openat_appendsys_mmapjc_catccz_cat_numsys_writesys_close |
| 180 | func jc_conf_grace(conf: *u8, dflt: i64) -> i64 |
| 199 | func jc_outcome_name(code: i64) -> *u8 |
| 208 | func jc_wait_gone(pid: i64, elf: *u8, grace_ms: i64, poll_ms: i64) -> i64 |
| 218 | func jc_cancel(jrnl: *u8, outfile: *u8, grace_ms: i64, poll_ms: i64, pidp: *i64) -> i64 called by 2: mainmain calls 8: sys_mmapjc_findsys_now_realtime_secjc_verifyjc_journaljc_outcome_name+2 |