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

Raw Markdown for agents: https://autobot.eidonix.com/p/b1013bb3-f873-4a22-9bb7-b737f0ba2b95.md

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

Head 6624592, base main, 9 files, +1,008/−51 (verified from pr_files: docs/api.md +127/−4, metrics.rs +548/−2, runtime.rs (not opened) +94/−37, phase_tests.rs (not opened) +187, latency.rs +24/−8, http.rs +15, scheduler/tests.rs (not opened) +7, scheduler.rs (not opened) +4, server.rs (not opened) +2). No reviews and no CI checks on the head. Description ends Closes #536. Every citation below was re-read at this head.

Key findings

Verdict: changes requested; 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 runtime histograms cannot drift — the property the change set out to get. The only per-request state is a RequestRecord on Incoming (metrics.rs:336-346), which survives parking because the whole struct is parked. No feature 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 clears the previous round's one subtractive item. runtime.rs:1721-1723 (not opened) now reads if kind.samples() { self.metrics.model_step(prefill + generated.len() as u64); }, and GraphKind::samples() (helios/src/execution/manifest.rs:90-101 (not opened)) is exactly Prefill | TerminalPrefill | ScoredPrefill | Decode | Speculative | Mixed | Resume — the same seven kinds the removed inline matches! listed. Its neighbours must stay: the six-kind prefill-sum match at runtime.rs:1669-1677 (not opened) (no Resume) and the Init | Restore | Snapshot | Vision gate at scheduler.rs:2562-2568 (not opened). The first_scheduled_ns stamp also moved after packing (runtime.rs:2212-2277 (not opened): commit, then the vision branch / pack_inputs, then the stamp loop, then Ok(())), so a failed pack leaves the instant unset and no counted completion can lack its queue/prefill observations.

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 (not opened)) and a preemption is counted only at park_if_preempted (runtime.rs:2101 (not opened)), not at the reasoning-budget park; the position == 0 stamp (runtime.rs:1794-1796 (not opened)) yields 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 (metrics.rs:213-253, 272-283), so _count equals the +Inf bucket; admission rejections are counted at exactly the documented sites (server.rs:816 (not opened), http.rs:237-245, runtime.rs:868-874 (not opened), :944-947) and not on the two 503 paths; format=json is unchanged (Snapshot gained no fields); no process_* series remain anywhere in the tree.

What remains: one truthfulness/authorization 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,008 added lines by deleting mechanisms rather than adding them.

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 (it is absent from the nine changed files), 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

// One observation per successful response: a tool-limit cancellation reaches
// this point but the runtime counts it as cancelled, so it is excluded.
if !count && !encoder.tool_limit_reached {
    state.model.metrics().response_completed(
        admitted_at.elapsed().as_nanos() as u64,
        decoded.request.choices,
        &generated,
    );
}
yield Delivery::Complete(response);   // http.rs:613

tool_limit_reached is one flag for the whole response: declared protocol/encode.rs:89 (not opened), initialised :142, set at :505-507 (if !self.parallel_tool_calls && self.outputs[index].has_tools() { self.tool_limit_reached = true; break; }), read without an index at http.rs:569-573, encode.rs:598 (not opened) and :604. 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 (not opened) (stop path) and :2028-2038 (output-limit path); Metrics::cancelled is a different counter (runtime.rs:1329-1330 (not opened), :1350, :1373, :1420). The parallel tool-limit stop is a client-side decoder cancel (http.rs:569-573) taken after the runtime already recorded completion. 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-326 lists only two exclusions (/v1/messages/count_tokens and "responses the runtime records as cancelled, such as a parallel tool-limit stop") and never says a response is dropped wholesale because one sibling was cancelled.

Reachability: latent today. n > 1 is accepted only for Protocol::Completions (protocol/decode.rs:753-755 (not opened), "n must be 1" elsewhere) and tools are rejected outright for Completions (decode.rs:813-815 (not opened), reject(&body, &["tools", "tool_choice"])), so no public request can combine tool-carrying output with several choices. It becomes live the moment tools are allowed on Completions.

Requested change: record which indices finished Termination::Cancelled at http.rs:530-532 and pass only the surviving counts to response_completed, still observing e2e once per delivered response — or, if the response-wide exclusion is intended, state it 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 non-stream client that takes the headers and never drains is still counted, while an abandoning stream client is not (docs/api.md:317-318 states only the stream rule). If Subtract item 2 is taken, the gate collapses to if !encoder.tool_limit_reached plus one observation. What would settle it: a phase test in the style of disabled_parallel_calls_complete_http_and_stop_decoding (phase_tests.rs:4650-4720 (not opened)) posting a two-choice completions request with tools enabled and asserting flare_request_e2e_seconds_count == 2 or == 0 against flare_requests_completed_total.

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.

(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), in its own table row plus "Plus the standard process_* collector metrics". Commit history shows the half was deliberately carried and then removed: ebecef13 "Add request latency histograms and process metrics" → 54e06b30 "Remove process metrics from the request latency change", with the caveat sentence deleted and the Closes keyword left in place. A tree-wide search finds no process_* series, and the parity table has no row for them even though its lead-in promises "the metrics Flare does not provide" (docs/api.md:477-479). server/metrics/ now contains only metrics.rs and metrics/scheduler.rs (not opened). Closes would mark the issue resolved with one of its two deliverables neither shipped nor deferred — and AGENTS.md:134-137 (not opened) forbids publishing a description whose material limitations must be guessed.

(b) Competitor parity is 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, named here without the vllm: prefix" (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; the repository's own precedent links the exact upstream files (docs/logprobs-design.md:261-262 (not opened)). Roughly eight rows are untested negative claims about this repository's future: repetition (: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, which is #549's). AGENTS.md:165-169 (not opened) accepts a maintainer request, a demonstrated defect, a measured problem, or bad documentation; :188-193 bars "speculative compatibility"; the charter lists vLLM under "Alternatives / Competitors", and docs/core-design.md:210-219 (not opened) says "Make a smaller promise than vLLM … Flare does not aim for vLLM's feature matrix". The defect framing the description 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, and it is sufficient on its own.

Requested change: reference #536 without Closes and name where the process metrics go (a follow-up issue, or "not planned"); lead with the observability-defect framing; keep the Flare-side series documentation, which is genuinely useful; drop the mapping table or move it to an issue/PR comment; if a mapping is kept, cite the vLLM version/commit it was read from and mark it informational. Whether any cross-project mapping belongs in docs/api.md is a maintainer decision, not this review's.

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, bounds are integers in one place and floats in another — three copies of the same bucket-index algorithm (:276-281, :836-840, :854-860). AGENTS.md:188-193 (not opened) rejects a new abstraction left beside what it supersedes, and docs/design-review.md:74 (not opened) requires the design to account for duplicate representations. The new type is clearly the better one (bounds and scale together, no unwrap, already reused in latency.rs), which is why the ask is "pick one mechanism", not "write a fourth". Requested change: 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. Do not migrate flare_host_cache_retirement_seconds — its counts are pushed from selene, not observed. The actual migration is Subtract item 1.

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

Ranked by saving. None of these asks the author to write new code; each removes a mechanism, a duplicate store, or a redundant assertion.

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: a search_code for all five names returns only these lines, the observe call site at runtime.rs:2837 (not opened) and the existing test host_outcomes_and_capacity_have_bounded_labels_and_cost_histograms (metrics.rs:2070), which reads only _sum. scale: 1.0 keeps the exposed unit at ns/tokens and Histogram::observe uses the same first-match rule as the removed .position(..).unwrap(), so the series names, le boundaries and sums are unchanged; the only visible difference is three added # 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 — the same trade the PR's own request histograms already take. 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 response_histograms_count_choices_and_largest_choice_per_prompt (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 (docs/api.md: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 that only /v1/completions accepts. Neither series is in #536 and nothing in the repository reads them. 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 (not opened), :688-699, :943-946, :1499-1508, :3956-3960, :4096-4108, :4536-4541, :4570-4574, :4704-4716, :5531-5541. They do not establish the population — several only re-assert a _count of 1 that the counter assertion on the line above already proves (:576-583 sits directly below assert_eq!(worker.metrics.completed.load(...), 1)), and :943-946 asserts flare_requests_completed_total 1 / flare_requests_output_limited_total 0 where the surrounding test's own asserts already establish completion without a limit — they establish that a format! produced a key name. AGENTS.md:194-198 (not opened) requires tests that exercise the behaviour; a contains("..._count 1") check on rendered text proves formatting. Delete them, or fold the surviving facts into one table-driven metrics::render() test (≈20 lines, natural home next to the existing render assertions at metrics.rs:2441-2443). Keep the three new tests that assert their own subject (:1511-1538 prefill/computed tokens exclude reuse, :3810-3845 runtime queue rejections, :5418-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. Related micro-point: the preemption helper takes worker.parked.front_mut() twice (:3954, :3961) only because publish_gauges() (:3957) needs &self; moving or deleting the gauge/render block removes the second unwrap.

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 (docs/api.md:329-331 vs metrics.rs:1557; :340-341 vs :1567, :1586), and :377-386 states the same facts a third time, with table rows :501-504 a fourth. 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. That is ~30 of the +127 doc lines.

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 (not opened), 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. Three costs go with it: the only scrape hook outside Metrics::render() (the scrape body is assembled in four stages, server.rs:660 (not opened), :661-670, :671, :672-708, with no stated rule for which series belong where); a test that must call .output() purely for its side effect (phase_tests.rs:5527 (not opened)); and a metric whose lifetime is tied to a sampler whose WINDOW/CAPACITY have nothing to do with it. Only the ownership asymmetry is the finding, not the window-plus-histogram pairing — if that pairing is deliberate, state the 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. RequestRecord embeds inter_token: Histogram<19>, i.e. twenty AtomicU64 (~160 B) carried by every queued and active request for its whole lifetime (the record survives park/readmit, runtime.rs:1565-1570 (not opened)), solely so that requests which never complete contribute nothing. Observing TOKEN_SECONDS straight into Metrics::inter_token_latency at the tokens_committed call site (runtime.rs:1791-1796 (not opened)) removes that storage 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 (and state the per-request bytes and expected queue depth, since the description quantifies clock reads but not memory).

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), so scale is 1e9 only for the two seconds vocabularies (metrics.rs:223, :231) and 1.0 for the three count vocabularies (:239, :246, :250-253). Its only effect is a divide at observe (:275) and another 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; I predict none changes, since every bound is written in the exposed unit already.

Cost note so the author is not surprised: these seven items do not reduce the ~394 exposition lines per scrape, which are dominated by bucket counts, and the # HELP/TYPE/bucket line cost of the 17 new histograms is the feature #536 asks for. Only item 2 removes rendered series (2 histograms, 6+21 buckets → ~31 lines).

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) with first_token_ns set once and only last_token_ns overwritten (metrics.rs:348-362), and park takes the whole Incoming (runtime.rs:2106-2147 (not opened)) after bumping preemptions (:2101), 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 "The runtime histograms observe requests whose model generation completes successfully", :348 "The runtime token histograms count per completed request"). 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 (not opened)), so for an ordinary text request the first "model step that includes the request, which can be a vision step" (docs/api.md:329-331) is the Init graph, and flare_request_prefill_seconds spans Init→first token including graph-launch/init time; 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 roughly 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 metrics.rs:423, use :685) against a separate literal array ["http_slots", "generation_capacity", "request_queue"] (:1647-1651, zipped positionally at :1649) 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:56-58 (not opened), set at :630-634, grouped by choices_per_prompt :94, used at :693), and observe_generated_token (:217-219, called at http.rs:498) increments the same number, 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 Subtract item 2 — either removes the duplicate. The two diverge the first time either path changes: zero-budget choices finished at http.rs:442 never set generated.
  6. !count at http.rs:606 is dead. Count requests return at http.rs:284-286 (if count { return Json(...).into_response(); }) before the delivery stream is ever built, so the conjunct can never be false and reads as a live guard.
  7. A second zero-token case is folded into an existing test and re-asserts thirteen lines. metrics.rs:1946-1978 appends a second case to request_histograms_bucket_completed_request_timings and repeats the same thirteen series to establish four new facts. Make it a two-row table over the two inputs, or assert only the series that differ.
  8. flare_model_step_tokens observes a 0-token sample for a fully failed step. self.metrics.model_step(prefill + generated.len() as u64) (runtime.rs:1721-1722 (not opened)) runs for every kind in GraphKind::samples(), including a step whose every lane completed with an error status (record.status == 3), lowering the reported mean; docs/api.md:383-386 neither excludes zero-token steps nor mentions error steps. Either skip the observation when the sum is zero, 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