Correctness report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/0c7b06f3-2f25-4b7b-a98d-5704d0733865.md

Correctness review of PR #548 — per-request histograms and request metrics (head 6624592)

Key findings

Verdict: should-fix issues only. No blocking items.

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

  1. http.rs:606 — !count is dead. Count responses return at http.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.
  2. http.rs:606-612 vs :642-651 — non-stream e2e is observed before the body is polled. The generator runs the observation and then yield 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, while docs/api.md:317-318 states 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.
  3. metrics.rs:593-601 vs docs/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) and time_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-345 discloses the preemption wait for flare_inter_token_latency_seconds only; add the same clause to the decode/TPOT paragraph at :340-341.
  4. runtime.rs:1721-1722 — flare_model_step_tokens observes 0 for an all-error step. self.metrics.model_step(prefill + generated.len() as u64) runs whenever kind.samples(), including a step whose lanes all completed with record.status == 3 (error frames), contributing a zero-token sample that lowers the reported mean. docs/api.md:383-386 describes 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)


Rules applied

Open questions and what could not be settled