Correctness review of PR #548 (head 6624592) — per-request histograms and vLLM-parity metrics
Key findings
- No blocking issues at this head. The build break that earlier rounds flagged (a permanent
crate::runtime_core::open_descriptors()call fromhelios/src/server/metrics/process.rs(not opened) whileruntime_coreis feature-gated athelios/src/lib.rs:22-26(not opened)) is gone: commit54e06b30deletedmetrics/process.rs(not opened) and its call site, the PR now changes 9 files and none of them ismetrics/process.rs(not opened) (pr_files), and noprocess_*series ormetrics::processreference remains in the tree. - One should fix remains (carried over, latent): the HTTP end-to-end/choice observations are gated on a response-wide flag while completions are per choice, so a sibling choice the runtime counted as completed records none of
flare_request_e2e_seconds,flare_request_choices, orflare_request_max_choice_generated_tokens(helios/src/server/http.rs:604-612vshelios/src/server/protocol/encode.rs:89,505-507,helios/src/server/http.rs:407,530). Unreachable through the public API today, but wrong in scope and silent when it happens. - Four nits, all minor: a dead
!countguard, a non-stream e2e observation taken before the body is polled (undocumented asymmetry with the stream rule), the decode/TPOT preemption span being undocumented although it is real, andflare_model_step_tokensobserving a 0-token sample for a step whose lanes all errored. - The runtime half holds up. The counter and the histograms cannot diverge inside the runtime, the recorded populations match
docs/api.mdline by line,RequestRecordsurvives preemption with itsmax_tokensand preemption count,cache_lookup_tokenssits at the onecache_lookupssite, and the four admission-rejection writers are exactly the documented ones. - The newest commit (66245920) is sound. Substituting
GraphKind::samples()for the inlinematches!is an exact population match, and moving thefirst_scheduled_nsstamp to after input packing cannot leave a counted completion with an unset instant.
Should fix 1 — response-wide tool-limit gate drops sibling choices' HTTP observations
Where: 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,
);
}
Evidence chain (each link read in context):
tool_limit_reachedis a single flag for the whole response: declaredhelios/src/server/protocol/encode.rs:89, initialisedfalseat:142, set at:505-507(if !self.parallel_tool_calls && self.outputs[index].has_tools() { self.tool_limit_reached = true; break; }), and read without any index athttp.rs:476-481,:531-532and:569-573.- Per-choice state is separate:
let mut generated = vec withgenerated[index] = generated_tokens(http.rs:530), one element per generation. - The runtime counts each choice as its own completed request, inside the single function that also writes the histograms —
Metrics::request_completed(helios/src/server/metrics.rs:545-603), the only writer offlare_requests_completed_total(metrics.rs:558), called fromhelios/src/server/runtime.rs:1866(stop path) and:2029(finish path;output_limitderived asreason == "length"). Cancellation has its own separate counter. - The tool-limit stop is a client-side decoder cancel (
http.rs:569-573→generation.cancel()), issued after the runtime has already completed that request. So a sibling choice that finished naturally is both counted and fully observed in the runtime histograms, yethttp.rs:606suppresses the HTTP observations for the whole response. - The documentation claims the exclusion is per response only for "responses the runtime records as cancelled" (
docs/api.md:311-314: "it excludes/v1/messages/count_tokensand responses the runtime records as cancelled, such as a parallel tool-limit stop"), and the mapping table repeats it (docs/api.md:501). A surviving sibling is not such a completion.
Consequence: in a response mixing a naturally finished choice with a choice that trips the parallel-tool limit, flare_request_e2e_seconds_count, flare_request_choices and flare_request_max_choice_generated_tokens under-count relative to flare_requests_completed_total by every surviving sibling — exactly the counter/histogram divergence this PR set out to remove by funnelling both through request_completed. It is also the divergence the PR description asserts does not exist ("the completed-counter delta was 24, equal to the time-to-first-token and generated-token histogram count deltas").
Reachability (verified — this is why it is should-fix, not blocking):
n > 1is accepted only forProtocol::Completions(helios/src/server/protocol/decode.rs:753-755:if protocol != Protocol::Completions && choices != 1 { return Err("n must be 1") }).- Tools are rejected outright for Completions (
helios/src/server/protocol/decode.rs:813-815:reject(&body, &["tools", "tool_choice"])). - So no public request today combines several generations with tools. The defect is latent; it becomes live the moment tools are allowed on Completions or
n > 1is allowed on a tool-carrying protocol.
Fix: decide per finished generation rather than per response — record which indices were finished with Termination::Cancelled at http.rs:531-532 and pass only the surviving choices' counts to response_completed, still observing e2e once when at least one choice was delivered. If the response-wide behaviour is intended, say so in docs/api.md:311-318: a response in which any choice hits the parallel tool limit contributes no e2e or choice observations for any of its choices.
What would settle it: a phase test in the style of disabled_parallel_calls_complete_http_and_stop_decoding (helios/src/server/runtime/phase_tests.rs) that builds a two-choice completions request with tools and asserts flare_request_e2e_seconds_count against flare_requests_completed_total. Today the request cannot even be built through the decoder, which is itself the evidence that the path is latent.
Nits
helios/src/server/http.rs:606— the!countconjunct is dead. Count responses return athttp.rs:284-286, long before the delivery stream is constructed, so the condition is always true there. Harmless, but it reads as a guard that does not exist.helios/src/server/http.rs:606-612vs:642-651— non-stream e2e is observed before the body is polled.response_completedruns inside the generator, whereas the non-stream body is streamed lazily afterwards; a client that takes the headers and drops the connection is still counted, while a stream client that abandons before draining is not (the documented rule atdocs/api.md:317-318, "For a stream it is observed when delivery completes, which requires the client to drain the body"). Document the asymmetry or move the observation into the body wrapper.helios/src/server/metrics.rs:593-601vsdocs/api.md:340-346— the preemption span is documented only for inter-token latency.flare_request_decode_secondsandflare_time_per_output_token_secondsare computed as last-minus-first committed token, so they also include the wait for readmission; onlyflare_inter_token_latency_secondssays so. One sentence besidedocs/api.md:340-341would remove the guess.helios/src/server/runtime.rs:1721-1722—model_stepobserves a zero-token sample for a fully failed step.self.metrics.model_step(prefill + generated.len() as u64)runs for every kind inGraphKind::samples(), including a step whose every lane completed with an error status (status3), so a 0 entersflare_model_step_tokensand lowers its mean.docs/api.md:383-386neither excludes zero-token steps nor mentions error steps. Either skip the observation whentokens == 0, or note it in the doc.
Verified in code — no finding
- Newest commit 66245920, part 1:
GraphKind::samples(helios/src/execution/manifest.rs:90-101) returns exactlyPrefill | TerminalPrefill | ScoredPrefill | Decode | Speculative | Mixed | Resume, the same set the replaced inlinematches!listed — no population change. Its pre-existing callers (manifest.rs:944,execution/transport.rs:1319 (not opened),1334,runtime.rs:2948) all use it for "this graph samples tokens", the same predicate.prefillis summed only for the non-Resumekinds (runtime.rs:1669-1677), so a resume graph contributesprefill = 0and just its committed tokens — consistent withdocs/api.md:383-386. - Newest commit 66245920, part 2: the
first_scheduled_nsstamp now follows both pack paths (runtime.rs:2259-2275, after the vision branch andcrate::model::pack_inputs), andOk(())is returned only after the stamp loop, so a failed pack leaves the instant unset; a pack failure propagates out ofWorker::run(runtime.rs:1154) and fails every request, so no completion can be counted with an unset instant andrequest_completed's queue/prefill/inference block (metrics.rs:581-591) cannot be silently skipped. The handle filterfilter(|a| a.request == lane.request)keeps a recycled slot from being stamped. The metric effect is that queue time now includes one step's input packing, whichdocs/api.md:329-331("the first model step that includes the request") permits. - Counter/histogram coupling:
request_completed(metrics.rs:545-603) is the only writer of the completion counter, and both former directfetch_addsites inruntime.rsnow go through it (:1866,:2029). - Populations match the docs:
output_limitedonly onreason == "length"(runtime.rs:2029→metrics.rs:559-561); time histograms requirefirst_token_ns(metrics.rs:577-602) so zero-token completions enter only token/preemption/output-limit series (docs/api.md:328-341); decode/TPOT requiregenerated_tokens > 1(metrics.rs:593-602);request_max_tokensonly when nonzero (metrics.rs:570-573). - Preemption lifecycle:
RequestRecordridesIncomingthrough park and requeue (runtime.rs:2101-2102,:2126,:2637-2664),max_tokensis set once under!readmitted(runtime.rs:1566-1570),preemptionsis bumped at the park, andinter_tokenaccumulates one interval per committing step atposition == 0and is absorbed at completion (metrics.rs:576). cache_lookup_tokensis added at the site that already countscache_lookups(helios/src/scheduler.rs:1801-1802), is zero for prompt-scoring (scheduler.rs:1601), and is copied inmetrics.rs:768-771; matching additions inscheduler/tests.rs(not opened).- Admission rejections have exactly four writers —
server.rs:816(http_slots, 429),http.rs:237-240(multi-choice slot exhaustion),runtime.rs:868-869(generation_capacity),runtime.rs:943-945(request_queue) — while both 503 paths (paused admission, unavailable runtime) are uncounted, asdocs/api.md:377-382states. flare_parked_requestsis written only bypublish_gauges(runtime.rs:1202-1211) and zeroed at shutdown (runtime.rs:749-750), fed byself.parked, matchingdocs/api.md:372-376./v1/messages/count_tokenscannot enter the e2e histogram (returns athttp.rs:284-286).docs/api.mddefines every new series with its population (:305-386) and maps vLLM's production list (:485-515), explicitly stating novllm:names are exported and thatkv_cache_usage_percis "not provided as one ratio" (:490) — a narrowed, honest reading ofCloses #536(#537/#549 supply that ratio).
Open questions
- Should a multi-choice response in which one choice hits the tool limit contribute e2e and choice observations for the choices that completed? The fix for the should-fix depends on that product decision.
- Should a non-stream response whose body the client never reads be counted in
flare_request_e2e_seconds? The code says yes, the doc is silent; the stream path says the opposite. - Is a zero-token model step (all lanes errored) meant to be a
flare_model_step_tokenssample?
Evidence limitations
- No compiler or live scrape was available in this review. The build-break resolution is established from the file list (
pr_files: nometrics/process.rs(not opened)), a tree-wide search finding noprocess_*series ormetrics::processreference, and the deletion in commit54e06b30;cargo check --features serverwould settle it in seconds. - The author's scrape (PR comment, 2026-11-28) ran on an image built from upstream
mainwith this PR, #549 and #560 merged, not on the PR alone; the unrun items (multi-GPU cores, Windows build, isolated recording cost) are disclosed in the description, which is the right practice per the repository's disclosure rule. The per-series export and the counter/histogram delta equality are therefore evidenced, but not independently reproduced here. - The "merges cleanly with #549 in either order" claim is asserted, not tested; both touch the same docs table and adjacent fixtures.