code wiki / (root) / nx_deadline_lib.nx

nx_deadline_lib.nx

buildroot/runtime/nx_deadline_lib.nx

9164 B173 linesdepth 2pulls 2 transitivereach 4 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_deadline_lib.nx -- REQUEST DEADLINE PROPAGATION: the CONSUMER half of X-Nishi-Deadline-Mono-Ms. WHY IT EXISTS, and it is a defect I created myself on 2026-09-03. The front door now stamps `X-Nishi-Deadline-Mono-Ms: <monotonic ms>` on every buffered proxy hop -- and NOTHING READ IT. That is the estate's own law firing on its author: ★AN ENVELOPE MEASURED, PRINTED, AND THEN DROPPED AT THE NEXT HOP IS AN ENVELOPE THAT WAS NEVER PUBLISHED. A producer with no consumer is not half a feature, it is zero of one, and it reads as progress on every board. WHY IT DOES NOT PARSE HEADERS. `gw_hdr_val` is byte-identical in FIVE gateway sources (sha 9410a9c6...), so writing a sixth copy here would add a duplicate ruler to fix a duplicate ruler. This lib takes the VALUE and answers the QUESTION; each backend keeps whatever header reader it already has. ★SEPARATE THE PARSER FROM THE POLICY AND THE POLICY BECOMES ADOPTABLE BY EVERY BACKEND AT ONCE. WHY THE CLAMP IS THE WHOLE POINT -- IT COMPOSES, IT DOES NOT REPLACE. The estate already has a timeout ruler per lane (`pr_lookup_tmo` and friends), and the standing instruction for this rung is to COMPOSE it rather than add a second. So `dl_wait_ms` NEVER returns more than the caller's own `want`: it can only ever SHORTEN a wait the caller already chose. That direction is load-bearing -- ★A DEADLINE PRIMITIVE THAT CAN EXTEND A CALLER'S TIMEOUT IS A SECOND TIMEOUT RULER WEARING A DEADLINE'S CLOTHES, AND THE TWO WILL DISAGREE THE FIRST TIME EITHER IS TUNED. With that property, "honouring the deadline" is BY CONSTRUCTION for any caller that routes its wait through this function, and adoption is one call rather than a policy everyone must remember. THE CLOCK IS MONOTONIC AND PER-BOOT, WHICH IS WHY THE HEADER SAYS SO IN ITS NAME. sys_now_ms is CLOCK_MONOTONIC: comparable only within one boot of one host. That is exactly right for an edge and a backend on the SAME box and exactly wrong across machines, so the name carries the constraint where a reader cannot miss it -- a cross-host caller must not use this without a wall-clock variant. license_tier: ORIGINAL Read-only. No hw writes (Rule 26). lib (no main)

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_deadline_lib.nx nx_deadline_gate.nx nx_sites_daemon_v2.nx nx_tool_http_backend_candidate_t31

imports: nx_syscalls.nx

imported by: nx_deadline_gate.nxnx_sites_daemon_v2.nxnx_tool_http_backend_candidate_t314.nx

structs

none

consts

34const DL_HDR: *u8 = "X-Nishi-Deadline-Mono-Ms: "
36const DL_ABSENT: i64 = 0 - 1 // no parseable deadline in the value
39const DL_S_NONE: i64 = 0 // the request declared no deadline -- do NOT invent one
40const DL_S_LIVE: i64 = 1 // a deadline exists and has time left
41const DL_S_EXPIRED: i64 = 2 // a deadline exists and has passed

functions

43func dl_state_name(s: i64) -> *u8
55func dl_parse_ms(val: *u8, n: i64) -> i64
called by 2: maindl_scan_request
90func dl_keylen() -> i64
98func dl_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: dl_is_hdr_line
103func dl_is_hdr_line(buf: *u8, p: i64, n: i64) -> i64
121func dl_scan_request(buf: *u8, n: i64) -> i64
148func dl_remaining_ms(deadline_ms: i64, now_ms: i64) -> i64
called by 1: main
153func dl_state(deadline_ms: i64, now_ms: i64) -> i64
called by 2: maindl_wait_ms
165func dl_wait_ms(deadline_ms: i64, now_ms: i64, want_ms: i64) -> i64