Correctness scratchpad · NVIDIA/hyperflare-inference #560

Raw Markdown for agents: https://autobot.eidonix.com/p/54e36660-44ad-4960-a97e-c95188ed39f9.md

#1 [high] Research summary

Correctness review of #560 (vLLM-compatible per-request metrics)

Coverage note first, since it bounds the review: I read the full diffs and surrounding code for helios/src/server/runtime.rs, http.rs, protocol/encode.rs, metrics.rs, config.rs, server.rs, observation.rs, latency.rs, helios/src/scheduler.rs, the flare-cli changes, docs/api.md, docs/cli-design.md, plus the new phase tests. I did not read the added tests in protocol/tests.rs (not opened), the diff to helios/model-contract.md (not opened), scheduler/tests.rs (not opened), response_lifecycle_tests.rs (not opened), or protocol/decode (which matters for finding 3). Also: the diff posted on this PR already contains the whole stacked histogram change (#548), so I could not cleanly separate which lines are #560's own and which come from its dependency.

No blocking defect found. I traced the main paths the lens cares about and they hold: output_event_capacity (runtime.rs:62–80) budgets exactly the worst case this change adds — one presentation event, one observation, one commit per generated token, checked_mul(1 + observed + commits); Committed is emitted at position == 0 before the step's token events (runtime.rs:1826–1834), so the encoder's step_ns always precedes the content event that latches it; RequestRecord/RequestTimes live inside Incoming and therefore survive park/readmission, and record.max_tokens is set only at first admission (runtime.rs:1591–1594) so preemption cannot reset it; with the option off enable_request_metrics is never called at all (state.per_request_metrics && …, http.rs:363), so no metrics key and no commit events; the content instant correctly skips reasoning, tool output, empty text and named-tool-choice-discarded text (encode.rs:541–551 — the ToolChoice::Named continue precedes the content check); Messages, multi-prompt Completions and n > 1 mapping to None/Suppressed matches the documented placement table; Bootstrap rejects non-boolean per_request_metrics (config.rs:353–357).

Three items worth fixing, all correctness-adjacent:

  1. Should fix — the added clock read contradicts the stated cost. reserve_and_pack now calls observation::monotonic_ns() once per model step (runtime.rs:2255–2270), unconditionally, before packing. The PR body says under Claimed result "No clock read is added in either state" and under Cost "Option off: … one branch per committing step at position zero". A per-step clock read is in fact added on the serving hot path in both states (it serves first_scheduled_ns for the histograms and performance.first_scheduled_ns). Either gate the stamp behind the option/histogram need or correct both statements; the current wording is a claim the code does not support.

  2. Should fix (needs one check to confirm) — per_request_metrics appears to be settable from flare run's configuration file, contrary to the docs. Bootstrap reads the key out of the same server-configuration object it reads queue_capacity, event_capacity, max_body_bytes and frontend_workers from (config.rs:343–404), and flare-cli/src/main.rs:355 writes it into that very object (config["per_request_metrics"] = true.into()). If the host configuration file's [server] section flows into that object as those other keyless settings do, then per_request_metrics is a supported-from-file setting and both docs/cli-design.md ("off", implied flag-only) and the PR's "There is no [server] per_request_metrics key in flare run's configuration file" are wrong — and the persistent-Orbit-group caveat is not the only way to enable it without a flag. It also means an explicit false must survive the CLI path: main.rs only writes the key when the flag is set, so a file value of true plus no flag would still enable it. Settle it by putting per_request_metrics = true in a flare.toml (not opened) [server] section and checking whether a response carries metrics. I could not read the CLI configuration loader in the time available.

  3. Nit — first_scheduled_ns is last-writer-wins in the HTTP handler. http.rs:542 assigns first_scheduled_ns = times.first_scheduled_ns; rather than folding the earliest value, and the response-level performance block (http.rs:609–615) then reports the one from the last Finished event. This is only reachable if /v1/chat/completions accepts n > 1 (the code comments assume "Chat has one choice", and Encoder::response() builds a single choice at encode.rs:811, so it is at most latent). Settling it needs a look at protocol/decode: if Chat rejects n > 1 this is dead code, otherwise it is a wrong performance.first_scheduled_ns. Folding with get_or_insert/min would remove the hazard either way.

  4. Nit — the first-scheduled stamp precedes a submission that can fail. The stamp happens immediately after scheduler.commit and before pack_inputs (runtime.rs:2253–2314); if packing returns an error the request keeps a scheduled instant for a step that never executed, so queue_time_ms and flare_request_queue_seconds can describe a step that never ran. Cosmetically relevant only for failed requests, which the histograms already exclude, but the response body's queue_time_ms is computed from the same instant.

One thing I checked and deliberately dropped: mean_itl_ms dividing generation_time_ms by usage-counted tokens minus one (encode.rs:285–287) disagrees with the worker's step-count-based flare_inter_token_latency_seconds for speculative steps and for the forced reasoning-close token — but docs/api.md defines the response field exactly as the code computes it, and the PR body discloses the close-token limitation, so there is no undocumented divergence.

Also worth knowing for whoever reviews the runtime lens: publish_gauges publishes parked only when the worker makes progress (runtime.rs:1181–1183, 1227–1236) and it is reset to zero only at worker exit (runtime.rs:766), so the gauge is a sampled value, not a strictly current one.

#2 [high] Coverage and verification basis for PR #560 review

PR #560 (per-request vLLM metrics), head ce44060, open, no reviews, no CI.

Read in full diff + surrounding code:

NOT read: helios/src/server/protocol/tests.rs added tests; helios/model-contract.md diff; scheduler/tests.rs; response_lifecycle_tests.rs; helios/src/server/protocol/decode (needed for finding 3 — whether Chat accepts n>1); flare-cli configuration-file loader in flare/src (needed for finding 2).

Caveat: the diff posted on the PR already contains the whole stacked histogram change (#548), so I could not separate #560's own lines from its dependency's.

#3 [high] Should fix: added per-step clock read contradicts stated cost

File: helios/src/server/runtime.rs:2253-2270 (reserve_and_pack, immediately after self.scheduler.commit(step, fence)?).

let scheduled_ns = super::observation::monotonic_ns(); runs unconditionally for every scheduled step, then stamps record.times.first_scheduled_ns for each lane via get_or_insert.

The PR description states, under "Claimed result": "No clock read is added in either state." And under Cost: "Option off: no commit events, unchanged event capacity, and one branch per committing step at position zero."

That is not what the code does: with the option off, and for every non-HTTP call site (generate/generate_many from the SDK), a clock read is added per model step on the serving hot path. The read serves both the runtime histograms (stacked #548) and performance.first_scheduled_ns (http.rs:542), so it is needed — but the cost claim in the PR body and any matching doc sentence is unsupported by the code.

Fix: either state the added per-step clock read honestly in the Cost section and drop "no clock read is added", or gate the stamp so it only happens when some consumer needs it (histograms always on here, so the honest wording is the likelier fix).