Simplicity report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/0658f56a-9a7c-44ed-8e18-852a1782e9e0.md

Simplicity review (lens D) — PR #548 "Add per-request histograms and vLLM-parity request metrics"

Reviewed at head 055663a7 (9 files, +1016/−51, base main). All nine changed files were read in context, each changed function read with its callers followed. This supersedes my earlier reports on the same PR at heads ebecef1, d64c3ea3 and a34c4d06; the six commits since a34c4d06 (54e06b30, 10c0b937, 01f1e92b, 15018689, 49373bc5, 055663a7) deleted helios/src/server/metrics/process.rs (not opened) and all its findings, so nothing about process_* appears below.

Governing rules I judged against:

Key findings

Nothing in this lens blocks. The change asks for no new abstractions beyond fixed-bucket histograms, and its central structural claim survives scrutiny in code: Metrics::request_completed (helios/src/server/metrics.rs:545-603) is still the sole increment of flare_requests_completed_total and the sole observation site for the per-request histograms, so counter and distributions cannot diverge; cancelled and failed requests observe nothing; RequestRecord really does survive park/readmit (helios/src/server/runtime.rs:1565-1570 sets max_tokens only on first admission). What is left is duplication and unnecessary machinery: four should-fix items plus one framing problem that is the author's call, and four nits. Everything here deletes code; nothing asks the author to add any.

Should fix

S1 — A third histogram mechanism in the same file

helios/src/server/metrics.rs:211-322

The PR introduces Buckets<const N: usize> { bounds: [f64; N], scale: f64 } (211-253) and a generic Histogram<N> with observe/render (257-322). metrics.rs already contains, unchanged, two other histogram implementations:

So one file now carries three bucket vocabularies (f64 bounds ending at f64::INFINITY, u64 bounds ending at u64::MAX, and the retirement array sourced from flare_selene::RETIREMENT_LATENCY_MS) and three exposition loops. That is exactly the "fallback layers / speculative compatibility" churn AGENTS.md:188-193 rejects, and it is the kind of split that makes the next histogram author guess which mechanism to copy.

Fix, smaller: express the new series as [u64; N] nanosecond bounds with u64::MAX and reuse the existing loop at 1178-1214 (the +Inf spelling at 1202-1206 already produces the required label); or, if the generic is preferred, migrate the two old mechanisms onto Histogram<N> in this PR so the file has one. Either direction removes ~40 lines; the first removes the most.

S2 — Buckets::scale is redundant

helios/src/server/metrics.rs:215, 223, 231, 239, 246, 252, 272-279, 318

Every observation passed to observe is already an integer on the exposed unit's grid — nanoseconds at helios/src/server/latency.rs:121-124 and helios/src/server/metrics.rs:562-601, plain token counts (u64::from(generated_tokens) etc.), so scale is 1e9 for the two seconds vocabularies and 1.0 for the three count vocabularies (TOKEN_COUNTS 239, PREEMPTION_COUNTS 246, CHOICE_COUNTS 252). The only thing scale buys is dividing at observe (275) and again at render (318) — two float ops per observation and per bucket line, plus the rounding dependence documented at 273-274 ("Division is correctly rounded, so an integer grid point lands exactly on a bound written as the same decimal"), a comment that exists only because the conversion exists.

Fix: make Buckets hold integer nanosecond (or count) bounds, compare value against them directly, and emit le labels as bound as f64 / 1e9 for the seconds series inside render only — where f64 formatting is already unavoidable. Deletes the scale field, its five initialisers, the division in observe, and the rounding comment. (The alternative — keeping scale — needs a second series whose observations are not on the integer grid; none exists in this PR.)

S4 — The TTFR histogram lives on the sampler, not on Metrics

helios/src/server/latency.rs:34-37, 101-108; helios/src/server.rs:671; helios/src/server/runtime/phase_tests.rs:5527-5537

FirstResponseSamples gained histogram: Histogram<21> (latency.rs:36) so that FirstResponse::output can observe it at 121-124, alongside the 60-second rolling window it was built for. Three costs follow:

  1. a public forwarder render_histogram (latency.rs:101-108) whose only purpose is to let the route handler reach into the sampler for one series;
  2. a scrape hook outside Metrics::render — helios/src/server.rs:671 calls state.first_response.render_histogram(&mut text) between two metric() calls, so /metrics output is no longer assembled in one place;
  3. a test-only observation path at helios/src/server/runtime/phase_tests.rs:5527-5537 that publishes the series with no observations, which only exists because the histogram is otherwise unreachable from a test that holds Metrics.

The sampler object already has a clone-into-Arc handoff (observe at latency.rs:64-70) and a lock; the histogram rides along only because it is observed at the same instant the window sample is recorded.

Fix, smaller: put time_to_first_response: Histogram<21> on Metrics (helios/src/server/metrics.rs:406-421 is the natural neighbourhood) and observe it from the two call sites that already have state.model.metrics() in hand — helios/src/server/http.rs:621 (streaming) and helios/src/server/http.rs:648 (nonstreaming) — immediately after first_response.output(). Render it inside the existing array at helios/src/server/metrics.rs:1548-1581. Deletes latency.rs:36, latency.rs:101-108, the server.rs line, and the test hook, and puts every series in one render loop. This also removes the only scrape path that bypasses Metrics::render. Cross-lens note: I raise the extra scrape hook as a simplicity cost; whether observing a metric from inside the window's mutex is a correctness or contention problem is not my call and I cannot show it from the code.

S7 — A ten-line kind list duplicating GraphKind::samples()

helios/src/server/runtime.rs:1721-1732

if matches!(
    kind,
    GraphKind::Prefill | GraphKind::TerminalPrefill | GraphKind::ScoredPrefill
        | GraphKind::Resume | GraphKind::Decode | GraphKind::Speculative | GraphKind::Mixed
) {
    self.metrics.model_step(prefill + generated.len() as u64);
}

GraphKind::samples() at helios/src/execution/manifest.rs:90-101 enumerates exactly those seven variants: Prefill | TerminalPrefill | ScoredPrefill | Decode | Speculative | Mixed | Resume. Two copies of the same set will drift the moment a text graph kind is added — the new kind would be counted in flare_graph_launches_total (which has its own match at metrics.rs:689-699) but silently omitted from flare_model_step_tokens.

Fix: if kind.samples() { self.metrics.model_step(prefill + generated.len() as u64); }, deleting ten lines. Note that the neighbouring match at helios/src/server/runtime.rs:1669-1677 is a different, six-kind set and must stay as it is — this is not a sweep, it is the one site that duplicates an existing predicate.

S8 — A full 19-bucket histogram embedded in every queued or active request (author's call)

helios/src/server/metrics.rs:343-346, 348-363, 285-295, 576

RequestRecord now owns inter_token: Histogram<19> (345), filled by tokens_committed (352-362) and merged into the server histogram by absorb (286-295) on completion (576). Because RequestRecord lives in Incoming, which is created on admission, parked, and reused on readmission, every queued and every active request permanently carries [AtomicU64; 19] + AtomicU64 — 20 × 8 = ~160 B, Default-initialised. This is the change's only per-request storage, and it sits in tension with the description's framing ("Fixed-bound histograms answer those questions in one scrape without per-request storage") and with its own cost section, which counts "a 19-bucket inter-token histogram and two u32 fields per queued or active request" but claims no measurement. Under the charter's "What gets merged" line (a measured memory issue, or bad docs), an unmeasured per-request allocation is not in itself forbidden — hence "author's call", not a defect — but it is the largest thing here that could be deleted.

Fix, if the stated population is negotiable: observe TOKEN_SECONDS straight into Metrics::inter_token_latency at helios/src/server/runtime.rs:1803-1805 (where tokens_committed is called), keeping only the two instants on the record, and delete RequestRecord::inter_token (345), the merge branch (353-357), tokens_committed's histogram use, Histogram::absorb (286-295) and the absorb call (576). The behavioural difference is that cancelled and failed requests would then also contribute inter-token intervals, which docs/api.md:361-364 currently says they do not; the author must decide which population is wanted before taking the deletion. If the answer is "keep the excluded population", keep the code and say so in the description.

Nits

N5 — Twelve render()-substring checks grafted onto tests named for other behaviour

helios/src/server/runtime/phase_tests.rs:576-583, 688-696, 944-946, 1501-1506, 1529-1535, 3836-3841, 3958-3960, 4099-4108, 4536-4541, 4570-4574, 4707-4716, 5534-5541

Tests named for reasoning-budget cuts, EOS stops, route negotiation, stream polling, tool-limit cancellation and admission grouping now end with one or two worker.metrics.render().contains("…") assertions. Several restate each other: 944-946 re-proves what the dedicated completion test proves, and 5535 re-proves the sampler snapshot. AGENTS.md:194-198 asks for tests that "exercise the affected behavior or contract"; a substring of the exposition text is a formatting check, not the behaviour the test is named for, and it makes the surrounding test slower and harder to read. Keep the two that earn their place — the completion-histogram test (metrics.rs:1946-1978 neighbourhood) and the single route-presence test that a scrape carries a histogram with zero observations — and drop the rest. That removes ~24 assertion lines and leaves each phase test asserting the one thing its name promises.

N6 — ~76 lines of docs/api.md prose duplicating the # HELP strings

docs/api.md:311-386 (per-series prose) and 475-520 (42-row vLLM mapping table)

For each series the doc restates the population and unit that helios/src/server/metrics.rs:1548-1642 already emits as # HELP — for example the inter_token_latency_seconds paragraph versus metrics.rs:1591, and the request_max_tokens paragraph versus metrics.rs:1613-1615. Two copies of the same sentence drift independently.

Fix: keep the table at 475-520 (that table is the answer to #536 and cannot be derived from the code) and keep the handful of facts a scrape cannot show — histograms are absent from format=json; e2e is per delivered response so it can be below flare_requests_completed_total; a zero-token completion enters token-count histograms but no time histogram; only flare_time_to_first_response_seconds can observe a request that later failed. Drop the per-series prose that duplicates # HELP.

N8 — AdmissionLimit indexes a bare array by variant position

helios/src/server/metrics.rs:375-385, 684-686, 1647-1656

admission_rejected does self.admission_rejections[limit as usize] (685), so the enum's declaration order (HttpSlots, GenerationCapacity, RequestQueue, 378-385) must stay in step with the separate string literal ["http_slots", "generation_capacity", "request_queue"] at 1647. Reordering the enum silently relabels the counters, and the as usize cast opts out of exhaustiveness entirely.

Fix: a table of (name, &AtomicU64) as the file already does at metrics.rs:1136-1142, with admission_rejected taking the index or the table entry; or match limit { HttpSlots => (&self.admission_rejections[0], "http_slots"), … }. Either puts the label next to the slot and removes the cast.

N7 — A second zero-token case folded into a test that already proved the counts

helios/src/server/metrics.rs:1946-1978

After the first request's thirteen assertions (ending at 1945), the test calls request_completed again with a zero-token RequestRecord::default() (1948-1957) and re-asserts thirteen lines, most of which restate the first block's output with count 1 unchanged. The genuinely new facts are four: the time histograms stay at 1, the token-count histograms reach 2, flare_requests_completed_total reaches 2, and output-limited stays 1.

Fix: either extract assert_counts(&render(), [...]) and call it twice with only the deltas, or move the zero-token case to its own #[test] fn zero_token_completion_enters_only_token_count_histograms. Both make the second case's purpose visible from the test name; as written a reader must diff thirteen strings against thirteen above it to find what is being proved.

Deliberately not raised

Open questions / not verified