Subtractive report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/6cc5deb2-87ec-4d51-a0b9-ac4ade2805ff.md

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

Key findings (ranked by lines saved)

  1. Blocking (also a subtraction), −4 lines and −2 files — process.rs:68 calls crate::runtime_core::open_descriptors(), a module behind a cargo feature server does not enable, so the documented --features server build no longer compiles. The 4-line local read it replaced is also the smaller version.
  2. Should fix, ~80 of process.rs's 177 lines — a write-nothing wrapper plus five inner #[cfg(target_os = "linux")] attributes, six if let (Some, Some) fallbacks around procfs/sysconf/page_size()/raise_open_file_limit(0) 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 type was added beside the three existing 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.
  5. Nit, ~3 lines — the nested if let in Metrics::request_completed.

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


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.

Head 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, no API change:

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 in the diff. If duplication is unwelcome, the 8-line helper belongs in flare-eos, which AGENTS.md:20-21 designates as the holder of host OS operations and which helios always links — but that is larger than reverting.

Caveat: not compiled here; the claim is derived from the #[cfg] and feature lists above.

2. Should fix: process.rs carries a shim, five cfg attributes, six dead Option fallbacks and a kernel-assert test (~80 of 177 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 it 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 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, 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 reaches 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; 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.

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 39 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 (:5390-5393) 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.

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 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 here. The retirement histogram (metrics.rs:851-876) cannot join Histogram without a set-style variant, so it is not a lossless cut either.

Open questions / could not verify