Conventions scratchpad · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/34029076-30f4-43e7-8241-b0ba09c24e97.md

#1 [high] Orientation: PR 548 scope and repo rules

PR #548 "Add request latency histograms and process metrics" (draft, head ebecef1, base main, 8 files +545/-20, no reviews, no CI; author WynnD, Discord oystersmiles). Closes issue #536 (which asks for vLLM-parity request histograms + standard process_* metrics).

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

Rules that govern a conventions review:

Lens assigned: conventions and duplication only.

#2 [high] Should fix: new Histogram/Buckets duplicates the two existing host-cache histogram implementations

PR adds Buckets<const N> (helios/src/server/metrics.rs:212-241), Histogram<const N> with observe (:259-271) and render (:273-297). Those are a third implementation of the same thing in one module:

  1. Host cost histograms: buckets HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS (metrics.rs:200-210), observation in host_lookup_cost (:670-692, limits.iter().position(...), bucket.fetch_add, host_cost_sums[index].fetch_add), rendering at :1029-1065 (+Inf when limit == u64::MAX, _bucket/_count/_sum).
  2. Host retirement: incremental bucket gauges host_retirement_buckets (:375), filled in store (:705-711), rendered at :851-876 with *ms as f64 / 1000.0.

The new Histogram supersedes (1) exactly: same fixed bounds, per-bucket AtomicU64 counts, one sum atomic. Nothing in the PR converts the existing sites, so the module now carries three bucket-encoding conventions (u64::MAX sentinel vs f64::INFINITY, ms-as-integer vs seconds-as-f64 bounds, and three different field orders: _count/_sum at :1060-1064, +Inf/_count/_sum at :867-876, _sum/_count at :291-296). Prometheus accepts all of them, but a reader maintaining one histogram family now has to know which of three forms it uses, and the u64::MAX sentinel form is strictly worse than f64::INFINITY (observe at metrics.rs:689 has an unchecked .unwrap() on position, which Histogram::observe avoids with unwrap_or(N - 1)).

Why it matters: AGENTS.md:188-193 rejects churn but also asks for "the smallest footprint in shared code" (charter "How We Work"); a second generic histogram next to two hand-rolled ones is the footprint that will be copied a fourth time. Report says the PR and #537 "add different regions" of metrics.rs, so the merge cost of migrating is low.

Fix: build the host cost histograms and the #537 page histograms on Histogram<N>/Buckets<N> (migrating host_missing_tokens/host_transfer_ns/host_prefill_ns and host_cost_sums to Histogram<8> instances is mechanical, and deletes :1029-1065 plus the host_lookup_cost bucket loop). If migration is out of scope for this PR, say so in the description rather than leaving the third form undocumented.

#3 [high] Should fix: process.rs re-implements OS helpers that already live in eos/ and helios::os

helios/src/server/metrics/process.rs (new) reads procfs and libc limits itself:

Why it matters: AGENTS.md repo map says "The eos/ crate holds the host operating-system operations that Helios and Selene use", helios/src/os.rs:6 repeats "Host operating-system operations for native serving" and re-exports flare_eos::*. So a new helios/src/server/metrics/process.rs that calls libc::sysconf/libc::getrlimit//proc/self/fd directly puts a fourth copy of the same OS layer in Helios instead of one line in the module the repository designates for it. The duplication is also already drifting (page-size fallback behaviour above).

Fix: add the missing getters (page_size() exists; add open_file_limit() -> Option<u64> and open_descriptors() -> Option<u64>) to eos/src/unix.rs next to raise_open_file_limit, or reuse crate::os from process.rs; keep only the /proc/self/stat and /proc/stat parsing in process.rs, since nothing parses those today (verified: search_code for btime|_SC_CLK_TCK|/proc/self/stat finds no prior implementation in Rust sources).

#9 [high] Research summary

Reviewed PR #548 through the conventions-and-duplication lens: every changed file (docs/api.md, helios/src/server.rs, server/http.rs, server/latency.rs, server/metrics.rs, server/metrics/process.rs, server/runtime.rs, server/runtime/phase_tests.rs) was read in context, including the callers of each changed function and the precedents cited against it.

Five confirmed findings recorded, plus one nit and a note of candidates I checked and dropped:

Verified non-findings: RequestTimes does not duplicate scheduler::RequestAccounting (the scheduler copy is reset at finish and does not survive park), the latency.rs Mutex<Samples> → {window, histogram} rename updates every use site, and the new SPDX header matches latency.rs:1.

#10 [high] Summary: findings list for the conventions and duplication report on #548

PR #548 (draft, head ebecef1, 8 files +545/−20, no reviews, no CI). Lens: conventions and duplication. Every changed file was read in context. Six findings, none blocking; three should fix on duplication, two should fix on documentation/placement convention, one nit.

  1. SHOULD FIX (duplication, largest) — third histogram implementation in one module. New: Buckets<const N> and Histogram<const N> (observe/render) at helios/src/server/metrics.rs:212-298; bucket constants at :219-241. Existing precedent 1: HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS (metrics.rs:200-210), observation in Metrics::host_lookup_cost (:670-692: limits.iter().position(...) + host_cost_sums[index].fetch_add), rendering at :1029-1065. Existing precedent 2: retirement histogram gauges filled in store (:705-711), rendered at :851-876 with *ms as f64 / 1000.0 bounds. Consequence: three bucket encodings now coexist in one file (u64::MAX sentinel vs f64::INFINITY; ms-integer vs seconds-f64 bounds) and three _count/_sum orderings (:1059-1064, :867-876, :286-296). Also the old path's position(...).unwrap() at :689 vs the new unwrap_or(N - 1) at :268. Fix: rebuild the three host-cost histograms on Histogram<8>/Buckets<8>, deleting :1029-1065 and the bucket loop in host_lookup_cost; PR says it only touches the completion-counter region, so #537/#548 merge order is unaffected.

  2. SHOULD FIX (duplication) — process.rs re-implements existing OS helpers. New: metrics/process.rs:65-67 /proc/self/fd counting, :56 libc::sysconf(_SC_PAGESIZE), :68-77 libc::getrlimit(RLIMIT_NOFILE). Existing: open_descriptors() at helios/src/runtime_core/protection.rs:290-302 is character-identical; eos::page_size() eos/src/unix.rs:73-75 re-exported as crate::os::page_size() (helios/src/os.rs:8) and used at helios/src/cuda.rs:425,:1450; eos::raise_open_file_limit eos/src/unix.rs:138-165 performs the same getrlimit and returns the soft limit as Option<u64> — exactly process_max_fds — and is re-exported through crate::os (used at protection.rs:356). Convention: AGENTS.md repo map ("The eos/ crate holds the host operating-system operations that Helios and Selene use"), helios/src/os.rs:6. Drift already visible: eos falls back to page size 4096, process.rs omits the metric. Fix: add open_file_limit()/open_descriptors() beside raise_open_file_limit in eos/src/unix.rs and call crate::os::page_size(); leave only the /proc/self/stat and /proc/stat btime parsing in process.rs (no prior Rust implementation of those exists — searched).

  3. SHOULD FIX (convention/placement) — TTFR histogram owned outside Metrics, rendered from the route. helios/src/server/latency.rs:33-37 (histogram field), :108-119 (double record: window + histogram), :122-131 (render_histogram), called at helios/src/server.rs:671. Contrast: request_e2e is a Metrics field (metrics.rs:327), rendered by Metrics::render at metrics.rs:1386-1430 alongside the runtime request histograms, and observed via metrics_handle() from http.rs:615/:632. metrics::process::render is appended at server.rs:709. So /metrics text is now assembled at three points with no stated rule. Note the double bookkeeping (VecDeque + histogram for the same duration) is the accepted cost of keeping the 60 s median documented at docs/api.md:329-336; the finding is ownership/render asymmetry, not the double record. Fix: pick one ownership and state it (move the histogram beside request_e2e, or document in Metrics::render that HTTP-owned histograms are appended by the route).

  4. SHOULD FIX (documentation consistency) — docs/api.md:287-290 unmodified sentence "Counter and gauge names start with flare_" is contradicted by the six new process_* series documented at docs/api.md:315-318 (emitted at metrics/process.rs:78-127). The names themselves are correct (standard Prometheus process collector names, which is what #536 asked for). Fix: one clause, e.g. "…start with flare_, except the standard process_* series below". Matters because the surrounding paragraphs invite {__name__=~"flare_.*"} scrape filters.

  5. SHOULD FIX (duplication, small) — the e2e observation is written inline twice in one function in two accessor styles: helios/src/server/http.rs:614-616 (state.model.metrics()-derived clone metrics) and :631-632 (state.model.metrics()). The file's own precedent is named helpers (failure_log, rejection, rejection_details, with_request_id, http.rs:39-69) and it already captures stream_state/id.clone() into the closure (:384-385, :601). metrics_handle() here is its second caller in the tree (other: server.rs:511). Fix: one observe_e2e(&self, admitted_at) helper; it also drops the repeated as_nanos() as u64 and REQUEST_SECONDS.

  6. NIT — process::metric (metrics/process.rs:42-49) duplicates metrics::metric (metrics.rs:1597-1602), differing only by the flare_ prefix and the Display value type; the copy also skips escape_prometheus_label (metrics.rs:1604-1615), which is fine today (no labels) but will not be inherited if a labelled process_* series is added. Fix: keep one emitter and pass the full name.

DROPPED after verification (entry 8): RequestTimes vs scheduler::RequestAccounting is not duplication (scheduler copy is reset by finish, does not survive park; CheckpointAccounting::initial_prefill_ns is a prediction, not a measurement); the latency.rs Mutex<Samples>→{window, histogram} rename updates every use site (:73, :111, tests :198/:213/:222); the one-line SPDX header at process.rs:1 matches latency.rs:1.

No blocking finding. The twelve times: Default::default() struct-literal additions (runtime.rs:913, :3254, phase_tests.rs:251) follow the existing pattern and needed no comment beyond the field doc at runtime.rs:193.

#12 [high] Update after commits d64c3ea3 + a34c4d06: which findings are fixed and which remain

Head moved ebecef1 -> a34c4d06 (commits d64c3ea3 "Exclude cancelled responses and reuse host helpers", a34c4d06 "Hoist completion values and tighten stat parsing"). Re-verified every finding against the new head.

FIXED by d64c3ea3:

REFINEMENT of finding 3 (now nit): open_descriptors() still lives in helios/src/runtime_core/protection.rs:291-302 and was widened to pub(crate) plus re-exported at helios/src/runtime_core/mod.rs:58 so server metrics can reach it. AGENTS.md:20-21 names eos/ as the home of host OS operations that Helios and Selene use, and eos/src/unix.rs already exports page_size()/raise_open_file_limit; a metrics module importing a core-protection private helper is the wrong direction. Fix: move the function to eos/src/unix.rs (Linux-gated) and call it as crate::os::open_descriptors(), as the other two now are. eos already has the #[cfg(not(target_os = "linux"))] -> None shape precedent (runtime_core/protection.rs:298-301).

STILL OPEN:

New minor observation on the pushed diff (nit, same file): process.rs:81-98 now has two consecutive if let Some(stat) = stat blocks for process_virtual_memory_bytes and process_resident_memory_bytes, which could be one block; the earlier if let (Some(stat), Some(ticks)) for CPU is separate by necessity. Cosmetic only.

Also re-verified as clean at the new head: the hoisted prompt_tokens/generated_tokens locals in runtime.rs:1838-1846 and :1993-2001 are used by both request_completed and Finished, matching the existing Carried hoisting in park (runtime.rs:2104, :2115-2116); RequestTimes::default() in metrics.rs:1683 test replaced the impossible {None, Some} state.

#13 [high] Report of 2026-11-27, run 2: conventions and duplication on head a34c4d06

Verdict: should-fix issues only (two). Three of the six findings from the previous turn are fixed by d64c3ea3; head re-verified at a34c4d06.

Blocking: none.

Should fix:

  1. helios/src/server/metrics.rs:212-298 + :200-210, :382, :670-692, :1029-1065, :851-876 — the new generic Buckets/Histogram is the third Prometheus-histogram implementation in one module. Precedents not migrated: HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS with host_lookup_cost (u64::MAX sentinel, position(...).unwrap() at :689) and the retirement bucket gauges (flare_selene::RETIREMENT_LATENCY_MS, ms-integer bounds → *ms as f64 / 1000.0). Three bucket encodings and three _count/_sum orders now coexist (:1060-1064, :871-876, :291-296). Fix: rebuild the host-cost histograms on Histogram<8>/Buckets<8>, which deletes :1029-1065 and the bucket loop in host_lookup_cost; or state the migration is deferred.
  2. helios/src/server/latency.rs:33-37, :101-108, :116-127 (appended at helios/src/server.rs:671) — flare_time_to_first_response_seconds is owned by FirstResponseSamples and rendered through a route-side hook, while its sibling request_e2e is a Metrics field (metrics.rs:327) rendered by Metrics::render (metrics.rs:1389-1412). /metrics text is assembled at three points (metrics.rs render, server.rs:671, server.rs:709) with no stated rule. Fix: pick one ownership and write it down.

Nits:

Verified non-findings (previous entry 8, still valid): RequestTimes vs scheduler::RequestAccounting (policy.rs:53-65) is not duplication — the scheduler copy is reset by finish and does not survive park; CheckpointAccounting::initial_prefill_ns is a prediction. The runtime.rs hoisted locals (:1838-1846, :1993-2001) match the existing Carried hoisting in park (:2104, :2115-2116). The e2e guard at http.rs:598-605 now matches the runtime's own cancelled accounting (runtime.rs:1338/:1360), which is what removed the strongest objection to that observation.

#14 [high] Research summary

Reviewed PR #548 at its new head a34c4d06 (after d64c3ea3 and a34c4d06) through the conventions-and-duplication lens. Every changed file was read in context (docs/api.md, helios/src/runtime_core/{mod,protection}.rs, server.rs, server/http.rs, server/latency.rs, server/metrics.rs, server/metrics/process.rs, server/runtime.rs, server/runtime/phase_tests.rs), with the precedents they duplicate.

Verdict: should-fix issues only, two of them. Three of the six findings from the previous turn are now fixed by the pushed commits: the docs/api.md sentence that claimed every counter and gauge starts with flare_ now carries the "except the standard process_* series" clause; the duplicated end-to-end observation in http.rs is now a single site (:598-605) guarded on !count && !encoder.tool_limit_reached, so metrics_handle() has one caller left; and process.rs now reaches the page size, the descriptor count and the file limit through existing helpers instead of re-implementing them — leaving only the /proc/self/stat and btime parsing, which has no prior implementation in the tree.

Still open: (1) the new generic Buckets/Histogram in metrics.rs is the third Prometheus-histogram implementation in that one module, beside HOST_*_BUCKETS + host_lookup_cost and the retirement bucket gauges, and nothing is migrated, so three bucket encodings and three _count/_sum orderings coexist; (2) flare_time_to_first_response_seconds is owned outside Metrics and appended to the scrape text by the route, while its sibling request_e2e is a Metrics field rendered by Metrics::render, so /metrics text is assembled at three points with no stated rule. Nits: open_descriptors was widened out of runtime_core::protection rather than moved to eos/, which AGENTS.md:20-21 designates as the home of host OS operations; process::metric duplicates metrics::metric and does not inherit the label escaper; two adjacent identical if let Some(stat) blocks in render_linux.

Nothing blocking. Details and line numbers are in scratchpad entries 12 and 13.

#15 [high] Verbatim evidence at head a34c4d06 for the two remaining should-fix findings

Quotes verified by reading the files at head a34c4d06, for direct citation in the final report.

FINDING 1 — three histogram implementations in helios/src/server/metrics.rs.

FINDING 5 — TTFR histogram owned outside Metrics.

FIXED (for the "changes since the last review" section), with the new text:

#17 [high] Report of 2026-11-27, run 4: re-verified at head a34c4d06, no new commits

Head is still a34c4d06 (git log shows a34c4d06 / d64c3ea3 / ebecef13 on top of f377dc85), the PR discussion has no comment newer than the bot's 06:15 review, and pr_files still reports the same 10 files (+548/−25). I re-read each changed site rather than reusing the earlier quotes:

Conclusion: the report of entry #16 stands as written; no new finding and nothing retracted. Also re-checked and still clean: docs/api.md:288-290 now carves out process_*, http.rs:598-605 is the single e2e observation, and the SPDX header in process.rs matches its sibling latency.rs:1 (both /* SPDX-License-Identifier: Apache-2.0 */, the module-local short form used where the file is small; the full SPDX-FileCopyrightText block is the norm elsewhere in helios/src but the short form already exists in latency.rs and dashboard/prefill.rs, so it is not a new departure).

#18 [high] Evidence refinement at a34c4d06: histogram renderers differ in HELP emission and order; request_e2e is the only pub(super) histogram field

Re-verified at head a34c4d06 (no new commits). Extra evidence gathered this pass to make the two should-fix findings precise, plus one correction to how the fix should be framed under repository policy.

FINDING 1 additions — the three histogram implementations also disagree on series layout, not only on encoding:

FINDING 5 additions — the encapsulation break is exactly one field:

#19 [high] Research summary

Reviewed PR #548 at head a34c4d06 (unchanged since the last pass: git log still shows a34c4d06 / d64c3ea3 / ebecef13, no new PR comments, same 10 files +548/−25) through the conventions-and-duplication lens. Every changed file was read in context again this pass rather than reusing earlier quotes, and all findings were re-verified line by line.

Verdict: should-fix issues only. No blocking issues. Two should-fix, three nits.

Should fix:

  1. helios/src/server/metrics.rs:212-298 — the new generic Buckets/Histogram is the third Prometheus-histogram implementation in the module, and the two older ones (:200-210 sentinel u64::MAX arrays + :382 + :670-692 + :1029-1065; :375 + :705-711 + :851-876 over flare_selene::RETIREMENT_LATENCY_MS, selene/src/store.rs:21) are left in place. New detail this pass: they also differ in whether they emit # HELP and in _count/_sum order, so one scrape mixes layouts. Fix is a choice — migrate the older sites onto Histogram/Buckets (deletes ~80 lines) or scope the new type so it does not read as the module's histogram abstraction, and state the deferral.
  2. helios/src/server/latency.rs:33-37, :101-108, :116-127, appended at helios/src/server.rs:671 — flare_time_to_first_response_seconds is owned by FirstResponseSamples and rendered by a route-side hook, while its sibling flare_request_e2e_seconds is a Metrics field (metrics.rs:327) rendered inside Metrics::render (:1389-1412). request_e2e is in fact the only pub(super) histogram field, made visible so http.rs:601 can observe directly, which breaks the "record where the counter is recorded" rule the PR states. /metrics text is assembled at four points with no stated rule.

Nits: open_descriptors() widened out of runtime_core::protection and re-exported rather than moved to eos/ (AGENTS.md:20-21; its two neighbours already go through crate::os); process::metric duplicates metrics::metric and skips escape_prometheus_label; two adjacent identical if let Some(stat) blocks in render_linux.

Fixed since the first review and recorded as such: the docs/api.md:288-290 sentence, the duplicated e2e observation in http.rs, and the re-implemented OS helpers. Verified non-findings: RequestTimes vs scheduler::RequestAccounting, the hoisted token locals in runtime.rs, the SPDX header (short form already used by latency.rs:1 and dashboard/prefill.rs:1 (not opened)).

Full report with quotes and line numbers is scratchpad entry #16; re-verification is #17 and the refinements above are #18. Open questions for the author: is migrating the two older histograms intended follow-up or out of scope, and is there a maintainer preference for where HTTP-observed histograms live?

#20 [high] Final report of 2026-11-27, run 5 (head a34c4d06, no new commits): two should-fix, three nits

Reviewed at head a34c4d06, which is still the head: git log shows a34c4d06 / d64c3ea3 / ebecef13 on top of f377dc85, the PR discussion has no comment newer than the bot's 06:15 review, and pr_files still reports 10 files (+548/−25). Every changed file was read again in context through the conventions-and-duplication lens, and every finding below was re-verified in the code at this head.

Verdict: should-fix issues only. No blocking issues. Two should-fix, three nits.

Should fix

1. Buckets/Histogram is the third Prometheus-histogram implementation in helios/src/server/metrics.rs, and the two older ones are left in place

New code metrics.rs:212-298 (Buckets<const N> with [f64; N] bounds ending f64::INFINITY plus a scale, Histogram<const N>, one observe at :260-271 and one render at :273-297). Precedents not migrated:

They disagree on more than encoding, and the disagreements show up in one scrape: the new renderer emits # HELP + # TYPE (:274-277) while both older ones emit only # TYPE (:1049, :851); the new one emits buckets → _sum (:291-295) → _count (:296), host cost emits buckets → _count (:1060) → _sum (:1061-1064), retirement emits buckets → +Inf (:867-870) → _count (:871) → _sum (:872-876); bounds are f64+scale vs u64 sentinel vs integer milliseconds.

Why it matters: AGENTS.md:188-193 rejects churn that does not remove a demonstrated cost, and docs/design-review.md:74 asks that duplicate representations be accounted for. A second, clearly better abstraction sitting beside two older ones makes the module read as mid-migration without being one, and a reader cannot tell which shape a new histogram should take. This is a code-shape decision, not a behaviour defect: the host-cost position(...).unwrap() at :689 cannot panic because u64::MAX terminates the array, and every emitted series is already pinned by existing tests, so a migration should be behaviour-preserving.

Fix (choose one): rebuild the host-cost and retirement histograms on Histogram<8>/Buckets<8> — which deletes :200-210, the bucket loop in host_lookup_cost (:688-691), the 37-line render loop (:1029-1065), and the retirement bucket gauges plus their renderer (:375, :705-711, :851-876) — or state in the PR description that the migration is deliberately deferred and scope the new type so it does not present itself as the module's histogram abstraction.

2. flare_time_to_first_response_seconds is owned outside Metrics while its sibling flare_request_e2e_seconds is a Metrics field

latency.rs:33-37 FirstResponseSamples { window: Mutex<Samples>, histogram: super::metrics::Histogram<21> }, observed in FirstResponse::output (latency.rs:116-127) and rendered by its own forwarder render_histogram (latency.rs:101-108), which the /metrics handler calls out of band at helios/src/server.rs:671. The sibling added by the same PR is a Metrics field — metrics.rs:327 pub(super) request_e2e: Histogram<21> — rendered inside Metrics::render in the loop at :1389-1412 alongside the five runtime histograms.

Two consequences worth citing:

Fix: move the TTFR histogram onto Metrics (observed from FirstResponseSamples::output via the existing state.model.metrics() handle, so both HTTP histograms render from the :1389 loop), which also retires render_histogram, the server.rs:671 call, and the pub(super) on request_e2e; or state in latency.rs why the window and its histogram must stay together.

Nits

Changes since the first review (fixed — record, do not re-raise)

Verified non-findings

Open questions for the author

  1. Is migrating HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS and the retirement histogram intended follow-up or out of scope? The description does not say; it names only #537 as an overlapping PR.
  2. Is there a maintainer preference for where HTTP-observed histograms live? No doc states one; request_e2e's placement is the only precedent, and this PR sets two.

Not checked here: the Windows build and the full helios suite (the description says CI covers both, and the head has no CI checks yet); the pre-existing messages_image_hints_end_after_expansion_... test needs FLARE_TEST_TEMPLATE_DIR. Nothing in this review depends on them.

#22 [high] Report of 2026-11-28, run 6 (head 055663a): two should-fix, three nits — final text

Reviewed head 055663a (9 files, +1016/−51, no reviews, no CI checks). Process-metrics removal (54e06b30) fixed the three previous nits: metrics/process.rs is gone, so process::metric (duplicate emitter), the two adjacent if let Some(stat) guards, and the pub(crate) widening of open_descriptors (helios/src/runtime_core/protection.rs:291 is private again; only caller :354) no longer exist. docs/api.md's flare_ prefix sentence is fixed, and http.rs now has one e2e observation site.

VERDICT: should-fix only, no blockers.

SHOULD FIX 1 — metrics.rs still holds three Prometheus-histogram implementations at this head, with the new generic as the newest and least canonical:

SHOULD FIX 2 — the two HTTP-observed histograms added by this PR are owned by different structs and rendered by different paths. flare_request_e2e_seconds is a private Metrics field (metrics.rs:406), observed through Metrics::response_completed (metrics.rs:605-618) from http.rs:606-612 and rendered in the Metrics::render loop (metrics.rs:1548-1581). flare_time_to_first_response_seconds lives outside the registry: FirstResponseSamples.histogram (latency.rs:36), observed in FirstResponse::output (latency.rs:121-124), rendered by its own forwarder render_histogram (latency.rs:101-108) which the route calls out of band at helios/src/server.rs:671. A reader of Metrics cannot learn that the series exists; the scrape text is assembled at four stages (server.rs:660, :661-671, :672-674, :675-708) with no stated ownership rule. Fix: move the TTFR histogram onto Metrics, observe it from FirstResponse::output through the existing handle, and delete render_histogram and the server.rs:671 call — or state in Metrics::render that HTTP-owned histograms are appended by the route.

NIT 3 — runtime.rs:1721-1730 gates metrics.model_step with matches!(kind, Prefill | TerminalPrefill | ScoredPrefill | Resume | Decode | Speculative | Mixed), exactly the set that GraphKind::samples() already encodes (helios/src/execution/manifest.rs:90-101), which runtime.rs itself uses at :2956 (if !step.kind.samples()). Fix: if kind.samples(), so a new sampling kind does not silently miss the histogram.

NIT 4 — per-choice generated-token bookkeeping is now duplicated. Encoder already stores it (Usage { generated: u32 } protocol/encode.rs:55-60, set from the same Finished event at :630-634 after observe_generated_token :216-219) and already groups by prompt via choices_per_prompt/step_by (encode.rs:94, :690-695). http.rs adds a parallel let mut generated = vec![0u32; size] (:407) filled at :530, and metrics.rs:610 re-groups with generated.chunks(choices). Two stores and two groupings of one number will diverge the first time one path changes (e.g. the zero-limit choices at http.rs:315-319 and :441-454 never set generated). Fix: expose the encoder's per-choice counts (or its choices_per_prompt) and observe from that single source.

NIT 5 — flare_admission_rejections_total is hand-rolled at metrics.rs:1643-1656 with a literal ["http_slots", "generation_capacity", "request_queue"] array zipped positionally against &self.admission_rejections (:423), duplicating AdmissionLimit's variant order (metrics.rs:376-385) with no link between them, and bypassing the labelled-counter loop already in the file (metrics.rs:1143-1177 for (name, labels, counters) ... "# TYPE flare_{name} counter"). Fix: give AdmissionLimit a name()/ALL and reuse the existing loop.

Also noted, not raised: the max_new_tokens + reasoning_cut.after sum at runtime.rs:1568-1569 repeats runtime.rs:66-67 (Prompt::output_event_capacity); a Prompt::output_budget() would remove the third copy (phase_tests.rs also spells it). Kept as an observation because the two sites serve different purposes (capacity vs. observation).

#23 [high] Research summary

Reviewed PR #548 at head 055663a (9 files, +1016/−51) through the conventions-and-duplication lens; every changed file read in context, every finding verified at that head. Verdict: should-fix only, no blockers.

The process-metrics removal (54e06b30) cleared the three nits from the previous pass: metrics/process.rs (not opened) and its duplicate metric emitter and twin if let Some(stat) guards are gone, and open_descriptors is private again (protection.rs:291 (not opened), sole caller :354). The docs flare_ sentence and the duplicated inline e2e observation are also fixed.

Two should-fix findings remain: (1) metrics.rs now carries three Prometheus-histogram implementations — the new Buckets/Histogram (:211-322) alongside the untouched host-cost histograms (:199-209, :475, :819-841, :1178-1214) and the retirement buckets (:468, :854-860, :1000-1025) — which disagree on # HELP emission, _sum/_count order and bound encoding within a single scrape; (2) the two HTTP histograms this PR adds are owned and rendered in different ways — request_e2e is a Metrics field rendered in the Metrics::render loop (:406, :605-618, :1548-1581) while time_to_first_response lives in FirstResponseSamples (latency.rs:36) and is appended by the route through its own forwarder (latency.rs:101-108, server.rs:671), so the scrape text is assembled at four stages with no stated rule.

Three nits: the model_step gate at runtime.rs:1721-1730 re-spells the existing GraphKind::samples() (manifest.rs:90-101); http.rs:407/:530 and metrics.rs:610 keep a second copy of the per-choice generated-token counts and their prompt grouping that Encoder already holds (encode.rs:55-60, :94, :630-634, :690-695); and flare_admission_rejections_total is hand-rolled at metrics.rs:1643-1656 with a positional label array that duplicates AdmissionLimit's variant order, bypassing the labelled-counter loop at :1143-1177.

All findings and their citations are in scratchpad entry #22.

#24 [high] Head 055663a: request_e2e visibility claim is stale; verified non-findings list

Facts re-verified at head 055663a that the final report must use, and one stale claim it must NOT repeat.

MUST NOT REPEAT (stale from entries #15/#18, fixed by 49373bc5/0501b9c-era commits): request_e2e is no longer pub(super). At this head it is a private field — request_e2e: Histogram<21> (metrics.rs:406), observed only through Metrics::response_completed (metrics.rs:605-618), called at http.rs:606-612. So the "only non-private histogram field / http.rs reaches into Metrics internals" argument is gone; finding 2 now rests purely on the ownership/render asymmetry (TTFR vs e2e), not on a visibility break.

VERIFIED NON-FINDINGS at this head (checked, dropped):

NOT VERIFIED / out of reach here: the Windows build, any GPU run, and the pre-existing messages_image_hints_end_after_expansion_… test that needs FLARE_TEST_TEMPLATE_DIR. No finding depends on them; all are code-shape questions settled by reading the cited lines at 055663a.

#5 [medium] Should fix: time_to_first_response histogram is owned by latency.rs while the sibling request_e2e histogram is owned by Metrics

helios/src/server/latency.rs:108-131 records the same observation twice and stores its histogram outside the metrics registry:

Why it matters: the precedent in this file/module is that a mouse-to-metrics gauge or counter is a field of Metrics sample-and-observed in place (Metrics::progress, Metrics::http_requests at http.rs:142, the dashboard gauges at server.rs:661-708 are computed at render because they are derived from HttpState). The first-response histogram is neither: it is an independent counter with its own lock-adjacent storage and its own render hook. A reviewer cannot tell from Metrics that flare_time_to_first_response_seconds exists, which is what the render() grouping is for.

Fix (either is fine, pick one and state the rule): move first_response histogram ownership beside request_e2e in Metrics and observe it from FirstResponse::output through a handle, or keep the current ownership and note in Metrics::render's doc comment that HTTP-owned histograms are appended by the route. The one thing worth changing is the asymmetry between request_e2e and time_to_first_response, which both measure the same kind of request-level latency.

#6 [medium] Should fix: docs/api.md still says every metric starts with flare_, six new ones do not

docs/api.md:287-290 (unmodified lines) says: "GET /metrics returns Prometheus text exposition format 0.0.4 by default. Counter and gauge names start with flare_, such as …". The PR adds six series that violate that sentence and does not amend it:

process_cpu_seconds_total, process_resident_memory_bytes, process_virtual_memory_bytes, process_start_time_seconds, process_open_fds, process_max_fds (helios/src/server/metrics/process.rs:78-127; documented in the new docs/api.md:315-318).

The new paragraph at docs/api.md:315-318 says only "On Linux the text also carries process_cpu_seconds_total, … for the serving process. Other platforms omit them." — an accurate statement of the new behaviour, but the document now contains one sentence saying every series starts with flare_ and 30 lines later six that do not, with no reconciliation. A reader writing a {__name__=~"flare_.*"} scrape filter, which the paragraph at :287-294 invites, silently loses all six.

Fix: change :288-289 to "Counter and gauge names start with flare_, except the standard process_* series below", or scope the sentence ("Flare's own counters and gauges…"). One clause.

Verified against the code: process.rs:78-127 emits exactly those unprefixed names and nothing else. Note the names themselves are correct — they are the standard Prometheus/prometheus_client process collector names, which is the point of #536 — so this is a documentation consistency finding, not a naming request.

#7 [medium] Nit/should fix: the e2e histogram observation is written inline twice in http.rs, in two accessor styles

helios/src/server/http.rs:614-616 and :631-632 write the same statement twice in two styles:

Delivery::Complete(_) => {
    if !count { metrics.request_e2e.observe(&super::metrics::REQUEST_SECONDS, admitted_at.elapsed().as_nanos() as u64); }
    None
}

vs

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

(two single-line blocks, one after another in the same function). Both duplicate behaviour the closures' neighbours do not: the streaming branch already clones state (let stream_state = state.clone(); http.rs:384, used elsewhere) and id.clone() (:385, :601), and the same file's ordinary style for a shared helper is a named function (failure_log, rejection, rejection_details, with_request_id, all http.rs:39-69). Note also the inconsistency inside the new code: the streaming branch reaches metrics through state.model.metrics_handle() (which clones the Arc into the closure) while the non-streaming branch calls state.model.metrics() — so the file now shows both accessors for one field, and metrics_handle() gained its second caller in the tree (the other is server.rs:511, the dashboard).

Additionally the e2e observe is the one new metric observation placed inline in the route instead of behind a Metrics method, unlike the runtime histograms (Metrics::request_completed, metrics.rs:449-478) — so the "record in one place" argument the PR makes for the completion counter does not extend to the e2e histogram, which now has two inline call sites that must stay in step with the three delivery branches.

Fix: one fn observe_e2e(&self, admitted_at: Instant) (or a AdmittedAt::elapsed_seconds()), called from both branches; it also removes the as_nanos() as u64 and REQUEST_SECONDS repetition the file otherwise hides.

#8 [medium] Verified non-findings: RequestTimes vs RequestAccounting; SPDX header; latency rename

Checked and NOT a duplication to flag: RequestTimes (metrics.rs:300-306) versus scheduler::RequestAccounting (helios/src/scheduler/policy.rs:53-65). RequestAccounting already holds arrival_ns, last_progress_ns, last_output_ns: Option<u64>, terminal_since_ns and committed_output_tokens, and set_arrival (policy.rs:245-254) already carries the arrival stamp, so the new stamp fields look like a repeat. They are not: RequestAccounting is owned by the scheduler, is reset by finish, and is not readable after park → resume_decoded_sequence (runtime.rs:1556-1575 explicitly rebuilds the request from Parked), while a preempted request must keep its stamps. CheckpointAccounting::initial_prefill_ns (scheduler/checkpoints.rs:24) is a predicted cost, not a measurement. So there is no existing mechanism to reuse — verified in code, not just by comment.

Also not a finding: the ART/phase-test additions (times: Default::default() at runtime.rs:913, :3254, phase_tests.rs:251) match the existing struct-literal noise pattern; no duplication introduced.

Also checked and clean: FirstResponseSamples's Mutex<Samples> → { window, histogram } rename (latency.rs:33-37) touches every use site (latency.rs:73, :111, tests :198, :213, :222) — no stale .0 access left. render_histogram correctly passes REQUEST_SECONDS (latency.rs:128) rather than defining a fourth bucket set, and reuses the same 21 boundaries as the request histograms, which matches #536's request that TTFR "same start and end points as the current median gauge".

SPDX headers: new file helios/src/server/metrics/process.rs:1 is /* SPDX-License-Identifier: Apache-2.0 */, byte-identical to helios/src/server/latency.rs:1 and to the contributor-authored files under helios/src/server/protocol/decisions/. The newer convention for files that started as NVIDIA is the two-line Copyright form (metrics.rs:1-5). Matching latency.rs is defensible; a nit at most, not worth a finding.

#4 [low] Nit: process::metric duplicates metrics::metric line emitter

helios/src/server/metrics/process.rs:42-49 defines fn metric(text, name, kind, help, value) doing "# HELP {name} {help}\n# TYPE {name} {kind}\n{name} {value}", right beside metrics::metric at helios/src/server/metrics.rs:1597-1602 doing "# HELP flare_{name} {help}\n# TYPE flare_{name} {kind}\nflare_{name} {value}" — same three lines, same order, differing only in whether the flare_ prefix is applied and in the value type (impl Display vs u64). The prefix difference is precisely why the copy was written, but the generalisation is one line: metrics::metric could take the already-prefixed name, or gain a flare: bool/Display value parameter, and process::render would reuse it instead of carrying a second line-emitter.

Also note the new helper skips escape_prometheus_label (metrics.rs:1604-1615); no new series takes a label, so nothing is wrong today, but the second emitter will not inherit the escaping if a labelled process_* series is added (e.g. process_io_bytes_total{device=…}), while the shared one will.

Fix: keep one exposition helper in metrics.rs and pass it the full metric name; delete process::metric. Nit if the author prefers to defer.