Correctness report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/226124f7-185b-490f-8c01-7dec0b97ab3e.md

Correctness review — PR #548 "Add request latency histograms and process metrics"

Head ebecef1, base main, 8 files (+545/−20). Lens: correctness — does the change work everywhere it reaches, across every caller, configuration, platform and edge path.

Key findings

Two should-fix issues, both about flare_request_e2e_seconds membership versus the runtime histograms and the new documentation, plus three nits in the new Linux process module. Nothing blocking: the counter/histogram coupling, the histogram arithmetic, the bucket rendering, the JSON snapshot and the non-Linux compilation all check out.

  1. Should fix — flare_request_e2e_seconds includes responses the runtime counts as cancelled, contradicting the invariant the new docs paragraph states (docs/api.md:312-313) and the PR description ("Cancelled and failed requests stay out of these histograms").
  2. Should fix — streaming e2e requires the client to drain the SSE body while non-streaming records before the body is polled, an operator-visible asymmetry the docs do not state.

Findings

Should fix 1 — e2e histogram observes cancelled (tool-limit) responses

Where: helios/src/server/http.rs:614-617 (stream) and helios/src/server/http.rs:631-635 (non-stream); cause at http.rs:471-476, http.rs:526, http.rs:563-567.

What the code does. When the output encoder hits the parallel-tool limit, the delivery loop marks the generation cancelled:

The terminal GenerationEvent::Finished still flows through the encoder and the loop ends with yield Delivery::Complete(response); (http.rs:598). Both delivery arms then observe e2e unconditionally inside the Complete arm, guarded only by !count (the count_tokens exclusion):

Delivery::Complete(_) => {
    if !count { metrics.request_e2e.observe(&super::metrics::REQUEST_SECONDS, admitted_at.elapsed().as_nanos() as u64); }

Why it is wrong under this PR's own rule. On the cancelled-by-tool-limit path the runtime counts the request in metrics.cancelled, never in request_completed: the parked path increments self.metrics.cancelled and calls incoming.finish_cancelled(...) at runtime.rs:1334-1342, the active path at runtime.rs:1343-1364, and neither reaches Metrics::request_completed (metrics.rs:452-480). So the request lands in flare_requests_cancelled_total and in flare_request_e2e_seconds, but in none of flare_request_queue_seconds, flare_request_prefill_seconds, flare_request_decode_seconds, flare_time_per_output_token_seconds, flare_request_prompt_tokens, and not in flare_requests_completed_total.

The new docs paragraph states the opposite as an absolute: docs/api.md:312-313 — "Cancelled and failed requests enter only flare_requests_cancelled_total and flare_requests_failed_total." An operator comparing flare_request_e2e_seconds_count against flare_requests_completed_total or against the other request histograms is therefore comparing different populations. This also bears on the repository rule in AGENTS.md:182-186 about not weakening guarantees: the docs claim an invariant the code does not hold.

Nuance found while verifying. Because generation.cancel() at http.rs:565 is inherently racy against the runtime's own natural-finish path, a tool-limit request may additionally be counted by request_completed (runtime.rs:1993-1998) if the runtime finishes before it observes the cancel flag. In that case the same request appears as completed and the client still sees Termination::Cancelled. Membership of these requests in the histograms is thus timing-dependent, which is worse for dashboards than a fixed rule.

Fix. Either (a) gate the e2e observation on the response not being cancelled — e.g. skip the observation in the Complete arm when the encoder reported tool_limit_reached, or thread the termination through Delivery::Complete and observe only for successful terminations — or (b) narrow docs/api.md:312-313 so the "only cancelled/failed counters" sentence covers the five runtime histograms and say explicitly that e2e measures every response delivered to the client. Option (a) keeps the stated invariant; option (b) is a docs-only change but must then also explain the e2e/count divergence. A test that drives a request past the parallel tool limit and asserts flare_request_e2e_seconds_count versus flare_requests_cancelled_total would settle which rule is intended.

Should fix 2 — streaming e2e depends on the client draining the body; non-streaming does not

Where: helios/src/server/http.rs:600-620 (stream) versus helios/src/server/http.rs:629-641 (non-stream).

What the code does. For streaming, the Delivery::Complete arm lives inside the filter_map closure that backs Sse::new(events) (http.rs:604-620), so flare_request_e2e_seconds is observed only if the client polls the event stream to its terminal element. A client that disconnects mid-stream — the ordinary cancel path for chat UIs — never reaches it, even though the generation may have completed server-side.

For non-streaming, the observation happens in the handler (http.rs:631-632) before the JSON body is handed to axum, so it records even if the client never reads the response. The PR's own test asserts this: first_response_http_nonstream_records_only_when_completed_body_is_offered (phase_tests.rs:4461-4465) expects flare_request_e2e_seconds_count 1 for the poll_body == false case.

Why it matters. flare_request_e2e_seconds_count diverges from flare_requests_completed_total in opposite directions for streamed and non-streamed requests, and streaming is the majority traffic for chat. Docs api.md:301-302 says only "counts each successful generation from admission to the completed response", with no mention of body drain — while the adjacent first-response sentence (api.md:303-304) does say "once the client reads it". That inconsistency in the same paragraph will read as a guarantee for e2e that the code does not give.

Fix. State the asymmetry in docs/api.md (streaming observations require the client to read to the end; non-streaming records when the handler produces the response), or record e2e on the runtime completion path so both transports behave alike and cancelled/abandoned requests are excluded uniformly. The streaming early-disconnect case needs a test (phase_tests.rs) to pin the chosen behaviour.

Nits

Nit 1 — vision steps end queue time (runtime.rs:2187-2208)

reserve_and_pack stamps first_scheduled_ns in a loop over all step.lanes (runtime.rs:2192-2203) before the if step.kind == GraphKind::Vision split at runtime.rs:2208. For an image request the queue observation therefore ends at the vision step and flare_request_prefill_seconds absorbs the vision work. docs/api.md:306-307 says "the first model step that includes the request", and a vision step arguably qualifies, so this may be intended — worth confirming rather than fixing. If vision is meant to be the queue boundary, a comment at runtime.rs:2192 would save the next reader the analysis; if not, restrict the stamp loop to generation kinds.

Nit 2 — parse_stat returns Some on ambiguous /proc/self/stat (metrics/process.rs:19-32)

The parser splits the stat line at the last ), the conventional heuristic for a parenthesized comm that may itself contain ) (proc(5) recommends it). Because it returns Some on any line with a ), a malformed or shifted line yields systematically wrong CPU/memory/start-time values rather than omitting the metrics, which the module doc (metrics/process.rs:1-6) says is the behaviour for sources that cannot be parsed. Practical impact is nil for flare's own comm, so this is a nit; an alternative is to validate that the tail has exactly the expected field count and otherwise return None.

Nit 3 — process_open_fds counts its own directory read (metrics/process.rs:65-67)

Iterating /proc/self/fd includes the handle doing the counting, so the value is +1 relative to Prometheus' client_golang, which excludes it. The HELP string for the series says so ("including the directory read that counts them" at metrics/process.rs:115-123), which makes it a documented deviation rather than a defect — noted only because operators comparing against stock process dashboards (the stated motivation in #536) will see the offset.

Verified correct (checked in code, no finding)

Rules applied

Evidence limitations (as disclosed, and as I confirmed)

Open questions

  1. Is the tool-limit path supposed to appear in e2e (a client did receive a response), in which case docs/api.md:312-313 needs narrowing rather than the code changing? Finding 1's fix depends on that call.
  2. Is a vision step intended to terminate queue time (runtime.rs:2192-2203), or should first_scheduled_ns be stamped only for generation lanes?
  3. Should e2e be recorded at runtime completion for both transports so streaming and non-streaming agree (http.rs:600-641)? That would also make cancelled/abandoned streamed requests consistently absent.