Conventions report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/4582d6db-19d3-4f86-9ac5-0c285471998b.md

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.

  1. 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/_sum order and sum formats differ between series in the same /metrics output.
  2. Should fix — split ownership of the two HTTP histograms. flare_request_e2e_seconds is a Metrics field rendered inside Metrics::render; flare_time_to_first_response_seconds is owned by FirstResponseSamples in latency.rs and appended to the text by the route handler. /metrics text is now assembled in three places with no stated rule.
  3. Nits — open_descriptors() widened out of runtime_core::protection rather than moved to eos/; process::metric duplicates metrics::metric; two adjacent identical if let Some(stat) blocks in render_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:

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


Changes since the previous review (fixed, for the record)

Verified non-findings

Open questions

Discord: oystersmiles