Conventions and duplication review — PR #548 (head 6624592, 9 files, +1008/−51)
Reviewed at head 6624592 with the merge base f377dc8. Every changed file was read in context
(docs/api.md, helios/src/server.rs, server/http.rs, server/latency.rs,
server/metrics.rs, server/runtime.rs, server/runtime/phase_tests.rs,
server/scheduler.rs (not opened), server/protocol/encode.rs) and each candidate finding was re-checked
line by line at this head. No reviews and no CI checks exist on this commit. Rules applied:
AGENTS.md:188-193 ("Reject unsupported abstractions and churn … Refactoring must directly support
the requested behavior"), docs/design-review.md:74 ("Account for duplicate representations and
retained temporary owners"), charter line 12 ("Keep the runtime small and model-agnostic").
Key findings
- No blocking findings. The PR's new constructs mostly follow existing precedent: new rows in
the counter table (
cache_lookup_tokens_total, metrics.rs:1406-1410), new fields besidecache_lookups/cache_hits(scheduler.rs:117), and every new observation method placed inside the existingMetricsimpl (progress:527,replay_completed:666). - Two should-fix duplications. (1)
metrics.rsnow contains three Prometheus-histogram implementations that disagree with each other inside a single scrape. (2) The two HTTP-observed histograms added by this same PR are owned by different structs and rendered by different paths. - Three nits, all duplications of state or tables that already exist next to the new code:
per-choice generated-token counts (Encoder vs.
http.rs), hand-rolled admission-rejection labels bypassing the file's labelled-counter loop, and themax_new_tokens + reasoning_cut.aftersum spelled twice inruntime.rs. - One nit from my earlier pass is resolved by commit
6624592and is not reported below (see "Resolved since the previous head").
Should fix 1 — metrics.rs carries three Prometheus-histogram implementations that disagree
File: helios/src/server/metrics.rs:211-322 (new code), against :199-209 / :475 / :819-841 /
:1178-1214 and :468 / :854-860 / :1000-1025 (pre-existing code the PR leaves untouched).
What is wrong. The PR introduces one histogram abstraction and leaves two older, hand-rolled ones in place, so the module now answers "how do I write a histogram" three different ways:
- New:
Buckets<const N>(metrics.rs:213-216) with shared per-unit constantsREQUEST_SECONDS:218-224,TOKEN_SECONDS:226-232,TOKEN_COUNTS:234-240,PREEMPTION_COUNTS:244-247,CHOICE_COUNTS:250-253;Histogram<const N>:257-260 withobserve:272-283,absorb:286-295 andrender:297-321.renderemits# HELP flare_{name} …\n# TYPE flare_{name} histogram(:298-301), then the buckets, then_sum(:315-319) before_count(:320). - Host cost:
HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS[u64; 8]terminating inu64::MAX(metrics.rs:199-209), summed inhost_cost_sums: [AtomicU64; 3](:475), observed inhost_lookup_cost:819-841 withlimits.iter().position(|limit| value <= *limit).unwrap()(:838), rendered at :1178-1214 with# TYPEonly — no# HELP(:1198) — and_count(:1209) before_sum(:1210-1213). - Retirement:
host_retirement_buckets: [AtomicU64; 8](:468), filled inline instore:854-860, rendered at :1000-1025 fromflare_selene::RETIREMENT_LATENCY_MSscaled at render time (*ms as f64 / 1000.0, :1008), also with no# HELP.
Why it matters. The disagreement is visible to a scrape: some of the new series carry # HELP
and some do not, _sum and _count come in opposite orders, and bucket bounds are integers in one
place (u64::MAX → +Inf) and floats in another. The bucket-index loops are literally the same
algorithm written three times (:276-281, :836-840, :854-860). This is exactly the "duplicate
representations" that docs/design-review.md:74 requires the design to account for, and the
unsupported-abstraction/churn rule at AGENTS.md:188-193 — a generic Histogram<N> added without
retiring the two implementations it supersedes leaves three ways to do one thing.
Fix. Rebuild the host-cost and retirement histograms on Histogram<8>/Buckets<8>. That
deletes metrics.rs:199-209, the host_cost_sums field (:475), the bucket loop at :836-840, the
whole host-cost render block :1178-1214, and, for retirement, the field :468, the fill at :854-860
and the render at :1000-1025. This is behaviour-preserving: u64::MAX terminates the bounds array,
so position(...).unwrap() cannot panic, and the existing tests pin every series. If the migration
is deliberately deferred, the PR description should name the deferred sites — today it names none,
and the description's cost section mentions only the added work.
Should fix 2 — the two HTTP-observed histograms have different owners and render paths
File: helios/src/server/latency.rs:36 and helios/src/server/metrics.rs:406, rendered at
helios/src/server.rs:660-708.
What is wrong. The PR adds two histograms observed from the HTTP layer, and gives each a different home:
flare_request_e2e_secondsis a privateMetricsfield (request_e2e: Histogram<21>, metrics.rs:406), observed only throughMetrics::response_completed(metrics.rs:605-618, observation at :609, callerhttp.rs:606-612), and rendered by the generic table loop inMetrics::render(metrics.rs:1548-1552).flare_time_to_first_response_secondslives outside the registry:FirstResponseSamples { window, histogram: super::metrics::Histogram<21> }(latency.rs:33-37), observed insideFirstResponse::output(latency.rs:121-124), and rendered by its own forwarderrender_histogram(latency.rs:101-108) which the/metricsroute calls out of band athelios/src/server.rs:671.
Why it matters. A reader of Metrics cannot discover that the TTFR series exists — it is the
only metric in the scrape that is neither a Metrics field nor produced by metrics::metric
(metrics.rs:1834-1839, used at server.rs:666/:673). The scrape body is consequently assembled in
four stages: state.model.metrics().render() (server.rs:660), the first-response gauges and
median (:661-670), the TTFR histogram (:671), then the input and HTTP gauges (:672-708), with no
stated rule for which series go where. Two series that share one observation layer and one
observation unit (REQUEST_SECONDS, latency.rs:106 and metrics.rs:609) should not need two
mechanisms. Charter line 12 (keep the runtime small) and docs/design-review.md:74 both point the
other way.
Fix. Move the TTFR histogram onto Metrics, observe it from FirstResponse::output through
the existing metrics_handle() (runtime.rs:813), and delete both render_histogram
(latency.rs:101-108) and the server.rs:671 call — or, if the rolling window and its all-time
histogram are deliberately kept together (a defensible pairing, documented at docs/api.md:302-389),
state that ownership rule in Metrics::render. Only the asymmetry is the finding, not the pairing.
Nits
Nit 1 — per-choice generated-token counts are stored and grouped twice.
helios/src/server/http.rs:407 (let mut generated = vec![0u32; size];, filled at :530 from the
same Finished event) duplicates what Encoder already holds: Usage { generated: u32 }
(protocol/encode.rs:55-58, set at :630-634, incremented by observe_generated_token at :216-219),
and the encoder already groups by prompt via choices_per_prompt (:94) with
.step_by(self.choices_per_prompt) (:693). Metrics::response_completed then re-groups the
caller's vector with generated.chunks(choices) (metrics.rs:610). Two stores and two groupings of
one number will diverge the first time either path changes — for example the zero-budget choices
finished in http.rs never pass through the encoder's counter. Fix: expose the encoder's
per-choice counts (or its choices_per_prompt) and observe from that single source.
Nit 2 — flare_admission_rejections_total bypasses the file's labelled-counter loop.
helios/src/server/metrics.rs:1643-1656 is hand-rolled: a literal
["http_slots", "generation_capacity", "request_queue"] (:1647) zipped positionally against
&self.admission_rejections (:1649), duplicating AdmissionLimit's variant order
(metrics.rs:375-385) with nothing linking the two — admission_rejected indexes it with
limit as usize (:685). The file already has the table-driven pattern for labelled counters at
metrics.rs:1143-1177 (for (name, labels, counters) … "# TYPE flare_{name} counter" then one line
per label). Fix: give AdmissionLimit a name()/ALL and feed the existing loop, so adding a
fourth limit cannot silently mislabel a series.
Nit 3 — the request output budget is spelled twice in runtime.rs.
helios/src/server/runtime.rs:1568-1569 (incoming.prompt.max_new_tokens + incoming.prompt.reasoning_cut.as_ref().map_or(0, |cut| cut.after)) repeats
Prompt::output_event_capacity's sum at runtime.rs:66-67, including the reasoning-cut term that
the comment there documents as "part of after" — the policy that a cut's forced token is inside
the budget is now encoded in two places. Fix: add a Prompt::output_budget() helper and call it
from both. Low severity because the two sites serve different purposes (event-capacity estimate
versus the recorded record.max_tokens value).
Resolved since the previous head (not reported as findings)
- Commit
6624592replaced the hand-written kind gate with the existing predicate:runtime.rs:1721-1723now readsif kind.samples() { self.metrics.model_step(...) }, matchingGraphKind::samples()(helios/src/execution/manifest.rs:90-101) and the pre-existing use at runtime.rs:2948. My earlier nit about re-spelling that set is dropped. - The same commit added
Worker::publish_gauges(runtime.rs:1202-1211), collapsing the scheduler-stats +pendingstore pair that had been inline in the run loop (called at :1157) — a dedup in the right direction, not a new convention. - Earlier heads also fixed, on re-check at
6624592: thedocs/api.md"names start withflare_" sentence (now :287-290 carves out theprocess_*series), the duplicated inline e2e observation inhttp.rs(single site now), and the whole duplicate OS-helper/emitter module (server/metrics/process.rs(not opened) no longer exists).
Verified non-findings (checked, then dropped)
RequestRecord/RequestTimes(metrics.rs:324-346) is not a duplicate ofscheduler::RequestAccounting: the scheduler copy carries no first-token instant,last_output_nsmarks publication rather than the last committed token, and it has no per-request inter-token histogram.Histogram::absorb(metrics.rs:286-295) has one caller (metrics.rs:576) and is the mechanism that keeps per-request histograms out of the shared registry — design-driven, not duplication.cache_lookup_tokens_total(metrics.rs:1406-1410) is a new row in the existing counter table besidecache_lookups/cache_hits, following the established pattern; the scheduler field at scheduler.rs:117 sits one line from the pair it belongs with. This is the correct convention.FirstResponseSamplesbecoming a named-field struct (latency.rs:33-37) updates every use site (latency.rs:73, :111, :119-124, tests :195, :210, :219) and replaced a tuple struct on main, so it is not gratuitous churn.- SPDX headers, test naming and the
phase_tests.rsadditions follow existing style. - The new histogram render tables (metrics.rs:1548-1581, :1582-1595, :1596-1624) follow the file's existing loop style; only the admission-rejection block (Nit 2) departs from it.
- docs/api.md matches the code it documents: histogram prose :302-389,
pendingredefined at :409 against HELP at metrics.rs:1709-1712,parked_requestsHELP :1714-1717 against its docs paragraph, and the vLLM correspondence table :475-522 names each mapped series correctly.
Open questions / could not be verified
- The
cargo testfailure the description reports (FLARE_TEST_TEMPLATE_DIR) and the untested Windows/multi-GPU paths are environmental; no finding above depends on them — all three rest on code shape settled by reading the cited lines at6624592. - Whether the histogram consolidation in Should fix 1 is acceptable to land in this PR or as a follow-up is a maintainer call; the finding stands either way, because the PR adds the third implementation and does not name the two it leaves behind.
- Whether
flare_time_to_first_response_secondsis intentionally window-scoped in a way that justifies its current home (Should fix 2) can only be settled by the author stating the ownership rule; the docs at api.md:302-389 describe the window but not the render path.