Key findings
No blocking issues. Two should-fix convention problems, both about the same thing: this PR adds a clean new abstraction and leaves the equivalent older code beside it untouched, and it puts two sibling histograms in two different owners.
- Should fix — three histogram implementations in one module. The new generic
Buckets/Histogram(helios/src/server/metrics.rs:212-298) sits next to two hand-rolled histograms that predate it, and nothing was migrated. Apart from doubling the code, it makes the scrape text inconsistent: bucket encodings,_count/_sumorder and sum formats differ between series in the same/metricsoutput. - Should fix — split ownership of the two HTTP histograms.
flare_request_e2e_secondsis aMetricsfield rendered insideMetrics::render;flare_time_to_first_response_secondsis owned byFirstResponseSamplesinlatency.rsand appended to the text by the route handler./metricstext is now assembled in three places with no stated rule. - Nits —
open_descriptors()widened out ofruntime_core::protectionrather than moved toeos/;process::metricduplicatesmetrics::metric; two adjacent identicalif let Some(stat)blocks inrender_linux.
Verdict: should-fix issues only. Reviewed at head a34c4d06, after the author pushed d64c3ea3 and a34c4d06; three findings from the previous pass (the docs/api.md sentence, the duplicated end-to-end observation in http.rs, and the re-implemented OS helpers) are fixed and are recorded under "Changes since the last review".
Repository rules applied: AGENTS.md:20-21 ("The eos/ crate holds the host operating-system operations that Helios and Selene use") and the charter's "keep the runtime small and model-agnostic" / "what gets merged" framing (read_charter lines 12 and 35). No contributor style doc or design-review doc exists for metrics naming; the de-facto precedent is the surrounding code in metrics.rs.
Should fix
1. Buckets/Histogram is the third Prometheus-histogram implementation in helios/src/server/metrics.rs, and the two older ones are left in place
Where: new code helios/src/server/metrics.rs:212-298; precedents :200-210, :382, :670-692, :1029-1065 and :375, :851-876.
The new generic is good code — typed bounds, scale for the integer grid, a single observe/render pair, +Inf coming from f64::INFINITY rather than a sentinel:
// metrics.rs:260-271
pub(super) fn observe(&self, buckets: &Buckets<N>, value: u64) {
let exposed = value as f64 / buckets.scale;
let index = buckets.bounds.iter().position(|bound| exposed <= *bound).unwrap_or(N - 1);
self.counts[index].fetch_add(1, Ordering::Relaxed);
self.sum.fetch_add(value, Ordering::Relaxed);
}
Two older histograms in the same file still do the same job differently:
- Host lookup cost.
const HOST_TIME_BUCKETS: [u64; 8] = [100_000, ..., u64::MAX](:200-209) andHOST_TOKEN_BUCKETS = [64, ..., u64::MAX](:210), summed inhost_cost_sums: [AtomicU64; 3](:382), filled byhost_lookup_cost, whose bucket pick is an unchecked unwrap on a sentinel-terminated array:
rendered by the loop at// metrics.rs:689 let bucket = limits.iter().position(|limit| value <= *limit).unwrap();:1029-1065, which prints_bucket(:1058), then_count(:1060), then_sum(:1061-1064). - Host retirement.
host_retirement_buckets: [AtomicU64; 8](:375), filled instore(:705-711), rendered at:851-876with bounds converted from integer milliseconds taken fromflare_selene::RETIREMENT_LATENCY_MS:*ms as f64 / 1000.0(:859), followed by+Inf(:867-870),_count(:871),_sum(:872-876).
So the module now holds three bucket encodings (u64 with u64::MAX sentinel; integer ms converted at render time from a Selene constant; f64 bounds ending at infinity with a scale), three sum representations (raw integer ns/tokens; elapsed_ns as f64 / 1e9; sum as f64 / scale), and three orderings of the exposition lines (metrics.rs:1060-1064 _count first, :871-876 _count then _sum, :291-296 _sum then _count). Prometheus itself accepts any order, so this is not a correctness bug, but a reader of metrics.rs now has to learn two more idioms to touch the host-cache series, and the older two cannot be relied on: host_lookup_cost's unwrap() panics if a value ever exceeds the sentinel, which is exactly the failure the new unwrap_or(N - 1) removes.
Fix: rebuild the host-cost histograms on Histogram<8>/Buckets<8> — which deletes the render loop at :1029-1065 and the position/unwrap loop in host_lookup_cost — and express the retirement histogram's bounds as Buckets over seconds so :851-876 collapses to one render call. If migration is deliberately out of scope, say so in the PR description; right now the new abstraction reads as the intended replacement without the replacement.
What would settle it if a test were the arbiter: nothing here is test-decidable; it is a code-shape decision. The bucket boundaries and emitted series are already asserted by request_histograms_bucket_completed_request_timings and the existing host-cache metrics tests, so a migration should be behaviour-preserving.
2. flare_time_to_first_response_seconds is owned outside Metrics while its sibling flare_request_e2e_seconds is a Metrics field
Where: helios/src/server/latency.rs:33-37, :101-108, :116-127; appended at helios/src/server.rs:671. Contrast helios/src/server/metrics.rs:327 and :1389-1412.
This PR adds two histograms observed from the HTTP layer. They are stored and rendered differently:
// latency.rs:33-37
pub(super) struct FirstResponseSamples {
window: Mutex<Samples>,
histogram: super::metrics::Histogram<21>,
}
with its own renderer (:101-108), and the /metrics handler calls it out of band:
// server.rs:660-671
let mut text = state.model.metrics().render();
for (name, help, value) in [ ... ] { metrics::metric(&mut text, ...); }
if let Some(median) = first_response.median_seconds { ... }
state.first_response.render_histogram(&mut text);
The sibling histogram instead lives on Metrics and is rendered by the aggregate renderer:
// metrics.rs:327
pub(super) request_e2e: Histogram<21>,
// metrics.rs:1389-1412
for (histogram, name, help) in [(&self.request_e2e, "request_e2e_seconds", ...), (&self.request_queue, ...), ...] {
histogram.render(&mut text, name, help, &REQUEST_SECONDS);
}
Counted at head: the scrape text is assembled at Metrics::render (:1389-1424), at server.rs:661-671 (first-response gauges, median, histogram) and at server.rs:672-709 (input metrics, HTTP gauges, process metrics). A new histogram observed from the HTTP layer has no evident rule saying which of these three it belongs to — the median window is the only thing that genuinely has to live in FirstResponseSamples, and even that is a gauge pair, which metrics::metric already emits.
Fix: pick one. Either give Metrics an Arc<FirstResponseSamples>-free field pair — an Option<Mutex<...>> is not needed; the simplest is to have FirstResponseSamples::output write into a request_ttfr: Histogram<21> field on Metrics (reachable as state.model.metrics()), so both HTTP histograms render from metrics.rs:1389 and server.rs:671 goes away; or state in latency.rs why the window and its histogram must stay together. Right now a reader cannot tell where a new histogram goes without reading all three assembly sites.
Note (not a finding, but relevant): latency.rs is not a module the PR description mentions owning this history; d64c3ea3 only relocated the impl FirstResponseSamples block above struct FirstResponse (latency.rs:101-109), so ownership is unchanged since the first push.
Nits
open_descriptors()was widened and re-exported instead of moved toeos/.helios/src/runtime_core/protection.rs:290-302keeps the/proc/self/fdcounter (nowpub(crate)), andhelios/src/runtime_core/mod.rs:58re-exports it sohelios/src/server/metrics/process.rs:68can call it.AGENTS.md:20-21designateseos/as the home of the host OS operations Helios and Selene use, and this PR's own other two syscall helpers now go through it —process.rs:61crate::os::page_size()and:70crate::os::raise_open_file_limit(0), both defined ineos/src/unix.rs:73and:138. A metrics module importing a core-protection private helper is the wrong direction, andprotection.rs:298-301already shows the#[cfg(not(target_os = "linux"))] -> Noneshape the move needs. Fix: move the function toeos/src/unix.rsand call it ascrate::os::open_descriptors(), matching its two neighbours. (This is the residue of a finding thatd64c3ea3largely fixed — the localsysconf(_SC_PAGESIZE),/proc/self/fdloop andgetrlimitblocks are gone.)process::metricduplicatesmetrics::metric.helios/src/server/metrics/process.rs:47-54emits# HELP / # TYPE / valuefrom a full name, whilehelios/src/server/metrics.rs:1597-1602does the same with aflare_prefix prepended toname. The only substantive differences are the prefix and the value type (impl Displayvsu64, needed because process values are f64). Fix: givemetrics::metricanimpl Displayvalue and a full-name variant (or make the prefix a parameter) and delete the copy.- Two adjacent identical guards.
process.rs:81-89and:90-98are two consecutiveif let Some(stat) = statblocks for the two memory gauges. The separateif let (Some(stat), Some(ticks))at:72and:99are justified by their extra dependencies; these two are not. Fix: one block emitting both gauges.
Changes since the previous review (fixed, for the record)
docs/api.mdcontradicted the new series. The sentence at:288-290claimed counter and gauge names start withflare_while six new series areprocess_*; it now reads "…flare_free_kv_pages, except the standardprocess_*series described below." The new documentation at:297-321correctly distinguishes histograms from the JSON snapshot.- The end-to-end observation was written inline twice in
helios/src/server/http.rs, in two accessor styles. It is now one site,http.rs:598-605, guarded on!count && !encoder.tool_limit_reachedand placed immediately beforeyield Delivery::Complete(response), andmetrics_handle()has a single remaining caller (server.rs:511). The guard also matches the runtime's own cancelled accounting, which was the substance of the earlier objection. - OS helpers were re-implemented. The local page-size, fd-count and file-limit code in
process.rsis gone; only the/proc/self/statandbtimeparsers remain local, and no prior implementation of those exists in the tree (checkedeos/).
Verified non-findings
RequestTimesvsscheduler::RequestAccounting(policy.rs:53-65) is not duplication: the scheduler copy is reset byfinishand does not survivepark, andCheckpointAccounting::initial_prefill_nsis a prediction, not an observation.- The hoisted
prompt_tokens/generated_tokenslocals (runtime.rs:1838-1846,:1993-2001) follow the existingCarriedhoisting inpark(runtime.rs:2104,:2115-2116) — consistent with precedent, not a new pattern. - SPDX headers and the
latency.rsblock move ind64c3ea3are conventions-compliant (header present inprocess.rs; the move placesimplbefore thestructthat uses it, matching the file's other types). - The new bucket constants (
REQUEST_SECONDS,TOKEN_SECONDS,PROMPT_TOKENS,metrics.rs:219-241) are named after the unit they expose and reused across every histogram of that unit, including the TTFR histogram — that reuse is the pattern the older host-cache histograms fail to follow, which is finding 1.
Open questions
- Is migrating
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETSand the retirement histogram intended follow-up work or deliberately out of scope? The PR description does not say, and it lists #537 as the only overlapping PR, not a follow-up. - Is there a maintainer preference for where HTTP-observed histograms live (finding 2)? No doc in the tree states one; I could only infer from
request_e2e's placement. A one-line note indocs/api.mdormetrics.rswould settle it for the next contributor. - Not run/not checked here: the Windows build, the full helios suite (CI covers both), and the pre-existing
messages_image_hints_end_after_expansion_...test noted in the PR description. Nothing in this review depends on them.
Discord: oystersmiles