Correctness review of PR #548 — per-request histograms and request metrics (head 6624592)
Key findings
Verdict: should-fix issues only. No blocking items.
- Should fix (1, latent):
helios/src/server/http.rs:604-612gates the HTTP e2e/choice observations on the response-wideencoder.tool_limit_reached, while the generated-token vector is per choice and the runtime counts each choice as its own completed request. A sibling choice that finished naturally therefore gets noflare_request_e2e_seconds,flare_request_choices, orflare_request_max_choice_generated_tokensobservation — a counter/histogram divergence thatdocs/api.md:311-326does not list. Unreachable through the public API today (tools are rejected for Completions;n > 1is rejected elsewhere), so it is latent, not live. - Nits (4): a dead
!countguard; non-stream e2e observed before the body is polled while the docs state the drain rule only for streams; decode/TPOT described as excluding a preemption wait they in fact include;flare_model_step_tokensrecording a 0-token sample for a step whose every lane errored. - Previously blocking, resolved: the
--features serverbuild break from commitd64c3ea3(metrics/process.rs(not opened) calling the feature-gatedcrate::runtime_core) is gone — commit54e06b30deletedhelios/src/server/metrics/process.rs(not opened), that file is absent from the PR's nine changed files, and noprocess_*series remain.
I read all nine changed files in context (docs/api.md, helios/src/scheduler.rs, scheduler/tests.rs, server.rs, server/http.rs, server/latency.rs, server/metrics.rs, server/runtime.rs, server/runtime/phase_tests.rs), including the one new commit 66245920 this round, and followed each changed function to its callers.
Should fix
1. Response-wide tool-limit gate drops sibling choices' e2e and choice 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
What is wrong. encoder.tool_limit_reached is one flag for the whole response: declared at helios/src/server/protocol/encode.rs:89, 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 to force Termination::Cancelled (encode.rs:598) and to drop the stop (:604). Per-choice state is separate: generated is vec![0u32; size] at http.rs:407 with generated[index] = generated_tokens at http.rs:530, and response_completed (metrics.rs:608-618) then emits one request_choices and one request_max_choice_generated_tokens observation per prompt chunk.
The runtime, in contrast, counts each choice as a completed request: flare_requests_completed_total is incremented only in Metrics::request_completed (metrics.rs:545-603, the completed.fetch_add at :558), called from the stop path at runtime.rs:1866 and the finish path at :2029-2038 — one call per choice, since Metrics::cancelled is a different counter (runtime.rs:1329-1330, :1350, :1373, :1420). The parallel tool-limit stop is a client-side decoder cancel (http.rs:569-573) after the runtime has already recorded the request as complete.
Why it matters. A response in which one choice trips the parallel tool limit suppresses the HTTP observations of every choice — including choices the runtime counted as successful completions. flare_request_e2e_seconds_count then trails flare_requests_completed_total by more than the documented causes. docs/api.md:311-326 lists only /v1/messages/count_tokens and "responses the runtime records as cancelled, such as a parallel tool-limit stop" as exclusions, and states that a multi-choice response adds fewer observations than completions only because the e2e observation is once per response while completions are per model request (:314-316) — it does not say a response is dropped wholesale because one sibling was cancelled.
Reachability. Latent today: tools are rejected for /v1/completions (protocol/decode.rs:813-815, reject(&body, &["tools", "tool_choice"])) and n > 1 is rejected for every other protocol (decode.rs:753-755, "n must be 1"). No public request can combine a tool-carrying response with multiple choices. It becomes live the moment tools are allowed on Completions.
Fix. Either decide per generation — http.rs:530-532 already knows which index was cancelled, so track cancelled indices and pass only the surviving choices to response_completed, still observing e2e once per delivered response — or state the response-wide rule in docs/api.md beside the e2e population text at :311-318.
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:4650-4720) that posts a two-choice completions request with tools enabled and asserts either flare_request_e2e_seconds_count == 2 or == 0 against flare_requests_completed_total. That the request cannot currently be constructed is itself the evidence the path is latent.
Nits
http.rs:606—!countis dead. Count responses return athttp.rs:284-286(if count { return Json(json!({"input_tokens": ...})).into_response(); }) before the delivery stream is ever built, so the guard can never be false here. Harmless, but it reads as a live condition.http.rs:606-612vs:642-651— non-stream e2e is observed before the body is polled. The generator runs the observation and thenyield Delivery::Complete(response)(:613); for the non-stream arm the body is only constructed afterwards as a lazy stream (:642-651), and the stream arm (:615-637) may be abandoned. So a non-stream client that never drains the body still gets an observation, whiledocs/api.md:317-318states the drain requirement only for streams ("For a stream it is observed when delivery completes, which requires the client to drain the body"). The asymmetry is defensible — say so in one clause, or move the observation into the response path.metrics.rs:593-601vsdocs/api.md:342-345— decode and TPOT include the preemption wait, but only the inter-token entry says so.decode = times.last_token_ns.saturating_sub(first)andtime_per_output_token = decode / (generated_tokens - 1)span first-to-last committed token, so a request preempted and readmitted mid-decode carries the whole readmission wait into both.docs/api.md:342-345discloses the preemption wait forflare_inter_token_latency_secondsonly; add the same clause to the decode/TPOT paragraph at:340-341.runtime.rs:1721-1722—flare_model_step_tokensobserves 0 for an all-error step.self.metrics.model_step(prefill + generated.len() as u64)runs wheneverkind.samples(), including a step whose lanes all completed withrecord.status == 3(error frames), contributing a zero-token sample that lowers the reported mean.docs/api.md:383-386describes the population as completed graph work and does not exclude zero-token steps; either skip the observation when the sum is zero or say the sample includes it.
Verified correct (checked this round, no finding)
- Counter/histogram coupling.
request_completed(metrics.rs:545-603) is the only writer offlare_requests_completed_total—completed.fetch_addappears nowhere else inhelios/src/server— so the runtime histograms cannot drift from the counter. output_limitedsemantics. Set only whenoutput_limit, which isreason == "length"on the finish path (runtime.rs:2028-2037),falseon the stop path (:1875-1884), matchingdocs/api.md:366-368.- Record lifetime across preemption.
RequestRecordsurvives park/requeue (runtime.rs:2101-2102,:2126,:2637-2664);max_tokensis written once under!incoming.readmitted(runtime.rs:1566-1570) as the limit at first admission including the deferred reasoning budget, matchingdocs/api.md:355-358;preemptionsis bumped only inpark_if_preempted(runtime.rs:2099-2102), not for the reasoning-budget park or the host requeue, matchingdocs/api.md:359-360. first_scheduled_nsstamping moved after both pack paths (runtime.rs:2258-2275);Ok(())returns only after the stamp loop, so a failed pack leaves the instant unset and no counted completion can lack its queue/prefill observations. The slot-reuse filter (filter(|a| a.request == lane.request)) prevents stamping a recycled slot.kind.samples()(execution/manifest.rs:90-101) returns exactly the seven variants the deleted inlinematches!listed, soflare_model_step_tokenspopulation is unchanged;Resumeis excluded from theprefillsum (runtime.rs:1669-1677), consistent withdocs/api.md:383-386.- Forced reasoning close bumps
carried.generated_tokens(runtime.rs:427-439) andscheduler.record_decoded_token(scheduler.rs:1111, called atruntime.rs:1968) symmetrically, sorequest_completed'sgenerated_tokensstays consistent withflare_generated_tokens_total. - Gauges.
flare_parked_requestsis written only bypublish_gauges(runtime.rs:1202-1211) and zeroed at shutdown (:749-750); admitted host-restore waiters live inself.active(:1578-1591), so they cannot inflate pending/parked, matchingdocs/api.md:372-376. flare_admission_rejections_totalwriters are exactlyserver.rs:816(http_slots),http.rs:237-245,runtime.rs:868-874(generation_capacity),runtime.rs:944-947(request_queue); the paused-admission and unavailable-runtime 503s are uncounted, matchingdocs/api.md:377-382.flare_cache_lookup_tokens_totalis added at the single site that already countscache_lookups(scheduler.rs:1801-1802), withlooked_up = 0for prompt scoring (scheduler.rs:1600), and copied inmetrics.rs:768-771.
Rules applied
- Charter line 42 (supported matrix & compatibility: check interactions across every supported cache scheme, parallel layout, hardware target and documented API surface) — the reason the per-choice
n/tool-limit interaction and the stream/non-stream body-drain asymmetry are in scope. - Charter line 13 ("don't silently ignore API fields") and AGENTS.md:182-186 (not opened) (do not weaken guarantees) — relevant where
docs/api.mdstates a population the code does not implement for sibling choices. - AGENTS.md:194-199 (not opened) and
docs/design-review.md(not opened) principle 12 (validate the real path and report evidence honestly; disclose unrun checks) — the PR description does disclose its unrun items, so this is satisfied.
Open questions and what could not be settled
- Sibling-choice exclusion: whether the response-wide gate is intended. Only a maintainer answer or a phase test over a two-choice completions request with tools (unconstructible today) settles it.
- No compiler or live scrape in this review. The author's scrape (PR comment 2026-11-28 03:26) ran on an image built from upstream
mainwith this PR, #549 and #560 merged; the PR also discloses that multi-GPU cores, the Windows build, and the isolated recording cost were not run.cargo check --features serverand one scrape under a tool-carrying multi-choice request would close the remaining gap. - Scope of
Closes #536:docs/api.md:477-490states novllm:names are exported and markskv_cache_usage_percas "not provided as one ratio" (that ratio is #549's). This is a narrowed claim in the doc text, not a false one — a scope observation for the docs lens, not a correctness finding here.