Subtractive scratchpad · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/f8236b35-7c57-4ee9-a3a7-059934457c39.md

#1 [high] Should fix: process.rs re-implements existing helpers and keeps fallbacks for sources that cannot fail (~70 lines)

File: helios/src/server/metrics/process.rs (new, +184).

(a) Duplicate metric writer. process.rs:42-49 defines fn metric(text,name,kind,help,value: impl Display) that is metrics::metric (helios/src/server/metrics.rs:1597-1602) minus the flare_ prefix and with a Display value. Call it from metrics.rs/server.rs with full names and one helper disappears (~9 lines). Same shape is also open-coded at metrics.rs:1626-1636 and server.rs:669, so the repo already tolerates one writer.

(b) Duplicate procfs/resource-limit readers:

(c) Fallback chains for sources that cannot fail. render_linux (process.rs:51-133, 83 lines) reads /proc/self/stat, /proc/stat btime, /proc/self/fd, RLIMIT_NOFILE as Options and emits each metric behind if let (Some(..), Some(..)) (6 blocks, ~54 lines). On Linux /proc/self/stat, /proc/stat and /proc/self/fd always exist and getrlimit(RLIMIT_NOFILE) always succeeds, so 6 of the 8 fallbacks are dead. Smaller version: one early return / unwrap_or_default per source and 6 straight metrics::metric(...) calls:

let Some(stat) = ... parse_stat(...) else { return };
metrics::metric(text, "process_cpu_seconds_total", "counter", "...", (stat[0]+stat[1]) as f64/ticks as f64);
... (5 more, one line each)

Saves ~30 lines of scaffolding plus the -> Option plumbing in parse_btime (process.rs:34-40).

(d) Test that proves the OS, not the code: render_reports_process_memory_descriptors_and_start_time (process.rs:157-183, ~27 lines) asserts live /proc values and that six # TYPE lines exist; the phase test metrics_route_serves_prometheus_or_json_without_the_api_key (runtime/phase_tests.rs:5387-5388) already asserts a process_* series reaches a scrape. Keeping only parse_stat_reads_fields_after_a_parenthesized_command_with_a_paren (process.rs:148-155) loses nothing. ~25 lines.

Total process.rs: ~70 of 184 lines (38%), no behaviour that a Linux run can observe.

Scope note: #536's missing-metrics table asks for process_cpu_seconds_total, process_resident_memory_bytes, process_open_fds, process_start_time_seconds only. process_virtual_memory_bytes (process.rs:88-96) and process_max_fds (process.rs:124-132) are not requested and virtual size is uninformative for a GPU server; dropping both removes another ~18 lines plus two doc lines (docs/api.md:316-317) and two test assertions (process.rs:163-164,178-179).

#2 [high] Should fix: request_completed keeps a per-request state that cannot occur and publish() recomputes two values

File: helios/src/server/metrics.rs:452-480 and helios/src/server/runtime.rs:1993-2019.

(a) metrics.rs:462-469 — the inner if let Some(first) = times.first_token_ns inside if let Some(scheduled) = times.first_scheduled_ns cannot fail. first_scheduled_ns is stamped in reserve_and_pack (runtime.rs:2189-2203) for every lane of every committed step, and first_token_ns is only stamped 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() ⇒ first_scheduled_ns.is_some(). Flatten to one if let:

if let Some(scheduled) = times.first_scheduled_ns {
    self.request_queue.observe(&REQUEST_SECONDS, scheduled.saturating_sub(arrival_ns));
}
if let (Some(scheduled), Some(first)) = (times.first_scheduled_ns, times.first_token_ns) {
    self.request_prefill.observe(&REQUEST_SECONDS, first.saturating_sub(scheduled));
}

(or one block using (Some(s), Some(f)) with the queue observation outside). The test at metrics.rs:1684-1697 constructs the impossible state (first_scheduled_ns: None, first_token_ns: Some(..)) and asserts on it; that half of the test goes too. ~5-8 lines including the test case.

(b) runtime.rs:1993-1998 and 2015-2019 compute the same two expressions twice: request.carried.prompt_tokens.unwrap_or(prompt_tokens) and request.carried.generated_tokens + generated. Worker::complete already hoists them into locals (runtime.rs:1838-1840) before calling request_completed and building the event. Do the same in publish:

let prompt_tokens = request.carried.prompt_tokens.unwrap_or(prompt_tokens);
let generated_tokens = request.carried.generated_tokens + generated;
self.metrics.request_completed(request.incoming.arrival_ns, request.incoming.times, prompt_tokens, generated_tokens);
... GenerationEvent::Finished { prompt_tokens, generated_tokens, .. }

~4 lines, and the two call sites become identical in shape.

#6 [high] Research summary

Reviewed PR #548 (8 files, +545/−20) against the charter, AGENTS.md and docs/design-review.md, strictly for subtraction. The request histograms themselves are the #536 deliverable and are minimal; the removable weight is concentrated in the new process.rs (184 lines) and in the fact that the new Histogram type was added beside the hand-rolled host histograms already in metrics.rs.

Findings, ranked by lines saved (all in the scratchpad with citations):

  1. Should fix, ~70 of 184 lines in helios/src/server/metrics/process.rs. A second metric writer duplicating metrics::metric (metrics.rs:1597), duplicate procfs readers (open_descriptors protection.rs:291, flare_eos::raise_open_file_limit(0), flare_eos::page_size()), and six dead if let (Some, Some) fallbacks around /proc sources that always exist on Linux. ~25 more lines in a test that asserts live /proc values already covered by the scrape test.
  2. Should fix, ~45 lines. The new Buckets/Histogram coexists with the hand-rolled HOST_*_BUCKETS + host_cost_sums + 37-line render loop (metrics.rs:200-210, 382-385, 1029-1065); converting the three host histograms deletes the old machinery. The e2e observation is also written twice (http.rs:614, 631) plus a needless Arc clone, and can be one call before the single yield Delivery::Complete (http.rs:598).
  3. Should fix, ~13 lines. request_completed nests a first_token_ns check that cannot fail (metrics.rs:462-469) and its test constructs the impossible state; Worker::publish recomputes the prompt/generated expressions twice (runtime.rs:1993-2019) where Worker::complete already hoists them.
  4. Nits, ~19 lines. Non-Linux shim for a function that writes nothing, second impl block in latency.rs, docs/api.md restating the HELP strings verbatim, duplicated histogram assertions in phase_tests.

Total: about 145 of the 545 added lines (~27%) removable with no behaviour lost; the change is not blocking on size.

#7 [high] Tally and framing for the final report (change size, per-finding savings, verdict)

Change size (from pr_files / diff): 8 files, +545/−20.

Ranked savings (details in notes 1-5, each title starts with its severity):

  1. Should fix — helios/src/server/metrics/process.rs: ~70 of 184 lines (38%).
  2. Should fix — helios/src/server/metrics.rs:212-298 + metrics.rs:1029-1065 + http.rs:603,614-617,631-632: ~45 lines.
  3. Should fix — metrics.rs:452-480, runtime.rs:1993-2019, metrics.rs:1684-1697: ~13 lines.
  4. Nit — process.rs:8-14 + server.rs:709 (shim, ~6), latency.rs:122-131 (2), docs/api.md:300-313 (~6), phase_tests.rs:4466-4470 (~5): ~19 lines. Total ~147 of +545 (~27%); ~100 of that is in the one new file. Verdict: not blocking on size; no finding asks for a new feature/check/test/option.

What is already minimal (say so plainly in the report): the five request histograms are exactly the #536 "Missing metrics" table (issue #536, opened 2026-11-26); the RequestTimes fields plus the two stamps (runtime.rs:1774-1775, 2189-2203) are the minimum that yields queue/prefill/decode intervals, and preemption preservation is free from Incoming moving into the parked list, not added code. Everything is observability-only; the description claims no performance change, which matches — but charter line 35 / AGENTS.md:165-169 ("what gets merged") means the case rests entirely on #536 being the maintainer-visible request it references, and #536 is a community issue, not a maintainer request. Worth one sentence, not a finding.

Charter/guidance citations to use: charter "Solve the right problem in the right place" (smallest footprint, way to solve without new code at all) and "Keep the runtime small"; AGENTS.md:188-193 ("Reject unsupported abstractions and churn… do not add frameworks… fallback layers"); AGENTS.md:194-199 ("Tests must exercise the affected behavior… source-text checks… cannot establish runtime correctness"); docs/design-review.md principle 1 ("Keep Helios as simple as possible"). Also AGENTS.md:448-451 (no env switches — not violated here; don't cite).

Note on the PR's own evidence: the author's live scrape and 109-test run are credible but include the agent session's own requests (stated in the description), so the histogram counts exceed the three test requests; not a subtraction finding, only context if the report mentions the evidence.

#9 [high] Blocking: process.rs reuses crate::runtime_core, which the documented --features server build does not have (2-line revert, fixes a build break)

Head a34c4d0 (commit d64c3ea3 "reuse host helpers") replaced process.rs's local /proc/self/fd count with crate::runtime_core::open_descriptors() (helios/src/server/metrics/process.rs:68) and widened/re-exported it (helios/src/runtime_core/protection.rs:291 pub(crate), helios/src/runtime_core/mod.rs:58 pub(crate) use protection::open_descriptors;).

runtime_core is behind its own cargo feature: helios/src/lib.rs:25-26 #[cfg(feature = "runtime-core")] pub mod runtime_core; and helios/Cargo.toml:21 runtime-core = [...]; server (Cargo.toml:25) does not enable it. metrics::process is declared unconditionally (helios/src/server/metrics.rs:12) and render_linux (process.rs:56-126) compiles on Linux, so cargo build/test --manifest-path helios/Cargo.toml --features server — the command documented at docs/model-development.md:99 and docs/scheduling-runtime-design.md:735-737 — cannot resolve crate::runtime_core. Everywhere else in server the module is cfg-gated (server.rs:26-27 mod session;) or the reference is #[cfg(all(test, feature = "runtime-core"))] (runtime.rs:3983).

Smaller version (what the file had before d64c3ea3), 4 lines, no cross-feature edge, no visible 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), the pub(crate) widening at protection.rs:291 (net 0). Net −2 lines and −2 files in the diff, and the --features server configuration compiles again. (If duplication is unwanted, the 8-line fn 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 a bigger change than reverting.)

Note: could not compile here; derived from the cfg gates above.

#10 [high] Should fix: process.rs still carries a shim, five cfg attrs, six dead Option fallbacks and a kernel-assert test (~80 of 177 lines)

File: helios/src/server/metrics/process.rs (new, 177 lines, unchanged in shape by d64c3ea3).

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

(b) Six if let (Some(..), Some(..)) fallbacks for sources that cannot fail, ~45 lines. process.rs:72-125 emits each metric behind an Option match; the module doc (:4-6) promises a scrape "never panics on a missing or malformed file". On Linux /proc/self/stat, /proc/stat and /proc/self/fd exist for a running process, page_size() is total (eos/src/unix.rs:73-75 falls back to 4096), sysconf(_SC_CLK_TCK) is positive, and crate::os::raise_open_file_limit(0) (eos/src/unix.rs:138-147) returns Some(current) for every desired <= current, so the max_fds Option (: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); }

Loses nothing on Linux (the only platform that emits anything) and keeps the pre-existing parse_stat/parse_btime Option returns.

(c) Test that asserts the kernel, not the code, ~37 lines. process.rs:150-176 render_reports_process_memory_descriptors_and_start_time plus its value helper (:132-139) assert 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 scrapes the series (phase_tests.rs:5398-5399 asserts process_resident_memory_bytes reaches a real /metrics body), and the parser is covered by parse_stat_reads_fields_after_a_parenthesized_command_with_a_paren (:141-148), which is the only test that proves something about this code. Removing the render test costs no behaviour: a broken reader would also break the scrape test.

Total for process.rs: ~80 lines of 177 (about 45 in (b), 6 in (a), 37 in (c), minus the 4-line local open_descriptors of note "Blocking: …").

Not a saving, checked and dropped: folding process.rs's metric (:47-54) into metrics::metric (metrics.rs:1597-1602). The shared writer hard-codes the flare_ prefix (metrics.rs:1600) and takes u64, so process names would come out as flare_process_* and the f64 CPU/start-time values would not fit; reuse requires editing the shared helper and its ~20 call sites for no net gain.

#11 [high] Should fix: the new Histogram type was added beside the hand-rolled host histograms instead of replacing them (~53 lines)

The PR adds Buckets<N>/Histogram<N> (helios/src/server/metrics.rs:212-298) and uses it for the five new request histograms, but leaves the three host prefix-store histograms on the older hand-rolled machinery in the same file. Converting them deletes ~53 lines with byte-identical exposition output.

What goes:

Smaller version (labels preserved: same integers in le, same integer sums, because scale: 1.0 keeps the exposed unit at nanoseconds/tokens exactly as today):

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: [100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0, 10000000000.0, 100000000000.0, 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 selects 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 rendered le values are the same integers ({} on 100000.0 prints 100000) and _sum prints the same integer. 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 writes them, :274-277), which is additive exposition, not a behaviour loss.

Savings: consts 11→2 lines (−9 as written; 2 lines each), fields 4→3 (−1), observe 20→3 (−17), render 37→8 (−29): about −53 net.

Side note: the four same-bucket request histograms are already one loop (:1389-1412), and time_per_output_token/request_prompt_tokens cannot join it only because Histogram<19> and Histogram<21> are distinct types; padding TOKEN_SECONDS to 21 bounds would join them but changes bucket boundaries, so it is not a lossless cut — do not propose it.

#13 [high] Tally at head a34c4d0 (548 added lines, ~165 removable) and what is already minimal

Change at head a34c4d0 (pr_files): 10 files, +548/−25 — docs/api.md +28/−3; helios/src/runtime_core/mod.rs +1; runtime_core/protection.rs +1/−1; server.rs +2; server/http.rs +8; server/latency.rs +24/−8; server/metrics.rs +219; server/metrics/process.rs +177 (new); server/runtime.rs +43/−13; server/runtime/phase_tests.rs +45.

Ranked, with the savings I stand behind:

  1. Blocking (also a subtraction) — process.rs:68 crate::runtime_core::open_descriptors() breaks the documented --features server build; revert to the 4-line local /proc/self/fd read, drop runtime_core/mod.rs:58: −4 lines, −2 files. CI only builds runtime-core,server (.github/workflows/native-serving.yml:63,68), so it cannot catch this; docs/scheduling-runtime-design.md:735 and docs/model-development.md:99 do build server alone.
  2. Should fix — process.rs: ~80 of 177 lines: outer+five inner cfg for a Linux-only file (~6), six Option fallbacks around sources that always exist (~45), render test that asserts live kernel values (~37, minus the 4 lines restored in 1).
  3. Should fix — metrics.rs: convert the three host histograms to the new Histogram<8>/Buckets<8>: −53 (HOST_*_BUCKETS 11→2, fields 4→3, observe 20→3, render 37→8).
  4. Nit — ~28: docs/api.md:309-316 repeating HELP text (~8), phase_tests.rs:4428-4432 and 4466-4471 duplicating the scrape test (~11), process.rs:24-28 unreachable state guard (~6), metrics.rs:462-469 nested Option (~3, and only ~3 because flattening would drop the queue observation for step-reaching requests with no token).

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

Caveat to state honestly for finding 3: Histogram renders _sum as sum as f64 / scale (metrics.rs:291-295), so above 2^53 the ns sums round, where today's host _sum is exact u64. The request histograms this PR adds already accept that; the bucket le labels and counts are unchanged either way.

Verified-minimal at head (say so plainly): the five request histogram definitions and bucket bounds are exactly issue #536's missing-metrics table; the three RequestTimes fields and the two stamps (runtime.rs:1774-1775, 2197-2201) are the minimum that yields queue/prefill/decode, and preemption preservation is free because parking moves Incoming; e2e is now observed once (http.rs:598-606) and Worker::publish hoists its locals (runtime.rs:1993-1998), so two findings from the earlier review are resolved by d64c3ea3/a34c4d0; folding process.rs's metric into metrics::metric does not work (the shared helper hard-codes the flare_ prefix and takes u64, metrics.rs:1597-1602); the retirement histogram (metrics.rs:851-876) cannot join Histogram without a set-style variant, so it is not a lossless cut.

Charter/issue anchors for the report: charter line 35 ("what gets merged": maintainer request, roadmap item, reproducible bug, measured perf/memory issue, or bad docs) — #536 is a community issue, so the histograms' right to exist rests on it being the referenced ask, not a subtraction finding; charter line 12/13 irrelevant here; AGENTS.md:20-21 puts host OS operations in eos/, which is where a shared descriptor counter belongs if it is shared at all; AGENTS.md:52-59 requires designed behaviour and unrun checks to be stated, which the description does.

#14 [high] Research summary

Verdict: make it smaller first. The two pushed commits fixed the earlier duplicate e2e observation and the unhoisted publish locals, but added one problem and left the bulk of the removable weight in place.

The change: +548 / −25 across 10 files (head a34c4d0).

Could remove: about 165 of the 548 added lines (~30%), in six places, roughly 100 of them inside the new helios/src/server/metrics/process.rs.

Biggest subtractions, ranked:

  1. Blocking (and a subtraction), −4 lines and −2 files: process.rs:68 now calls crate::runtime_core::open_descriptors(), but runtime_core is behind its own cargo feature that server does not enable (helios/src/lib.rs:25-26, helios/Cargo.toml:21/25), so the documented --features server build (docs/model-development.md:99, docs/scheduling-runtime-design.md:735-737) no longer compiles. Restore the four-line local /proc/self/fd read and drop the pub(crate) use at runtime_core/mod.rs:58.
  2. Should fix, ~80 of process.rs's 177 lines: the write-nothing wrapper plus five inner cfg attributes for a Linux-only file; six if let (Some, Some) fallbacks around procfs sources, sysconf, page_size() and raise_open_file_limit(0) that all always succeed on Linux; and a test that asserts live kernel values (resident > 0, start time within the hour) that the existing /metrics route test already scrapes.
  3. Should fix, ~53 lines in metrics.rs: the new Buckets/Histogram type was added beside the hand-rolled host histograms, not in place of them. Converting the three host histograms deletes HOST_TIME_BUCKETS, HOST_TOKEN_BUCKETS, host_cost_sums, the .position(..).unwrap() loop and the 37-line render loop. Labels and counts are byte-identical (with scale: 1.0); the one caveat is that _sum becomes f64, which the request histograms already accept.
  4. Nits, ~28 lines: docs/api.md repeating the HELP strings, two phase-test assertions that repeat the route test, and an unreachable state-character guard in parse_stat.

Already minimal, say so plainly: the five histogram definitions and their bounds are exactly #536's missing-metrics table, the three RequestTimes stamps are the minimum for queue/prefill/decode, preemption preservation is free, and e2e is now observed in one place. Folding process.rs's metric into the shared writer is not a saving — the shared helper hard-codes the flare_ prefix and takes u64.

Full detail with code for each smaller version is in scratchpad notes #9-#13 (report body in #13).

#15 [high] Findings resolved at head a34c4d0 (do not re-raise) and what remains open

Reconciliation of the earlier review (comment on the PR at 2026-11-26 22:00, and scratchpad notes #1-#6) against head a34c4d0, so the final report does not re-raise fixed points. Commits: d64c3ea3 "Exclude cancelled responses and reuse host helpers", a34c4d06 "Hoist completion values and tighten stat parsing".

Resolved at head — do NOT repeat as findings:

Still open at head, with the note where each is argued: feature-gate build break (#9); process.rs shim/fallbacks/kernel test (#10); host histograms not converted (#11); doc-HELP duplication, two redundant phase-test assertions, unreachable parse_stat state guard (#12).

Also worth stating in the report: the two pushes raised the diff from +545/−20 to +548/−25 and moved work into the new file's neighbours (three files touched only to expose/re-export open_descriptors), so the change grew slightly while two findings closed. Cannot verify here: no compilation was run on this turn; the build-break claim in #9 is derived from the cfg gates and Cargo feature lists, and Windows was not built by the author either.

#3 [medium] Should fix: new Histogram type coexists with the hand-rolled host histograms; e2e observation written twice (~45 lines)

File: helios/src/server/metrics.rs:212-298 (new Buckets/Histogram, ~87 lines) and helios/src/server/server.rs-adjacent call sites.

(a) The new generic histogram duplicates machinery that already exists in the same file. HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS plus the parallel arrays host_missing_tokens/host_transfer_ns/host_prefill_ns and host_cost_sums (metrics.rs:200-210, 382-385) and the 37-line render loop (metrics.rs:1029-1065) do exactly what Histogram<N> + Buckets<N> do. Smaller version: convert the three host histograms to Histogram<8> and delete HOST_TOKEN_BUCKETS, HOST_TIME_BUCKETS, host_cost_sums, the .zip(limits) bucket loop and the .position(...).unwrap() in host_lookup_cost (metrics.rs:670-692) — the existing host_outcomes_and_capacity_have_bounded_labels_and_cost_histograms test (metrics.rs:1740-1796) keeps passing unchanged because it only reads the rendered text. ~40 lines net saving after subtracting what the PR adds (the PR currently adds the type alongside the hand-rolled version, so both exist).

(b) The e2e observation is written twice, once per delivery shape (helios/src/server/http.rs:614-617 and 631-632), and needs a second Arc clone only for the streaming arm (let metrics = state.model.metrics_handle(); at http.rs:603). Every successful generation yields exactly one Delivery::Complete from the generator body (http.rs:598, the only such yield); failures return after Delivery::Failed. Recording once in the generator immediately before that yield replaces both match-arm copies:

if !count {
    state.model.metrics().request_e2e.observe(&super::metrics::REQUEST_SECONDS, admitted_at.elapsed().as_nanos() as u64);
}
yield Delivery::Complete(response);

Deletes the metrics_handle() line, both if !count {...} copies, and keeps the same timing (the generator reaches that point only when the client polls to completion, which is what the two arms test today). ~5 lines and one Arc clone removed.

#4 [medium] Nit: thin platform shim, second impl block, docs restating HELP text, duplicated test assertions (~20 lines)

Smaller items, all verified:

(a) Nit — non-Linux shim. helios/src/server/metrics/process.rs:8-14 wraps render_linux so other platforms compile a function that writes nothing (#[cfg(not(target_os="linux"))] let _ = text;), and metrics.rs:12 pub(super) mod process; is unconditional. The repo already cfg-gates platform modules (helios/src/runtime_core/protection.rs:291-302, eos crate). Smaller: #[cfg(target_os = "linux")] pub(super) mod process; in metrics.rs:12 and #[cfg(target_os = "linux")] metrics::process::render(&mut text); at server.rs:709, dropping the wrapper and the let _ = text arm. ~6 lines, and one less dead path to reason about on Windows builds (which the description says were not run).

(b) Nit — latency.rs:122-131 adds a second impl FirstResponseSamples block for render_histogram instead of putting it in the existing impl at latency.rs:63-101. 2 lines of churn.

(c) Nit — docs/api.md:300-313 restates, sentence for sentence, the HELP strings added at metrics.rs:1387-1425 ("from model-scheduler arrival to the first model step...", "decode time divided by generated tokens after the first", etc.). One of the two is enough for an operator; the API doc could keep the names and the one non-obvious rule (cancelled/failed excluded, prefix-reused tokens counted) and drop the four start/end clauses, ~6 lines.

(d) Nit — duplicated assertion. phase_tests.rs:4429-4432 and 4464-4470 check e2e/ttfr counts in two separate tests and metrics_route_serves_prometheus_or_json_without_the_api_key (phase_tests.rs:5379-5388) checks the same series through a real scrape. The scrape test covers the rendering; the two per-test assertions could keep only the behavioural bit each proves (a failed stream leaves e2e at 0; one offered body leaves it at 1) and drop the re-render of the histogram at 4466-4470, ~5 lines.

Verified-minimal parts (do not ask to cut): the five histogram definitions themselves are the #536 deliverable (issue #536 "Missing metrics" table); the RequestTimes field additions and the two reserve_and_pack/complete stamps are the minimum that produces queue/prefill/decode intervals, and the parked-request preservation falls out of moving Incoming into the parked list (runtime.rs:2058+ park path) rather than any added code; RequestTimes derives Debug unused, 0 lines. The state.first_response.render_histogram split (latency.rs:123-131, server.rs:671) is needed because the first-response histogram lives outside Metrics.

#5 [medium] Correction: open_descriptors lives behind the runtime-core feature; move it to eos

Correction/adjustment to entry 1(b): open_descriptors() (helios/src/runtime_core/protection.rs:291-302) is not directly callable from the server — runtime_core is a separate cargo feature (helios/Cargo.toml:21,25; server does not enable it). So reuse needs one of: move that 8-line fn into flare_eos (eos/src/unix.rs already holds the platform split, and helios/src/lib.rs:36 already re-exports from it), or keep the duplication. Prefer moving it: flare_eos is an unconditional dependency of helios (Cargo.toml:34) and already owns /proc and rlimit access (page_size unix.rs:73-75, windows.rs:152; raise_open_file_limit unix.rs:138-165). Either way the process.rs copy at lines 65-67, 68-77 and 55-58 collapses onto eos calls, saving ~15 lines and three unsafe blocks in the new file.

flare_eos::page_size() and flare_eos::raise_open_file_limit(0) are both reachable from server code today (helios/src/lib.rs:36, eos is not feature-gated), so 1(b)'s max_fds and page parts stand as written.

Also confirmed for the report: the hand-rolled metric in process.rs (43-49) is fine to fold into metrics::metric (metrics.rs:1597) — both live in helios::server, and metrics::metric is pub(super) within server.

#12 [medium] Nit: docs repeat the HELP strings, two phase-test assertions repeat the scrape test, an unreachable stat guard (~25 lines)

Small items at head a34c4d0, all verified:

(a) docs/api.md:309-316 repeats the HELP strings almost verbatim. "spans model-scheduler arrival to the first model step that includes the request" vs metrics.rs:1398 "Model-scheduler arrival to the first model step that includes the request, for completed requests."; "decode time divided by generated tokens after the first" vs metrics.rs:1416. The HELP text is emitted in every scrape, so the operator already has it. Roughly 8 of the 39 added doc lines could go, keeping the names, the "histograms are Prometheus-only and cumulative" sentence, the cancelled/failed exclusion and the prefix-cache note. Not a loss of information — same statements, one copy less.

(b) phase_tests.rs:4428-4432 (5 lines) asserts flare_request_e2e_seconds_count 0 in a failed-stream test that already asserts the first-response sample count is 0 (same condition, :4425-4427); the exclusion of cancellations is the thing that needed proving and is covered by the tool-limit test at :4601-4616. phase_tests.rs:4466-4471 (6 lines) 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. Removing both loses no behaviour: about 11 lines.

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

(d) metrics.rs:462-469 — if let Some(first) = times.first_token_ns nested inside if let Some(scheduled): 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, or a test calling it directly), so the inner Some is guaranteed. Flattening to

if let (Some(scheduled), Some(first)) = (times.first_scheduled_ns, times.first_token_ns) { … }

would also drop the queue observation for a completed request that reached a step but committed no token, so it is not a clean win: about 3 lines at most, nit.

Already minimal, checked and dropped: RequestTimes derives (Clone, Copy used when the value is passed by value; Debug unused but zero lines); 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; the five new bucket tables are the #536 deliverable; flare_request_e2e_seconds now records in exactly one place (http.rs:598-606), so the earlier duplicate-observation finding is resolved at head; Worker::publish already hoists prompt/generated into locals (runtime.rs:1993-1998), resolved at head.