Simplicity scratchpad · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/f197112c-e8ee-46e3-9295-88c22ae8aa2a.md

#1 [high] PR 548 overview and scope

PR #548 "Add request latency histograms and process metrics" (draft, opened 2026-11-26, head ebecef1, 8 files +545/-20). Closes #536 (opened by Napuh, a non-maintainer; asks for vLLM-parity request histograms + process_* metrics).

Files: docs/api.md (+25/-3), helios/src/server.rs (+2), helios/src/server/http.rs (+6/-1), helios/src/server/latency.rs (+27/-8), helios/src/server/metrics.rs (+228), helios/src/server/metrics/process.rs (new +184), helios/src/server/runtime.rs (+38/-8), helios/src/server/runtime/phase_tests.rs (+35).

What it adds:

Repo rules relevant to lens D:

#2 [high] Findings: lens D (simplicity) on PR 548 — final list

PR #548 "Add request latency histograms and process metrics" (draft, head ebecef1, 8 files +545/-20, closes #536). Lens D (simplicity) findings, all verified against the diff and surrounding code.

  1. [should fix] Duplicate histogram plumbing — helios/src/server/metrics.rs:212-298 (Buckets/Histogram) vs the existing host-cache histogram code at metrics.rs:200-210 (HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS as [u64; N]), 670-692 (host_lookup_cost), 1029-1065 (render loop writing _bucket/_count/_sum and +Inf). The PR adds a second, differently-shaped histogram mechanism (f64 bounds + scale divisor + impl Display render) while three existing series already render the same exposition. Fix: make Histogram<N>/Buckets<N> the one mechanism and delete HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS plus the 1029-1065 block; or, smaller still, drop Histogram and reuse the existing u64-bucket arrays, since two of the three new seconds histograms share one bound list.

  2. [should fix] The scale: f64 field is redundant — metrics.rs:214-241, 260-270, 291-295. Every observation is already ns; scale is used only as value as f64 / scale for bucketing and sum / scale for rendering. Smaller version: keep bounds in ns as [u64; N] like the existing HOST_*_BUCKETS and divide by 1e9 once at render. This removes the scale field, the PROMPT_TOKENS scale: 1.0 special case, and the "integer grid / correctly rounded" comment at 261-262.

  3. [should fix] request_prompt_tokens does not need a histogram type at all — metrics.rs:235-241, 332, 471-472, 1419-1424, plus the docs/api.md paragraph. Prompt size is a whole-token count and the repo already exposes flare_prefill_tokens_total and flare_cache_reused_tokens_total. If the per-request distribution is genuinely required, share the existing renderer with a fixed bucket list; as written it is the largest of the six added histograms (21 atomics + sum).

  4. [should fix] Separate render_histogram at latency.rs:122-131 is a third impl block on FirstResponseSamples, takes &mut String and hard-codes the metric name, and exists only because the histogram lives on FirstResponseSamples (constructed at server.rs:313). Smaller version: move the Histogram<21> onto Metrics (which already owns request_e2e), observe it from FirstResponse::output through a metrics handle as http.rs does for e2e; then delete render_histogram, the extra impl block, and the scrape line at server.rs:671.

  5. [should fix] #[cfg(not(target_os = "linux"))] { let _ = text; } at metrics/process.rs:12-15 is dead code that silences an unused parameter. Other platform-gated code in helios uses real empty branches or cfg'd item bodies (runtime_core/protection.rs:298-301, core/cache.rs:4196). Smaller version: gate the whole render item on linux and gate the call at server.rs:709.

  6. [should fix] process.rs re-implements metric() (metrics/process.rs:42-49) differing from metrics.rs:1597-1602 in that it takes impl Display and omits the flare_ prefix. No caller needs impl Display for anything but f64/u64. Keep one writer. AGENTS.md L188-193 rejects abstractions and churn without a concrete requirement.

  7. [should fix] Four per-source Option fallbacks in render_linux (metrics/process.rs:55-131: sysconf _SC_CLK_TCK/_SC_PAGESIZE, getrlimit return, read_dir, parse_stat) are speculative robustness with no concrete requirement and cost more code than the metrics they guard (four if let (Some, Some) blocks, two then_some sites). Smaller version: read both sysconf values once, default the page size as eos/src/unix.rs:74 already does (unwrap_or(4096)), and let the rest fail early. The module doc's "a scrape never fails and never panics" is a guarantee nothing in the repo requires for process_*.

  8. [nit] parse_stat skip arithmetic (metrics/process.rs:21-32) — the value(11)/value(0)/value(6)/value(0)/value(0) chain plus the "token N - 3" comment is harder to check than naming the fields. Smaller version: split_whitespace().skip(11) then next() in field order.

  9. [nit] last_token_ns duplicates existing scheduler accounting — runtime.rs:1774-1775 stamps first/last token ns in Worker::complete, while the scheduler already maintains accounting.last_output_ns (scheduler/policy.rs:275, surfaced at runtime.rs:1172-1173, used at policy.rs:478). Only the first-token instant has no existing home. Smaller version: keep first_token_ns only and read the last-token instant from accounting; deletes one u64 per in-flight request and one store per committed token.

  10. [nit] Comment bloat: metrics.rs:212-213, 243-244, 261-262, 300 (four doc comments around three struct fields), runtime.rs:193 and 2189-2190, process.rs:1-6. metrics.rs:261-262 explains an invariant the code should not have (finding 2); runtime.rs:2189-2190 only makes sense if the reader knows reserve_and_pack has a second caller. The prose skill asks comments to explain invariants, not defenses.

  11. [nit] Part of request_histograms_bucket_completed_request_timings (metrics.rs:1674-1701) proves nothing about the PR's claim: the first_scheduled_ns: None second observation asserts counts stay at 1, exercising the helper's branch rather than the runtime stamping. The stamping is covered by runtime/phase_tests.rs:576-583 (count == 1), which itself asserts only that a count exists, not a bucket. AGENTS.md L194-199.

  12. [nit] phase_tests.rs:4428-4432, 4461-4471, 5380-5389 bolt render() string assertions onto three pre-existing tests (first_response_http_*, metrics_route_*), restating what metrics.rs:1652 and the latency tests already prove and making unrelated tests brittle to HELP-text edits. Keep only the process_resident_memory_bytes presence check in the route test as the one end-to-end check.

  13. [nit] docs/api.md +25 lines enumerates eleven series, repeating definitions that the HELP strings at metrics.rs:1393-1423 carry verbatim. Keep the two facts a scrape cannot supply: histograms are absent from format=json, and process_* is Linux-only; point at the scrape for the rest.

Non-findings verified: state.model.metrics_handle() at http.rs:603 is required by the filter_map closure; if !count correctly excludes /v1/messages/count_tokens, which server.rs:584 routes to the same http::generate handler; RequestTimes survives parking because park moves Incoming wholesale (runtime.rs:2096, 2121) and readmission reuses it.

Repo rules cited: AGENTS.md L16-18 and docs/design-review.md principle 1 ("Keep Helios as simple as possible"); AGENTS.md L188-193 (reject unsupported abstractions and churn); AGENTS.md L194-199 (focused, meaningful validation); .agents/skills/repo-prose/SKILL.md L38-46 (comments explain invariants).

#4 [high] Delta after commits d64c3ea3 + a34c4d06 (lens D)

Head now a34c4d06 ("Hoist completion values and tighten stat parsing"), after d64c3ea3 ("Exclude cancelled responses and reuse host helpers"). 10 files, +548/-25.

FIXED by d64c3ea3:

STILL OPEN (unchanged by the delta):

  1. should fix — three histogram mechanisms: new Buckets/Histogram (metrics.rs:212-298) vs HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS u64 arrays (metrics.rs:200-210) rendered at 1029-1065, vs the hand-written retirement histogram block at 851-877.
  2. should fix — scale: f64 (metrics.rs:216, 263, 294) plus the PROMPT_TOKENS scale: 1.0 (metrics.rs:240) and the rounding comment (261-262). Every observation is integer ns; u64 ns bounds + one division at render deletes all three.
  3. should fix — second metric() writer at metrics/process.rs:48-54 duplicating metrics.rs:1597-1602 with only impl Display widening.
  4. should fix/nit — time_to_first_response histogram lives on FirstResponseSamples (latency.rs:36) instead of Metrics, so it needs the forwarding render_histogram (latency.rs:101-108), the scrape hook at server.rs:671 and a test-only call at phase_tests.rs:4467.
  5. nit — #[cfg(not(target_os="linux"))] let _ = text; shim metrics/process.rs:12-13.

NEW in a34c4d06: 6. should fix (nit) — metrics/process.rs:81-98: two consecutive if let Some(stat) = stat blocks with the same test, one per metric. Merge into one block writing both gauges (or one loop over (name, help, value)). 7. nit — metrics/process.rs:24-28: added state-character whitelist "RSDZTtWXxKPI" parsing /proc/self/stat. Speculative validation: procfs cannot emit anything else, and the parser is only called on /proc/self/stat (process.rs:62-64). ~5 lines and a comment for a case that cannot occur; AGENTS.md L188-193. 8. should fix (nit) — metrics/process.rs:69-70: crate::os::raise_open_file_limit(0) used as a read-only getter of RLIMIT_NOFILE. Reads as a mutation at the call site; eos has no getter, so either add one or comment the trick (the comment is there but the API misuse remains). Windows path returns None (eos/src/windows.rs:215). 9. nit — pub(crate) use protection::open_descriptors (runtime_core/mod.rs:58) widens a runtime_core private for one metrics call. AGENTS.md L20-21 puts host OS operations in eos/; the fd count belongs beside page_size there.

Tests: phase_tests.rs:4428-4432, 4461-4471, 4601-4611, 5391-5398 still bolt full metrics().render() string checks onto three unrelated tests; 4611's tool-limit check restates 4428; 5391 duplicates 4466-4471. Each assert re-renders the whole scrape inside a loop (4461-4471 renders twice per iteration). AGENTS.md L194-199.

#5 [high] Report of 2026-11-27, run 2 (post-delta) — lens D verdict and findings

Verdict: should-fix issues only (no blockers in lens D). Supersedes entry #3 for head a34c4d06.

Should fix

1. Three histogram mechanisms in one file — helios/src/server/metrics.rs:212-298 vs :200-210/:1029-1065 vs :851-877

The PR adds Buckets<const N> (f64 bounds ending at f64::INFINITY + a scale divisor) and Histogram<N> with its own render writing # HELP/# TYPE. The same file already renders histograms two other ways: HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS as [u64; N] with u64::MAX for +Inf (host_lookup_cost :670-692, render loop :1029-1065) and the hand-written flare_host_cache_retirement_seconds block (:851-877). Three implementations means three places for a +Inf/cumulative/escaping bug and two bucket vocabularies in one struct. Fix: express the new seconds histograms as [u64; N] ns bounds like the existing ones (four of the five seconds series already share one bound list), or, larger but better, migrate the host and retirement series onto Histogram<N> and delete :200-210, :1029-1065 and :851-877. AGENTS.md L188-193.

2. scale: f64 is redundant — metrics.rs:216, 240, 261-263, 291-295

Every observation is already an integer nanosecond count (as_nanos() as u64 at http.rs:601-603, latency.rs:121-124; saturating_sub at metrics.rs:464-477). scale exists only so observe can divide (value as f64 / buckets.scale, :263) and render can divide the sum (:294). Keep bounds in ns as [u64; N], bucket with integer comparison, divide by 1e9 once when writing _sum. That deletes the field, the PROMPT_TOKENS scale: 1.0 (:240) and the "Division is correctly rounded" comment (:261-262), which exists only to justify the representation.

3. Second metric() writer — helios/src/server/metrics/process.rs:48-54 vs metrics.rs:1597-1602

Same name, same shape, differing only in value: impl Display vs u64 and a hard-coded process_ prefix instead of flare_. Every caller passes u64 or an f64 it computed inline (process.rs:78, 87, 96, 105, 114, 123); nothing needs impl Display. Fix: keep metrics::metric and either pass the formatted CPU/start-time values through it or widen the one function to impl Display and delete the copy. One writer, one prefix rule.

4. The TTFR histogram hangs off the sampler instead of Metrics — helios/src/server/latency.rs:36, 101-108, :121-124; helios/src/server.rs:671

FirstResponseSamples gained a histogram field and a render_histogram(&self, text) forwarder that hard-codes the series name and help; server.rs:671 exists solely to call it, and phase_tests.rs:4466-4471 calls it directly because the series is otherwise unreachable except through a scrape. Metrics already owns request_e2e and is rendered by the same scrape. Fix: put time_to_first_response: Histogram<21> on Metrics, observe it from FirstResponse::output through the metrics handle http.rs already fetches, render it in the same loop as the other six (metrics.rs:1389-1424). Deletes the field, the forwarder, the scrape hook and the special-case test call.

5. Duplicate if let Some(stat) block — metrics/process.rs:81-98

Two consecutive blocks test the same Option to write one gauge each. Merge into one block writing both process_virtual_memory_bytes and process_resident_memory_bytes, or one small loop over (name, help, value).

6. raise_open_file_limit(0) used as a getter — metrics/process.rs:69-70

The call reads as a mutation in a scrape path; its only effect is returning the current soft limit. eos has no read-only accessor. Fix: add pub fn open_file_limit() -> Option<u64> to eos/src/unix.rs beside raise_open_file_limit (eos/src/unix.rs:138-165 already does the getrlimit and returns early) and call that. AGENTS.md L20-21 puts host OS operations in eos/.

Nits

  1. metrics/process.rs:24-28 — the added state-character whitelist ("RSDZTtWXxKPI") validates a value procfs cannot get wrong and the parser is only fed /proc/self/stat (process.rs:62-64). Five lines and a comment for an impossible case; drop it, or keep rfind(')') and parse. Settled only by argument, not by test.
  2. metrics/process.rs:12-13 — let _ = text; on non-Linux exists only to silence an unused parameter. Gate the render item and the call site as runtime_core/protection.rs:292-301 gates open_descriptors, and delete the branch.
  3. metrics/process.rs:1-6 — module doc promises "a scrape never fails and never panics"; with three sources left, say only that missing procfs entries omit their series.
  4. metrics.rs:212-213, 243-244, 300 — four doc comments over three declarations, two of which restate the type name.
  5. phase_tests.rs:4428-4432, 4461-4471, 4601-4611, 5391-5398 — four metrics().render() substring asserts grafted onto three unrelated tests; 4611 restates 4428, 5391 restates 4466-4471, and 4461-4471 renders the whole scrape twice per loop iteration. Keep the _count assertions on the tests that own the behaviour and one presence check in the route test. AGENTS.md L194-199.
  6. docs/api.md:299-317 — eleven series described in prose that the # HELP strings at metrics.rs:1389-1424 already carry. Keep the two facts a scrape cannot supply (histograms absent from format=json; process_* Linux-only) and list the names.
  7. metrics.rs:1678-1690 — the zero-token case now proves only that request_prompt_tokens still observes; name the test for that or fold it into the first-case assertions.

Non-findings checked: if !count still correctly excludes /v1/messages/count_tokens; encoder.tool_limit_reached guard now covers both arms because there is only one observation site (http.rs:598-605); RequestTimes survives parking (park moves Incoming wholesale, runtime.rs:2096/2121, readmission reuses it); last_token_ns vs accounting.last_output_ns (policy.rs:275, set in published_output) differ because publication can be skipped for unread streams, so the separate stamp is justified — drop my earlier nit.

#6 [high] Research summary

Reviewed PR #548 at head a34c4d06 (after d64c3ea3 and a34c4d06) through the simplicity lens; nothing blocks, six should-fix items and seven nits. The two new commits resolved four of my earlier findings (the OS reads now go through eos/protection helpers, the separate render_histogram impl block is gone, e2e is observed once in generate, and the impossible {None, Some} test state is replaced) and left the core duplication intact.

Should fix: the PR still adds a third histogram mechanism (Buckets/Histogram with f64 bounds and a scale divisor, metrics.rs:212-298) beside the two u64-bucket renderers already in the file (:200-210/:1029-1065, :851-877); scale is redundant because every observation is integer ns (metrics.rs:216/240/261-263/291-295); a second metric() writer duplicates metrics.rs:1597-1602 (process.rs:48-54); TTFR is attached to FirstResponseSamples rather than Metrics, which is the only reason for the forwarder, the server.rs:671 hook and the test-only call; two consecutive identical if let Some(stat) blocks (process.rs:81-98) and raise_open_file_limit(0) used as a getter (process.rs:69-70) are new small costs from the delta.

Nits: the added state-character whitelist validating procfs, the let _ = text; shim, module-doc overpromise, comment weight, four render() substring asserts grafted onto unrelated tests (two of them restating each other), the api.md enumeration of eleven series that the HELP strings already define, and the zero-token histogram test's naming. I dropped my earlier last_token_ns-vs-accounting.last_output_ns nit: publication can be skipped for unread streams, so the separate stamp is justified.

#7 [high] Citations and housekeeping for the final report (head a34c4d06)

Use entry #5 as the report body; it supersedes #3, and #2 (the pre-delta finding list) is superseded too — do not list both. Entry #4 holds the delta detail (what d64c3ea3 and a34c4d06 fixed, what they introduced).

PR facts to state:

Governing rules, with the line numbers to cite:

Supporting line references already verified (in #4/#5, repeated here compactly in case a line is questioned):

Wording rule for the report: no performance or memory claim, drop nothing about behaviour — the PR's serving behaviour is unchanged and I found no defect in it.

#9 [high] Re-verification of 2026-11-27 (run 3): head unchanged, all citations re-checked

Checked for this run: no new commits since a34c4d06 (PR still draft, 10 files, +548/-25, no reviews, no CI checks). Re-read each cited region at head; every line number in note #8 still matches:

New context checked this run and dropped as a finding: author's #553 ("Add vLLM-compatible per-request metrics") measures first-token/decode/ITL in http.rs at HTTP admission. It does not read or replace the runtime stamps this PR adds (incoming.first_scheduled_ns/first_token_ns/last_token_ns) and does not render any histogram, so it is not a parallel implementation of this PR's series; the only overlap is semantic (both expose decode rate), and the two diffs touch disjoint hunks of http.rs/phase_tests.rs per its own description. No alien-instruction attempt found in the PR text or comments.

Verdict unchanged: should-fix issues only, no blockers; 6 should-fix, 7 nits.

#10 [high] Research summary

Reviewed PR #548 at head a34c4d06 through the simplicity lens. The head has not moved since my previous report and there are no reviews or CI checks on it, so I re-read every cited region in context rather than restating from memory: all file:line citations still match, nothing needs withdrawing, and no new finding emerged. Verdict unchanged: no blockers, six should-fix items, seven nits.

The cost here is code, not correctness. The PR adds a third histogram mechanism (f64 Buckets + Histogram<N> at metrics.rs:212-298) beside the existing [u64; N] buckets rendered at :1029-1065 and the hand-written retirement block at :851-877; Buckets::scale is redundant because every observation is already integer nanoseconds; process.rs re-implements metric() with a different prefix rule than metrics.rs:1597; the TTFR histogram lives on FirstResponseSamples, which is the only reason for a forwarder, a scrape hook at server.rs:671 and a test-only call; render_linux has two consecutive identical if let Some(stat) blocks; and a scrape path calls raise_open_file_limit(0) as a getter. The nits cover comment weight, a procfs validation that cannot fail, a let _ = text; cfg shim, four render()-substring asserts grafted onto unrelated tests, and an api.md paragraph duplicating the HELP strings.

New work this run: I confirmed that the author's open PR #553, which also reports tokens-per-second, is not a parallel implementation of this PR's series — it times the HTTP path and renders no histogram, so it does not touch the runtime stamps added here. Details are in scratchpad entries #8 and #9; entry #8 holds the full report with per-finding fixes.

#11 [high] Report-ready digest: PR 548 lens D findings, citations, verification limits

Head reviewed: a34c4d06 (draft, base main, 10 files, +548/-25, no reviews, no CI checks; closes #536). Author WynnD. Earlier heads: ebecef1 -> d64c3ea3 -> a34c4d06. This is run 3; head unchanged since run 2.

RULE CITATIONS (as quoted in note #8, cite these in the report):

SHOULD FIX (6): S1 metrics.rs:212-298 vs :200-210/:1029-1065 vs :851-877 — third histogram mechanism in one file (f64 Bounds+Histogram vs [u64;8] with u64::MAX->"+Inf" at :1053-1057 vs hand-written retirement block :851-877). Two bucket vocabularies (f64 s vs u64 ns) in one Metrics. Fix: express the five new seconds histograms as [u64; N] ns bounds like HOST_TIME_BUCKETS and reuse the existing render loop; or migrate the two older paths onto Histogram and delete them. S2 metrics.rs:216/:240/:261-263/:294 — scale: f64 is redundant; observations are already integer ns (metrics.rs:460-478, latency.rs:123, http.rs). Fix: u64 ns bounds, compare integers, divide by 1e9 once when writing _sum; deletes scale, the PROMPT_TOKENS scale: 1.0, and the correctly-rounded comment. S3 metrics/process.rs:48-54 vs metrics.rs:1597-1602 — second metric() writer, same body, no flare_ prefix, widened to impl Display; six callers at process.rs:73-124 pass u64 or an inline f64. Fix: one writer (full name + impl Display) used by both. S4 latency.rs:36/:101-108/:121-124 + server.rs:671 + phase_tests.rs:4466-4471 — TTFR histogram on FirstResponseSamples forces a forwarder, an out-of-render-path scrape hook, and a test-only call. Metrics already renders request_e2e in an array at metrics.rs:1389-1412. Fix: move time_to_first_response: Histogram<21> to Metrics, observe via the metrics handle http.rs already holds, render in that array; deletes field, forwarder, hook, special test call. S5 metrics/process.rs:81-98 — two consecutive identical if let Some(stat) = stat blocks writing virtual then resident memory. Fix: one block writing both, or a (name, help, value) loop as metrics.rs:1425-1440 does. S6 metrics/process.rs:69-70 — raise_open_file_limit(0) used as a read-only getter in a scrape path (relies on the early return at eos/src/unix.rs:145-147). Fix: add pub fn open_file_limit() -> Option<u64> in eos/src/unix.rs beside it, have raise_open_file_limit call it, call it here.

NITS (7): N1 process.rs:24-28 — procfs state-character whitelist "RSDZTtWXxKPI" guards a value procfs cannot get wrong; drop it, keep rfind(')'). N2 process.rs:8-14 — #[cfg(not(target_os="linux"))] let _ = text; shim only silences an unused parameter; gate the render item and server.rs:709 on linux (cf. runtime_core/protection.rs:291-302). N3 process.rs:2-6 — module doc promises "a scrape never fails and never panics"; say only that an unavailable source omits its series. N4 metrics.rs:212-213/:243-244/:300 — four doc comments over three declarations; drop the two that restate type names, keep :300's note that stamps survive preemption. N5 phase_tests.rs:4428-4432, :4461-4471, :4601-4611, :5391-5397 — four metrics().render() substring asserts grafted onto tests about stream polling, tool-limit cancellation and route negotiation; :4611 restates :4428, :5391 restates :4466-4471, :4461-4471 renders the whole scrape twice per loop iteration. Keep the assertions on the tests that own the behaviour. N6 docs/api.md:297-321 — eleven series enumerated in prose the # HELP strings already carry; keep only what a scrape cannot supply (histograms absent from format=json; process_* Linux-only) plus the names. N7 metrics.rs:1681-1690 — after the zero-token case, the asserts only re-prove the first call is unchanged plus prompt_tokens_count 2; name that or fold it into the first case.

CHECKED, NOT FINDINGS (do not re-raise): if !count still excludes /v1/messages/count_tokens from e2e (http.rs:598-605); RequestTimes survives preemption (park moves Incoming wholesale); the separate last_token_ns stamp is justified because publication can be skipped for an unread stream (I withdrew that earlier nit); cancelled/failed requests observe nothing because request_completed (metrics.rs:452-480) is the only observation site and the only place that increments flare_requests_completed_total; author's #553 is not a parallel implementation of these series (HTTP-path timing, no histogram).

NOT VERIFIED HERE: no test run of my own; the PR reports server::metrics:: 20 passed and server::runtime::phase_tests 109 passed; Windows build and full helios suite not run by the author either. S2's exact printed le spelling (0.001, 0.0025, ...) needs a scrape diff to confirm identical output; no test asserts the printed TOKEN_SECONDS bounds.

VERDICT to print: should-fix issues only, no blockers; nothing asks the author to add code.