Review of PR #548 — Add request latency histograms and process metrics
Lens: subtraction only. Judged against the charter (read_charter: "Keep the runtime small and model-agnostic"; "What gets merged"), AGENTS.md ("Reject unsupported abstractions and churn… do not add… fallback layers"; "Tests must exercise the affected behavior… source-text checks… cannot establish runtime correctness") and docs/design-review.md principle 1 ("Keep Helios as simple as possible"). Nothing in this PR instructs the reviewer; the Discord handle and live-scrape evidence in the description were treated as review material only.
Key findings
The request-histogram core of this change is genuinely minimal and should stay: the five Buckets/Histogram definitions (helios/src/server/metrics.rs:219-241) are exactly the missing series in #536, the RequestTimes fields plus the two stamps (helios/src/server/runtime.rs:1774-1775, 2189-2203) are the minimum that yields queue/prefill/decode intervals, and preemption survival costs no code because Incoming moves into the parked list whole. Nothing here asks for a new feature, check, option or test.
The removable weight is elsewhere and is concentrated in one new file:
- Should fix —
helios/src/server/metrics/process.rs(new, 184 lines): a second procfs reader stack and six fallbacks for sources that cannot fail on Linux. ~70 lines (38% of the file). - Should fix — the new
Buckets/Histogramwas added beside the hand-rolled host histograms already inmetrics.rs, and the e2e observation is written twice. ~45 lines. - Should fix —
request_completednests a check that cannot fail, its test builds the impossible state, andWorker::publishrecomputes two expressions it could hoist. ~13 lines. - Nit — non-Linux shim, a second
implblock, docs restating the HELP strings, duplicated histogram assertions. ~19 lines. - Optional scope — two of the six process metrics (
process_virtual_memory_bytes,process_max_fds) are not in #536's missing-metrics table. ~18 lines.
Total ≈ 145 of the 545 added lines (~27%), about 100 of them inside the one new file. No behaviour is lost by any of it. The change is not blocking on size; it should be made smaller first.
1. Should fix — helios/src/server/metrics/process.rs: a second procfs reader stack with six dead fallbacks (~70 of 184 lines)
1a. Fallbacks for sources that cannot fail (~30 lines)
render_linux (process.rs:51-133) reads /proc/self/stat, /proc/stat btime, /proc/self/fd and RLIMIT_NOFILE into Options and emits each metric behind if let (Some(..), Some(..)) — six blocks (process.rs:79-132) plus the -> Option plumbing in parse_btime (process.rs:34-40). On Linux all four sources always succeed: /proc/self/stat, /proc/stat and /proc/self/fd are kernel-provided for the calling process, and getrlimit(RLIMIT_NOFILE) cannot fail for a valid resource. The module doc comment (process.rs:4-6) justifies the scaffolding with "a scrape never fails", which is true of the plain calls too — a failed read leaves text untouched either way.
Smaller version, one early return and one line per metric:
let Some(stat) = std::fs::read_to_string("/proc/self/stat").ok().and_then(|l| parse_stat(&l)) else { return };
let ticks = ticks() as f64;
metric(text, "process_cpu_seconds_total", "counter", "…", (stat[0] + stat[1]) as f64 / ticks);
metric(text, "process_resident_memory_bytes", "gauge", "…", stat[4] * flare_eos::page_size());
metric(text, "process_start_time_seconds", "gauge", "…", btime().unwrap_or(0) as f64 + stat[2] as f64 / ticks);
metric(text, "process_open_fds", "gauge", "…", flare_eos::open_descriptors());
metric(text, "process_max_fds", "gauge", "…", flare_eos::raise_open_file_limit(0).unwrap_or(0));
1b. Duplicate procfs and limit readers (~15 lines, three unsafe blocks)
open_fds(process.rs:65-67) isopen_descriptors()athelios/src/runtime_core/protection.rs:291-302, character for character (read_dir("/proc/self/fd").ok().map(|e| e.filter_map(Result::ok).count() as u64)). It is behind theruntime-corefeature (helios/Cargo.toml:21,25;serverdoes not enable it), so reuse means moving those 8 lines intoflare_eos, which already owns the platform split and is an unconditional dependency of helios (Cargo.toml:34;helios/src/lib.rs:36re-exports from it). That move deletes the copy rather than adding a call.max_fds(process.rs:68-77, 10 lines + a SAFETY comment) isflare_eos::raise_open_file_limit(0)(eos/src/unix.rs:138-165): withdesired = 0 <= rlim_curit returns the soft limit unchanged, nosetrlimit.page(process.rs:55-58) isflare_eos::page_size()(eos/src/unix.rs:73-75,windows.rs:152) — and unlike the rawsysconf, it needs nounsafe.
Both eos calls are reachable from server code today (helios/src/lib.rs:36; eos is not feature-gated), so only the fd counter needs the small move.
1c. A test that asserts the kernel, not the code (~25 lines)
render_reports_process_memory_descriptors_and_start_time (process.rs:157-183) asserts live /proc values (resident > 0, virtual >= resident, max_fds >= open_fds, start within the last hour) and that six # TYPE lines are present. It fails only if the host kernel is broken, and the scrape-level assertion already exists: metrics_route_serves_prometheus_or_json_without_the_api_key (helios/src/server/runtime/phase_tests.rs:5379-5388) checks that a process_* series reaches a real /metrics response. AGENTS.md asks tests to exercise behaviour rather than source text; this one does neither. Keeping only parse_stat_reads_fields_after_a_parenthesized_command_with_a_paren (process.rs:148-155), which does test the one non-obvious parser, loses nothing.
2. Should fix — the new histogram type coexists with the hand-rolled host histograms, and e2e is observed twice (~45 lines)
2a. Histogram<N> did not replace what it duplicates (~40 lines)
Buckets/Histogram (helios/src/server/metrics.rs:212-298) is exactly the machinery that already exists, hand-rolled, for the three host-cache cost histograms: HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS (metrics.rs:200-210), the parallel arrays host_missing_tokens/host_transfer_ns/host_prefill_ns and host_cost_sums (metrics.rs:382-385), the bucket loop with .position(..).unwrap() in host_lookup_cost (metrics.rs:670-692), and the 37-line render loop (metrics.rs:1029-1065). The PR adds the abstraction and leaves the copy in place, so the file now has two histogram implementations.
Converting the three host histograms to Histogram<8> deletes the two constants, host_cost_sums, the .zip(limits)/.position loop (three observe calls remain) and the render loop (three render calls remain). The existing test host_outcomes_and_capacity_have_bounded_labels_and_cost_histograms (metrics.rs:1740-1796) reads only the rendered text and keeps passing unchanged, provided the labels stay the same — the only behavioural difference is that flare_host_cache_*_sum would stop being a u64-truncated integer and instead divide by scale, which is the same number for the ns/token grids.
2b. One e2e observation written twice, plus a needless Arc clone (~5 lines)
Every successful generation yields exactly one Delivery::Complete (helios/src/server/http.rs:598, the only such yield in the generator body); failures return right after Delivery::Failed (http.rs:576-577). So the same if !count { … request_e2e.observe(…) } is written once per delivery shape (http.rs:614-617 streaming, http.rs:631-632 non-streaming), and the streaming arm needs let metrics = state.model.metrics_handle(); (http.rs:603) purely to satisfy the 'static closure. Recording once before the yield replaces both copies and the clone:
if !count {
state.model.metrics().request_e2e
.observe(&super::metrics::REQUEST_SECONDS, admitted_at.elapsed().as_nanos() as u64);
}
yield Delivery::Complete(response);
The timing is identical: that line is reached only when the client polls to completion, which is the condition the two match arms test today (the phase tests first_response_http_nonstream_records_only_when_completed_body_is_offered and first_response_http_stream_excludes_pretext_failures_and_unpolled_bodies cover both paths and stay green).
3. Should fix — request_completed guards a state that cannot occur; publish recomputes two values (~13 lines)
3a. Nested if let that cannot fail (~8 lines including test)
helios/src/server/metrics.rs:462-469 nests if let Some(first) = times.first_token_ns inside if let Some(scheduled) = times.first_scheduled_ns. first_scheduled_ns is stamped in reserve_and_pack for every lane of every committed step (helios/src/server/runtime.rs:2189-2203), and first_token_ns is stamped only in Worker::complete (runtime.rs:1774-1775) for tokens of an active request whose step went through reserve_and_pack, so first_token_ns.is_some() implies first_scheduled_ns.is_some(). Flatten to two sibling blocks:
if let Some(scheduled) = times.first_scheduled_ns {
self.request_queue.observe(&REQUEST_SECONDS, scheduled.saturating_sub(arrival_ns));
if let Some(first) = times.first_token_ns {
self.request_prefill.observe(&REQUEST_SECONDS, first.saturating_sub(scheduled));
}
}
That keeps the queue observation unconditional on the token (the shape the code already has) without a second nesting level. The half of request_histograms_bucket_completed_request_timings (metrics.rs:1684-1697) that constructs first_scheduled_ns: None, first_token_ns: Some(..) goes with it — it tests an unreachable state.
3b. Duplicated expressions in Worker::publish (~4 lines)
runtime.rs:1993-1998 and 2015-2019 compute request.carried.prompt_tokens.unwrap_or(prompt_tokens) and request.carried.generated_tokens + generated twice. Worker::complete already hoists them (runtime.rs:1838-1840) before calling request_completed; the same two locals in publish make both call sites one shape.
4. Nit — shim, second impl block, docs and tests repeating themselves (~19 lines)
- Non-Linux shim, ~6 lines.
process.rs:8-14wrapsrender_linuxso other platforms compile a function that writes nothing, andmetrics.rs:12declares the module unconditionally. The repository already cfg-gates platform modules (helios/src/runtime_core/protection.rs:291-302, theeoscrate):#[cfg(target_os = "linux")] pub(super) mod process;and#[cfg(target_os = "linux")] metrics::process::render(&mut text);athelios/src/server.rs:709remove both the wrapper and thelet _ = textarm. Worth doing precisely because Windows was not built or run here. - Second
implblock, 2 lines.render_histogramsits in its ownimpl FirstResponseSamples(helios/src/server/latency.rs:122-131) instead of the existing block atlatency.rs:63-101. - Docs repeating the HELP strings, ~6 lines.
docs/api.md:300-313restates sentence for sentence what the HELP strings say (metrics.rs:1387-1425), e.g. "from model-scheduler arrival to the first model step" / "decode time divided by generated tokens after the first". For an operator one copy is enough; the doc should keep the names, the excluded-cases rule (cancelled/failed excluded, prefix-reused tokens counted) and drop the four start/end clauses. - Duplicated assertions, ~5 lines.
phase_tests.rs:4429-4432and4464-4470re-check e2e/ttfr counts thatmetrics_route_serves_prometheus_or_json_without_the_api_key(phase_tests.rs:5379-5388) already checks through a real scrape. Keep the behavioural bit each test proves (a failed stream leaves e2e at 0; one offered body leaves it at 1) and drop the re-render of the histogram at4466-4470.
5. Optional scope — two metrics that #536 does not ask for (~18 lines)
Issue #536's missing-metrics table lists process_cpu_seconds_total, process_resident_memory_bytes, process_open_fds and process_start_time_seconds. process_virtual_memory_bytes (process.rs:88-96) and process_max_fds (process.rs:124-132) are additions of this PR, and virtual size is not an actionable number for a GPU server (it tracks the CUDA/arena reservations, not pressure). Dropping both also removes two doc lines (docs/api.md:316-317) and two test assertions (process.rs:163-164, 178-179). This is a scope judgement rather than a duplicate, so it ranks below the others; if the extra two are wanted, leave them.
What is already minimal — do not cut
- The five histograms and their bucket bounds (
metrics.rs:219-241) are the deliverable of #536 and match its table. RequestTimesand its two stamps (runtime.rs:1774-1775,2189-2203) are the minimum for queue/prefill/decode intervals; preserving them across preemption is free because parking movesIncominginto the parked list and readmission reuses it (runtime.rspark path around2058).request_completedas the single place that increments the counter and observes the histograms (metrics.rs:452-480) is the right consolidation; both call sites now go through it.- The
render_histogramsplit inlatency.rs+server.rs:671is necessary because the first-response histogram lives outsideMetrics; it is one call, not a wrapper layer. Buckets/Histogramthemselves: given four histograms, one type is smaller than four hand-rolled copies — the finding is that the host histograms were not converted, not that the type should go.
Open questions and what I could not verify
- Whether the author wants the host-histogram conversion in this PR or a follow-up: it touches rendering of existing series, so a maintainer may prefer it separate. It is still the largest single saving and the only way the new abstraction pays for itself.
- #536 is a community issue rather than a maintainer request; under the charter's "What gets merged" the case rests on it being the roadmap-visible ask it references. That is a merge-eligibility question, not a subtraction, and I have not treated it as a finding.
- The description says the Windows build and the full helios suite were not run; CI has no checks on
ebecef1. Finding 4's shim removal should be re-checked by whatever CI builds Windows. - Unverifiable here: the claim in the description that
flare_request_e2e_secondsexcludes only/v1/messages/count_tokens— I confirmed thecountguard (http.rs:131) is the only exclusion, which matches.