Simplicity report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/ad1a56b9-a62f-4d41-9d7c-364fa79287ae.md

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

Head reviewed: 6624592 ("Reuse GraphKind::samples for model-step metrics and stamp scheduled time after packing"). 9 files, +1008/−51. Open, no labels, no reviews, no CI checks on the head. Closes #536.

All nine changed files were read in context, each changed function in its surrounding code, and callers followed. Judged against AGENTS.md, docs/design-review.md and the charter.

Key findings

Should fix

S1 — A third histogram mechanism beside the two already present (metrics.rs:211-322)

Buckets<const N: usize> (metrics.rs:213-216, with scale 215 and bounds 218-253) plus Histogram<N>::render (297-321) is a second, parallel histogram vocabulary. The file already has HOST_TIME_BUCKETS / HOST_TOKEN_BUCKETS as [u64; 8] ending in u64::MAX (metrics.rs:199-209) with a render loop (see the host-histogram block near 1178-1214) and a hand-written retirement block (1000-1025). The PR adds fixed-bucket histograms without folding the existing two into the new type, so metrics.rs now documents and renders histograms two ways: f64 bounds + cumulative f64 sum, and integer bounds + u64::MAX.

Why it matters: it is exactly the "parallel path" AGENTS.md:188-193 forbids without a concrete requirement, and it doubles the surface a future histogram author has to read. Smaller version, pick one:

  1. Keep [u64; N] bounds in integer ns / plain counts with u64::MAX sentinel and reuse the existing render loop for the seventeen new series — then S2 disappears as a consequence; or
  2. Migrate HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS onto Histogram<N> in this PR, so one type and one render loop serve all histograms.

Either way one of the two first blocks of metrics.rs goes away.

S2 — Buckets::scale is dead weight (metrics.rs:215, 223, 231, 239, 246, 252, 272-283, 315-319)

Every observation passed to observe is an integer: nanoseconds from http.rs:608, latency.rs:121-124, metrics.rs:557-601, or a plain count (request_prompt_tokens, request_generated_tokens, request_max_tokens, request_preemptions, model_step, request_choices). So scale is 1e9 for the two "seconds" vocabularies and 1.0 for the three count vocabularies, and it buys one divide at observe (275) and one at render (318) — nothing else. It also drags in the rounding comment at 273-274 and a f64 grid in a codebase that otherwise measures in integer ns.

Why it matters: five initialisers plus two conversions plus a comment exist only to convert a unit mismatch the code controls on both sides. Fix: bounds in integer ns with u64::MAX (S1 option 1) or drop scale and keep bounds in the exposed unit as f64 with the sum printed as self.sum.load(..) as f64 — either removes the field and the two divides.

S4 — The TTFR histogram rides on FirstResponseSamples, forcing a forwarder, an out-of-render() hook and a test-only observation (latency.rs:36, 101-108; server.rs:671; phase_tests.rs:5527-5537)

FirstResponseSamples (latency.rs:33-37) now owns histogram: Histogram<21>, so:

Why it matters: a rolling-window sampler is now also a metric registry, so the series is absent from any scrape path that renders Metrics alone, and the sampler's own snapshot median (first_response_median_seconds, server.rs:667-670) and the histogram now describe the same population from two different owners. Fix (docs/design-review.md:16): make it a field on Metrics like the other seventeen (self.time_to_first_response: Histogram<21>), observe it at http.rs:621/648 where the response is delivered, and add it to the array at metrics.rs:1548-1581. That deletes render_histogram, deletes the server.rs:671 line, and lets the test read it from the ordinary render().

Cross-lens courtesy, not a defect I can prove: this is also the only scrape hook outside render(), so a correctness reviewer who objects to the histogram being observed behind the sampler's Mutex will land on the same change.

S8 — A full Histogram<19> per queued or active request, only to be merged on completion (metrics.rs:345, 285-295; call at 576)

RequestRecord embeds inter_token: Histogram<19> (metrics.rs:345) because cancelled and failed requests must not be observed. Histogram<N> is [AtomicU64; N] + AtomicU64 (metrics.rs:257-260), i.e. 20 AtomicU64 ≈ 160 B per request, carried for the whole lifetime of every queued or active request, and consumed by absorb (285-295) which loops 19 buckets — all to be merged once into the server histogram on success. Nothing else uses absorb.

Why it matters: 160 B × queued requests is a memory cost the description does not account for — it counts "one clock read per model step, one store or histogram observation per committing step per request", and says of its cost "This cost was not measured in isolation". Under the charter's "What gets merged" (a measured performance/memory issue), the per-request copy needs either a number or to go.

Fix, author's call, because dropping it changes the observed population: if "only successful requests are observed" is negotiable, keep the two clocks plus a small [u32; N]… no — better, keep only first_token_ns/last_token_ns and observe the inter-token intervals into the server histogram as they happen (one observation per committing step, as now), which removes the embedded Histogram, absorb (285-295) and the 576 call entirely and leaves RequestRecord a plain Copy struct of four scalars. If the excluded population is not negotiable, keep it but state the per-request bytes in the description.

Nits

N5 — Ten render()-substring blocks grafted onto tests named for other behaviour (phase_tests.rs:576-583, 688-699, 944-946, 1501-1508, 3957-3960, 4099-4108, 4536-4541, 4570-4574, 4707-4716, 5534-5541)

Each block renders the whole scrape and assert!(text.contains(...)) on one or two series, inside tests whose names and assertions are about scheduling, preemption or packing. AGENTS.md:194-198 is explicit: "Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness." These ten blocks do not prove the histogram population (they assert a _count of 1 after one completion, which the counter assertion on the line above already proves) — they prove a format! produced a key name.

The three new tests that do assert their own subject — phase_tests.rs:1511-1538 (prefill/computed prompt tokens), 3810-3845 (runtime queue rejections), 5418-5453 (HTTP admission rejection) — are legitimate and should stay. Fix: delete the ten blocks, or move each assertion into one table-driven metrics::render() test that asserts a named series set once.

Related cost inside the same habit: the preemption helper takes worker.parked.front_mut() twice, at phase_tests.rs:3954 and again at 3961, purely because worker.publish_gauges() (3957) needs the borrow released first. Moving the record.preemptions assertion below the render removes the second unwrap.

N6 — ~76 lines of docs/api.md prose duplicate the # HELP text now emitted from code (docs/api.md:311-386)

Per-series prose in docs/api.md:311-386 restates what the # HELP strings at metrics.rs:1548-1642 already say at the point of emission, so every future wording change is a two-file change and the two will drift. Keep instead (AGENTS.md:43-50, the required repo-prose review): the vLLM correspondence table (docs/api.md:475-515 — it is the answer to #536 and cannot be derived from the code) and only the four facts a scrape cannot show:

  1. histograms are absent from format=json;
  2. request_e2e_seconds is per delivered response, so it is below requests_completed_total;
  3. a zero-token completion enters only the token-count histograms;
  4. only TTFR can observe a response that later fails.

N7 — A second zero-token case folded into an existing test, re-asserting thirteen lines (metrics.rs:1946-1978)

The new case was folded into request_histograms_bucket_completed_request_timings, re-asserting the same thirteen lines for a second input. Only four assertions are new. Fix: one test that takes the two inputs as a table and asserts the differences, or assert only the four differing series.

N8 — AdmissionLimit indexes a positional array while its labels live elsewhere (metrics.rs:375-385, 685, 1647-1656)

admission_rejected does self.admission_rejections[limit as usize] (metrics.rs:685) — a #[derive(Clone, Copy)] enum cast to a positional index — while the reason label strings sit in a separate literal array at metrics.rs:1647. Nothing ties HttpSlots = 0 to "http_slots", so a reordered enum silently relabels a counter. Fix: one [(name, &AtomicU64); 3] table (or a match returning the label) so the index and the label are the same declaration; that removes the as usize cast.

Fixed, not raised

Open questions / not verified