Conventions report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/c5297f31-6c4b-4f36-80a2-6e88daac181f.md

Conventions and duplication review of PR #548 — Add request latency histograms and process metrics

PR #548 (draft, head ebecef1, base main, 8 files +545/−20, no reviews, no CI yet, author WynnD / oystersmiles, closes #536). Lens: conventions and duplication. I read every changed file in context and followed the callers of each changed function. No blocking finding. Five should-fix findings and one nit; each is a departure from an existing in-repo precedent, cited below.

Key findings

  1. (Should fix) A third histogram implementation lands in metrics.rs with nothing migrated onto it. Buckets/Histogram (helios/src/server/metrics.rs:212-298) sits beside two hand-rolled fixed-bucket histograms in the same module, so three bucket encodings and three _count/_sum orders now coexist.
  2. (Should fix) metrics/process.rs re-implements OS helpers that already exist in runtime_core/protection.rs and eos/src/unix.rs, although eos/ is the repository-designated home for host OS operations (AGENTS.md:20-21).
  3. (Should fix) The two HTTP-observed histograms in one PR are owned by two different structs and rendered through two different paths, giving /metrics three assembly points.
  4. (Should fix) docs/api.md still claims every counter and gauge starts with flare_, contradicted by the six new process_* series documented 27 lines below.
  5. (Should fix) The request_e2e observation is duplicated inline twice in one function, in two accessor styles, against the file's own named-helper convention.
  6. (Nit) process::metric duplicates metrics::metric and does not inherit label escaping.

Should fix

1. Histogram/Buckets is the third Prometheus-histogram implementation in one module — metrics.rs:212-298

New in this PR: Buckets<const N> (metrics.rs:212-241, with REQUEST_SECONDS/TOKEN_SECONDS/PROMPT_TOKENS), Histogram<const N> (metrics.rs:245-257) with observe (metrics.rs:260-271) and render (metrics.rs:273-297).

The same module already contains two fixed-bucket histograms:

The new Histogram<21> is exactly what the host-cost site needs (same fixed bounds, per-bucket AtomicU64 counts, one sum atomic), but nothing in the PR converts either existing site. Consequences visible in the code:

Why it matters. AGENTS.md:188-193 rejects churn but asks for the smallest footprint in shared code; a second generic histogram left beside two hand-rolled ones is the form a fourth copy will take. The PR description states it and #537 "add different regions" of metrics.rs, so migrating the host-cost histograms is merge-order safe.

Fix. Express host_missing_tokens / host_transfer_ns / host_prefill_ns and host_cost_sums as Histogram<8> instances over Buckets<8>, deleting the bucket loop in host_lookup_cost (metrics.rs:672-691) and the render block at metrics.rs:1029-1065. If migration is deliberately out of scope, say so in the description so the third form is at least documented.

2. process.rs duplicates OS helpers already in eos/ and helios::os — metrics/process.rs:56, 65-77

The new helios/src/server/metrics/process.rs reads procfs and libc limits itself:

Why it matters. AGENTS.md:20-21: "The eos/ crate holds the host operating-system operations that Helios and Selene use." A new file calling libc::sysconf/libc::getrlimit//proc/self/fd directly adds a fourth copy of that layer inside Helios instead of one getter in the designated module.

Fix. Add open_file_limit() -> Option<u64> (or return the limit from the existing helper) and open_descriptors() -> Option<u64> beside raise_open_file_limit in eos/src/unix.rs, call crate::os::page_size(), and leave only the /proc/self/stat and /proc/stat btime parsing in process.rs — I searched and found no existing Rust implementation of those two, so that part is genuinely new.

3. The TTFR histogram is owned outside Metrics while its sibling is inside — latency.rs:33-37, 108-119, 122-131; server.rs:671

FirstResponseSamples gains histogram: super::metrics::Histogram<21> (latency.rs:36). FirstResponse::output records the same duration twice — into the rolling window (latency.rs:111-112) and into the histogram (latency.rs:113-116). render_histogram (latency.rs:122-131) is called from the route handler at helios/src/server.rs:671. (The double bookkeeping itself is legitimate: the 60-second median is a documented JSON field, docs/api.md:329-336.)

The asymmetry is the finding. The other HTTP-observed histogram in this same PR, request_e2e, is a Metrics field (metrics.rs:327), set through Metrics::render (metrics.rs:1391-1392) alongside every runtime request histogram (metrics.rs:1413-1423), and observed via metrics_handle() from http.rs:615/:632. With state.first_response.render_histogram at server.rs:671 and metrics::process::render at server.rs:709, /metrics text is now assembled at three points with no stated rule, and flare_time_to_first_response_seconds cannot be discovered from Metrics at all.

Fix. Pick one rule and state it: move the histogram beside request_e2e in Metrics and observe it from FirstResponse::output through a handle, or keep the ownership and note in Metrics::render's doc comment that HTTP-owned histograms are appended by the route handler.

4. docs/api.md contradicts itself about the flare_ prefix — docs/api.md:287-289 vs 315-318

docs/api.md:287-289 (unchanged by this PR) reads "GET /metrics returns Prometheus text exposition format 0.0.4 by default. Counter and gauge names start with flare_, such as …". The PR adds six series that do not, emitted at metrics/process.rs:78-127 and documented at docs/api.md:315-318. The new paragraph is accurate, but it does not reconcile the older sentence, and the surrounding paragraphs invite {__name__=~"flare_.*"} scrape filters that would silently drop all six.

The names themselves are right — they are the standard Prometheus process-collector names #536 asked for. This is a documentation consistency finding only.

Fix. One clause at docs/api.md:288-289: "Counter and gauge names start with flare_, except the standard process_* series below…".

5. The request_e2e observation is written inline twice, in two styles — http.rs:615 and http.rs:632

In one function (deliver, the streaming/non-streaming split at http.rs:600-645):

The file's own convention for shared one-liners in this region is a named helper (failure_log, rejection, rejection_details, with_request_id, http.rs:39-69), and the closure already captures stream_state/id.clone() (http.rs:384-385, :601). This is also the one new observation not behind a Metrics method — the runtime histograms go through Metrics::request_completed (metrics.rs:449-478) — so the PR's own "record in one place" argument is not extended to the e2e histogram, which now has two call sites that must track three delivery branches.

Fix. One fn observe_e2e(&self, admitted_at: Instant) on the metrics handle, called from both branches; it also removes the repeated as_nanos() as u64 and REQUEST_SECONDS.

Nit

6. process::metric duplicates metrics::metric — metrics/process.rs:42-49 vs metrics.rs:1597-1602

Both emit # HELP/# TYPE/value; the copy differs only by not applying the flare_ prefix and by taking impl Display rather than u64. The prefix difference is why it was written, but the generalisation is a parameter. Note also that the copy does not use escape_prometheus_label (metrics.rs:1604-1615): harmless today (no process_* series takes a label), but the second emitter will not inherit escaping if one is added. Fix. Keep one emitter in metrics.rs, pass the full name, delete process::metric.

Verified non-findings

Open questions / not verifiable from the code