#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:
- metrics.rs: generic
Buckets<const N>{ bounds: [f64;N], scale: f64 } consts REQUEST_SECONDS(Buckets<21>), TOKEN_SECONDS(Buckets<19>), PROMPT_TOKENS(Buckets<21>, scale 1.0);Histogram<const N>{ counts: [AtomicU64;N], sum: AtomicU64 } with observe(buckets, u64) + render(text, name, help, buckets) that writes# HELP flare_{name};RequestTimes{ first_scheduled_ns: Option, first_token_ns: Option, last_token_ns: u64 }; six new Metrics fields (request_e2e pub(super) Histogram<21>, request_queue/prefill/decode Histogram<21>, time_per_output_token Histogram<19>, request_prompt_tokens Histogram<21>);Metrics::request_completed(arrival_ns, times, prompt_tokens, generated_tokens)incrementscompletedthen observes. - runtime.rs: Incoming.times, stamped in Worker::complete (first/last token ns, completed_at_ns) and Worker::reserve_and_pack (first_scheduled_ns); both former
self.metrics.completed.fetch_add(1, ...)sites (Worker::complete stop path ~1836, Worker::publish ~1993) now call request_completed. - latency.rs: FirstResponseSamples gains
histogram: Histogram<21>besidewindow: Mutex<Samples>; output() observes; newrender_histogram(separate impl block at 122-131). - server.rs:
state.first_response.render_histogram(&mut text)at 671;metrics::process::render(&mut text)at 709. - http.rs: e2e observed in Delivery::Complete for streaming (615) and non-stream (632), guarded by
if !count(count = path is /v1/messages/count_tokens). - process.rs (Linux only): /proc/self/stat parse_stat, /proc/stat btime, /proc/self/fd count, getrlimit(NOFILE); six metrics; per-source Option fallbacks;
metric()helper (takes impl Display, no flare_ prefix); non-Linux stublet _ = text;. - api.md: new paragraphs listing histograms and process metrics.
Repo rules relevant to lens D:
- AGENTS.md L188-193: "Reject unsupported abstractions and churn. Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement... Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost."
- AGENTS.md L194-199 "Require focused, meaningful validation... source-text checks and mocks that bypass the behavior cannot establish runtime correctness."
- AGENTS.md L16-18 / docs/design-review.md principle 1: "Keep Helios as simple as possible."
- AGENTS.md contribution rules L165-169: contributions must address a maintainer request, demonstrated defect, measured perf/memory problem, or inaccurate docs.
- design-review.md principle 15 (scope) and 16 (prose).
- .agents/skills/repo-prose/SKILL.md: present-state spec, no hidden context, no bloat.
#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.
-
[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/_sumand+Inf). The PR adds a second, differently-shaped histogram mechanism (f64 bounds +scaledivisor +impl Displayrender) while three existing series already render the same exposition. Fix: makeHistogram<N>/Buckets<N>the one mechanism and delete HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS plus the 1029-1065 block; or, smaller still, dropHistogramand reuse the existing u64-bucket arrays, since two of the three new seconds histograms share one bound list. -
[should fix] The
scale: f64field is redundant — metrics.rs:214-241, 260-270, 291-295. Every observation is already ns;scaleis used only asvalue as f64 / scalefor bucketing andsum / scalefor rendering. Smaller version: keep bounds in ns as[u64; N]like the existing HOST_*_BUCKETS and divide by 1e9 once at render. This removes thescalefield, the PROMPT_TOKENSscale: 1.0special case, and the "integer grid / correctly rounded" comment at 261-262. -
[should fix]
request_prompt_tokensdoes 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 exposesflare_prefill_tokens_totalandflare_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). -
[should fix] Separate
render_histogramat latency.rs:122-131 is a third impl block onFirstResponseSamples, takes&mut Stringand hard-codes the metric name, and exists only because the histogram lives onFirstResponseSamples(constructed at server.rs:313). Smaller version: move theHistogram<21>ontoMetrics(which already ownsrequest_e2e), observe it fromFirstResponse::outputthrough a metrics handle as http.rs does for e2e; then deleterender_histogram, the extra impl block, and the scrape line at server.rs:671. -
[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 orcfg'd item bodies (runtime_core/protection.rs:298-301, core/cache.rs:4196). Smaller version: gate the wholerenderitem on linux and gate the call at server.rs:709. -
[should fix] process.rs re-implements
metric()(metrics/process.rs:42-49) differing from metrics.rs:1597-1602 in that it takesimpl Displayand omits theflare_prefix. No caller needsimpl Displayfor anything but f64/u64. Keep one writer. AGENTS.md L188-193 rejects abstractions and churn without a concrete requirement. -
[should fix] Four per-source
Optionfallbacks inrender_linux(metrics/process.rs:55-131: sysconf_SC_CLK_TCK/_SC_PAGESIZE,getrlimitreturn,read_dir,parse_stat) are speculative robustness with no concrete requirement and cost more code than the metrics they guard (fourif let (Some, Some)blocks, twothen_somesites). 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 forprocess_*. -
[nit]
parse_statskip arithmetic (metrics/process.rs:21-32) — thevalue(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)thennext()in field order. -
[nit]
last_token_nsduplicates existing scheduler accounting — runtime.rs:1774-1775 stamps first/last token ns inWorker::complete, while the scheduler already maintainsaccounting.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: keepfirst_token_nsonly and read the last-token instant from accounting; deletes oneu64per in-flight request and one store per committed token. -
[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_packhas a second caller. The prose skill asks comments to explain invariants, not defenses. -
[nit] Part of
request_histograms_bucket_completed_request_timings(metrics.rs:1674-1701) proves nothing about the PR's claim: thefirst_scheduled_ns: Nonesecond 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. -
[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 theprocess_resident_memory_bytespresence check in the route test as the one end-to-end check. -
[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, andprocess_*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:
- process.rs previously read sysconf(_SC_PAGESIZE), getrlimit, read_dir itself; now
crate::os::page_size()(eos/src/unix.rs:73-75),crate::runtime_core::open_descriptors()(protection.rs:291-302, widened to pub(crate) at runtime_core/mod.rs:58) andcrate::os::raise_open_file_limit(0)(eos/src/unix.rs:138-165). My earlier "four speculative Option fallbacks" finding shrinks to one (sysconf _SC_CLK_TCK) + procfs reads. - latency.rs:122-131 separate impl block for
render_histogramis gone; it now sits in the main impl at latency.rs:101-108. (Third-impl-block nit resolved; forwarder + server.rs:671 hook remain.) - http.rs: e2e observed once, before
yield Delivery::Complete(http.rs:598-605); the two duplicateif !countobservations in the stream/nonstream arms are gone (stream arm is nowDelivery::Complete(_) => Noneat http.rs:621; nonstream Complete arm at 635-644 no longer observes). - runtime.rs Worker::publish hoists prompt_tokens/generated_tokens (runtime.rs:1993-2001) as Worker::complete does (1838-1846).
- metrics.rs test: the impossible
{first_scheduled_ns: None, first_token_ns: Some}state is replaced by a zero-tokenRequestTimes::default()case (metrics.rs:1678-1690).
STILL OPEN (unchanged by the delta):
- should fix — three histogram mechanisms: new
Buckets/Histogram(metrics.rs:212-298) vsHOST_TIME_BUCKETS/HOST_TOKEN_BUCKETSu64 arrays (metrics.rs:200-210) rendered at 1029-1065, vs the hand-written retirement histogram block at 851-877. - should fix —
scale: f64(metrics.rs:216, 263, 294) plus the PROMPT_TOKENSscale: 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. - should fix — second
metric()writer at metrics/process.rs:48-54 duplicating metrics.rs:1597-1602 with onlyimpl Displaywidening. - should fix/nit —
time_to_first_responsehistogram lives onFirstResponseSamples(latency.rs:36) instead ofMetrics, so it needs the forwardingrender_histogram(latency.rs:101-108), the scrape hook at server.rs:671 and a test-only call at phase_tests.rs:4467. - 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
- 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 keeprfind(')')and parse. Settled only by argument, not by test. - metrics/process.rs:12-13 —
let _ = text;on non-Linux exists only to silence an unused parameter. Gate therenderitem and the call site asruntime_core/protection.rs:292-301gatesopen_descriptors, and delete the branch. - 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.
- metrics.rs:212-213, 243-244, 300 — four doc comments over three declarations, two of which restate the type name.
- 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_countassertions on the tests that own the behaviour and one presence check in the route test. AGENTS.md L194-199. - docs/api.md:299-317 — eleven series described in prose that the
# HELPstrings at metrics.rs:1389-1424 already carry. Keep the two facts a scrape cannot supply (histograms absent fromformat=json;process_*Linux-only) and list the names. - metrics.rs:1678-1690 — the zero-token case now proves only that
request_prompt_tokensstill 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:
- PR #548, draft, base main, head a34c4d06, 10 files, +548/−25 (pr_files). Closes #536 (opened by Napuh, non-maintainer, a vLLM-parity feature request with no discussion).
- No CI checks on the head commit; no reviews.
Governing rules, with the line numbers to cite:
- AGENTS.md L188-193: "Reject unsupported abstractions and churn. Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement. … Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost." → findings 1, 3, 6, nit 7.
- AGENTS.md L194-199: "Require focused, meaningful validation. Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness." → nits 11, 13.
- AGENTS.md L20-21: "The
eos/crate holds the host operating-system operations that Helios and Selene use." → finding 6. - AGENTS.md L16-18 and docs/design-review.md L16 ("Keep Helios as simple as possible") → framing of findings 1-4.
- AGENTS.md L43-50 requires the repo prose skill (.agents/skills/repo-prose/SKILL.md) for code comments → nits 9, 10.
Supporting line references already verified (in #4/#5, repeated here compactly in case a line is questioned):
- eos/src/unix.rs:73-75 (page_size), :138-165 (raise_open_file_limit, getrlimit then early return), eos/src/lib.rs:9-16 (unix/windows split), eos/src/windows.rs:215 (raise_open_file_limit returns None).
- helios/src/runtime_core/protection.rs:291-302 (open_descriptors, non-Linux branch returns None — the cfg pattern to imitate), :356-357 (existing caller), runtime_core/mod.rs:58 (new pub(crate) re-export).
- helios/src/server.rs:671 (render_histogram hook), :709 (process::render), :313 (FirstResponseSamples constructed), :660 (metrics().render()).
- helios/src/server/metrics.rs:200-210, 670-692, 851-877, 1029-1065 (existing histogram code), 212-298 (new), 327-332 (six new fields), 450-480 (request_completed), 1389-1424 (new render loop), 1597-1602 (existing metric()), 1652-1700 (new test).
- helios/src/server/latency.rs:36, 101-108, 121-124; helios/src/server/http.rs:598-605, 621, 635-644.
- helios/src/server/metrics/process.rs as of head: 1-14 (doc + render shim), 19-37 (parse_stat, whitelist at 24-28), 48-54 (metric), 57-126 (render_linux; 69-70 max_fds; 81-98 duplicate blocks), 128-177 (tests).
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.