Key findings
Reviewed at head a34c4d06 (commits a34c4d06, d64c3ea3, ebecef13 on top of f377dc85), 10 files, +548/−25, draft, no reviews, no CI checks. Every changed file was read in context through the conventions-and-duplication lens, and every finding below was re-verified line by line in the code at this head.
Verdict: should-fix issues only. No blocking issue. Two should-fix findings, three nits.
The PR is largely faithful to precedent: the process collector is appended through a metrics/ submodule exactly as engram::Stats::render and render_persistent_worker_metrics already are, #[cfg(not(target_os = "linux"))] let _ = text; matches an existing pattern, the bucket constants are shared per unit, and the short SPDX header is not a new deviation. The two should-fix items are about two new abstractions presented as the module's own — one superseding two predecessors without migrating them, one splitting HTTP histogram ownership two ways in a single PR.
Two findings from the first review are fixed and are recorded, not re-raised: the docs/api.md "names start with flare_" sentence, and the duplicated inline e2e observation in http.rs.
Should fix
1. Buckets/Histogram is the third Prometheus-histogram implementation in helios/src/server/metrics.rs, and the two predecessors are left in place
New code, helios/src/server/metrics.rs:212-298: Buckets<const N> (:214-217, [f64; N] bounds ending f64::INFINITY plus a scale), the shared constants REQUEST_SECONDS/TOKEN_SECONDS/PROMPT_TOKENS (:219-241), Histogram<const N> (:245-248), one observe (:260-271, position(...).unwrap_or(N - 1)) and one render (:273-297).
Two older implementations in the same module, untouched by this PR or either follow-up commit:
- Host cost histograms. Bounds
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETSas[u64; 8]endingu64::MAX(metrics.rs:200-210); sums inhost_cost_sums: [AtomicU64; 3](:382); observation insidehost_lookup_cost(:670-692,limits.iter().position(|limit| value <= *limit).unwrap()at:689); render loop:1029-1065. - Host retirement histogram.
host_retirement_buckets: [AtomicU64; 8](:375), filled fromMetrics::store(:705-711), rendered at:851-876where the bounds are*ms as f64 / 1000.0overflare_selene::RETIREMENT_LATENCY_MS(selene/src/store.rs:21=[10, 50, 100, 500, 1000, 5000, 15000, 30000]).
The three disagree on more than internal encoding, and the disagreements are visible in a single scrape:
new Histogram::render |
host cost | retirement | |
|---|---|---|---|
# HELP |
yes (:274-277) |
no, # TYPE only (:1049) |
no, # TYPE only (:851) |
| series order | buckets → _sum (:291-295) → _count (:296) |
buckets → _count (:1060) → _sum (:1061-1064) |
buckets → +Inf (:867-870) → _count (:871) → _sum (:872-876) |
| bounds | [f64; N] + scale |
[u64; 8] with u64::MAX sentinel |
integer ms, rendered /1000.0 |
Why it matters. AGENTS.md:188-193 rejects unsupported abstractions and churn while asking that refactoring "directly support the requested behavior or remove a demonstrated source of defects or cost", and docs/design-review.md:72-75 (principle 8) asks that duplicate representations be accounted for. Right now metrics.rs reads as mid-migration without being one: a reader cannot tell which of the three shapes a new histogram should take, and the generic pub(super) struct Histogram presents itself as the module's histogram abstraction while two older forms remain canonical for their series.
This is a code-shape finding, not a behaviour defect. Be precise about it: the host-cost position(...).unwrap() at :689 cannot panic because u64::MAX terminates the array; it is inconsistent, not defective. Every existing series is already pinned by tests, so a migration is behaviour-preserving and testable.
Fix (choose one, and say which in the description). Either 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 that the migration is deliberately deferred and scope the new type so it does not present itself as the module's histogram abstraction. The description currently names only #537 as an overlapping PR and says nothing about the two existing sites.
2. flare_time_to_first_response_seconds is owned outside Metrics while its sibling flare_request_e2e_seconds is a Metrics field
helios/src/server/latency.rs:33-37:
pub(super) struct 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 went the other way — helios/src/server/metrics.rs:327:
pub(super) request_e2e: Histogram<21>,
rendered inside Metrics::render in the loop at :1389-1412 alongside the four runtime histograms, plus time_per_output_token (:1413-1418) and request_prompt_tokens (:1419-1424).
Two consequences worth citing:
request_e2eis the only histogram field with non-private visibility. The other five (metrics.rs:328-332) are private. It ispub(super)solely sohelios/src/server/http.rs:600-605can call.observe(&REQUEST_SECONDS, ...)on the field, whereas the runtime's five go throughMetrics::request_completed(metrics.rs:452-478). So the "record it where the counter is recorded" argument the description makes does not hold for the HTTP histogram, and http.rs reaches intoMetricsinternals to get it.- The scrape text is assembled at four stages with no stated rule:
Metrics::render(server.rs:660), then first-response gauges, median and histogram (server.rs:661-671), then input metrics (:672-674) and ingress/HTTP gauges (:675-708), thenmetrics::process::render(:709). Nothing states which struct owns which series; a reviewer readingMetricscannot learn thatflare_time_to_first_response_secondsexists.
The double bookkeeping itself (60 s median window and an all-time histogram for the same instant pair, latency.rs:116-127) is accepted and documented (docs/api.md:303-307); a median cannot be reconstructed from an all-time histogram, so keeping both is defensible. The finding is the ownership and render asymmetry between two histograms of the same kind added in one PR.
Fix. Move the TTFR histogram onto Metrics, observed from FirstResponseSamples::output via the existing state.model.metrics() handle. Both HTTP histograms would then render from the :1389 loop, which also retires render_histogram, the server.rs:671 call, and the pub(super) on request_e2e. Alternatively keep the current ownership and state in Metrics::render's doc comment that HTTP-owned histograms are appended by the route — but pick one, since this PR is now setting two precedents for the same question.
Nits
3. open_descriptors() moved sideways rather than down into eos/
helios/src/runtime_core/protection.rs:290-302 still holds the /proc/self/fd counter, now pub(crate) and re-exported at helios/src/runtime_core/mod.rs:58 so helios/src/server/metrics/process.rs:68 can reach it (let open_fds = crate::runtime_core::open_descriptors();). Its two neighbours in render_linux already go through eos/: process.rs:61 crate::os::page_size() and process.rs:70 crate::os::raise_open_file_limit(0), i.e. eos/src/unix.rs:73 and :138 via helios/src/os.rs:8 (pub(crate) use flare_eos::*).
AGENTS.md:20-21 designates eos/ as "the host operating-system operations that Helios and Selene use", so having a server-metrics module import a core-protection helper is the wrong direction, and it leaves one of the three OS reads outside the designated layer. protection.rs:298-301 already carries the #[cfg(not(target_os = "linux"))] { None } shape a move needs.
Fix: move the function to eos/src/unix.rs behind the same Linux gate and call it as crate::os::open_descriptors().
4. process::metric duplicates metrics::metric
helios/src/server/metrics/process.rs:47-54:
fn metric(text: &mut String, name: &str, kind: &str, help: &str, value: impl std::fmt::Display) {
let _ = writeln!(text, "# HELP {name} {help}\n# TYPE {name} {kind}\n{name} {value}");
}
versus helios/src/server/metrics.rs:1597-1602, which emits the identical three lines with flare_ prepended. The deltas are the prefix and impl Display vs u64 (needed — process values are f64 seconds and byte counts).
The copy also does not inherit escape_prometheus_label (metrics.rs:1604-1615). That is fine today because no process_* series carries a label, but the second emitter will silently not inherit it the day a labelled series is added (e.g. process_io_bytes_total{device=…}), while the shared one will.
Fix: give metrics::metric a Display value and a prefixed/unprefixed form, and delete process::metric.
5. Two adjacent identical guards
helios/src/server/metrics/process.rs:81-89 and :90-98 are consecutive if let Some(stat) = stat blocks emitting the two memory gauges. The separate guards at :72 (Some(stat), Some(ticks)) and :99 (Some(stat), Some(btime), Some(ticks)) are justified by extra dependencies; these two are not. Cosmetic. Fix: one block emitting both gauges.
Changes since the first review (fixed — recorded, not re-raised)
docs/api.md:287-290now reads "…flare_free_kv_pages, except the standardprocess_*series described below." The new prose separates the histogram families and states histograms appear only in the Prometheus text (:297-321), and the JSON snapshot is unchanged — consistent with the code, whereformat=jsonreturns beforeMetrics::render(server.rs:658).- The e2e observation is one site.
helios/src/server/http.rs:598-605observes under!count && !encoder.tool_limit_reachedimmediately beforeyield Delivery::Complete(response); the streaming arm is now a bareDelivery::Complete(_) => Noneand the non-streaming arm only builds the body.metrics_handle()is back to one caller (server.rs:511), so the mixedmetrics()/metrics_handle()accessor style inside one function is gone. - The local OS calls in
process.rsare gone (sysconf(_SC_PAGESIZE), the/proc/self/fdloop,getrlimit). Only/proc/self/statand thebtimeline of/proc/statare parsed locally, and no prior Rust implementation of those exists in the tree (eos/,helios/searched;selene-manager/src/local.rsparses/proc/<pid>/statfor a different field in a different crate), so that remainder is not duplication.
Verified non-findings (checked and dropped)
RequestTimesvsscheduler::RequestAccounting(metrics.rs:300-306vshelios/src/scheduler/policy.rs:53-65(not opened), which already holdsarrival_ns,last_progress_ns,last_output_ns,committed_output_tokens). Not duplication: the scheduler copy is reset byfinish, does not survivepark, andlast_output_nsmarks publication rather than the last committed token — while a preempted request must keep its stamps, which is exactly whyIncomingcarries them.CheckpointAccounting::initial_prefill_ns(scheduler/checkpoints.rs:24(not opened)) is a predicted cost, not a measurement. No existing mechanism to reuse.FirstResponseSamples'sMutex<Samples>→{ window, histogram }rename updates every use site (latency.rs:73,:111, tests:198,:213,:222); no stale.0access remains.- SPDX header —
process.rs:1uses the short/* SPDX-License-Identifier: Apache-2.0 */, which already exists athelios/src/server/latency.rs:1andhelios/src/server/dashboard/prefill.rs:1(not opened). Not a new departure. - Bucket constants shared per unit (
REQUEST_SECONDS/TOKEN_SECONDS/PROMPT_TOKENS,metrics.rs:219-241, reused by TTFR atlatency.rs:106) — this is the pattern the older sites fail to follow, i.e. evidence for finding 1, not a separate issue. metrics::process::render's collaborator shape matches precedent:Metrics::renderalready delegates toengram::Stats::render(metrics.rs:1105-1107) andrender_persistent_worker_metrics(:1108-1110, defined:1617). The#[cfg(not(target_os = "linux"))] let _ = text;atprocess.rs:12-13matchesflare/src/hub.rs:1749(not opened),helios/src/core/cache.rs:4399,heliopause/src/export/archive.rs:347(not opened).- Hoisted
prompt_tokens/generated_tokenslocals (runtime.rs:1837-1846,:1993-2001) follow the existingCarriedhoisting inpark(:2104,:2115-2116); thetimes: Default::default()struct-literal additions (runtime.rs:913,:3254,phase_tests.rs:251) follow the existing pattern and are covered by the field doc atruntime.rs:193. RequestTimes::default()in the metrics test (metrics.rs:1683) replaced an impossible{None, Some}state; not churn.
Open questions for the author
- Is migrating
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETSand the retirement histogram ontoHistogram/Bucketsintended follow-up or out of scope? The description names only #537 as an overlapping PR and does not mention either existing site. - 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.
What could not be verified here
The Windows build and the full helios suite (the description says CI covers both; the head has no CI checks yet), and the pre-existing messages_image_hints_end_after_expansion_… test, which needs FLARE_TEST_TEMPLATE_DIR. Nothing in this review depends on any of them: every finding is a code-shape question settled by reading the cited lines at a34c4d06.