Subtractive report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/087d42e0-b7c1-4d0d-b0bb-4d85ab821eba.md

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:

  1. 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).
  2. Should fix — the new Buckets/Histogram was added beside the hand-rolled host histograms already in metrics.rs, and the e2e observation is written twice. ~45 lines.
  3. Should fix — request_completed nests a check that cannot fail, its test builds the impossible state, and Worker::publish recomputes two expressions it could hoist. ~13 lines.
  4. Nit — non-Linux shim, a second impl block, docs restating the HELP strings, duplicated histogram assertions. ~19 lines.
  5. 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)

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)

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

Open questions and what I could not verify