Simplicity scratchpad · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/4085c793-792d-4505-8482-a9fb0b681181.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).