Code review summary report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/7d1a31fa-adc4-40c5-aa56-c97ff41da2ba.md

Full review — PR #548 "Add per-request histograms and vLLM-parity request metrics"

Head 6624592, base main, 9 files, +1,016/−51, no reviews and no CI checks on the head. Closes #536. Every citation below was re-read at this head.

Key findings

Verdict: changes requested, and nothing blocks. The design is right and it is in the right layer: Metrics::request_completed (metrics.rs:545-603) holds the only completed.fetch_add in helios/src (metrics.rs:558), so flare_requests_completed_total and the ten request histograms cannot drift; the only per-request state is a RequestRecord on Incoming (metrics.rs:336-346), which survives parking because the whole struct is parked; there is no flag, no per-model branch, no Snapshot/format=json change, no Cargo change, and nothing touches scheduling, eviction, response bodies or cache state.

The newest commit (66245920) is sound and resolves the previous round's one subtractive item. runtime.rs:1721-1723 now reads if kind.samples() { self.metrics.model_step(prefill + generated.len() as u64); }, and GraphKind::samples() (helios/src/execution/manifest.rs:90-101) is exactly Prefill | TerminalPrefill | ScoredPrefill | Decode | Speculative | Mixed | Resume — the same seven kinds the removed inline matches! listed, and the same predicate the file already uses elsewhere. Its neighbours must stay: the six-kind prefill-sum match at runtime.rs:1669-1677 (no Resume) and the Init | Restore | Snapshot | Vision gate at scheduler.rs:2562-2568. The first_scheduled_ns stamp also moved after packing (runtime.rs:2212-2277: commit, then the vision branch / pack_inputs, then the stamp loop, then Ok(())), so the instant marks a step whose inputs were accepted, a failed pack leaves it unset, and docs/api.md:329-331 still describes it correctly.

Verified sound, so it need not be re-derived. Decode and time-per-output-token require ≥2 generated tokens (metrics.rs:593-602); a zero-token completion enters only the token-count and preemption histograms (metrics.rs:562-575, docs/api.md:334-336); max_tokens is recorded once under !incoming.readmitted (runtime.rs:1566-1570) and a preemption is counted only at the park (runtime.rs:2101), not at the reasoning-budget park; the position == 0 stamp (runtime.rs:1794-1796) makes one inter-token interval per committing step, so a speculative round is one observation; observe uses exposed <= bound with unwrap_or(N - 1) and every preset ends at f64::INFINITY, so _count equals the +Inf bucket; admission rejections are counted at exactly the documented sites (server.rs:816, http.rs:240, runtime.rs:869, :945) and not on the two 503 paths; no process_* series remain anywhere in the tree.

What remains is one authorization and truthfulness question about the closing keyword and the parity table, one latent population bug at the HTTP gate, one convention gap inside metrics.rs, and a diff that can shrink by roughly 235 of its 1,016 added lines by deleting mechanisms rather than adding them. Three should-fix items, seven subtractive items, eight nits.

Blockers (0)

None. The --features server build break and the unreconciled-evidence findings from earlier rounds are fixed: helios/src/server/metrics/process.rs (not opened) is deleted, and the description separates claim from measurement and keeps the unrun checks visible.

Should Fix (3)

S1 — A response whose other choice trips the parallel-tool limit loses its sibling choices' HTTP observations

helios/src/server/http.rs:604-612

tool_limit_reached is one flag for the whole response: declared encode.rs:89, initialised :142, set at :505-507 (if !self.parallel_tool_calls && self.outputs[index].has_tools() { self.tool_limit_reached = true; break; }), and read without an index at http.rs:569-573. Per-choice state is separate: generated[index] = generated_tokens (http.rs:530) over vec![0u32; size] (http.rs:407). The runtime counts each choice as its own completed request, and observes every runtime histogram for it, before the HTTP layer decides — runtime.rs:1866 (stop path) and :2029 (output-limit path). So a sibling choice that finished naturally is counted and fully observed in the runtime histograms, yet http.rs:606 suppresses the HTTP observations for the whole response: flare_request_e2e_seconds_count, flare_request_choices and flare_request_max_choice_generated_tokens under-count against flare_requests_completed_total — the very divergence the PR funnels request_completed to prevent. docs/api.md:311-314 lists only two exclusions (count_tokens and "responses the runtime records as cancelled"); a surviving sibling is not one.

It is latent: n > 1 is accepted only for Protocol::Completions (decode.rs:753-755) and tools are rejected outright for Completions (decode.rs:813-815), so no public request reaches "several generations plus tools" today.

Requested change: record which indices finished Termination::Cancelled at http.rs:531-532 and pass only the surviving counts, still observing e2e once when at least one choice was delivered — or, if the response-wide exclusion is intended, say so in docs/api.md:311-318, together with the non-stream timing rule: e2e is observed inside the generator (http.rs:606-612) before the non-stream body is streamed lazily at :642-651, so a client that takes the headers and drops the connection is still counted, while an abandoning stream client is not (docs/api.md:317-318 states only the stream rule). If Subtraction item 2 is taken, the gate collapses to if !encoder.tool_limit_reached plus one observation.

S2 — Closes #536 overstates the delivery, and an unpinned competitor-parity table has become the organizing justification

PR description ("Closes #536"); docs/api.md:475-515; issue #536; AGENTS.md:165-169 (not opened), :188-193, :201-203.

(a) The closing keyword no longer matches the issue. #536 asks for request histograms and four standard process_* series (process_cpu_seconds_total, process_resident_memory_bytes, process_open_fds, process_start_time_seconds). Commit 54e06b30 deleted exactly that half; a tree-wide search finds no process_* series and the description concedes the omission. Closes would mark the issue resolved with one of its two deliverables neither shipped nor deferred. Fix: reference #536 without Closes and name where the process metrics go (a follow-up issue or "not planned").

(b) Competitor parity is now the stated purpose, with no pinned upstream. The new section opens "The table gives the Flare series that measure each metric in vLLM's production metric list" (docs/api.md:477-482) with no version, link or commit, so all ~40 rows are coupled to another project's release notes and will silently rot. Several rows are untested negative claims about this repository's future: repetition not provided (:498), corrupted_requests (:511), KV page residency (:512), FLOP/byte estimates (:513), LoRA/watermark/sleep (:514), KV connectors (:515), and the single kv_cache_usage_perc ratio (:490). AGENTS.md:165-169 (not opened) accepts a maintainer request, a demonstrated defect, a measured problem, or bad docs; :188-193 bars "speculative compatibility"; the charter lists vLLM under "Alternatives / Competitors", not as a compatibility target. The defect framing the description now states plainly — a scrape cannot show tail latency, queue delay, prefill time, decode rate, request sizes or queue-limit rejections — is what the rules authorize. Fix: lead with that framing, keep the Flare-side series documentation (genuinely useful), and drop the mapping table or move it to an issue/PR comment; if a mapping is kept, cite the vLLM version it was read from.

S3 — metrics.rs now answers "how do I write a histogram" three ways, and nothing says which one is current

helios/src/server/metrics.rs:211-322 (new) against :199-209, :475, :819-841, :1178-1214, :468, :854-860, :1000-1025.

The disagreement is visible in one scrape: some series carry # HELP and some do not, _sum/_count come in opposite orders, and bounds are integers in one place and floats in another — three copies of the same bucket-index algorithm (:276-281, :836-840, :854-860). Fix: one module-doc sentence naming Histogram/Buckets as the convention for observed histograms, plus a one-line comment at :854-860/:1000-1025 that pushed store counts cannot use observe and are frozen. The migration itself is Subtract item 1.

Subtract / Simplify (~235 lines, ≈23% of +1,016)

Ranked by saving. None of these asks the author to write new code.

1. ≈55 lines — rebuild the three host lookup histograms on Histogram<8>/Buckets<8>. Deletes HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS (metrics.rs:199-209), host_cost_sums (:475), the tuple-array loop plus .position(..).unwrap() in host_lookup_cost (:819-841 → three observe calls) and the whole render block (:1178-1214 → one three-entry table through render). Nothing else reads those fields. scale: 1.0 keeps the exposed unit at ns/tokens; the only visible change is three # HELP lines. Honest caveat: render prints _sum as sum as f64 / scale (:315-319), so ns sums past 2^53 round where today's host _sum is exact u64. Do not fold the 19-bound TOKEN_SECONDS request histograms into the 21-bound REQUEST_SECONDS loops — the bounds differ.

2. ≈50 lines — drop the per-response choice pair. request_choices: Histogram<6> and request_max_choice_generated_tokens: Histogram<21> (metrics.rs:407-408), CHOICE_COUNTS (:249-253), Metrics::response_completed (:608-618) reduced to response_completed(&self, elapsed_ns: u64), the http.rs:407/:530 bookkeeping and the two extra arguments at :606-612, the render entry (:1617-1621) and block (:1625-1630), the test at metrics.rs:1981-2001, docs/api.md:322-326 and table row :507. flare_request_generated_tokens already observes each completed request's count, and the docs say Flare runs each choice as its own model request (:325-326), so each of the n choices is already in a histogram with identical TOKEN_COUNTS bounds; the max-choice series adds only "the max of values already counted individually", and flare_request_choices reports the n parameter only /v1/completions accepts. Neither is in #536. Counter-argument, stated honestly: both are names in vLLM's production list, so removal weakens the parity framing — which is exactly the framing S2 asks be dropped. If the author keeps request_choices, dropping only the max-choice series and its Vec still saves ≈25 lines.

3. ≈60 lines — stop asserting rendered scrape text inside unrelated tests. Ten blocks render the whole scrape and assert!(text.contains(...)) inside tests named for scheduling, preemption, budget or packing: phase_tests.rs:576-583, :688-699, :944-946, :1499-1508, :3957-3960, :4096-4106, :4536-4541, :4570-4574, :4704-4713, :5531-5541. They do not establish the population — most only re-assert a _count of 1 that the counter assertion on the line above already proves — they establish that a format! produced a key name. AGENTS.md:194-198 (not opened) requires tests that exercise the behaviour. Delete them, or fold the surviving facts into one table-driven metrics::render() test asserting a named series set once (≈20 lines). Keep the three new tests that assert their own subject (:1511-1538 prefill/computed tokens, :3810-3845 runtime queue rejections, :5419-5457 HTTP admission rejection) and the one unique fact at :1501-1508 (flare_model_step_tokens_count 2 / _sum 3), which no other test pins.

4. ≈30 lines — stop restating the # HELP strings in prose. docs/api.md:311-346 narrates e2e, queue, prefill, inference, TTFT, decode and inter-token in words that metrics.rs:1548-1595 already ships in every scrape (api.md:329-331 vs metrics.rs:1557; api.md:340-341 vs :1567), and :377-386 states the same facts a third time. Keep only what # HELP cannot carry: which requests are excluded from which population, per-response versus per-request, the abandoned-stream rule, the zero-token and ≤1-token rules.

5. ≈15 lines — put flare_time_to_first_response_seconds on Metrics. Delete FirstResponseSamples.histogram (latency.rs:36), the pure forwarder render_histogram (latency.rs:101-108) and its out-of-band hook server.rs:671, and observe from FirstResponse::output (latency.rs:116-127) through the existing metrics handle, rendering in the REQUEST_SECONDS table at metrics.rs:1548-1581. The rolling-window sampler stops being a metric registry, and the one scrape hook outside Metrics::render disappears. Only the asymmetry is the finding, not the pairing — if the window and its all-time histogram are deliberately kept together, state that ownership rule at Metrics::render instead.

6. ≈15 lines — delete RequestRecord::inter_token, Histogram::absorb and their call. (metrics.rs:345, :285-295, call at :576.) Observing TOKEN_SECONDS straight into Metrics::inter_token_latency at the tokens_committed call site (runtime.rs:1794-1796) removes ≈160 B (20 × AtomicU64) that every queued and active request currently carries and a 19-iteration merge. The behavioural difference is that cancelled and failed requests would then contribute intervals, which docs/api.md:361-364 says they do not — so this is the author's product call: if the excluded population is wanted, keep it and keep the sentence.

7. ≈8 lines — Buckets::scale is redundant. Every observation is already an integer on the exposed unit's grid (nanoseconds at latency.rs:121-124 and metrics.rs:562-601, plain counts otherwise), and scale is 1e9 only for the two seconds vocabularies (:223, :231) and 1.0 for the three count vocabularies (:239, :246, :252); its only effect is dividing at observe (:275) and again at render (:318), plus the rounding comment at :273-274 that exists only because the conversion does. Hold integer nanosecond or count bounds, compare directly, format le in render only. Verify with a before/after scrape diff that the le labels stay byte-identical.

Nits (8)

  1. docs/api.md:340-341 omits the preemption stall from the decode and per-output-token spans. The fact is stated for inter-token latency at :344-346; decode is first-to-last committed token (metrics.rs:593-601) and parking keeps first_token_ns because the whole Incoming moves (runtime.rs:2101, :2126), so a high p99 decode time silently contains the readmission wait. Add "a preemption stall is included".
  2. docs/api.md:311 leads with the implementation verb. "The HTTP histograms observe delivery" names the mechanism; the neighbouring groups open with the quantity (:328, :348). Say "measure response delivery time".
  3. The queue interval and the description's cost line are under-labelled. The stamp is unconditional over graph kinds (runtime.rs:2259-2275), so for an ordinary text request the first "model step that includes the request" (docs/api.md:329-331) is the Init graph and flare_request_prefill_seconds spans init time as well as prefill — one clause naming init settles it. Separately, the description's "17 histograms (394 lines) per text scrape" is exactly this PR's request histograms (metrics.rs:1548-1642 plus TTFR); a scrape also carries four host histograms (:1178-1214, :1000-1025), so a reader counting # TYPE … histogram finds 21. Label the population.
  4. flare_admission_rejections_total casts the variant to an index while its labels live elsewhere. admission_rejected indexes self.admission_rejections[limit as usize] (field :423, use :685) against a separate literal array ["http_slots", "generation_capacity", "request_queue"] (:1647) that must track AdmissionLimit's declaration order (:378-385); nothing links them, and the as usize opts out of exhaustiveness. Give the enum a name()/ALL and feed the existing labelled-counter loop (:1143-1177).
  5. Per-choice generated-token counts are stored twice. Encoder already keeps them (protocol/encode.rs:57, set at :630-634, grouped by choices_per_prompt :94, used at :685-695), while http.rs keeps a parallel vec![0u32; size] (:407, :530) that metrics.rs:610 re-groups with chunks(choices). Expose the encoder's counts, or take Subtraction item 2 — either removes the duplicate.
  6. !count at http.rs:606 is dead. Count requests return at http.rs:284-286, before the delivery stream exists; the conjunct reads as a guard that does not exist.
  7. A second zero-token case is folded into an existing test and re-asserts thirteen lines. metrics.rs:1946-1978 repeats the same thirteen series for a second input; only four assertions are new. Make the test take the two inputs as a table and assert the differences, or assert only the four differing series.
  8. flare_model_step_tokens observes a 0-token sample for a fully failed step. model_step runs for every kind in GraphKind::samples() (runtime.rs:1721-1723), including a step whose every lane completed with an error status, lowering the mean; docs/api.md:383-386 neither excludes zero-token steps nor mentions error steps. Either skip the observation when tokens == 0, or note it in the doc.

Deliberately not raised (reconciled across lenses)

Open questions / what could not be verified

Link: https://github.com/NVIDIA/hyperflare-inference/pull/548