code wiki / (root) / nx_replyreserve_lib.nx

nx_replyreserve_lib.nx

buildroot/runtime/nx_replyreserve_lib.nx

12573 B285 linesdepth 3pulls 3 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_replyreserve_lib.nx -- KILL THE reply_reserve_ms MAGIC NUMBER BY MEASURING IT (lane E, 2026-08-25). Function side; the CLI is nx_replyreserve.nx and the gate composes THIS in-process on planted buffers. THE NUMBER. knowledge/edge_window.conf carries `reply_reserve_ms 1000` and says so honestly in its own prose: "1000 is INHERITED from the compiled pair (TEA_EXEC_TIMEOUT_SYNC_MS = TEA_EDGE_WINDOW_MS - 1000), not measured", and it instructs the next reader to "RATCHET this row from the measured reply_ms p99 once samples exist, and replace this paragraph with the number and the date you measured it." This organ is that instruction made mechanical. NOT A SECOND RULER. The quantile machinery is nx_loadceil_lib (lc_recommend_kv), the calibrator that already kills the build-admission load ceiling the same way. This file adds only what is specific to the reply reserve: which key, which filter, the derivation, the refusals, and the conf rewrite. THE DERIVATION, and why each step exists rather than being a number someone liked: scaled = quantile(q) * margin_permil / 1000 -- headroom for load the sample did not see. floor 1 = never below the worst reply ACTUALLY WITNESSED. A reserve smaller than a reply we have already measured is a reserve that has already failed once. floor 2 = never below replyreserve-floor-ms. Every sample so far reads 0 or 1 ms, i.e. AT OR BELOW the stamp resolution -- "0" here means "under 1 ms", not "no time". Deriving 0 from that would be an artifact of the instrument, not a measurement, and 0 makes tea_sync_promote_ms degenerate. refuse = a derived reserve <=0, >= the window, or above replyreserve-max-permil-of-window is REFUSED and the current value is KEPT. Beyond that envelope the reserve is no longer protecting the reply, it is materially shortening the inline budget -- an operator decision, not a calibrator's. This mirrors tea_sync_promote_ms, which already fails safe when the reserve swallows the window (d <= 0 -> d = w). The cost asymmetry is why the safe direction is UP: over-reserving spends R ms of a 15000 ms window; under-reserving truncates a reply mid-write, which is the defect the sync lane was rebuilt to remove. ABSTAIN LOUDLY. Below replyreserve-min-samples it returns INSUFFICIENT and changes nothing. That is the live state on the day this shipped (8 samples), and the abstention prints its own numbers -- an axis that goes quiet is indistinguishable from an axis that is fine. license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_loadceil_lib.nx nx_replyreserve_lib.nx nx_replyreserve.nx nx_replyreserve_gate.nx

imports: nx_loadceil_lib.nx

imported by: nx_replyreserve.nxnx_replyreserve_gate.nx

structs

none

consts

36const RR_LOG: *u8 = "knowledge/status/actlog.jrnl" as *u8
37const RR_CONF: *u8 = "knowledge/status/replyreserve.conf" as *u8
38const RR_WINDOW_CONF: *u8 = "knowledge/edge_window.conf" as *u8
39const RR_STATUS: *u8 = "knowledge/status/replyreserve.status" as *u8
40const RR_JRNL: *u8 = "knowledge/status/replyreserve.log" as *u8
43const RR_VALUE_KEY: *u8 = "reply_ms=" as *u8
44const RR_FILTER_KEY: *u8 = "lane=sync-promoted" as *u8
46const RR_WINDOW_KEY: *u8 = "edge_window_ms" as *u8
47const RR_RESERVE_KEY: *u8 = "reply_reserve_ms" as *u8
49const RR_HASH: i64 = 35
50const RR_DASH: i64 = 45
51const RR_SP: i64 = 32
54const RR_RATCHET: i64 = 0
55const RR_HOLD: i64 = 1
56const RR_UNREADABLE: i64 = 2
57const RR_INSUFFICIENT: i64 = 3
58const RR_REFUSED: i64 = 4
60const RR_O_VERDICT: i64 = 0
61const RR_O_N: i64 = 1
62const RR_O_QVAL: i64 = 2
63const RR_O_MAX: i64 = 3
64const RR_O_SCALED: i64 = 4
65const RR_O_DERIVED: i64 = 5
66const RR_O_CURRENT: i64 = 6
67const RR_O_WINDOW: i64 = 7
68const RR_O_CAPMS: i64 = 8
69const RR_O_FLOOR: i64 = 9
70const RR_O_MIN: i64 = 10
71const RR_O_P50: i64 = 11
72const RR_O_P90: i64 = 12
73const RR_O_P99: i64 = 13
74const RR_O_LINES: i64 = 14
75const RR_O_MISSING: i64 = 15
76const RR_O_CAPPED: i64 = 16
77const RR_O_MINN: i64 = 17
78const RR_O_Q: i64 = 18
79const RR_O_MARGIN: i64 = 19
80const RR_O_SLOTS: i64 = 24

functions

83func rr_cat(o: *u8, at: i64, s: *u8) -> i64
89func rr_catc(o: *u8, at: i64, c: i64) -> i64 { o[at] = c as u8; return at + 1 }
90func rr_catn(o: *u8, at: i64, v0: i64) -> i64
102func rr_catn2(o: *u8, at: i64, v: i64) -> i64
called by 1: rr_catdate calls 2: rr_catcrr_catn
109func rr_cline(o: *u8, at: i64, s: *u8) -> i64
called by 2: vrr_confrr_rewrite calls 2: rr_catcrr_cat
119func rr_civil(epoch: i64, ymd: *i64) -> i64
called by 2: mainrr_catdate
137func rr_catdate(o: *u8, at: i64, epoch: i64) -> i64
152func rr_derive(buf: *u8, n: i64, q: i64, minn: i64, margin: i64, floor_ms: i64, max_permil: i64,
called by 2: mainmain calls 1: lc_recommend_kv
197func rr_line_starts(b: *u8, ls: i64, le: i64, key: *u8) -> i64
called by 1: rr_rewrite calls 1: lc_slen
211func rr_rewrite(inb: *u8, n: i64, o: *u8, ocap: i64, newval: i64, oldval: i64, nsamp: i64,