Subtractive report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/a7648bc5-725b-4680-bcef-3e77a132adaf.md

Verdict: make it smaller first. The request histograms themselves are the right shape and are close to minimal, but the new helios/src/server/metrics/process.rs (~178 of the 548 added lines) is mostly scaffolding, the PR adds a histogram abstraction without retiring the three hand-rolled histograms it supersedes, and one cross-feature reference breaks the build documented for --features server.

Change at head a34c4d060f96553c490eceb44b2fcf09ed277098: 10 files, +548/−25 (pr_files, read_item #548). No commits after d64c3ea3/a34c4d0, so nothing from the previous round changed; I re-read every cited line in the head files (notes #16, #17).

Key findings, ranked by lines saved

  1. Blocking (also a subtraction), −4 lines and −2 files — process.rs:68 crate::runtime_core::open_descriptors() crosses a cargo feature server does not enable, so the documented --features server build no longer compiles; the 4-line local /proc/self/fd read it replaced is also the smaller version.
  2. Should fix, ~80 of process.rs's 178 lines — write-nothing wrapper plus five inner #[cfg(target_os = "linux")], six Option fallbacks around sources that cannot fail on Linux, and a test that asserts live kernel values.
  3. Should fix, ~53 lines in metrics.rs — the new Buckets/Histogram was added beside the three hand-rolled host histograms instead of in place of them.
  4. Nit, ~28 lines — docs/api.md repeating the HELP strings, two phase-test assertions the route test already makes, an unreachable state-character guard in parse_stat, a nested if let.
  5. Nit, ~3 lines — the nested if let in Metrics::request_completed (part of finding 4).
  6. Optional, ~7 lines (not counted in the total) — latency.rs:101-108 render_histogram is a pure pass-through to Histogram::render; inlining it at its only caller (server.rs:671) removes it, but moves the help string away from the observation, so it trades a little readability for the lines.

Total ≈ 165 of 548 added lines (~30%), about 100 of them in the single new file.

Charter anchors: line 35 (what gets merged: maintainer request, roadmap item, reproducible bug, measured perf/memory issue, or bad docs) — the histograms' right to exist rests on issue #536 being the referenced ask, a scope judgement I do not argue against; AGENTS.md:20-21 puts host OS operations in eos/, where a shared descriptor counter would belong if it is shared at all; AGENTS.md:188-193 "Reject unsupported abstractions and churn" — no frameworks, fallback layers, or configuration switches without a concrete requirement, which is exactly findings 2 and 3; AGENTS.md:194-196 "Require focused, meaningful validation" — a test that asserts the kernel's own values is not validation of this code (finding 2c).


1. Blocking: open_descriptors reuse crosses a cargo feature boundary, breaking the documented --features server build

Files: helios/src/server/metrics/process.rs:68, helios/src/runtime_core/mod.rs:58, helios/src/runtime_core/protection.rs:291.

Commit d64c3ea3 replaced process.rs's local /proc/self/fd count with crate::runtime_core::open_descriptors() and re-exported it (runtime_core/mod.rs:58 pub(crate) use protection::open_descriptors;, protection.rs:291 widened to pub(crate)).

Smaller version (what the file had before d64c3ea3), 4 lines, no cross-feature edge:

let open_fds = std::fs::read_dir("/proc/self/fd")
    .ok()
    .map(|entries| entries.filter_map(Result::ok).count() as u64);

Goes: runtime_core/mod.rs:58 (1 line) and the pub(crate) widening at protection.rs:291 (net 0). Net −2 lines and −2 files. If duplication is unwelcome, the 8-line helper belongs in flare-eos, which AGENTS.md:20-21 designates for host OS operations and which helios always links — larger than reverting.

2. Should fix: process.rs carries a shim, five cfg attributes, six dead Option fallbacks and a kernel-assert test (~80 of 178 lines)

(a) Non-Linux shim and five inner cfgs, ~10 lines. process.rs:8-14 defines pub(crate) fn render(text) with #[cfg(target_os = "linux")] render_linux(text); / #[cfg(not(target_os = "linux"))] let _ = text;, and #[cfg(target_os = "linux")] is repeated on parse_stat (:18), parse_btime (:39), metric (:47), render_linux (:56) and the test module (:128). The repository gates whole platform modules instead (helios/src/server.rs:26-27). Smaller: #[cfg(target_os = "linux")] pub(super) mod process; at metrics.rs:12 plus #[cfg(target_os = "linux")] metrics::process::render(&mut text); at server.rs:709; all six attributes and the wrapper go. ~6 lines, and removes a never-exercised path on the Windows build the description says was not run.

(b) Six if let (Some(..), Some(..)) fallbacks, ~45 lines (process.rs:72-125). The module doc (:4-6) promises a scrape "never panics on a missing or malformed file", but on Linux /proc/self/stat, /proc/stat and /proc/self/fd exist for a live process, page_size() always returns a value (eos/src/unix.rs:73-75 falls back to 4096), a positive sysconf(_SC_CLK_TCK) is guaranteed, and crate::os::raise_open_file_limit(0) returns Some(current) for every desired <= current (eos/src/unix.rs:138-147), so max_fds (:117) is always Some. Smaller, one guard per source and straight calls:

let ticks = unsafe { libc::sysconf(libc::_SC_CLK_TCK) } as u64;
let stat = std::fs::read_to_string("/proc/self/stat").ok().and_then(|l| parse_stat(&l));
let btime = std::fs::read_to_string("/proc/stat").ok().and_then(|c| parse_btime(&c));
let Some(stat) = stat else { return };
metric(text, "process_cpu_seconds_total", "counter", "…", (stat[0] + stat[1]) as f64 / ticks as f64);
metric(text, "process_virtual_memory_bytes", "gauge", "…", stat[3]);
metric(text, "process_resident_memory_bytes", "gauge", "…", stat[4] * crate::os::page_size() as u64);
if let Some(btime) = btime { metric(text, "process_start_time_seconds", "gauge", "…", btime as f64 + stat[2] as f64 / ticks as f64); }
if let Some(open) = open_fds { metric(text, "process_open_fds", "gauge", "…", open); }
if let Some(max) = crate::os::raise_open_file_limit(0) { metric(text, "process_max_fds", "gauge", "…", max); }

Nothing is lost on Linux, the only platform that emits anything; parse_stat/parse_btime keep their Option returns.

(c) Test that asserts the kernel, ~37 lines. process.rs:150-176 (render_reports_process_memory_descriptors_and_start_time plus its value helper at :132-139) asserts live /proc values — resident > 0, virtual ≥ resident, fds ≥ 1, start time within the last hour — and that six # TYPE lines exist. The route test already checks the series in a real scrape body (phase_tests.rs:5398-5399 asserts process_resident_memory_bytes), and the only test that proves something about this code is parse_stat_reads_fields_after_a_parenthesized_command_with_a_paren (:141-148). A broken reader would fail the scrape test too.

Not a saving, checked and dropped: folding process.rs's metric (:47-54) into the shared metrics::metric. The shared writer hard-codes the flare_ prefix (metrics.rs:1597-1602) and takes u64, so process_* names and the f64 CPU/start-time values do not fit.

3. Should fix: the new Histogram type should replace the hand-rolled host histograms, not sit beside them (~53 lines)

The PR adds Buckets<N>/Histogram<N> (metrics.rs:212-298) for the five new request histograms but leaves the three host prefix-store histograms on the older machinery in the same file.

What goes:

Smaller version (labels and sums preserved exactly, because scale: 1.0 keeps the exposed unit at nanoseconds/tokens):

const HOST_TOKENS: Buckets<8> = Buckets { bounds: [64.0, 256.0, 1024.0, 4096.0, 16384.0, 65536.0, 262144.0, f64::INFINITY], scale: 1.0 };
const HOST_NANOSECONDS: Buckets<8> = Buckets { bounds: [1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, f64::INFINITY], scale: 1.0 };

pub(super) fn host_lookup_cost(&self, hit: &flare_selene::HostHit, rate: f64) {
    let missing = hit.consumed_tokens - hit.resident_tokens;
    self.host_missing_tokens.observe(&HOST_TOKENS, missing);
    self.host_transfer_ns.observe(&HOST_NANOSECONDS, (hit.estimated_seconds * 1e9) as u64);
    self.host_prefill_ns.observe(&HOST_NANOSECONDS, (missing as f64 / rate.max(1.0) * 1e9) as u64);
}

for (histogram, name, help, buckets) in [
    (&self.host_missing_tokens, "host_cache_missing_tokens", "…", &HOST_TOKENS),
    (&self.host_transfer_ns, "host_cache_estimated_transfer_ns", "…", &HOST_NANOSECONDS),
    (&self.host_prefill_ns, "host_cache_estimated_prefill_ns", "…", &HOST_NANOSECONDS),
] {
    histogram.render(text, name, help, buckets);
}

Why nothing is lost: Histogram::observe picks position(|bound| exposed <= *bound).unwrap_or(N - 1) (metrics.rs:264-268), the same rule the removed .position(..).unwrap() used (:689); with scale: 1.0 the le labels and _sum print the same integers. host_outcomes_and_capacity_have_bounded_labels_and_cost_histograms (metrics.rs:1785-1787) reads only _sum and keeps passing. The only output change is that the three series gain # HELP lines (render, :274-277) — additive exposition, not lost behaviour. Honest caveat: Histogram::render writes _sum as sum as f64 / scale (:291-295), so ns sums above 2^53 round where today's host _sum is exact u64. The request histograms this PR adds already accept that trade. Do not propose padding TOKEN_SECONDS to 21 bounds to fold the request histograms into one loop: that changes bucket boundaries, so it is not lossless. The retirement histogram (metrics.rs:851-876) cannot join Histogram without a set-style variant either.

4. Nit: doc prose that repeats the HELP text, two redundant assertions, an unreachable guard (~28 lines)

(a) docs/api.md:309-316 restates the metric HELP strings almost verbatim (compare "spans model-scheduler arrival to the first model step that includes the request" with metrics.rs:1398, and "decode time divided by generated tokens after the first" with metrics.rs:1416). The HELP text ships in every scrape. ~8 of the added doc lines can go, keeping the series names, the "Prometheus format only / cumulative since start" sentence, the cancelled/failed exclusion and the prefix-cache note.

(b) phase_tests.rs:4428-4432 asserts flare_request_e2e_seconds_count 0 in a failed-stream case that already asserts the first-response sample count is 0 for the same condition (:4425-4427); the exclusion that needed proving is pinned by the tool-limit test (:4601-4616). phase_tests.rs:4466-4471 re-renders render_histogram to check flare_time_to_first_response_seconds_count, which metrics_route_serves_prometheus_or_json_without_the_api_key (:5389-5395) already checks through the real route. ~11 lines, no behaviour lost.

(c) process.rs:24-28 — the state-character guard ("rejecting a line without one keeps this parser from reading unrelated text that happens to contain )") cannot trigger: parse_stat has one production caller, the /proc/self/stat read at :62-64, plus its own test. Junk input already fails on parse in value(10). Dropping the guard and the parse_stat("42 (no tail)") line (:147) removes ~6 lines and leaves the utime offset fix intact.

(d) metrics.rs:462-469 — the inner if let Some(first) is guaranteed, since first_token_ns is only stamped in Worker::complete (runtime.rs:1774-1775) for an active request, and every active request reaches a step through reserve_and_pack (runtime.rs:2197-2201). Worth only ~3 lines, because flattening to if let (Some(scheduled), Some(first)) = (…) would also drop the queue observation for a request that reached a step but committed no token.

5. Optional nit: the pass-through renderer in latency.rs (~7 lines, not counted above)

helios/src/server/latency.rs:101-108 render_histogram only forwards to Histogram::render with the name, help and REQUEST_SECONDS hard-coded; its sole caller is server.rs:671. Inlining that call at the route (making the histogram field pub(super) at latency.rs:36) removes the wrapper. The trade: the request histograms keep their names and helps in metrics.rs's render loop (:1389-1412), so this one would live in the route handler instead of beside its observation. I rank it below finding 4 and do not count its lines in the total.

Already minimal — say so plainly

The five request histogram definitions and their bounds (metrics.rs:219-241) are exactly issue #536's missing-metrics table; the three RequestTimes fields and the two stamp sites (runtime.rs:1774-1775, :2197-2201) are the minimum that yields queue/prefill/decode, and preemption preservation is free because parking moves Incoming; cancelled/failed requests correctly stay out; flare_request_e2e_seconds is now observed in exactly one place (http.rs:598-606) and Worker::publish hoists its prompt/generated locals (runtime.rs:1993-1998), so the two findings from the earlier review (duplicate e2e observation, recomputed locals) are resolved at head and are not repeated. The window field rename in latency.rs (11 self.0 → self.window sites) is the unavoidable cost of a named struct with a second field.

Open questions / could not verify