Conventions report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/94f78dda-cbdd-43a2-b39c-868eac1205a2.md

Key findings

Reviewed at head a34c4d06 (commits a34c4d06, d64c3ea3, ebecef13 on top of f377dc85), 10 files, +548/−25, draft, no reviews, no CI checks. Every changed file was read in context through the conventions-and-duplication lens, and every finding below was re-verified line by line in the code at this head.

Verdict: should-fix issues only. No blocking issue. Two should-fix findings, three nits.

The PR is largely faithful to precedent: the process collector is appended through a metrics/ submodule exactly as engram::Stats::render and render_persistent_worker_metrics already are, #[cfg(not(target_os = "linux"))] let _ = text; matches an existing pattern, the bucket constants are shared per unit, and the short SPDX header is not a new deviation. The two should-fix items are about two new abstractions presented as the module's own — one superseding two predecessors without migrating them, one splitting HTTP histogram ownership two ways in a single PR.

Two findings from the first review are fixed and are recorded, not re-raised: the docs/api.md "names start with flare_" sentence, and the duplicated inline e2e observation in http.rs.


Should fix

1. Buckets/Histogram is the third Prometheus-histogram implementation in helios/src/server/metrics.rs, and the two predecessors are left in place

New code, helios/src/server/metrics.rs:212-298: Buckets<const N> (:214-217, [f64; N] bounds ending f64::INFINITY plus a scale), the shared constants REQUEST_SECONDS/TOKEN_SECONDS/PROMPT_TOKENS (:219-241), Histogram<const N> (:245-248), one observe (:260-271, position(...).unwrap_or(N - 1)) and one render (:273-297).

Two older implementations in the same module, untouched by this PR or either follow-up commit:

The three disagree on more than internal encoding, and the disagreements are visible in a single scrape:

new Histogram::render host cost retirement
# HELP yes (:274-277) no, # TYPE only (:1049) no, # TYPE only (:851)
series order buckets → _sum (:291-295) → _count (:296) buckets → _count (:1060) → _sum (:1061-1064) buckets → +Inf (:867-870) → _count (:871) → _sum (:872-876)
bounds [f64; N] + scale [u64; 8] with u64::MAX sentinel integer ms, rendered /1000.0

Why it matters. AGENTS.md:188-193 rejects unsupported abstractions and churn while asking that refactoring "directly support the requested behavior or remove a demonstrated source of defects or cost", and docs/design-review.md:72-75 (principle 8) asks that duplicate representations be accounted for. Right now metrics.rs reads as mid-migration without being one: a reader cannot tell which of the three shapes a new histogram should take, and the generic pub(super) struct Histogram presents itself as the module's histogram abstraction while two older forms remain canonical for their series.

This is a code-shape finding, not a behaviour defect. Be precise about it: the host-cost position(...).unwrap() at :689 cannot panic because u64::MAX terminates the array; it is inconsistent, not defective. Every existing series is already pinned by tests, so a migration is behaviour-preserving and testable.

Fix (choose one, and say which in the description). Either rebuild the host-cost and retirement histograms on Histogram<8>/Buckets<8> — which deletes :200-210, the bucket loop in host_lookup_cost (:688-691), the 37-line render loop (:1029-1065), and the retirement bucket gauges plus their renderer (:375, :705-711, :851-876) — or state that the migration is deliberately deferred and scope the new type so it does not present itself as the module's histogram abstraction. The description currently names only #537 as an overlapping PR and says nothing about the two existing sites.

2. flare_time_to_first_response_seconds is owned outside Metrics while its sibling flare_request_e2e_seconds is a Metrics field

helios/src/server/latency.rs:33-37:

pub(super) struct FirstResponseSamples { window: Mutex<Samples>, histogram: super::metrics::Histogram<21> }

observed in FirstResponse::output (latency.rs:116-127) and rendered by its own forwarder render_histogram (latency.rs:101-108), which the /metrics handler calls out of band at helios/src/server.rs:671.

The sibling added by the same PR went the other way — helios/src/server/metrics.rs:327:

pub(super) request_e2e: Histogram<21>,

rendered inside Metrics::render in the loop at :1389-1412 alongside the four runtime histograms, plus time_per_output_token (:1413-1418) and request_prompt_tokens (:1419-1424).

Two consequences worth citing:

The double bookkeeping itself (60 s median window and an all-time histogram for the same instant pair, latency.rs:116-127) is accepted and documented (docs/api.md:303-307); a median cannot be reconstructed from an all-time histogram, so keeping both is defensible. The finding is the ownership and render asymmetry between two histograms of the same kind added in one PR.

Fix. Move the TTFR histogram onto Metrics, observed from FirstResponseSamples::output via the existing state.model.metrics() handle. Both HTTP histograms would then render from the :1389 loop, which also retires render_histogram, the server.rs:671 call, and the pub(super) on request_e2e. Alternatively keep the current ownership and state in Metrics::render's doc comment that HTTP-owned histograms are appended by the route — but pick one, since this PR is now setting two precedents for the same question.


Nits

3. open_descriptors() moved sideways rather than down into eos/

helios/src/runtime_core/protection.rs:290-302 still holds the /proc/self/fd counter, now pub(crate) and re-exported at helios/src/runtime_core/mod.rs:58 so helios/src/server/metrics/process.rs:68 can reach it (let open_fds = crate::runtime_core::open_descriptors();). Its two neighbours in render_linux already go through eos/: process.rs:61 crate::os::page_size() and process.rs:70 crate::os::raise_open_file_limit(0), i.e. eos/src/unix.rs:73 and :138 via helios/src/os.rs:8 (pub(crate) use flare_eos::*).

AGENTS.md:20-21 designates eos/ as "the host operating-system operations that Helios and Selene use", so having a server-metrics module import a core-protection helper is the wrong direction, and it leaves one of the three OS reads outside the designated layer. protection.rs:298-301 already carries the #[cfg(not(target_os = "linux"))] { None } shape a move needs.

Fix: move the function to eos/src/unix.rs behind the same Linux gate and call it as crate::os::open_descriptors().

4. process::metric duplicates metrics::metric

helios/src/server/metrics/process.rs:47-54:

fn metric(text: &mut String, name: &str, kind: &str, help: &str, value: impl std::fmt::Display) {
    let _ = writeln!(text, "# HELP {name} {help}\n# TYPE {name} {kind}\n{name} {value}");
}

versus helios/src/server/metrics.rs:1597-1602, which emits the identical three lines with flare_ prepended. The deltas are the prefix and impl Display vs u64 (needed — process values are f64 seconds and byte counts).

The copy also does not inherit escape_prometheus_label (metrics.rs:1604-1615). That is fine today because no process_* series carries a label, but the second emitter will silently not inherit it the day a labelled series is added (e.g. process_io_bytes_total{device=…}), while the shared one will.

Fix: give metrics::metric a Display value and a prefixed/unprefixed form, and delete process::metric.

5. Two adjacent identical guards

helios/src/server/metrics/process.rs:81-89 and :90-98 are consecutive if let Some(stat) = stat blocks emitting the two memory gauges. The separate guards at :72 (Some(stat), Some(ticks)) and :99 (Some(stat), Some(btime), Some(ticks)) are justified by extra dependencies; these two are not. Cosmetic. Fix: one block emitting both gauges.


Changes since the first review (fixed — recorded, not re-raised)


Verified non-findings (checked and dropped)


Open questions for the author

  1. Is migrating HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS and the retirement histogram onto Histogram/Buckets intended follow-up or out of scope? The description names only #537 as an overlapping PR and does not mention either existing site.
  2. Is there a maintainer preference for where HTTP-observed histograms live? No doc states one; request_e2e's placement is the only precedent, and this PR sets two.

What could not be verified here

The Windows build and the full helios suite (the description says CI covers both; the head has no CI checks yet), and the pre-existing messages_image_hints_end_after_expansion_… test, which needs FLARE_TEST_TEMPLATE_DIR. Nothing in this review depends on any of them: every finding is a code-shape question settled by reading the cited lines at a34c4d06.