nx_loadceil_lib.nx
buildroot/runtime/nx_loadceil_lib.nx
about
nx_loadceil_lib.nx -- DERIVE THE BUILD-ADMISSION LOAD CEILING FROM THE BOX'S OWN HEALTHY-BEAT HISTORY,
function side (LV3, loadgov.plan, 2026-08-24). Split from the CLI so nx_loadceil_gate composes it in-process.
Removes a real magic number: the ceiling sits DISABLED at an unreachable max_centiload (mgmt 100000,
runner 1000000) because, until nx_resmon began logging load1_centi on every beat, there was no history to
calibrate it from. That history is now live (resmon.log carries load1_centi= and state= per row), so the
ceiling can be a MEASURED quantile of the loads at which the box was actually GREEN.
THE ARITHMETIC THIS COUPLES TO, READ FROM ba_verdict: a build QUEUEs when load1 > max_centiload *
BA_HARD_FACTOR (=2). So the STORM TRIGGER is 2*max_centiload; this derives the trigger from a high quantile
of GREEN load and reports max_centiload = trigger / BA_HARD_FACTOR. Every ba_verdict failure is a QUEUE
(defer), never a hard DENY -- so a mis-calibration defers builds, it cannot brick the lane; the safe
direction is UP and this derives a HIGH quantile with the whole distribution returned for audit.
NO MAGIC: quantile level and minimum sample are conf rows; LC_HARD_FACTOR is mirrored from the coupled
organ and NAMED (the gate asserts recommend*factor == trigger). Below the minimum GREEN sample it REFUSES
rather than arm from too little history -- the permanently-red-detector failure the plan's risk row names.
GENERALISED 2026-08-25 (lane E). The shape here -- parse a line-oriented log, take a per-line key= integer,
filter by a per-line marker, sort, nearest-rank quantile, abstain below a sample floor -- is not specific
to load. It is now parameterised (lc_collect_kv / lc_recommend_kv) so a SECOND magic number is killed by
the SAME calibrator instead of a second ruler: nx_replyreserve derives edge_window.conf reply_reserve_ms
from reply_ms= on lane=sync-promoted actlog rows. lc_collect / lc_recommend / lc_line_green are now thin
delegates passing the original literals, so the load-ceiling path is unchanged BY CONSTRUCTION rather than
by assertion.
Three additions the second caller forced, each a defect the first caller never hit:
lc_conf_line_num -- LINE-ANCHORED conf lookup mirroring nx_tool_exec_allow.tea_conf_int, the contract
that actually owns knowledge/edge_window.conf. The whole-buffer lc_conf_num is WRONG there: the keys
edge_window_ms and reply_reserve_ms both occur inside that file PROSE above their rows, so a
first-occurrence scan reads the comment, finds no digits, and silently returns the default.
lc_read_tail -- a journal is APPEND-ONLY, so a head read samples its PAST. Measured 2026-08-25: every
reply_ms= row sat in the last 25 KB of a 30 MB actlog, and a 4 MB read from offset 0 finds ZERO of
them -- an abstention for the wrong reason, from an organ that could then never arm itself.
lc_first_int -- first integer ANYWHERE after a key on its line, for space-separated conf rows.
license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_loadceil.nxnx_loadceil_gate.nxnx_replyreserve_lib.nx
structs
| none |
consts
| 39 | const LC_LOGCAP: i64 = 4194304 |
| 40 | const LC_MAXBEATS: i64 = 65536 |
| 41 | const LC_CONFCAP: i64 = 8192 |
| 42 | const LC_NL: i64 = 10 |
| 43 | const LC_ZERO: i64 = 48 |
| 44 | const LC_NINE: i64 = 57 |
| 46 | const LC_HARD_FACTOR: i64 = 2 |
| 47 | const LC_SEEK_SET: i64 = 0 |
| 48 | const LC_SEEK_END: i64 = 2 |
| 51 | const LC_RECOMMENDED: i64 = 0 |
| 52 | const LC_UNREADABLE: i64 = 2 |
| 53 | const LC_INSUFFICIENT: i64 = 3 |
| 56 | const LC_O_VERDICT: i64 = 0 |
| 57 | const LC_O_GREEN: i64 = 1 |
| 58 | const LC_O_TOTAL: i64 = 2 |
| 59 | const LC_O_MISSING: i64 = 3 |
| 60 | const LC_O_CAPPED: i64 = 4 |
| 61 | const LC_O_MIN: i64 = 5 |
| 62 | const LC_O_P50: i64 = 6 |
| 63 | const LC_O_P90: i64 = 7 |
| 64 | const LC_O_P99: i64 = 8 |
| 65 | const LC_O_MAX: i64 = 9 |
| 66 | const LC_O_TRIGGER: i64 = 10 |
| 67 | const LC_O_REC: i64 = 11 |
| 68 | const LC_O_Q: i64 = 12 |
| 69 | const LC_O_MINN: i64 = 13 |
| 70 | const LC_O_N: i64 = 16 |
| 73 | const LC_M_SIZE: i64 = 0 |
| 74 | const LC_M_WHOLE: i64 = 1 |
| 75 | const LC_M_BYTES: i64 = 2 |
| 76 | const LC_M_N: i64 = 4 |
functions
| 78 | func lc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 79 | func lc_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 90 | func lc_read_tail(path: *u8, buf: *u8, cap: i64, meta: *i64) -> i64 |
| 130 | func lc_line_num(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64 |
| 159 | func lc_first_int(buf: *u8, lo: i64, hi: i64) -> i64 called by 1: lc_conf_line_num |
| 183 | func lc_line_has(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64 |
| 200 | func lc_line_green(buf: *u8, lo: i64, hi: i64) -> i64 calls 1: lc_line_has |
| 203 | func lc_conf_num(cb: *u8, cn: i64, key: *u8, dflt: i64) -> i64 |
| 211 | func lc_conf_line_num(cb: *u8, cn: i64, key: *u8, dflt: i64) -> i64 |
| 261 | func lc_sift(a: *i64, root: i64, n: i64) -> i64 called by 1: lc_sort |
| 277 | func lc_sort(a: *i64, n: i64) -> i64 |
| 290 | func lc_quant(a: *i64, n: i64, q_permil: i64) -> i64 called by 1: lc_recommend_kv |
| 299 | func lc_collect_kv(buf: *u8, n: i64, vals: *i64, cap: i64, counts: *i64, value_key: *u8, filter_key: *u8) -> i64 |
| 331 | func lc_collect(buf: *u8, n: i64, greens: *i64, cap: i64, counts: *i64) -> i64 calls 1: lc_collect_kv |
| 338 | func lc_recommend_kv(buf: *u8, n: i64, q: i64, minn: i64, value_key: *u8, filter_key: *u8, out: *i64) -> i64 |
| 368 | func lc_recommend(buf: *u8, n: i64, q: i64, minn: i64, out: *i64) -> i64 |