nx_replyreserve_lib.nx
buildroot/runtime/nx_replyreserve_lib.nx
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
imports: nx_loadceil_lib.nx
imported by: nx_replyreserve.nxnx_replyreserve_gate.nx
structs
| none |
consts
| 36 | const RR_LOG: *u8 = "knowledge/status/actlog.jrnl" as *u8 |
| 37 | const RR_CONF: *u8 = "knowledge/status/replyreserve.conf" as *u8 |
| 38 | const RR_WINDOW_CONF: *u8 = "knowledge/edge_window.conf" as *u8 |
| 39 | const RR_STATUS: *u8 = "knowledge/status/replyreserve.status" as *u8 |
| 40 | const RR_JRNL: *u8 = "knowledge/status/replyreserve.log" as *u8 |
| 43 | const RR_VALUE_KEY: *u8 = "reply_ms=" as *u8 |
| 44 | const RR_FILTER_KEY: *u8 = "lane=sync-promoted" as *u8 |
| 46 | const RR_WINDOW_KEY: *u8 = "edge_window_ms" as *u8 |
| 47 | const RR_RESERVE_KEY: *u8 = "reply_reserve_ms" as *u8 |
| 49 | const RR_HASH: i64 = 35 |
| 50 | const RR_DASH: i64 = 45 |
| 51 | const RR_SP: i64 = 32 |
| 54 | const RR_RATCHET: i64 = 0 |
| 55 | const RR_HOLD: i64 = 1 |
| 56 | const RR_UNREADABLE: i64 = 2 |
| 57 | const RR_INSUFFICIENT: i64 = 3 |
| 58 | const RR_REFUSED: i64 = 4 |
| 60 | const RR_O_VERDICT: i64 = 0 |
| 61 | const RR_O_N: i64 = 1 |
| 62 | const RR_O_QVAL: i64 = 2 |
| 63 | const RR_O_MAX: i64 = 3 |
| 64 | const RR_O_SCALED: i64 = 4 |
| 65 | const RR_O_DERIVED: i64 = 5 |
| 66 | const RR_O_CURRENT: i64 = 6 |
| 67 | const RR_O_WINDOW: i64 = 7 |
| 68 | const RR_O_CAPMS: i64 = 8 |
| 69 | const RR_O_FLOOR: i64 = 9 |
| 70 | const RR_O_MIN: i64 = 10 |
| 71 | const RR_O_P50: i64 = 11 |
| 72 | const RR_O_P90: i64 = 12 |
| 73 | const RR_O_P99: i64 = 13 |
| 74 | const RR_O_LINES: i64 = 14 |
| 75 | const RR_O_MISSING: i64 = 15 |
| 76 | const RR_O_CAPPED: i64 = 16 |
| 77 | const RR_O_MINN: i64 = 17 |
| 78 | const RR_O_Q: i64 = 18 |
| 79 | const RR_O_MARGIN: i64 = 19 |
| 80 | const RR_O_SLOTS: i64 = 24 |
functions
| 83 | func rr_cat(o: *u8, at: i64, s: *u8) -> i64 |
| 89 | func rr_catc(o: *u8, at: i64, c: i64) -> i64 { o[at] = c as u8; return at + 1 } |
| 90 | func rr_catn(o: *u8, at: i64, v0: i64) -> i64 |
| 102 | func rr_catn2(o: *u8, at: i64, v: i64) -> i64 |
| 109 | func rr_cline(o: *u8, at: i64, s: *u8) -> i64 |
| 119 | func rr_civil(epoch: i64, ymd: *i64) -> i64 |
| 137 | func rr_catdate(o: *u8, at: i64, epoch: i64) -> i64 |
| 152 | func rr_derive(buf: *u8, n: i64, q: i64, minn: i64, margin: i64, floor_ms: i64, max_permil: i64, |
| 197 | func rr_line_starts(b: *u8, ls: i64, le: i64, key: *u8) -> i64 |
| 211 | func rr_rewrite(inb: *u8, n: i64, o: *u8, ocap: i64, newval: i64, oldval: i64, nsamp: i64, |