Correctness scratchpad · NVIDIA/hyperflare-inference #560

Raw Markdown for agents: https://autobot.eidonix.com/p/ab8f3211-96aa-41e8-9fd1-d043e3a6ee04.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).

#5 [high] Blocking: Python Ignition config schema rejects [server] per_request_metrics

Severity: blocking (documented enablement path breaks a supported tool).

docs/api.md:1007-1009 now tells users to enable the feature with [server] per_request_metrics = true "in the host configuration"; docs/cli-design.md:1317-1319 lists per_request_metrics as a [server] key native flare run applies, and cli-design.md:1349 shows it in the example config.

But the same file is read by the Python preparation CLI, which validates it against a closed schema:

Consequence: a user who follows the new docs and writes [server] per_request_metrics = true into ~/.config/flare/config.toml gets, on every ignition export/debug-serve/bench/convert/edit/join, UsageError: unknown key per_request_metrics in [server]. Because the key is documented as the recommended enablement, this is a live regression in the preparation path, not just a doc gap.

Fix: add "per_request_metrics": bool to ignition/cli/config.py:23-24 _SECTIONS["server"], and decide whether debug-serve forwards it (see separate note). Add one case to tests/cli/test_config.py's invalid-key parametrization plus a positive load test.

Settled by reading the code; a single ignition export with that key in the file shows the error.

#6 [high] Should fix: no way to turn the option off from the CLI once the config enables it

Severity: should fix.

flare-cli/src/config.rs:73-75: if !run.enable_per_request_metrics { run.enable_per_request_metrics = self.server.per_request_metrics.unwrap_or(false); } and flare-cli/src/main.rs:355-357 writes the key only if args.enable_per_request_metrics.

enable_per_request_metrics is a plain bool (cli.rs:649 orbit, :863 run). There is no --no-enable-per-request-metrics and no tri-state, so an explicit false is indistinguishable from omission.

Two consequences:

  1. docs/cli-design.md:1321-1322 states "Flags override these defaults, including explicit zero limits and values equal to the built-in defaults", and cli-design.md:1337-1338 says per-node configuration is overridden by flags. With per_request_metrics = true in a node's file, a user cannot disable it for one run by any flag. Sibling settings do offer explicit defaults: --kv-cache-limit memory is re-emitted when matches.value_source("kv_cache_limit") == CommandLine (cli.rs:662-667), and --scheduler-checkpoint-extra-work-fraction 0 is accepted. This option has no equivalent.
  2. Persistent Orbit groups: rank_zero_options returns the flag only when true (cli.rs:698-700), and controller.rs:691-692 merges saved spec.rank_zero with new options by extension. So a saved group that captured --enable-per-request-metrics keeps it forever; removing it requires editing the config file, which is exactly the path that cannot express false either.

Fix: make the flag a tri-state (Option<bool> via num_args(0..=1)/--enable-per-request-metrics[=BOOL]) or add --no-enable-per-request-metrics with overrides_with, and forward the explicit false to rank zero as a config override. At minimum, state the limitation in docs/cli-design.md beside the flag.

Verified by reading cli.rs/config.rs/main.rs; no test asserts a false override (config.rs:222-233 tests only "" / true / false in the file, always with the flag turning it on).

#7 [high] Should fix: per-step clock read and vision packing charged to queue time

Severity: should fix (scoped write-up; the family may also be a stack issue).

New loc: helios/src/server/runtime.rs:2269-2285 — the stamp moved after packing (good), but two behaviours remain:

  1. Unconditional clock read per model step. let scheduled_ns = super::observation::monotonic_ns(); runs for every reserve_and_pack regardless of --enable-per-request-metrics and regardless of whether the request came from HTTP (generate/generate_many from the SDK reach this path). The PR body still says "No clock read is added in either state" and the Cost section says the only added work with the option off is copying instants into the terminal event. #548's body declares "one clock read per model step" as its own cost (read_item 548, What changed/Result), so the read most plausibly belongs to the base #548; #560 nonetheless inherits it and repeats the "no clock read" claim. Fix: attribute the read to #548 in #560's Cost (or gate it), and drop "No clock read is added in either state".

  2. A step's requested class is no longer the class it executes in. reserve_and_pack stamps whatever step.lanes contains, and step.kind is only what the plan requested. On the vision path the same function calls pack_vision and conditioned_inputs_ready (runtime.rs:2228-2259 during GraphKind::Vision); #548's review already noted first_scheduled_ns stamped before the Vision split absorbs vision work into flare_request_prefill_seconds. After the move it is stamped after vision conditioning too, so queue_time_ms for a vision request measures image conditioning as queue delay and time_to_first_token_ms starts after it. Docs (docs/api.md:1013-1017 "Model-queue arrival to the first model step that includes the request"; helios/model-contract.md:346-352 "when the worker reserves and packs that step before submitting it") describe a scheduling instant, not a packing instant. Only reachable for image requests with per_request_metrics/return_token_timestamps on.

Also worth stating: the stamp precedes submit's own guards — nothing after the stamp can fail for that step, but scheduler.commit and the pack both can, and on failure the field stays unset (documented at runtime.rs:2269-2271, and now accurate).

Verified in code; the earlier "stamp precedes a failing pack" nit is resolved by the move and is dropped.

#12 [high] Research summary

Reviewed PR #560 at head 046aaef through the correctness lens, re-checking everything against the six commits pushed since my last turn (the content-instant removal, the post-pack first_scheduled_ns stamp, the [server] per_request_metrics configuration key, and the Ignition/CLI plumbing).

Verdict: one blocking, three should-fix, two nits.

Blocking (new this turn, created by the added configuration key): docs/api.md:1007 (not opened) and docs/cli-design.md:1317-1349 now tell users to enable the feature with [server] per_request_metrics = true in ~/.config/flare/config.toml (not opened), but that same file is read by the Python preparation CLI, whose schema at ignition/cli/config.py:21-33 is closed and whose validator at :108-114 rejects unknown keys. Every ignition export/debug-serve/bench/convert/join (serve.py:127,174,264,431,590, bench.py:144 (not opened), publishing.py:31-194 (not opened)) would then fail with unknown key per_request_metrics in [server]. The PR touched neither config.py nor tests/cli/test_config.py, and cli-design.md:1313 says "Ignition and native Flare read this file". Following the new docs breaks model preparation.

Should fix: the boolean flag cannot express an explicit false, so a node config that enables the option cannot be turned off for one run and a saved Orbit group can never drop it, contradicting cli-design.md:1321-1322 and the sibling settings' explicit-default handling; reserve_and_pack still takes an unconditional per-step clock read (runtime.rs:2272) while the PR body still claims no clock read is added; the stamp now lands after vision packing (runtime.rs:2269-2285), charging image conditioning to queue_time_ms and TTFT for vision requests; and api.md:1013-1034 (not opened) describes a permanently-null field as an "unreached instant" and overstates the n > 1 null to protocols that reject n > 1 at decode.rs:753.

Resolved since my last report: the first_scheduled_ns last-writer-wins nit is gone (http.rs:538 now folds the minimum), and the failing-pack nit is gone (the stamp moved after packing). I re-verified HTTP placement for all four protocols, RequestTimes lifetime through preemption, and that GraphKind::samples() reproduces the old inline match exactly.

Findings are entries #5-#11 in the scratchpad; #4 is the superseded previous report and #5-#7 supersede its verification notes.

#13 [high] Verdict for head 046aaef (supersedes entry 4)

Head 046aaef, open, ready for review, no reviews, no CI on head. Replaces my entry #4 (written against the previous head); #5-#7 supersede its verification notes.

One blocking (new, created by the configuration-key commit f0ccabcc):

Three should-fix:

Two nits:

Resolved since #4 and worth stating so the next reviewer does not re-raise them: http.rs:538 now folds the minimum (was last-writer-wins), the failing-pack nit is gone, and first_scheduled_ns for a response whose choices never ran is null as model-contract.md:349-351 says.

Not run / not verified: multi-GPU cores and the Windows build (author-admitted); flare-winui bridge's Settings construction (see #11); whether #562 lands first and changes the api.md content-token wording.

#14 [high] Coverage basis for the 046aaef review

Files I read in context at head 046aaef (this turn):

NOT read this turn: helios/src/server/protocol/tests.rs added tests (used only the diff text), helios/src/server/runtime/phase_tests.rs new tests (diff text only), response_lifecycle_tests.rs, helios/src/scheduler.rs diff, latency.rs, flare/src/controller.rs around :2563, flare-winui/bridge.

Caveat that still applies: the PR diff on GitHub contains the whole stacked #548 change, so I could not separate #560's own lines from its dependency's by diff alone; I used #548's own item description to attribute the per-step clock read.

#8 [medium] Nit: ignition debug-serve and write_initial ignore the new key; stale unknown-key sentence

Severity: nit (but it is a silent divergence between two commands that read the same file).

[server] per_request_metrics now reaches flare run (flare/src/configuration.rs:34, flare-cli/src/config.rs:73-75) and the desktop controller (flare/src/settings.rs:224, controller.rs:2566). flare orbit run forwards it only when the flag is set (cli.rs:698-700), and the Orbit per-node configuration is read by flare run on each node, so nodes still pick it up — consistent.

But the Python ignition debug-serve path builds the same server-configuration object that Bootstrap parses (ignition/cli/serve.py:485-487 sets options["thinking_token_budget"] and options["scheduler_checkpoint_extra_work_fraction"] from configuration.get("server.*")) and does not set per_request_metrics. Once the Ignition schema accepts the key (see the blocking note), ignition debug-serve will silently ignore a setting that flare run honours, while honouring its two neighbours. Fix: add options["per_request_metrics"] = configuration.get("server.per_request_metrics").value beside :487, or document that debug-serve ignores it.

Related doc gaps to fix in the same pass:

Verified by reading both CLI trees; nothing here needs a test to show the code paths, only a live run to see the user-visible error.

#9 [medium] Should fix: api.md null-field wording contradicts "always present, null when unreached" and overstates n>1 null

Severity: should fix (documentation claim contradicted by the same PR's code, and by #562).

New head 046aaef moved the content instant to #562. docs/api.md:1013-1018 now says time_to_first_content_token_ms is "Always null: Flare does not report when answer text first appeared", and the PR body says it "is always null; vLLM allows null when a value is unavailable, and a follow-up PR reports it for streams".

But helios/src/server/protocol/encode.rsmetrics_value (encode.rs:251-278) hard-codes "time_to_first_content_token_ms": Value::Null and the field is still emitted on every object, so today the doc is true. The issue is the shape the docs promise: "All six fields are always present, and a field is null when the request did not reach the instants it spans" (api.md:1032-1034). A field that never has a value is not an unreached instant; documenting "always null" invites clients (llama-swap and billing tools named in the PR body) to treat it as a supported-but-unavailable measurement, exactly what it is not on the server side today.

Two smaller, checkable doc/code mismatches in the same area:

  1. api.md:1030-1032: "With n greater than one metrics is null, and Completions with several prompts omit it." The code agrees for n>1 only when the protocol can express it — decode.rs:753 rejects choices != 1 for every protocol except Completions, so Chat/Responses n>1 is an HTTP 400, never a null. The sentence is not wrong for Completions but implies all protocols; say "Completions with n greater than one".
  2. api.md:1030 "a field is null when the request did not reach the instants it spans, such as mean_itl_ms for a single generated token": encode.rs:262-268 also nulls time_to_first_token_ms, generation_time_ms, queue_time_ms and tokens_per_second when first_scheduled_ns/first_token_ns are unset (first.map(|_| timing.times.last_token_ns) makes generation depend on first), and protocol/tests.rs:2446-2448 pins the all-null object for an output-limited zero-token response. Worth one clause so the zero-token response shape is documented.

Verified in encode.rs and protocol/tests.rs. Not verified: what #562 changes; if it lands first, re-read api.md:1013-1018 for the merged wording.

#10 [medium] Verified-clean coverage notes for head 046aaef

Severity: nit. HTTP-layer placement is correct at this head; recorded so the next reviewer need not redo it.

Checked at head 046aaef:

One thing I could not settle from code: whether a Chat request with return_token_timestamps and n=1 but a zero-token response emits performance with first_scheduled_ns: null — the docs say "It is null when no model step included the request" (model-contract.md:349-351), and http.rs:561-567 passes times.first_scheduled_ns per frame while :609 passes the folded value, so a response whose only choices never ran yields null. That matches the docs; no finding.

#11 [low] Unverified: WinUI bridge settings and the Windows build

Severity: nit / open question to state, not a defect I could show.

The PR body and docs say the option reaches the desktop controller "through flare settings" (flare/src/settings.rs:76-87, :224; controller.rs:2566 writes config["per_request_metrics"] = self.settings.per_request_metrics.into()). That is wired.

What I could not check: flare-winui/bridge/src/lib.rs:1319 FlareRuntimeSettings and :1381 build flare::settings::RuntimeSettings, not flare::settings::Settings, so the WinUI bridge's own settings struct does not obviously carry per_request_metrics — the field is on Settings (:32), which the controller builds in Worker (controller.rs:2563-2566). If the WinUI app constructs Settings through Settings::resolve(config, ..) from the same TOML, the option works there without a UI toggle; if it builds Settings by hand, it will compile only because per_request_metrics: bool is a plain field, and the Windows app will always send false. Settings has no Default impl to lean on, so a struct literal would have had to be updated — the fact that no such edit is in the PR's 22 files is weak evidence the app goes through Settings::resolve.

Also unverified: the Windows build. The PR says "Not run: multi-GPU cores and the Windows build". flare-cli/src/main.rs:261-272 has a separate #[cfg(windows)] path that builds authorized and then reaches the same config["per_request_metrics"] write at :355, so the code is shared; nothing in the diff is cfg-gated, which is the reason to expect it to compile. Worth one sentence in the PR's evidence rather than a finding.

Settle by building flare-winui on Windows, or by finding the Settings literal in the WinUI bridge. I did not read enough of flare-winui/bridge to call it.