Skip to content

Report the first content token of per-request metrics in streams - #562

Closed
WynnD wants to merge 24 commits into
NVIDIA:mainfrom
WynnD:metrics/content-ttft
Closed

WynnD wants to merge 24 commits into
NVIDIA:mainfrom
WynnD:metrics/content-ttft

Conversation

@WynnD

@WynnD WynnD commented Nov 28, 2026 •

Copy link
Copy Markdown

vLLM's per-request metrics object includes time_to_first_content_token_ms: the time from scheduling to the first output that is answer text rather than reasoning or tool-call output. #560 reports that field as null. Only the HTTP decoder can tell answer text from reasoning and tool calls, and only the model worker knows when each step completed, so the instant has to cross from the worker to the stream.

Depends on #560 (which depends on #548); merge order #548, #560, this PR.

What changed

  • For a stream that reports per-request metrics, the worker sends GenerationEvent::Committed { at_ns } before each generating step's output, reusing the completion instant it already reads for the histograms. The request asks for these events through a commits admission flag passed to generate_many_observed; the single-prompt wrappers generate_observed and enqueue are folded into the existing entry points.
  • output_event_capacity budgets one more event per generated token for such requests, and helios/model-contract.md states the larger budget.
  • The encoder keeps the latest step instant and latches it at the first non-empty answer text that survives tool-choice filtering; reasoning and tool-call output never set it. JSON bodies keep reporting null, as in vLLM.

Result

Streams with --enable-per-request-metrics report time_to_first_content_token_ms; for a reasoning model it follows time_to_first_token_ms by the reasoning time. The cost is one event per generating step for those streams only; no clock read is added, and other requests and the option off are unchanged.

Evidence

Discord: oystersmiles

WynnD added 10 commits November 26, 2026 14:05
`/metrics` reports counters, gauges, and the dashboard snapshot, but no
distribution of request latency, so an operator cannot see tail latency, queue
delay, prefill time, decode rate, or prompt size from a scrape, and generic
Prometheus process dashboards have nothing to read. Issue NVIDIA#536 requests
histograms for per-request latency and prompt size together with the standard
process_* metrics. Fixed-bound histograms answer those questions without
per-request storage, and the runtime already counts completions in one place, so
recording the histograms there keeps the counter and the observations together.

The runtime now keeps lifecycle instants on `Incoming` so they survive
preemption: `Worker::reserve_and_pack` stamps the first model step that includes
a request, `Worker::complete` stamps its first and last committed generated
tokens, and `Metrics::request_completed` records queue, prefill, decode, time per
output token, and prompt tokens while incrementing `requests_completed_total`.
Both call sites that incremented the counter directly now call
`request_completed`, so the counter cannot drift from the histograms. Cancelled
and failed requests stay out of the request histograms.

The generation handler records `request_e2e_seconds` when delivery completes a
successful response, except for `/v1/messages/count_tokens`, and the existing
first-response sampler now also observes `time_to_first_response_seconds` when it
offers answer or reasoning text; its median gauge is unchanged. On Linux,
`server/metrics/process.rs` derives `process_cpu_seconds_total`,
`process_resident_memory_bytes`, `process_virtual_memory_bytes`,
`process_start_time_seconds`, `process_open_fds`, and `process_max_fds` from
procfs and `RLIMIT_NOFILE`, omitting only the metrics whose source cannot be
read; other platforms write nothing. Names, types, and endpoints are documented
in `docs/api.md`, and the JSON snapshot is unchanged.

The claimed result is observability only: latency, prompt-size, and process
resource distributions become scrapeable with no change to serving behavior.

Evidence: `cargo test --locked --release --manifest-path helios/Cargo.toml
--target-dir ~/.cache/hyperflare-target --features runtime-core,server --lib --
server::runtime::phase_tests` passed 109 tests, including
`reasoning_budget_cuts_or_plainly_continues_with_exact_history_and_usage` (a
preempted and readmitted request records one queue, prefill, and prompt-token
observation),
`first_response_http_nonstream_records_only_when_completed_body_is_offered`,
`first_response_http_stream_excludes_pretext_failures_and_unpolled_bodies`, and
`metrics_route_serves_prometheus_or_json_without_the_api_key`, whose text scrape
carries the first-response histogram, an empty request histogram, and a resident
memory gauge. `server::metrics::` passed 20 tests, including
`request_histograms_bucket_completed_request_timings`,
`render_reports_process_memory_descriptors_and_start_time`, and
`parse_stat_reads_fields_after_a_parenthesized_command_with_a_paren`. The whole
`server::` filter ran 326 tests with one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
which requires templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`; no templates are installed on this host, so that test
is unrun here. Windows builds and the rest of the helios suite are left to CI.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
A review of the previous commit found three defects. A response cancelled by
the parallel tool-call limit still reaches `Delivery::Complete`, so the HTTP arms
observed `flare_request_e2e_seconds` for a request the runtime counts as
cancelled, and both arms duplicated the same observation. The documentation
claimed request histograms cover "the served response" and named only `flare_`
series, contradicting the stream-drain condition, the two-token condition on
decode histograms, and the `process_*` series. And `process.rs` read page size,
the open-file limit, and the descriptor count with ad-hoc libc and procfs code
instead of the host helpers the repository already owns.

`generate` now observes the end-to-end histogram once, inside the delivery
stream, guarded by `!encoder.tool_limit_reached`, and the two delivery arms only
deliver. `disabled_parallel_calls_complete_http_and_stop_decoding` asserts that
every path and stream mode in that test records zero end-to-end observations,
which covers the cancellation path directly (it ran 326 tests in the `server::`
filter, with the one pre-existing template-fixture failure).

`docs/api.md` now separates the HTTP histograms, which count delivered responses
and require a drained stream, from the runtime histograms, which count completed
generations and record decode and time-per-output-token only with at least two
generated tokens; it states cumulative-since-start, notes that a request's first
model step can be a vision step, and exempts `process_*` from the `flare_`
prefix.

`process.rs` uses `crate::os::page_size()`, `crate::os::raise_open_file_limit(0)`
(read-only), and the descriptor counter that core protection already keeps,
re-exported within the crate; only `/proc/self/stat` and the `btime` parse stay
local. No behavior changes beyond the cancelled-request exclusion, and no new
cost on the serving path.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
Review nits on the previous commits: `Worker::publish` repeated the prompt and
generated-token expressions in the metric call and the terminal event, the
first-response histogram renderer sat in a second impl block, `parse_stat`
accepted any line containing `)`, and the histogram test used a state a real
request cannot reach (`first_scheduled_ns: None` with a token present).

`publish` now hoists the two values as `complete` does, the renderer lives in the
existing `FirstResponseSamples` impl, `parse_stat` rejects a line whose first
field after the command name is not a process state character, and the zero-work
case uses `RequestTimes::default()`, which is reachable through a zero-token
completion.

No behavior changes; the parsers and metrics output are unchanged for valid input.

Evidence: `cargo test --locked --release --manifest-path helios/Cargo.toml
--target-dir ~/.cache/hyperflare-target --features runtime-core,server --lib --
server::metrics` passed 20 tests, including the request histogram and both
process-metrics tests, and `-- server::` passed 326 with the one pre-existing
template-fixture failure.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
The process_* series (CPU time, resident and virtual memory, start time,
open and maximum file descriptors) describe the serving process, not request
latency, so they formed a second outcome inside a change whose purpose is
request histograms. Their renderer also read procfs on every text scrape and
called crate::runtime_core from server code, which does not compile when helios
is built with only the server feature.

This deletes helios/src/server/metrics/process.rs and its render call in the
/metrics handler, the docs/api.md paragraph and the naming exception that
described the series, the route-test assertion, and the open_descriptors
re-export that only the renderer used.

/metrics again exports only flare_-prefixed series, a text scrape reads no
procfs files, and the server-only build compiles.

cargo check --locked --manifest-path helios/Cargo.toml --features server is
clean. cargo test --features runtime-core,server --lib -- server::metrics
server::latency metrics_route_serves passed 23 tests. No GPU workload ran.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
`/metrics` has per-request histograms for end-to-end, queue, prefill, and
decode time, time per output token, and prompt size, but none for the other
per-request distributions vLLM exposes: time to first token inside the engine,
inter-token latency, time from first scheduling to the last token, generated
and freshly computed prompt tokens, the output limit, preemptions per request,
the `n` parameter, and the largest output among one prompt's choices. A
dashboard built on vLLM's metrics therefore has no Flare series to read for
them. The project maintainer approved bringing Flare's metrics to vLLM parity
for quantities Flare already has. Every one of these values already exists in
the runtime worker or the HTTP generation handler at the points where the
existing histograms record, so recording them there adds no instrumentation to
GPU or cache paths.

`Incoming.times` becomes `Incoming.record`, a `RequestRecord` that keeps the
lifecycle instants, the output limit taken at first admission (the prompt's
limit plus the tokens a reasoning budget defers), a preemption count that
`Worker::park_if_preempted` increments when it parks a preempted request, and a
19-bucket histogram of intervals between the request's committing steps.
`Worker::complete` calls `RequestRecord::tokens_committed` once per model step
that commits tokens for a request, so a speculative round that commits several
tokens adds one interval, as vLLM's per-iteration accounting does. The record
moves with the request through parking and readmission.
`Metrics::request_completed` takes the record and a `CompletedRequest` (prompt,
reused, and generated tokens) and now also records
`flare_time_to_first_token_seconds`, `flare_request_inference_seconds`,
`flare_request_prefill_computed_tokens` (prompt minus tokens reused at first
admission), `flare_request_generated_tokens`, `flare_request_max_tokens`, and
`flare_request_preemptions`, and merges the request's intervals into
`flare_inter_token_latency_seconds`. Cancelled and failed requests never reach
`request_completed`, so they stay out of every new histogram, as they do out of
the existing ones. The HTTP handler's end-to-end observation moves into
`Metrics::response_completed`, which also records `flare_request_choices` (the
`n` parameter) and `flare_request_max_choice_generated_tokens` once per prompt
of a successful response; only `/v1/completions` accepts `n` above one, and
each choice runs as its own model request. The prompt-token bucket constant is
renamed `TOKEN_COUNTS` because every token-count histogram uses it; the
preemption and `n` histograms use vLLM's default bounds, the preemption one with
an added zero bound so never-preempted requests stay separate.
`docs/api.md` defines each series, its units, and which requests it counts.

The claimed result is observability only: the distributions above become
scrapeable, and no admission, scheduling, or cache decision changes. The added
cost, stated from the code and not measured, is one bucket search over at most
19 bounds and two uncontended atomic adds per committing step per request, about
ten histogram observations and a 20-counter merge per completed request, two
observations per prompt per HTTP response, and 168 bytes per queued or active
request for the record's histogram, limit, and count.

Evidence: `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --target-dir /tmp/mc/target --lib -- server::metrics
server::runtime` passed 148 tests (one ignored).
`request_histograms_bucket_completed_request_timings` drives
`tokens_committed` through three committing steps and checks every new
histogram's buckets and sums, and that a zero-token completion adds only token
and preemption observations.
`response_histograms_count_choices_and_largest_choice_per_prompt` checks the
per-prompt grouping of choices.
`reasoning_budget_cuts_after_a_multi_token_speculative_completion` checks two
inter-token observations for three committing steps that include a three-token
speculative round, an output limit spanning the reasoning budget and its
remainder, and zero preemptions for a reasoning park.
`exercise_text_preemption` (through
`reasoning_budget_survives_preemption_and_checkpoint_recomputation`) checks that
the parked request carries one preemption and that the completed request lands
in the one-preemption bucket.
`prefill_computed_tokens_exclude_the_prefix_reused_at_admission` completes two
identical prompts and checks 13 computed tokens for the first and zero for the
second, which restored the first one's checkpoint. These tests run the worker
without a GPU; serving on hardware has not been run. Time to first token starts
at model-scheduler arrival rather than at HTTP arrival as in vLLM, and vLLM also
observes aborted requests, which Flare excludes.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
…ejections

Four quantities vLLM exposes as counters or gauges exist in Flare but no
series reports them. `flare_cache_lookups_total` counts GPU prefix lookups,
not the prompt tokens looked up, so the token hit rate that vLLM's
`prefix_cache_queries` and `prefix_cache_hits` give cannot be computed from
`flare_cache_reused_tokens_total` alone. `flare_requests_completed_total` does
not separate requests that stopped at their output limit from those that
stopped at EOS or a stop. `flare_pending_requests` reports only requests that
await their first admission, so requests parked for readmission after a
preemption, a reasoning budget cut, or a returned host-store restore are in no
gauge. HTTP 429 responses and the runtime's capacity and channel refusals are
not counted anywhere, unlike vLLM's `admission_rejections`. vLLM also reports
the tokens each engine step processes; Flare's existing per-kind launch counts
and token totals give only means, not that distribution. The project maintainer
approved bringing Flare's metrics to vLLM parity for quantities Flare already
has; each value here is already computed at the point where it is recorded.

`RequestScheduler::admit_planned_with_checkpoint_accounting` adds the prompt
length to `SchedulerStats::cache_lookup_tokens` beside `cache_lookups`, once per
admitted request; prompt-scoring requests, which skip the lookup, add nothing.
The field changes only when `cache_lookups` does, so the deferred-copy-out retry
key that embeds `SchedulerStats` changes no more often than before.
`CompletedRequest` gains `output_limit`, set where `Worker::publish` already
decides the `length` finish reason (its EOS test now runs before the metrics
call) and false on the token-stop completion in `Worker::complete`;
`Metrics::request_completed` counts it in
`flare_requests_output_limited_total`. A new `flare_requests_completed_total`
label was not used because it would change that series' identity, and a
separate counter by finish reason would duplicate it; stop completions are the
difference between the two counters, and cancelled and failed requests keep
their own counters. `Worker::publish_gauges`, extracted from the worker loop,
stores `flare_parked_requests` beside `flare_pending_requests`.
`Metrics::admission_rejected` counts `flare_admission_rejections_total{reason}`
where the 429 and capacity errors are produced: `admit_http` and the extra
choice slots in `http::generate` (`http_slots`) and
`ModelRuntime::enqueue_many` (`generation_capacity`, `request_queue`). Paused
admission and an unavailable runtime are not queue limits and stay uncounted.
`Worker::complete` observes `flare_model_step_tokens`, the prompt tokens
computed plus the generated tokens committed, for every completed prefill,
resume, decode, speculative, or mixed graph, using the values it already passes
to `Metrics::progress`. `docs/api.md` defines each series, and the pending
gauge's help and JSON field now say "first admission".

The claimed result is observability only; no admission, scheduling, or cache
decision changes. The added cost, from the code and not measured, is one
addition per admission, one histogram observation (a search over at most 21
bounds and two atomic adds) per completed text graph, one atomic store per
worker-loop pass with progress, and one atomic add per rejection.

Evidence: `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --target-dir /tmp/mc/target --lib -- server::metrics
server::runtime scheduler::tests` passed 236 tests (one ignored). The scheduler
admission tests check 192 lookup tokens for three admitted 64-token prompts and
none for refused attempts. `reasoning_budget_does_not_readmit_eos_or_user_stops`
checks that EOS, text-stop, and token-stop completions count no output-limit
stop, and `ignored_eos_at_the_output_limit_finishes_for_length` checks one,
together with two text-graph observations totalling three tokens.
`exercise_text_preemption` checks one parked and no pending request after a
preemption. `full_runtime_queue_limits_count_admission_rejections` fills the
worker channel and then the runtime capacity, and
`full_http_admission_counts_a_queue_limit_rejection` sends a completion through
the router with every HTTP slot held and checks the 429 and its count. These
tests run without a GPU; serving on hardware has not been run.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
An operator moving dashboards or alerts from vLLM to Flare has to find, for
each vLLM metric, the Flare series that measures the same quantity, the
arithmetic that derives it, or the fact that Flare does not provide it. Flare
deliberately exports no `vllm:` aliases and adds no second series for a
quantity it already reports, so that correspondence exists only as
documentation.

`docs/api.md` gains a "Correspondence with vLLM metrics" table under "Health
and metrics". It covers every metric in vLLM's General and Speculative Decoding
tables, plus vLLM's aggregate speculative counters and connector families. Each
row gives the Flare series or expression and the material difference in origin
or population: time to first token starts at model-scheduler arrival, prefix
lookup counters include readmissions, `num_requests_running` includes requests
waiting for a host restore, and Flare's per-request histograms exclude
cancelled and failed requests. Rows for corrupted requests, KV block residency,
FLOPs estimates, LoRA, watermarking, sleep state, and KV connectors state that
Flare does not provide them and why.

The claimed result is documentation only; no code changes.

Evidence: each Flare name in the table was checked against the renderer in
`helios/src/server/metrics.rs` and `helios/src/server.rs`, and each vLLM name
against vLLM's published production-metrics list and its Prometheus logger
source. The table has not been exercised by a dashboard.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
…assertions

docs/api.md described a narrower instrument than the code records. The
end-to-end histogram is observed once per delivered successful response, it
excludes /v1/messages/count_tokens and responses the runtime counts as
cancelled (including a parallel tool-limit stop), and it can be lower than
flare_requests_completed_total because a multi-choice response adds one
observation for several model-request completions and an abandoned stream adds
none. The closing sentence claimed cancelled and failed requests enter only two
counters, but flare_time_to_first_response_seconds observes a stream that
offered text before it failed. The runtime paragraph now also says a zero-token
completion still increments flare_requests_completed_total and enters the
prompt-token histograms, while the queue observation needs a model step and
time-to-first-token, prefill, and inference need a committed token. The vLLM
table rows and its intro state the same populations.

phase_tests.rs rendered the whole scrape three times in the failed-stream loop
for one assertion and re-rendered the first-response histogram that the
/metrics route test already exercises. Both duplicates are removed; the
end-to-end exclusion for a failed response is still asserted, once, and the
tool-limit count assertion is kept because it pins a distinct guard.

Validation: cargo check --locked --manifest-path helios/Cargo.toml --features
server (passes). cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server:: scheduler:: cache::: 816 passed, 1 failed
- the known server::protocol::decode::native_prompt_tests::
messages_image_hints_end_after_expansion_for_text_and_segmented_templates,
which needs FLARE_TEST_TEMPLATE_DIR.

Limitations: documentation and test-duplication only; no production code
changes. The test-only drift assertion in Cache::stats and the first-response
histogram on FirstResponseSamples are outside this change.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
The request-histogram documentation and two expected rows of the counter
exposition test were inserted at the same lines as the KV-page gauge change
(NVIDIA#549) adds its paragraph and rows, so whichever of the two merged second
would stop on a textual conflict although the changes are independent.

The histogram paragraphs in docs/api.md now follow the paragraph about the
JSON format of the /metrics route instead of directly following the route's
introduction, and in counters_expose_fixed_names_without_request_payloads the
cache_lookup_tokens field and the parked_requests row move to the end of their
lists. The text and assertions are unchanged; the test checks each row with
`contains`, so row order does not matter.

The two changes now merge in either order without manual resolution.

cargo test --features runtime-core,server --lib -- server::metrics passed 19
tests, and `git merge-tree` of this branch with the KV-page branch reports no
conflict.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
…ime after packing

The completion path spelled the seven sampling graph kinds inline to decide whether a
completed step contributes to flare_model_step_tokens, duplicating GraphKind::samples()
in helios/src/execution/manifest.rs, which the same file already uses to validate
sampling admissions. A sampling kind added to samples() would update its other
consumers but not this list, so the counter would silently stop counting it. In
reserve_and_pack, the first_scheduled_ns stamp preceded pack_inputs/pack_vision, which
can return Err, so a request whose packing failed kept a scheduled instant for a step
that never executed.

The completion path now tests kind.samples(). reserve_and_pack performs its single
monotonic_ns() read and the per-lane get_or_insert after packing returns Ok, so a
successful step stamps the same instant as before and a failed pack leaves
first_scheduled_ns unset.

flare_model_step_tokens counts the same steps: samples() lists exactly the seven
variants the inline list named (Prefill, TerminalPrefill, ScoredPrefill, Decode,
Speculative, Mixed, Resume), now from one source of truth. The queue-time and
prefill/inference histograms no longer record a scheduled instant for a step whose
packing failed.

cargo check --locked --manifest-path helios/Cargo.toml --features server finished with
four pre-existing warnings. cargo test --locked --manifest-path helios/Cargo.toml
--features runtime-core,server --lib -- server:: scheduler:: cache:: passed 814 tests
and failed one:
server::protocol::decode::native_prompt_tests::messages_image_hints_end_after_expansion_for_text_and_segmented_templates,
which requires FLARE_TEST_TEMPLATE_DIR and exercises no changed path. No GPU server run
was performed, so the emitted metrics were not checked end to end.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
WynnD added 14 commits November 28, 2026 16:45
The metrics module wrote histograms three ways. The request histograms used
`Histogram` and `Buckets`, with `# HELP` and `_sum` before `_count`. The three
host prefix-store lookup histograms (`flare_host_cache_missing_tokens`,
`flare_host_cache_estimated_transfer_ns`, `flare_host_cache_estimated_prefill_ns`)
used separate integer bound arrays, a sum array, and a hand-written render loop
without `# HELP` that printed `_count` before `_sum`. `Buckets` held `f64` bounds
in the exposed unit plus a `scale`, so every observation was divided before
comparison. `flare_time_to_first_response_seconds` was a `Histogram` owned by the
rolling first-response window and rendered through a separate hook in the
`/metrics` handler. Folding all of them onto one type gives every scrape one
histogram format and one bucket search.

`Buckets` now holds `u64` bounds on the observation grid (nanoseconds or
counts) ending at `u64::MAX`, and a `per_unit` divisor applied only when
rendering `le` labels and `_sum`. The three host lookup histograms are
`Histogram<8>` fields observed with `HOST_NANOSECONDS` and `HOST_TOKEN_COUNTS`
and rendered by `Histogram::render`; `host_cost_sums`, `HOST_TIME_BUCKETS`,
`HOST_TOKEN_BUCKETS`, and the custom loop are removed.
`flare_time_to_first_response_seconds` is a `Metrics` field observed through
`Metrics::first_response`, which `FirstResponse::output` calls through the
metrics handle it receives when the observation starts; the window keeps only its
rolling samples. A module doc names `Histogram` over `Buckets` as the form of
every observed histogram, and comments at `Metrics::store` and the retirement
render state that `flare_host_cache_retirement_seconds` copies counts owned by
the selene store.

Result: metric names, bucket bounds, and observed values are unchanged. The host
lookup histograms gain `# HELP` lines and emit `_sum` before `_count`, and their
nanosecond sums stay exact integers. Every `le` label renders the same text as
before because each integer bound divided by 1e9 is the same double as the
former decimal literal.

Evidence: the host lookup test asserts the `# HELP` line, bucket boundaries,
sums, counts, and `_sum` before `_count`; the first-response unit test asserts
one `flare_time_to_first_response_seconds` observation after two `output` calls.
Each nanosecond bound of `REQUEST_SECONDS` and `TOKEN_SECONDS` divided by 1e9
compares equal to its former literal in IEEE double arithmetic.
Build and tests: on the tree with this commit and the two that follow it,
`cargo check --locked --features server` succeeds and
`cargo test --locked --features runtime-core,server --lib -- server:: scheduler:: cache::`
reports 816 passed, 1 failed, 11 ignored. The failure is
server::protocol::decode::native_prompt_tests::messages_image_hints_end_after_expansion_for_text_and_segmented_templates,
which requires FLARE_TEST_TEMPLATE_DIR and exercises no changed path. No GPU
server run was performed, so a live scrape was not compared.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
One flag, `Encoder::tool_limit_reached`, gated the HTTP response histograms for
a whole response. When any choice reached the parallel-tool-call limit, the
response added no `flare_request_e2e_seconds`, `flare_request_choices`, or
`flare_request_max_choice_generated_tokens` observation, although the runtime
counts each choice as its own request and had already counted a sibling choice
that finished on its own as completed. The runtime termination of each choice is
what decides whether it counts as cancelled, so the HTTP gate records that
termination per choice and excludes only the cancelled choices. Only
`/v1/completions` accepts more than one choice and it rejects tools, so no public
request reaches a multi-choice tool-limit response today.

`Encoder::finish` records whether the runtime ended each choice as
`Termination::Cancelled`, before the tool-limit override of the finish reason,
and `Encoder::choice_generated_tokens` returns each choice's generated-token
count, or `None` for a cancelled choice. The HTTP handler passes that list to
`Metrics::response_completed` and no longer keeps its own per-choice count
vector or the `!count` condition, which never held because token-count requests
return before the delivery stream starts. `response_completed` observes
`flare_request_e2e_seconds` once when at least one choice was delivered, and per
prompt observes the delivered choice count and the largest delivered
generated-token count, skipping a prompt with no delivered choice. The
`# HELP` text of both choice histograms and the HTTP histogram paragraph and
vLLM table row in docs/api.md state the per-choice rule.

Result: a response whose only choices were cancelled is not observed, as
before, and a choice the runtime completed enters the response histograms even
when another choice of the same response reached the tool-call limit.

Evidence: a unit test drives an `Encoder` with two choices and parallel tool
calls disabled through two tool calls on choice 0, finishes choice 1 at EOS and
choice 0 as cancelled, asserts `[None, Some(5)]`, and asserts one e2e
observation, one choice, and a largest-choice sum of 5, with no observation for
an all-cancelled response. The existing HTTP tool-limit test still asserts zero
e2e observations for a single cancelled choice.
Build and tests: on the tree with this commit and the one that follows it,
`cargo check --locked --features server` succeeds and
`cargo test --locked --features runtime-core,server --lib -- server:: scheduler:: cache::`
reports 816 passed, 1 failed, 11 ignored. The failure is
server::protocol::decode::native_prompt_tests::messages_image_hints_end_after_expansion_for_text_and_segmented_templates,
which requires FLARE_TEST_TEMPLATE_DIR and exercises no changed path. No GPU
server run was performed, so a live scrape was not compared.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
…metric docs

Four review findings remained in the metrics and their documentation.
`flare_model_step_tokens` observed a 0-token sample for a step in which every
lane failed, lowering the mean without measuring work. The
`flare_admission_rejections_total` labels were a literal array that had to
track the declaration order of `AdmissionLimit` with nothing linking them. One
test checked a full completion and then a zero-token completion on the same
`Metrics`, so the zero-token assertions restated the first request's counts.
docs/api.md restated `# HELP` text in prose, omitted that decode time includes a
preemption stall and that the first model step of a request can be an
initialization step, and named vLLM's metric list without a source or date.

`Metrics::model_step` skips a step with zero tokens, which is a step in which
no lane made progress. `AdmissionLimit` has an `ALL` array, which also sizes
the counter array, and an exhaustive `reason` match that the render loop uses
for labels. The zero-token completion has its own test on a fresh `Metrics`
that asserts every interval histogram is empty and every token-count histogram
holds one observation. docs/api.md keeps the population rules (which requests
enter, the cancelled and failed exclusion, the two-token rule, the zero-token
rule, and the tool-limit rule from the HTTP histogram paragraph) and drops the
interval definitions the `# HELP` lines already carry. It states that decode
time, time per output token, and the spanning inter-token interval include the
wait for readmission; that the first model step can be an initialization or
vision step, so prefill time includes initialization; that a step without
progress is not observed; and that the vLLM table follows
https://docs.vllm.ai/en/latest/usage/metrics/ as checked on 2026-11-27.

Result: the model-step histogram counts only steps that did work, admission
reason labels are bound to their enum variants, the zero-token population is
tested in isolation, and the documentation describes each population without
duplicating the scrape. Metric names, labels, bucket bounds, and the vLLM table
rows are unchanged.

Evidence: the scheduler metrics test calls `model_step(0)` beside the two
nonzero steps and asserts `flare_model_step_tokens_count 2`, and still asserts
the three admission reason labels and their counts. The zero-token test asserts
zero counts for the queue, prefill, inference, time-to-first-token, decode,
time-per-output-token, inter-token, and max-token histograms, and one
observation in the prompt, computed-prompt, generated, and preemption
histograms.
Build and tests: on this commit's tree,
`cargo check --locked --features server` succeeds and
`cargo test --locked --features runtime-core,server --lib -- server:: scheduler:: cache::`
reports 816 passed, 1 failed, 11 ignored. The failure is
server::protocol::decode::native_prompt_tests::messages_image_hints_end_after_expansion_for_text_and_segmented_templates,
which requires FLARE_TEST_TEMPLATE_DIR and exercises no changed path. No GPU
server run was performed, so a live scrape was not compared.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
A Chat request that sets `return_token_ids` and `return_token_timestamps`
receives a `performance` object with its HTTP ingress and model-queue enqueue
instants, and a timestamp for every generated token, all on Flare's monotonic
observation clock. It cannot separate the time spent waiting for the scheduler
from the time spent in prefill, because no instant marks when the request first
reached a model step. The worker already records that instant: it stamps
`RequestTimes::first_scheduled_ns` when it reserves and packs the first step that
includes the request, and preserves it across preemption, for the request queue
histogram. Reporting it next to the existing instants lets a client derive queue
time, time to first token, decode time, inter-token latency, and throughput from
one timed response.

`GenerationEvent::Finished` now carries the request's `RequestTimes`, and the
Chat handler adds `first_scheduled_ns` to `performance`, on the terminal choice
chunk of a stream and on the JSON body otherwise. The value is null when no model
step included the request. `helios/model-contract.md` defines the field and the
intervals it closes. Requests that do not ask for timestamps are unchanged; the
terminal event copies three integers the worker already holds and reads no clock.

Evidence: `server::runtime::phase_tests::performance_reports_the_first_scheduled_model_step`
serves a timed two-token Chat request through `http::generate` and a worker
driven step by step, streaming and not, pausing between steps. The reported
`first_scheduled_ns` falls inside the first worker step, after `enqueue_ns` and
before the first token timestamp, which falls inside the first generating step.
`cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server::` passed 325 tests; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`, which this host does not have. No GPU or live server
was used.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
Gateways, billing, and SLA tooling that show per-request speed read vLLM's
`metrics` object from the response body when the server runs with
`--enable-per-request-metrics`. Flare reports aggregate latency histograms on
`/metrics` but nothing per request in OpenAI output, so these consumers show no
rates for Flare. The model worker already records each request's arrival, first
scheduled step, first committed token, and last committed token for those
histograms, on the same monotonic clock and preserved across preemption. vLLM
derives its fields from the corresponding engine instants, so reading them from
the worker measures what vLLM measures, independently of HTTP delivery and of
stop-string matching, which the worker performs before publishing output.

`GenerationEvent::Finished` now carries the request's model-queue arrival beside
its `RequestTimes`. `flare run --enable-per-request-metrics` (forwarded to rank
zero by `flare orbit run`, and passed to Helios as the server configuration key
`per_request_metrics`) makes the encoder render `time_to_first_token_ms`,
`time_to_first_content_token_ms`, `generation_time_ms`, `queue_time_ms`,
`mean_itl_ms`, and `tokens_per_second` with vLLM's definitions. A JSON body
carries the object at the top level; a Chat or Completions stream carries it on
the final usage chunk, so it needs `stream_options.include_usage`; a Responses
stream carries it in the `response` of `response.completed` or
`response.incomplete`. `n` greater than one makes the object null, several
Completions prompts omit it, and Messages never carries it, because vLLM defines
it only for the three OpenAI APIs. Fields whose instants the request did not
reach are null.

The content field needs the instant of the model step whose output first
produced answer text, which only the HTTP decoder can recognize. A stream that
reports it asks the worker for a `Committed` event before each step's output,
carrying the completion instant the worker already read for that step; the
encoder keeps the latest one and records it when the first non-empty content
event passes its tool-choice filtering, so reasoning, tool-call output, and text a
named tool choice discards do not count. The response event budget grows by one
event per generated token for such streams. With the option off, the encoder
holds no metrics state, the worker sends no extra events, and nothing reads a
clock; the option on reads no clock either. The encoder is now built before
submission, because its placement rules decide whether the request asks for
commit instants.

The option has no `[server]` configuration-file key: like
`--bypass-performance-check`, `--verify-weights`, and the scheduler policy
flags, it is a serving flag that `docs/cli-design.md` lists without a
configuration fallback.

The claimed result is vLLM-compatible per-request timing in OpenAI output when
the option is on, and unchanged responses and serving work when it is off.

Evidence: `server::runtime::phase_tests::per_request_metrics_report_the_runtime_instants_of_a_stopped_reasoning_answer`
serves a Chat request with a stop string through `http::generate` and a worker
driven step by step with pauses, streaming and not. The model reasons, closes,
answers, and generates the stop string. Combining `metrics` with
`performance.first_scheduled_ns` places the first scheduled step, first token,
first answer text, and last token inside the worker steps that produced them; the
content instant is two steps after the first token in the stream and null in the
JSON body; arrival lies between HTTP ingress and `enqueue_ns`; and the mean
inter-token latency and token rate reconcile with those instants.
`per_request_metrics_reach_completions_and_responses_where_vllm_places_them`
checks the usage chunk, `response.incomplete`, and top-level placements through
the worker. `per_request_metrics_are_absent_without_the_option_and_null_for_several_choices`
checks that Completions output carries no key and requests no commit instants
with the option off, and that two choices give `"metrics": null` in both modes.
`server::protocol::tests::per_request_metrics_follow_vllm_placement_and_null_rules`
and `content_instant_excludes_reasoning_tool_calls_and_suppressed_text` check
the encoder's placement, values, and null rules for every protocol;
`server::config` checks the configuration key, and
`cli::tests::per_request_metrics_flag_is_off_by_default_and_reaches_rank_zero`
checks the flag and its Orbit forwarding. `cargo test --locked --manifest-path
helios/Cargo.toml --features runtime-core,server --lib -- server::` passed 330
tests; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`, which this host does not have. `cargo test --locked
--manifest-path flare-cli/Cargo.toml --bin flare -- cli::` passed 33 tests. No
GPU, exported core, live server, or gateway was used, and the CPU cost of the
option under load has not been measured.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
vLLM's per-request `metrics` object includes `time_to_first_content_token_ms`,
the time from the first scheduled step to the step whose output first produced
answer text. Only the HTTP decoder can recognize answer text, so measuring it
needs the worker to send the completion instant of every generating model step
to the stream, adding one runtime event per step and a third term to the
response event budget. The other five fields come from instants the worker
already places on each request's terminal event. vLLM documents the field as
null when a server cannot provide it, so the object stays complete without the
per-step events.

`time_to_first_content_token_ms` is always null. `GenerationEvent::Committed`,
the `commits` admission flag, the commit term of `output_event_capacity`, and
the encoder's step and content instants are removed; the admission entry points
and the HTTP handler's submission order are those the server had without
per-request metrics. `docs/api.md` defines the field as always null, and
`helios/model-contract.md` states the event budget without a commit term.

With `--enable-per-request-metrics`, OpenAI output carries the same `metrics`
object as before except that the content field is null in streams as well as
JSON bodies; the worker sends no event beyond the terminal one for metrics.

Evidence: `server::protocol::tests::per_request_metrics_follow_vllm_placement_and_null_rules`
checks the placement and the null content field for every protocol, and
`per_request_metrics_report_the_runtime_instants_of_a_stopped_reasoning_answer`
and `per_request_metrics_reach_completions_and_responses_where_vllm_places_them`
check through a worker driven step by step that streams and JSON bodies report
a null content field while the other instants fall inside the steps that
produced them. `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server:: scheduler:: cache::` passed 819 tests at
the head of the series this commit belongs to; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`, which this host does not have. No GPU or live server was used.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
`GenerationEvent` is public, and its `Finished` variant carries a
`RequestTimes` with the request's lifecycle instants, but that type lived in the
private `server::metrics` module, so a caller outside the crate could neither
read the instants nor build a `Finished` event. The HTTP handler also assigned
`performance.first_scheduled_ns` from whichever generation finished last,
rather than the earliest step of the response, which is the instant the field
defines.

`flare_helios::server` re-exports `RequestTimes` beside `Snapshot`; its fields
are already public. The handler keeps the minimum of the first scheduled
instants across `Finished` events, ignoring generations that never reached a
model step. The doc comment on `Encoder::enable_request_metrics` refers to
`docs/api.md` for placement instead of restating it, and the encoder test builds
its expected `metrics` objects, including the all-null one, from one key list,
so the field set is spelled once.

Out-of-crate code can name and construct the instants carried by
`GenerationEvent::Finished`. Responses are unchanged today, because Chat, the
only protocol that reports `performance`, runs one generation per response.

Evidence: `per_request_metrics_follow_vllm_placement_and_null_rules` compares whole
`metrics` objects built from one key list, including the all-null object, and
`performance_reports_the_first_scheduled_model_step` checks the reported
instant through a worker. `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server:: scheduler:: cache::` passed 819 tests at
the head of the series this commit belongs to; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`, which this host does not have. No test serves a Chat
response with several generations, because Chat accepts only one choice.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
Native `flare run` takes its serving defaults from the `[server]` section of the
host configuration, and the desktop controller in the `flare` library reads only
that file. Per-request metrics could be enabled only by the
`--enable-per-request-metrics` flag, so the desktop controller could not enable
them, and a `[server] per_request_metrics` key was accepted and ignored because
`[server]` tolerates unknown keys. A configuration key, applied the way
`scheduler_checkpoint_extra_work_fraction` is, gives both front ends one home for
the setting.

`flare::configuration::Server` has an optional boolean `per_request_metrics`.
`Settings` resolves it to a boolean, defaulting to off, and the controller passes
it to Helios as the server configuration key of the same name. Native
`flare run` enables the option when the key is true or the flag is given, so the
flag still enables it over `per_request_metrics = false`. `flare run --help` and
`flare orbit run --help` describe the flag with the same sentence, and
`docs/cli-design.md` lists the key among the `[server]` keys native `flare run`
applies, shows it in the sample configuration, and names it as the flag's
default; `docs/api.md` names both switches.

`[server] per_request_metrics = true` enables vLLM's per-request `metrics` in
native `flare run` and in the desktop controller; a non-boolean value is a
configuration error.

Evidence: `flare::settings::tests::per_request_metrics_reach_application_settings`
checks the absent, true, and false keys and rejects a string value;
`config::tests::per_request_metrics_configuration_and_flag_precedence` in
`flare-cli` checks that the key enables the option and that the flag enables it
over a false key. `cargo test --locked --manifest-path flare-cli/Cargo.toml
--bin flare -- cli:: config::` passed 50 tests and `cargo test --locked
--manifest-path flare/Cargo.toml --lib -- settings:: configuration::` passed 11.
The desktop controller was not run.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
The per-request metrics section of `docs/api.md` placed model-queue arrival at
the worker side of the request queue, and it did not say that a Chat or
Completions stream without `stream_options.include_usage` carries no `metrics`,
which is why gateways that read rates from the response body show none for such
streams. It referred to `performance.first_scheduled_ns` without defining the
`performance` object anywhere in the file, and it restated null rules the field
table already implies.

The section states that `ModelRuntime::enqueue_many` reads arrival while
building the request group, before publishing it to the worker channel, so
`queue_time_ms` includes the channel send and worker pickup and starts later
than vLLM's engine-core scheduler queue. It states that streams without
`include_usage` receive no `metrics`, that vLLM closes this with
`--enable-force-include-usage`, and that Flare has no equivalent option. The null
rules are two sentences, and one sentence defines the Chat `performance`
object: its fields and their shared process-local origin with
`choices[0].token_timestamps_ns`, with the model-contract link kept.

A reader of the HTTP API reference can tell where `queue_time_ms` starts, why a
stream may carry no metrics, and what `performance` holds. No behavior changes.

Evidence: Documentation only. The arrival boundary matches
`ModelRuntime::enqueue_many` in `helios/src/server/runtime.rs`, which reads
`arrival_ns` while building each `Incoming` and sends the group with
`try_send` after the loop. `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server:: scheduler:: cache::` passed 819 tests at
the head of the series this commit belongs to; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates from `tests/frontend/prepare_templates.py` through
`FLARE_TEST_TEMPLATE_DIR`, which this host does not have.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
`docs/api.md` and `docs/cli-design.md` enable per-request metrics with
`[server] per_request_metrics = true` in `~/.config/flare/config.toml`, the file
Ignition and native Flare share. The Ignition schema lacked the key, so every
Ignition command that loads the file failed with `unknown key
per_request_metrics in [server]`. The key joins the schema as a boolean, the way
`thinking_token_budget` and `scheduler_checkpoint_extra_work_fraction` do.

`ignition/cli/config.py` lists `per_request_metrics: bool` under `[server]`,
defaults it to false, and writes it as a comment in the initial configuration
file. `ignition debug-serve` passes it to the Helios bootstrap options beside the
two other `[server]` serving keys. `docs/cli-design.md` states that
`debug-serve` applies these three keys as native `flare run` does.

A configuration with `per_request_metrics = true` loads in every Ignition
command, a non-boolean value is a usage error, and `ignition debug-serve`
enables vLLM's per-request `metrics` when the key is true.

Evidence: `tests/cli/test_config.py` adds `test_per_request_metrics_configuration`
(absent, true, false) and two rejection rows (integer, string);
`uv run --with pytest python -m pytest tests/cli/test_config.py -q` passed 77
tests. `ignition debug-serve` was not run; it needs a GPU and a cached checkpoint.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
… enables

`docs/cli-design.md` gave `[server] per_request_metrics` as the configuration
default of `--enable-per-request-metrics` without saying which node's file applies
under `flare orbit run`, and did not say that the flag cannot turn the option off.
The Orbit agent starts rank zero as `flare run`, and `Configuration::apply` applies
the key from rank zero's node configuration, so Orbit already honors it there; a
test pins that path instead of adding a second configuration read on the
controller. The flag stays enable-only; the configuration key is the per-host
setting.

`flare-cli/src/config.rs` adds
`orbit_rank_zero_reads_per_request_metrics_from_its_node_configuration`, which
parses `flare orbit run`, forwards its rank-zero options as `flare run`
arguments, and applies a node configuration. The `--help` text of `flare run` and
`flare orbit run` names `[server].per_request_metrics` (rank zero's, for Orbit).
The `docs/cli-design.md` flag row states that the flag can only enable the
option, that the key sets it per host, and that Orbit reads rank zero's file.

The documentation and `--help` text describe the configuration source Orbit
uses; serving behavior does not change.

Evidence: `cargo test --locked --manifest-path flare-cli/Cargo.toml --bin flare --
cli:: config::` passed 51 tests, including the Orbit test for an absent key, a
true key, and the flag over a false key. `cargo check --locked --manifest-path
flare-cli/Cargo.toml` passed. No Orbit group was run.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
… API reference

The per-request metrics section of `docs/api.md` described
`time_to_first_content_token_ms` as a field null only when an instant was not
reached, although the encoder always writes null; applied the `n > 1` null to
every protocol, although only Completions accepts `n > 1`; omitted the shape of a
response with no generated token; and compared the instants to
`choices[0].token_timestamps_ns`, which the file never defined. The section now
states what `Encoder::metrics_value` produces.

The null paragraph says `time_to_first_content_token_ms` is always null, limits
the `n > 1` null to Completions, and states that a response with no generated
token has every field null except `queue_time_ms`, which is null too when no
model step included the request. The timestamp paragraph defines
`return_token_timestamps` (requires `return_token_ids`), the aligned
`choices[0].token_timestamps_ns` array, and the `performance` object, and points
to the prepared model contract for field definitions. The `mean_itl_ms` row
states that tokens one speculative step commits count as zero-length intervals,
and the boundary paragraph states that the first scheduled instant is read after
the worker packs the step's inputs, including vision inputs, and before
submission.

A client reading `docs/api.md` alone learns which `metrics` fields can carry a
value and what the timestamp extension returns.

Evidence: each statement was checked against `helios/src/server/protocol/encode.rs`
(`enable_request_metrics`, `metrics_value`), `helios/src/server/observation.rs`
(`ObservationOptions::parse`), `helios/src/server/runtime.rs` (the
`first_scheduled_ns` stamp after packing), and `helios/model-contract.md`. The
request-histogram section is unchanged.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
…ents

Three worker test drivers in `helios/src/server/runtime/phase_tests.rs` copied
the predicate that decides whether a step samples a token, the per-request
metrics encoder test fed reasoning and empty content events that no assertion
reads, and `encode.rs` restated the placement and null rules that
`docs/api.md#per-request-metrics` states. One helper, one answer event, and
pointer comments keep each rule in one place.

`phase_tests.rs` adds `generates`, used by `budget_pass`, `timed_pass`, and the
tool-limit cancellation test. `metered_generation` in
`helios/src/server/protocol/tests.rs` feeds one content event and records four
generated tokens; `carriers` is a function returning borrowed frame and metrics
values. `enable_request_metrics` and `metrics_value` carry one pointer comment
each to `docs/api.md#per-request-metrics`.

Every assertion of the metrics encoder test and the worker phase tests is
unchanged; behavior is unchanged.

Evidence: `cargo check --locked --manifest-path helios/Cargo.toml --features
server` passed. `cargo test --locked --manifest-path helios/Cargo.toml --features
runtime-core,server --lib -- server:: scheduler:: cache::` reported 819 passed, 1
failed, 11 ignored; the failure is
`server::protocol::decode::native_prompt_tests::messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
which does not involve these files.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: enterprise/deepseek-v4.1-flash (omp agent); design-review=eb2f
vLLM's per-request `metrics` object includes `time_to_first_content_token_ms`,
the time from the first scheduled step to the step whose output first produced
answer text, and Flare reports that field as null. Clients that read the object
for parity with vLLM's fields need the value. Only the HTTP
decoder can recognize answer text, because reasoning, tool-call output, and text
a named tool choice discards are separated after the worker publishes tokens,
while only the worker knows when each model step completed. The worker already
reads that completion instant once per step for the request histograms, so
passing it to the stream before the step's output lets the encoder latch the
instant at the first answer text without reading a clock.

A stream that reports per-request metrics with a content instant asks the
worker for `GenerationEvent::Committed { at_ns }` before each generating step's
output; the `commits` admission flag reaches the worker through
`generate_many_observed`, which the HTTP handler now uses for every submission,
and `generate`, the only other single-prompt entry, calls `enqueue_many`
directly. `output_event_capacity` adds one event per generated token for such
requests. The encoder keeps the latest step instant and records it when the first
non-empty content event passes tool-choice filtering. The HTTP handler builds
the encoder before submission, because its placement rules decide whether a
request needs commit instants. `docs/api.md` defines the field for streams, and
`helios/model-contract.md` states the larger event budget.

With `--enable-per-request-metrics`, a Chat, Completions, or Responses stream
that carries `metrics` reports `time_to_first_content_token_ms`; JSON bodies and
streams without answer text report null. The cost is one runtime event per
generating model step for those streams; other requests and the option off are
unchanged.

Evidence: `server::protocol::tests::content_instant_excludes_reasoning_tool_calls_and_suppressed_text`
checks that reasoning, tool calls, and text a named tool choice drops do not set
the instant; `per_request_metrics_follow_vllm_placement_and_null_rules` checks
the stream value and the null JSON-body value for every protocol;
`per_request_metrics_report_the_runtime_instants_of_a_stopped_reasoning_answer`
places the content instant inside the third generating worker step, after
reasoning and its close; `per_request_metrics_reach_completions_and_responses_where_vllm_places_them`
checks that plain text equals the first token instant; and
`per_request_metrics_are_absent_without_the_option_and_null_for_several_choices`
checks that no commit instants are requested with the option off or with
several choices. `cargo test --locked --manifest-path helios/Cargo.toml
--features runtime-core,server --lib -- server:: scheduler:: cache::` passed 820
tests; the one failure,
`messages_image_hints_end_after_expansion_for_text_and_segmented_templates`,
needs templates through `FLARE_TEST_TEMPLATE_DIR`, which this host does not
have. No GPU or live server was used, and the cost of the extra events under
load has not been measured.

Signed-off-by: Wynn Drahorad <[email protected]>
Design-Signed-Off-By: Claude Opus 5.5 (omp agent); design-review=eb2f
@WynnD
WynnD force-pushed the metrics/content-ttft branch from 4aa7b3a to 3e8fd28 Compare November 28, 2026 22:54
@WynnD

WynnD commented Nov 28, 2026

Copy link
Copy Markdown
Author

Closing to keep the metrics work to three PRs (#549, #548, #560). In #560, time_to_first_content_token_ms is always null, which vLLM permits when the value is unavailable. The streaming content-instant implementation stays on branch WynnD:metrics/content-ttft (commit 3e8fd28) and can be reopened as a follow-up.

@WynnD WynnD closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant