Subtraction review — PR #560 "Emit vLLM-compatible per-request metrics from runtime instants"
Key findings
The mechanism is close to minimal and I have no blocking finding. The encoder decides placement once, before submission (helios/src/server/http.rs:361-363), so the worker emits Committed events only when a carrier exists; with the option off there is one branch per committing step and no extra event capacity; the encoder adds no clock read. What this change can do without is bulk in its tests and its docs, plus a thin wrapper and a duplicated flag in the encoder: about 140–175 of its +1898 added lines (≈8%), almost all of it in helios/src/server/runtime/phase_tests.rs (+559) and docs/api.md (+178), with no behaviour lost.
Ranked by lines saved:
- Should fix, ~90–100 lines — three of the new phase tests re-prove placement and null rules that the new encoder test
per_request_metrics_follow_vllm_placement_and_null_rulesalready pins (helios/src/server/protocol/tests.rs:2350-2488). - Should fix, ~35–40 lines — the new
docs/api.mdhistogram prose (docs/api.md:305-386) restates, nearly sentence for sentence, the Prometheus HELP strings the same change adds (helios/src/server/metrics.rs:1548-1600), and the vLLM table (docs/api.md:475-517) states the same populations a third time. - Nit, ~28 lines — the new "Per-request metrics" section repeats its own table, the encoder's null rules and the cost statement that
helios/model-contract.mdcarries. - Nit, ~12 lines —
Timing::streamingduplicatesEncoder::streaming;RequestMetrics::Suppressedcosts a declaration plus a match arm in three methods;record_commit/record_timeswrap one-line assignments. - Nit, ~12 lines, lower confidence —
generate_many_observedis a pure pass-through overenqueue_many. - Nit, ~14 lines, marginal — the strict-type loop in the
config.rsbootstrap test.
One candidate I investigated and withdrew: the Bootstrap per_request_metrics key is not dead (see "Withdrawn" below).
1. Should fix — ~90–100 lines: three new phase tests duplicate the encoder test
helios/src/server/protocol/tests.rs:2350-2488 already asserts, at the encoder and in one place:
- the single carrier frame and exact values for Chat/Completions/Responses streams (:2350-2394);
- top-level placement in a JSON body, content instant null there (:2398-2401);
- no carrier without
include_usage(:2404-2409); - Messages omitted in stream and body (:2412-2417);
n > 1→null, several prompts → omitted (:2420-2432);- single token / no-times nulls (:2435-2452).
helios/src/server/runtime/phase_tests.rs then re-proves the same rules through HTTP:
:4746-4797per_request_metrics_reach_completions_and_responses_where_vllm_places_themre-asserts the Completions usage chunk withchoices == [], the Responsesresponse.incompletestop, top-level body placement, and content TTFT == TTFT. Every one of these is already in the unit test list above.:4800-4815the flag-off loop asserts nometricskey andcommits == false. The only genuinely new fact — thatstate.per_request_metricsreachesEncoder::enable_request_metricsand the runtimecommitsflag (helios/src/server/http.rs:363) — needs one short test, not a two-protocol × two-stream loop.:4816-4871then = 2block (56 lines) hand-drives the worker channel to observe"metrics": null; that isprotocol/tests.rs:2420-2432again, and it overlaps:4813in the same test.
Smaller version: keep performance_reports_the_first_scheduled_model_step (:4616-4646) and per_request_metrics_report_the_runtime_instants_of_a_stopped_reasoning_answer (:4693-4744) — those prove the runtime instants land inside the right worker step, which nothing else does. Replace the other two tests with one ~20-line test that serves a stream and a body with the flag on and off and asserts presence/absence plus commits; keep placement and null detail only in the encoder test. Also fold :4728-4730 and :4741 into the assertions already at :4638-4645 and :4683.
Saves ~90–100 of the +559 added lines in phase_tests.rs; nothing is lost because the deleted assertions are all still made at the encoder, where placement is decided.
2. Should fix — ~35–40 lines: docs/api.md histogram prose is a third copy of the HELP strings
The change states each histogram's population three times:
- the Prometheus HELP string in
helios/src/server/metrics.rs— e.g.request_queue_secondsat:1554-1558,request_prefill_seconds:1559-1563,inter_token_latency_seconds:1588-1592(the whole table loop is:1548-1600); - the four new prose paragraphs at
docs/api.md:305-386, which re-say who is observed and who is excluded; - the vLLM correspondence table at
docs/api.md:475-517, which repeats the same condition per row ("from model-scheduler arrival", "also recorded when a stream that offered text later fails").
A scrape ships (1) with the series, so an operator already has it. Compare docs/api.md:328-346 with the HELP strings at metrics.rs:1554-1577, and docs/api.md:348-364 with the token-histogram HELP block — the wording is near-identical. What only (2) can say is three sentences: which histograms pair, that they accumulate since server start, and the cancelled/failed caveat.
Smaller version: cut docs/api.md:321-386 to ~8 lines naming the groups and the single exclusion rule, and let the table at :475-517 be the place that ties a vLLM name to a Flare series. Saves ~35–40 of the +178 docs lines.
Note: this block also arrives through the stacked #548; if the two merge together it is one cut, not two.
3. Nit — ~28 lines: the "Per-request metrics" section restates itself and the model contract
docs/api.md:1005-1054:
:1038-1045restates the null cases that the table directly above (:1015-1022) already defines and thatmetrics_valuecomputes (helios/src/server/protocol/encode.rs:270-293), including "mean_itl_msis null for a single generated token" (already in the table row at:1021) and the token-field rule (:1022). Two sentences cover all of it: "all six keys are always present; a field is null when the request did not reach the instants it spans (content: bodies and non-text streams; itl: a single token; token fields: no generation).":1047-1054restates the cost/event-budget statement thathelios/model-contract.mdcarries normatively, and links to it in the same paragraph.
Also: the placement rules at :1031-1036 are the doc comment of Encoder::enable_request_metrics (encode.rs:238-243) verbatim in prose. Keep the table (:1011-1022), the placement paragraph, and the two-sentence null rule; drop the field-by-field prose and the cost restatement, keeping the existing link. Saves ~25–30 lines.
4. Nit — ~12 lines: encoder plumbing duplicates state and wraps assignments
helios/src/server/protocol/encode.rs:
Timing::streaming(:79-80, set at:250) duplicatesEncoder::streaming(:97, set at:192from the samedecoded.streamthathttp.rs:363passes toenable_request_metrics).record_commit's&& timing.streaming(:257) can readself.streaming; the field and its initialiser go.RequestMetrics::Suppressed(:68-72) exists only sometrics_valuecan returnSome(Value::Null)(:271-273).metrics: Option<Timing>plus asuppressed: boolcarries the same information without a five-line declaration and a match arm in three methods.record_commit(:254-261) andrecord_times(:262-267) are one-line assignments behind a repeatedif let Some(RequestMetrics::Single(timing))guard thatapply(:543-552) also repeats; onefn timing(&mut self) -> Option<&mut Timing>removes the third copy.
Saves ~10–12 of the +93 lines in encode.rs with no behaviour change (the Suppressed/Single/absent three-way is preserved as two fields).
5. Nit, lower confidence — ~12 lines: generate_many_observed is a pass-through
helios/src/server/runtime.rs:860-869 is exactly self.enqueue_many(prompts, observation, commits), reached only from helios/src/server/http.rs:367 and :374. Its doc comment at :860-861 restates enqueue_many's own parameter names (:871-876). generate/generate_observed (:843-849) already wrap enqueue_many; the new commits argument lengthened the wrapper chain instead of collapsing it.
Confidence: verified that the wrapper is redundant and that its two call sites pass Some(observation.timestamps) and None; not verified that the caller's four-arm if (http.rs:364-375) can be folded into one call — the observation.token_ids && size == 1 arm also does prompts.remove(0), and the prompts.is_empty() arm must avoid the runtime entirely. So the honest saving is the wrapper's name, doc comment and signature (~12 lines), not the branching. generate/generate_many must stay (used at helios/src/server/protocol/decisions/mod.rs:838 (not opened) and by tests).
6. Nit, marginal — ~14 lines: config test's strict-type loop
helios/src/server/config.rs:727-739 loops over true/false and then over 1, "true", null. The only writer of this key emits a literal (flare-cli/src/main.rs:355-357), so the rejecting branch guards no product path; one "absent → false" assertion plus the shipped CLI test per_request_metrics_flag_is_off_by_default_and_reaches_rank_zero (flare-cli/src/cli.rs:1378-1401) covers the behaviour. Saving is ~14 lines; borderline, not worth blocking.
Withdrawn candidate (recorded for honesty)
I first flagged per_request_metrics in helios/src/server/config.rs:353-357 as an unreachable Bootstrap validation path, on the grounds that flare run's documented config file has no such key. That was wrong: flare-cli/src/main.rs:355-357 writes config["per_request_metrics"] into the JSON that both serve paths parse — Bootstrap::load at main.rs:626 and LoadedSession::new at main.rs:701 — so the merge code is the only route and must stay. per_request_metrics is therefore consistent with the flag, not dead. Only the strict-type test loop survives as a (marginal) subtraction, reported as finding 6.
Scope checked and found already minimal
helios/src/server/runtime.rs:1803-1811— the option-off path adds one branch at position zero, no events, no clock read.helios/src/server/http.rs:361-363— placement decided once, before submission, so the worker knows whether to send instants; no duplication between the HTTP layer and the encoder.flare-cli/src/cli.rs(+40) andmain.rs(+3) — one flag, one forwarding site; parity with--bypass-performance-check/--verify-weightsas the description claims. Nothing to remove.helios/src/server.rs,latency.rs,observation.rs,scheduler.rs,response_lifecycle_tests.rs(not opened) — small additive wiring (+4 to +24 each) with no superseded code left behind; no old path in the repository becomes dead because nothing is removed by this change.- No existing helper is re-implemented:
metrics_value'smsclosure and theRequestTimes/Timingsplit have no precedent in the tree.
Open questions / not verified
- Whether the
enqueue_manycaller athttp.rs:364-375can be reduced (finding 5) — I did not run the substitution through the single-prompt and empty-prompt arms. - The
docs/api.mdhistogram block at:305-386mostly belongs to the stacked #548; the cut in finding 2 should be agreed with that PR rather than duplicated in both. - No CPU measurement was attempted; the cost claims in the description were taken as stated.
Totals: about 140–175 lines removable, in 6 places (phase_tests ~95, api.md ~65, encode.rs ~12, runtime.rs ~12, config.rs ~14 — the config cut is the least certain). Recommended split: phase_tests.rs ~95/559, api.md ~65/178, encode.rs ~12/93, runtime.rs ~12/155.