code wiki / (root) / nx_loadceil_lib.nx

nx_loadceil_lib.nx

buildroot/runtime/nx_loadceil_lib.nx

16511 B370 linesdepth 2pulls 2 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_loadceil_lib.nx nx_loadceil.nx nx_loadceil_gate.nx nx_replyreserve_lib.nx

imports: nx_syscalls.nx

imported by: nx_loadceil.nxnx_loadceil_gate.nxnx_replyreserve_lib.nx

structs

none

consts

39const LC_LOGCAP: i64 = 4194304
40const LC_MAXBEATS: i64 = 65536
41const LC_CONFCAP: i64 = 8192
42const LC_NL: i64 = 10
43const LC_ZERO: i64 = 48
44const LC_NINE: i64 = 57
46const LC_HARD_FACTOR: i64 = 2
47const LC_SEEK_SET: i64 = 0
48const LC_SEEK_END: i64 = 2
51const LC_RECOMMENDED: i64 = 0
52const LC_UNREADABLE: i64 = 2
53const LC_INSUFFICIENT: i64 = 3
56const LC_O_VERDICT: i64 = 0
57const LC_O_GREEN: i64 = 1
58const LC_O_TOTAL: i64 = 2
59const LC_O_MISSING: i64 = 3
60const LC_O_CAPPED: i64 = 4
61const LC_O_MIN: i64 = 5
62const LC_O_P50: i64 = 6
63const LC_O_P90: i64 = 7
64const LC_O_P99: i64 = 8
65const LC_O_MAX: i64 = 9
66const LC_O_TRIGGER: i64 = 10
67const LC_O_REC: i64 = 11
68const LC_O_Q: i64 = 12
69const LC_O_MINN: i64 = 13
70const LC_O_N: i64 = 16
73const LC_M_SIZE: i64 = 0
74const LC_M_WHOLE: i64 = 1
75const LC_M_BYTES: i64 = 2
76const LC_M_N: i64 = 4

functions

78func lc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
79func lc_read(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
90func lc_read_tail(path: *u8, buf: *u8, cap: i64, meta: *i64) -> i64
130func lc_line_num(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64
called by 2: lc_conf_numlc_collect_kv calls 1: lc_slen
159func lc_first_int(buf: *u8, lo: i64, hi: i64) -> i64
called by 1: lc_conf_line_num
183func lc_line_has(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64
200func lc_line_green(buf: *u8, lo: i64, hi: i64) -> i64
calls 1: lc_line_has
203func lc_conf_num(cb: *u8, cn: i64, key: *u8, dflt: i64) -> i64
called by 2: mainmain calls 1: lc_line_num
211func lc_conf_line_num(cb: *u8, cn: i64, key: *u8, dflt: i64) -> i64
called by 2: mainmain calls 2: lc_slenlc_first_int
261func lc_sift(a: *i64, root: i64, n: i64) -> i64
called by 1: lc_sort
277func lc_sort(a: *i64, n: i64) -> i64
called by 2: mainlc_recommend_kv calls 1: lc_sift
290func lc_quant(a: *i64, n: i64, q_permil: i64) -> i64
called by 1: lc_recommend_kv
299func lc_collect_kv(buf: *u8, n: i64, vals: *i64, cap: i64, counts: *i64, value_key: *u8, filter_key: *u8) -> i64
331func lc_collect(buf: *u8, n: i64, greens: *i64, cap: i64, counts: *i64) -> i64
calls 1: lc_collect_kv
338func lc_recommend_kv(buf: *u8, n: i64, q: i64, minn: i64, value_key: *u8, filter_key: *u8, out: *i64) -> i64
368func lc_recommend(buf: *u8, n: i64, q: i64, minn: i64, out: *i64) -> i64
called by 2: mainmain calls 1: lc_recommend_kv