Correctness review — PR #560 "Emit vLLM-compatible per-request metrics from runtime instants"
Head 046aaef, open, no reviews, no CI on the head commit, 22 files +1757/−77, base main. Reviewed against the charter (read_charter: the "Don't silently ignore API fields" and "no per-model flags" rules, and the supported-matrix rule at line 42) and against docs/cli-design.md / docs/api.md / helios/model-contract.md. All conclusions are from reading code; I built and ran nothing (the author likewise did not run multi-GPU cores or the Windows build).
Key findings
The metrics object itself is correct: it is gated once in http.rs, placed exactly where docs/api.md promises for all four protocols, arithmetically sound, and the request's instants survive preemption to reach the terminal event. The problems are all around it — enablement and override semantics (one blocking, one should-fix) and the cost/accuracy claims in the PR body and docs (two should-fix), plus three nits.
Blocking
B1. The documented way to enable the feature breaks every Python ignition command
- Files/lines.
docs/api.md:1007-1008anddocs/cli-design.md:1317-1319tell users to set[server] per_request_metrics = truein~/.config/flare/config.toml(not opened) (ignition/cli/config.py:19DEFAULT_PATH).docs/cli-design.md:1313states "Ignition and native Flare read this file". Butignition/cli/config.py:21-33_SECTIONS["server"]is{host, port, api_key, thinking_token_budget, scheduler_checkpoint_extra_work_fraction}— noper_request_metrics;config.py:108-114_validateraisesUsageError(f"{path}: unknown key {key} in [{section}]")for any key outside that schema (the type check at:115-118is the only other gate). EveryConfiguration.loadsite reaches it:ignition/cli/serve.py:127,174,264,431,590;ignition/cli/bench.py:144(not opened);ignition/cli/publishing.py:31 (not opened),73,174,194.docs/cli-design.md:1385confirms "Ignition rejects any section or key outside its schema". - Why it matters. A user who follows the new docs breaks the preparation path —
ignition export,debug-serve,bench,convert— on the very file Ignition is documented to generate (cli-design.md:1311-1312), with a usage error and no hint that the serving flag is fine. This is exactly the charter's "don't silently ignore/break API fields" spirit, and it makes the PR's only file-based enablement path unusable end to end. - Fix. Add
"per_request_metrics": boolto_SECTIONS["server"]atignition/cli/config.py:23-24(and_BUILT_IN["server.per_request_metrics"] = Falseat:37-40if the generated template should show it), plus a positive-load case intests/cli/test_config.py—:151-177today only parametrizes rejection.flare/src/configuration.rs:26-35shows the native side is#[serde(default)]withoutdeny_unknown_fields, so only Ignition is closed. The PR touched neither Python file.
Should fix
S1. No way to turn the option off once a config file or a saved Orbit group turns it on
- Files/lines.
flare-cli/src/cli.rs:646-649(Run) and:860-863(OrbitRun) declarepub enable_per_request_metrics: bool— plain boolean, no--no-…, no tri-state.flare-cli/src/config.rs:73-75resolves it asif !run.enable_per_request_metrics { run.enable_per_request_metrics = self.server.per_request_metrics.unwrap_or(false); }, so "explicitly false" and "flag omitted" are the same value.flare-cli/src/cli.rs:698-700emits the forwarded flag only when true.flare-cli/src/orbit/controller.rs:691-692merges a saved group withrank_zero.extend(options.rank_zero…), so a group that ever captured the flag keeps it and cannot be dropped. - Why it matters.
docs/cli-design.md:1321-1322promises "Flags override these defaults, including explicit zero limits and values equal to the built-in defaults", and:1337-1338promises "saved group options and explicit flags take precedence". Here the file (or group) always wins, and the operator has no escape hatch short of editing the file or the saved group — for a feature that changes every response body. - Same fix, related path.
flare-cli/src/main.rs:355-357writesconfig["per_request_metrics"] = trueonly when the flag is true, whileflare/src/controller.rs:2566always writes it from settings. A core whose exported server config declaresper_request_metrics: true(parsed athelios/src/server/config.rs:353-357) therefore stays on underflare runeven when the operator's file saysfalse. Latent today only because Ignition cannot emit the key (B1). - Fix. Make the flag tri-state (
Option<bool>, or--enable-per-request-metricspaired with--no-enable-per-request-metricsusingoverrides_withascli.rs:954-1020already does for boolean siblings), forward an explicit false to rank zero as a config override, and writeconfig["per_request_metrics"] = args.enable_per_request_metrics.into();unconditionally inmain.rs. At minimum, document the limitation. No test covers a false override:flare-cli/src/config.rs:222-234tests only omission,true, andfalse-in-file with the flag turning it on.
S2. The PR body's cost claim is contradicted: a clock read runs unconditionally, once per model step
- File/line.
helios/src/server/runtime.rs:2272let scheduled_ns = super::observation::monotonic_ns();sits insidereserve_and_pack, whichsubmitcalls atruntime.rs:2312for every scheduled step, for every request source, regardless of whether the option is on. - Why it matters. The description says "This PR adds no clock read; the one monotonic read per scheduled model step comes from #548" and "With the option off, the only work this PR adds is copying the request's instants into the terminal event" / "No clock read is added in either state". The first half is right; the second half is wrong, and a reviewer or release note relying on it will mis-attribute the per-step cost of the dependency. It is a claim/accuracy defect, not a behavioural one (the instant itself is correct and is folded with
get_or_insert, so only the first step of each request is stamped). - Fix. Attribute the read to #548 in the Cost/Result text and delete the "no clock read" sentence. Optionally, skip the read when neither the option nor observation is enabled — not required for correctness.
S3. docs/api.md misdescribes when metrics fields are null
- Lines.
docs/api.md:1040-1041: "All six fields are always present, and a field is null when the request did not reach the instants it spans, such asmean_itl_msfor a single generated token." Buttime_to_first_content_token_msis hard-codedValue::Null(helios/src/server/protocol/encode.rs:263) and the table at:1020even says "Always null" — so the preamble describes a value that is never measured as an instant the request failed to reach.docs/api.md:1042: "Withngreater than onemetricsis null", buthelios/src/server/protocol/decode.rs:753rejectschoices != 1for every protocol except Completions, so Chat and Responses clients get a 400, never a null; only Completions can reachRequestMetrics::Suppressed(encode.rs:238). And the zero-token shape — all six fields null becauselast = first.map(...)(encode.rs:257-273), pinned byhelios/src/server/protocol/tests.rs:2445-2448— is not documented at all. - Why it matters. The audience is gateways and billing tools that key on these fields (llama-swap). Telling them a permanently-null field is "an instant the request did not reach" invites them to wait for it; describing the
n > 1null as reachable in Chat and Responses describes an error as a valid payload. - Fix. Say the content field is intentionally always null for vLLM shape compatibility (until #562 reports it for streams); restrict the
n > 1sentence to Completions; add one clause for a response that generated no token (all six null).
Nits
- N1.
ignition/cli/serve.py:485-487builds the same bootstrapoptionsdict and, unlike its two neighbours on the following lines, never setsper_request_metrics;ignition/cli/config.py:183-215(write_initial) omits the key from the generated template thoughcli-design.md:1311-1312says the file is written "with the resolved values present as comments". After B1, add the key to both, orignition debug-servewill silently ignore a settingflare runhonours. - N2.
docs/cli-design.md:1385-1387"Native Flare ignores keys it does not use, except in[prefix_cache]" is now stale: native Flare reads[server] per_request_metrics, and Ignition's schema rejects it. Reword together with B1. - N3.
helios/src/server/runtime.rs:2269-2271stampsfirst_scheduled_nsafterpack_vision/conditioned_inputs_ready, so for image requestsqueue_time_msincludes image conditioning and TTFT starts after it. This matcheshelios/model-contract.md:349-352(the instant marks the step "when the worker reserves and packs that step") anddocs/api.md:1010("which can be a vision step"), so it is not a defect; one clause inapi.mdnoting that image conditioning precedes the instant would remove the surprise. Note also that the stamp precedessubmit's guards (runtime.rs:2292-2299), so a step that then fails validation is charged as scheduled.
Verified clean (checked in context, no finding)
- Gating and placement.
helios/src/server/http.rs:387-389callsenable_request_metricsonly whenstate.per_request_metrics(wired fromServerConfig, default false:helios/src/server.rs:148,333, parsed athelios/src/server/config.rs:353-357).encode.rs:233-241returnsNonefor Messages and multi-prompt Completions,Some(Null)forn > 1,Singleotherwise, and honours "no usage chunk, no object" for streams unless the protocol is Responses. Body placementhttp.rs:613-615; Chat/Completions usage chunkencode.rs:711-719; Responses terminalencode.rs:731-744; Messages never (encode.rs:235-236). - Lifetime through preemption.
RequestTimesis exported besideSnapshot(helios/src/server/metrics.rs:324-330,server.rs:33); the record lives inIncoming(runtime.rs:196-198) and moves through park/requeue (runtime.rs:2116-2157,:2647-2675), so the instants survive preemption andlast_token_nsspans the park.Finishedcarriesarrival_ns+timeson all three terminal paths:runtime.rs:298-307,:1884-1896,:2057-2072. - Earliest-value fold.
http.rs:538first_scheduled_ns.into_iter().chain(times.first_scheduled_ns).min()is used at:564(per-frame performance) and:609(response-level), so a streamed request reports the earliest scheduled step, consistent withget_or_insertat the worker. - Arithmetic.
encode.rs:251-275: ttft = first − scheduled, queue = scheduled − arrival, generation = last − first withlastgated onfirst,mean_itl_msdivides bygenerated − 1and only when > 1,tokens_per_second= generated / (last − scheduled) and only when the span is > 0. Matches the field definitions indocs/api.md:1016-1023. - Desktop/controller path.
flare-winui/bridge/src/lib.rs:1367-1399buildsflare::settings::RuntimeSettings, notSettings, so the app inheritsper_request_metricsthroughSettings::resolve(flare/src/settings.rs:120-127,224), and the controller applies it atflare/src/controller.rs:2566. No WinUI edit needed (Windows build not run). - Native config tolerance.
flare/src/configuration.rs:26-35Serveris#[serde(default)]withoutdeny_unknown_fields, so native Flare tolerates the key; only Ignition's schema is closed (B1).
Open questions / not verified
- If #562 (first content token in streams) lands,
docs/api.md:1013-1020must be re-read; "Always null" is accurate only while #560 stands alone. - If #548's per-step clock read is ever made conditional, S2 becomes moot.
- Author-admitted not run: multi-GPU cores and the Windows build. I also did not run the live llama-swap matrix; the "40 checks passed" evidence is the author's, not re-derived here.
- Whether the maintainers consider Ignition's schema part of this PR's contract is the judgement call behind B1; the code says the file is shared and closed, so the fix is one line plus a test.