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
- Nothing in this lens blocks. The PR's central claim holds in the code:
Metrics::request_completed(metrics.rs:545-603) is the sole increment offlare_requests_completed_totaland the sole observation site for the ten request histograms, so counter and histograms cannot diverge;response_completedhas one production call site (http.rs:607);Histogram::absorbhas exactly one caller (metrics.rs:576). - Four should-fix items remain, all deletions: a third histogram mechanism (S1), the redundant
Buckets::scale(S2), the TTFR histogram living onFirstResponseSampleswith a render forwarder (S4), and a per-requestHistogram<19>carried by every queued or active request (S8). - Four nits: ten
render()-substring assertions grafted onto tests named for other behaviour (N5), ~76 lines of docs prose duplicating the# HELPstrings (N6), a folded zero-token test case (N7), andAdmissionLimit's positional array indexing (N8). - Fixed by the new head and dropped: my previous S7 — runtime.rs:1721-1723 now calls
kind.samples()instead of a ten-linematches!, semantically identical (execution/manifest.rs:90-101 lists exactly the same seven kinds). The same commit moves thefirst_scheduled_nsstamp after packing (runtime.rs:2259-2275); behavioural, adds no code, no lens D cost. - Correction to an earlier review of mine: the description does not promise "no per-request storage"; it says each request carries a small record. S8 therefore rests on the unmeasured 160 B, not on a contradiction.
- Governing rules: AGENTS.md:188-193 (no frameworks, extension points or fallback layers without a concrete requirement; refactoring must remove a demonstrated cost), AGENTS.md:194-198 (tests must exercise the behaviour, not source text), docs/design-review.md:16 = AGENTS.md:338 ("Keep Helios as simple as possible"), and the charter's "Look for the smallest footprint in shared code, or a way to solve it without new code at all".
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:
- Keep
[u64; N]bounds in integer ns / plain counts withu64::MAXsentinel and reuse the existing render loop for the seventeen new series — then S2 disappears as a consequence; or - Migrate
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETSontoHistogram<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:
FirstResponseSamples::render_histogram(latency.rs:101-108) is a pure forwarder toHistogram::render;- the metric is rendered by
state.first_response.render_histogram(&mut text)(server.rs:671) fromserver.rs, i.e. outside theMetrics::render()dispatch at metrics.rs:1548-1581 that renders every other histogram — a second scrape hook for one series; - publishing it requires
FirstResponse::output()to be called, so the test at phase_tests.rs:5527-5537 must call the test-only accessor to get the series into the scrape.
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:
- histograms are absent from
format=json; request_e2e_secondsis per delivered response, so it is belowrequests_completed_total;- a zero-token completion enters only the token-count histograms;
- 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
- Former S7: runtime.rs:1721-1732 used a ten-line
matches!over seven graph kinds to decide whether to record model-step tokens; at this head it isif kind.samples() { self.metrics.model_step(prefill + generated.len() as u64); }(runtime.rs:1721-1723), andGraphKind::samples()(execution/manifest.rs:90-101) is exactly Prefill|TerminalPrefill|ScoredPrefill|Decode|Speculative|Mixed|Resume — verified identical. The different six-kind block at runtime.rs:1669-1677 must stay (noResumethere). - The
first_scheduled_nsstamp moved to after packing (runtime.rs:2259-2275): behavioral, no added code. - Deliberately not raised because they are already minimal:
publish_gaugesas a one-line extraction,request_completed's three arguments,response_completed'schunks(choices). The duplicatedkv_cache_usage_percrow against #549 is a merge-order matter the author already flagged; #548 and #549 are independent and merge cleanly in either order.
Open questions / not verified
- I ran no tests, no scrape, no GPU workload and no Windows build at any head. The PR reports
cargo check --features serverclean andcargo test --features runtime-core,server --lib -- server:: scheduler:: cache::at 814 passed / 1 failed, the failure being a template test that needsFLARE_TEST_TEMPLATE_DIR— plausible but unconfirmed by me. - S2 needs a before/after scrape diff to confirm the printed
lelabels are unchanged if the bounds move to integer ns (float formatting of0.001vs an integer bound is the only risk). - S8's ~160 B is a count of twenty
AtomicU64fields, not a measurement; how many requests sit queued or parked at peak was measured by neither the author nor me, so the total cost is unknown — a single/metricsscrape under load (flare_pending_requests,flare_parked_requests) would settle it. - Whether the excluded population matters (S8) is a product question for a maintainer, not something the code answers.
- Not re-raised from my earlier reviews: everything about
helios/src/server/metrics/process.rs(not opened) (three should-fix, three nits) — the file is gone from this head; theprocess_*docs prose nit is gone from docs/api.md.