Architecture & scope review — PR #548 "Add request latency histograms and process metrics"
Head reviewed: a34c4d06 ("Hoist completion values and tighten stat parsing"), atop d64c3ea3 ("Exclude cancelled responses and reuse host helpers") and ebecef13. No commits since my previous pass. All 10 changed files read with surrounding code. Judged against the charter (read in full), AGENTS.md, docs/design-review.md, and the surrounding Helios/selene/eos code.
Key findings
Verdict: should-fix issues only — no blocking architectural defect. The approach is correct and belongs in this layer. Recording all observations inside Metrics::request_completed, the one function that already increments flare_requests_completed_total, is exactly the charter's "solve the right problem in the right place": divergence between counter and histograms becomes structurally impossible, and fixed-bound histograms need no per-request storage. The stamps live on Incoming, the request's own lifecycle record, and survive preemption because parking moves the whole struct. Snapshot/format=json is untouched, there is no Cargo change (libc already unconditional), Windows compiles to a no-op, and there is no flag, no per-model branch, no environment switch, and no preparation/runtime boundary crossing.
I explicitly considered and rejected the obvious alternative — sourcing these timings from the scheduler trace (metrics/scheduler.rs). That trace is a gated, bounded diagnostic (detail_requested: AtomicBool at :94, TRACE_CAPACITY = 1024 at :21, is_enabled() at :117), so building histograms on it would need exactly the switch AGENTS.md:188-190 forbids. RequestTimes is the right design, not a duplicate one.
Four should-fix items remain. None is a code defect: one is procedural (scope authorization), one is a narrow layering ask in eos, one is a duplication question, one is an evidence-honesty question in the description. Three nits follow. The PR is still a draft with no human reviews and no CI checks on the head commit, so everything below is a pre-merge ask, not a post-merge objection — the description items can be fixed by rewording alone.
Should fix
1. Residual OS access in a serving formatting module, and a mutating helper used as a getter
helios/src/server/metrics/process.rs:57-70. Rule: AGENTS.md:20-22 — "The eos/ crate holds the host operating-system operations that Helios and Selene use"; helios/src/os.rs:8 is just pub(crate) use flare_eos::*;.
d64c3ea3 fixed most of this (crate::os::page_size() at :61 → eos/src/unix.rs:73-75; crate::runtime_core::open_descriptors() at :68; the hand-rolled getrlimit gone). Remaining:
:58-60callslibc::sysconf(libc::_SC_CLK_TCK)inline — two lines ofunsafe libcin a module whose job is parsing and formatting, beside eos's own_SC_PAGESIZEcall ateos/src/unix.rs:74.:62-67reads/proc/self/statand all of/proc/statinline. Narrow: metrics-only source with no other consumer, so defensible.:70reads the softRLIMIT_NOFILEascrate::os::raise_open_file_limit(0). That function (eos/src/unix.rs:138-165) is a mutator:getrlimitat :141,current >= desiredshort-circuit at :145-147,setrlimitat :160. It is read-only fordesired == 0only because of that short-circuit. A metrics renderer whose safety rests on an accident is fragile — any future edit treating0as "raise to a floor" would mutate the process's fd limit on every scrape, from an axum worker thread. The comment at :69 documents the trick rather than forbidding its removal.
Fix: add clock_ticks() -> Option<u64> and open_file_limit() -> Option<u64> (getrlimit only) to eos/src/unix.rs beside page_size, and drop the raise_open_file_limit(0) call. No new code outside eos.
2. Scope authorization: "monitoring parity with vLLM" is not a merge criterion
PR description ("Closes #536"); issue #536; AGENTS.md:165-169, :201-203; charter "What gets merged" and "Alternatives / Competitors".
The stated justification is issue #536 (Napuh, outside contributor), whose summary is "This makes it hard to move existing vLLM Grafana dashboards and SLO alerts to Flare", with a column headed "vLLM metric (reference)".
AGENTS.md:165-169: "Every contribution must address an explicit maintainer request, a demonstrated defect, a measured performance or memory problem, or inaccurate documentation. … Hypothetical future consumers, agent-generated suggestions, and lint findings alone do not establish a need for a change."AGENTS.md:201-203: "An explicit maintainer request covering the work is sufficient authorization… A feature request, passing tests, or a performance gain does not waive an architectural invariant." The converse follows: an outside feature request is not authorization.- Charter "What gets merged": maintainer request, roadmap item, reproducible bug, measured performance/memory issue, or bad docs. The description cites #536 and nothing else — no maintainer request, no roadmap item, no measured problem, no doc defect.
- The charter lists vLLM under "Alternatives / Competitors" (with SGLang, TensorRT-LLM, llama.cpp (not opened)). Dashboard parity with a competitor is not a stated compatibility goal, and
AGENTS.md:188-189warns against "speculative compatibility".
Nothing here is architecturally wrong, and the observability gap is real: tail latency, queue delay, prefill time and per-request decode rate genuinely are unobservable from a scrape today, and #536's "Why histograms" section is a sound argument. But the fix is procedural, and cheap while the PR is a draft: get a maintainer decision recorded on #536, or reframe the description around the defect (p99/tail latency is unobservable from /metrics) rather than competitor parity. Worth flagging for that decision: the same author's #549, #551 and #552 rebuild overlapping observability surfaces (KV pages held by active requests; per-request timings on final responses), and #553 was halted as off-charter — a maintainer should shape this cluster once rather than merge four variants.
3. A third histogram convention added where three already coexist, and a copied metric formatter
helios/src/server/metrics.rs:214-298 vs :200-210, :670-692, :705-711, :851-876, :1029-1065; helios/src/server/metrics/process.rs:48-54 vs metrics.rs:1597-1602. Rule: AGENTS.md:188-193 — "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."; docs/design-review.md:16-25 (principle 1, keep Helios simple).
metrics.rs now contains four ways to declare and render a histogram:
| Mechanism | Where | Shape |
|---|---|---|
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS |
:200-210, observe :689, render :1029-1065 | [u64; 8], u64::MAX as +Inf |
flare_host_cache_retirement_seconds |
:705-711, :851-876 | counts pushed from selene, rendered by hand |
new Buckets<N>/Histogram<N> |
:214-298 | [f64; N], f64::INFINITY |
single-value families via metrics::metric |
:1597-1602 | fixed flare_ prefix |
The PR adds the third bucket convention in one module with no guidance for the next author; the diff there is +219/−0 and leaves the older ones in place (the PR does not touch :200-210 / :670-692 / :1029-1065).
Fix, in order of preference:
- Adopt
Histogramas the single observe-based convention and migrate the threehost_*lookup histograms onto it (:670-692 and :1029-1065). That deletes the.position(...).unwrap()at :689 andhost_cost_sums, and is justified underAGENTS.md:193as removing a demonstrated defect source. The new type is genuinely better: it carries bounds and scale together, which is whylatency.rs:63-109could reuse it forFirstResponseSamples. - Do not try to migrate
flare_host_cache_retirement_seconds(:851-876): those counts are pushed from the selene store, not observed, so it legitimately cannot useHistogram. Say so in a comment if the migration happens. - Fold
process::metric(:48-54) intometrics::metricby giving the formatter a full-name parameter, withflare_supplied by the caller.process.rsis a new file, so that copy is new duplication, not pre-existing.
Not blocking — but it is the "same thing four times" that the design-review principles push back on, and this PR is the moment to settle it.
4. "Nothing about serving changes" is asserted, not measured
PR description ("Observability only … nothing about serving changes"); docs/design-review.md:97-105 (principle 12: report evidence honestly, disclose unrun checks and material limitations); AGENTS.md:194-199.
The added hot-path work is real, if small, and the description says there is none:
Worker::reserve_and_packnow readsmonotonic_ns()and walksstep.laneson every submitted step (runtime.rs:2191-2203), stamping before theGraphKind::Visionsplit at :2208.Worker::completedoes two stores per committed generated token (runtime.rs:1774-1775). Itsmonotonic_ns()is free —completed_at_nswas already read.- Every text scrape does blocking file I/O on the axum worker thread:
read_to_string("/proc/self/stat"),read_to_string("/proc/stat")(the whole file),read_dir("/proc/self/fd"), plussysconfandgetrlimit(server.rs:709 → process.rs:57-70, :99-126)./metricsis the only production caller — the terminal dashboard readsmetrics.scheduler_tracedirectly (dashboard.rs:135, :143, :236, :381) and never callsMetrics::render(metrics.rs:797) — so the cost is bounded to scrapes, but it is new and unstated.
Fix: one sentence — "the added cost is one clock read per scheduled step, two stores per generated token, and one /proc read per scrape; not measured" — instead of "nothing about serving changes".
Related, description-only: the live-scrape evidence does not reconcile. Runtime families gained 5 observations while flare_time_to_first_response_seconds gained 6; the prompt-token accounting ("le=\"64\" gained exactly one … le=\"2048\" gained four") totals 5; and the text concedes the deltas "include" this agent session's requests and "exceed the three requests below", so per-request counts cannot be checked, and no duration is attributed to a single request, so decode_sum/e2e_sum cannot be cross-checked against the reported completion tokens (60, 1500, 695). The base is the AzallazA fork commit 5ffe4d54 with this diff cherry-picked, not main — that limitation is disclosed, which is correct. Note also that the description's "CI covers the first two" is an expectation, not an observation: the head commit has no CI checks. Fix: keep the scrape as a labelled smoke check and lean on request_histograms_bucket_completed_request_timings (metrics.rs:1651-1697), which does establish the bucket boundaries and the zero-token exclusions.
Nits
process.rs:72-125is a fallback layer for sources that cannot fail independently. Sixif letarms (:72, :81, :90, :99, :108, :117) each drop a subset of series, andstatis re-matched in three of them. The module doc (:4-6) advertises "a source that cannot be read omits only the metrics derived from it, so a scrape never fails" — the nested-fallback styleAGENTS.md:188-189dislikes, and per-source degradation is untested either way (the route test only covers success). Onelet (Ok(stat), Ok(btime), Some(ticks), …) = … else { return }would be shorter and equally safe.docs/api.md:309-316population mismatch. ":309 The runtime histograms observe completed generations" is not quite true of all of them:flare_request_prompt_tokensandflare_requests_completed_totalalso count a completion that committed no token, while queue/prefill/decode skip it — asserted by the PR's own test (metrics.rs:1681-1696;request_completedat :459-461 observes prompt tokens unconditionally, decode only undergenerated_tokens > 1at :470-472). Sohistogram_quantileover prefill against the completed counter divides by a larger denominator than the histogram's own base. One clause fixes it. Likewise :315-316 reads as an invariant but a request cancelled afterrequest_completedalready ran (runtime.rs:1841-1846, :1996-2001) is in both.- TTFR histogram renders from
server.rs.render_histogramcorrectly lives in the mainimpl FirstResponseSamplesblock (latency.rs:63-109) but is called at server.rs:671, while every other family formats insideMetrics::render(metrics.rs:1389-1424). Harmless split, worth noting once.
Verified sound (no finding)
- Counter and histograms cannot diverge. The only
completed.fetch_addinhelios/srcis insiderequest_completed(metrics.rs:459); both call sites go through it (runtime.rs:1841-1846 text stop, :1996-2008 natural finish). - Stamps survive preemption.
Incoming.times(runtime.rs:193-194) moves with theIncominginto the parked deque (:2121) and back (:1387-1394);arrival_ns(:183, :901) is preserved the same way.reasoning_budget_cuts_or_plainly_continues_with_exact_history_and_usageasserts, after a forced park,flare_request_queue_seconds_count1,flare_request_prefill_seconds_count1 andflare_request_prompt_tokens_sum1, withmetrics.completed == 1andworker.parked.is_empty()(phase_tests.rs:576-583). - One timestamp per step is correct. Tokens committed in one model step share
completed_at_ns, solast_token_ns - first_token_nsmeasures wall time between the first and last committing step, which is what a decode histogram should report. - Bucket and render arithmetic.
observeusesexposed <= boundwithposition/unwrap_or(N-1); every array ends at infinity; cumulative_countmatches the+Infline (metrics.rs:259-298).saturating_subplus thegenerated_tokens > 1guard (:470-472) prevent underflow and division by zero. parse_stat(process.rs:19-37) skips to the last), validates the state character, and indexes correctly; pinned at :141-148.- Cancellation exclusion. http.rs:598-605 observes e2e once, before
yield Delivery::Completeat :606, guarded by!count && !encoder.tool_limit_reached;countis/v1/messages/count_tokensonly (http.rs:131) andtool_limit_reachedforcesTermination::Cancelled. Pinned at phase_tests.rs:4604-4613 across stream, non-stream, and all three protocols. - JSON snapshot unchanged, as claimed; the dashboard never calls
Metrics::render, so the added text families cannot leak into it. - The two extra
process_*series are justified.process_virtual_memory_bytesandprocess_max_fdsare not in #536's four-row table, but they are exactly what the standard Prometheus process collector exports, which serves the PR's own stated purpose (generic process dashboards can read them). Not a scope-creep finding.
Coverage
All 10 changed files read with surrounding code: helios/src/server/metrics/process.rs (whole file, plus eos/src/unix.rs:60-175, helios/src/os.rs:1-8, runtime_core/protection.rs:280-320,354), metrics.rs (:1-40, :200-400, :440-480, :1380-1424, :1630-1697), runtime.rs (:151-245, :293-302, :1310-1420, :1755-2015, :2187-2230, stamp construction at :913, :3254), http.rs (:120-200, :380-470, :540-656), latency.rs (:1-140), server.rs (:9-35, :640-718), docs/api.md (:280-340), runtime_core/{mod.rs,protection.rs}, runtime/phase_tests.rs (:4540-4650), and the rules (AGENTS.md:1-230, docs/design-review.md:1-231, charter, .github/workflows/native-serving.yml:56-68 (not opened) for what CI actually runs). Not re-read this run: the remainder of docs/api.md, and the diffs of #537/#549; Windows behaviour of process.rs is inferable only from its #[cfg(target_os = "linux")] gates (:10-13, :18, :39, :47, :56, :128) and eos/src/windows.rs:152-215 (not opened).
Open questions (only a maintainer or a measurement can settle)
- Will a maintainer record authorization on #536, or reframe the justification as the defect? Nothing in the repository settles it (item 2).
- Actual scrape latency and scheduler impact of the added observations (item 4). No test settles it.
- Whether the four overlapping observability PRs (#548, #549, #552, #553) should be consolidated by a maintainer before any is merged.
Link: https://github.com/NVIDIA/hyperflare-inference/pull/548