Conventions report · NVIDIA/hyperflare-inference #560

Raw Markdown for agents: https://autobot.eidonix.com/p/cab45ae0-b9f0-4d77-946e-64c770a494b2.md

Review of PR #560 — conventions and duplication lens

PR #560 "Emit vLLM-compatible per-request metrics from runtime instants" (head ce44060, base main, 18 files, +1898/−123).

Key findings

No blocking issues. Two should-fix departures from established precedent, both cases where the PR introduces a second spelling of something the repository already has a named mechanism for:

  1. Should fix — helios/src/server/runtime.rs:1746-1757 re-spells the set of graph kinds that run the model instead of calling GraphKind::samples(), which the same file already uses.
  2. Should fix — helios/src/server/protocol/encode.rs:80 adds Timing.streaming beside the existing Encoder.streaming (:97); two booleans in one struct answer "is this a stream", with nothing enforcing agreement.

Two nits follow on partial migrations of existing mechanisms. The rest of the diff is conventional: I checked each new construct against its nearest precedent and it matched.

Rules applied: docs/design-review.md principles 1 (keep Helios simple), 3 (preserve canonical semantics and shared mechanisms), 10 (explicit configuration), 12 (honest evidence); AGENTS.md:347-348 ("Do not ... duplicate them"); the charter lines 12 (model-agnostic runtime) and 43 (no per-model flags).


Should fix

1. helios/src/server/runtime.rs:1746-1757 — inline GraphKind list duplicates GraphKind::samples()

if matches!(
    kind,
    GraphKind::Prefill
        | GraphKind::TerminalPrefill
        | GraphKind::ScoredPrefill
        | GraphKind::Resume
        | GraphKind::Decode
        | GraphKind::Speculative
        | GraphKind::Mixed
) {
    self.metrics.model_step(prefill + generated.len() as u64);
}

That is exactly the predicate GraphKind::samples() already defines — helios/src/execution/manifest.rs:90-101:

pub fn samples(self) -> bool {
    matches!(
        self,
        Self::Prefill | Self::TerminalPrefill | Self::ScoredPrefill
            | Self::Decode | Self::Speculative | Self::Mixed | Self::Resume
    )
}

Precedent for consuming it inside this very file: runtime.rs:2988 if !step.kind.samples() { return Ok(()); } in validate_sampling_admissions. It is also used at execution/transport.rs:1319 (not opened),1334, execution/manifest.rs:944 and model/testing.rs:170 (not opened).

Why it matters: samples() is the manifest's own definition of "this graph runs the model and produces token/logprob output" — the predicate the step's output path is already keyed on. A seventh spelling in the server layer is a second source of truth: adding a sampling graph kind updates samples() and every consumer except this one, and metrics.model_step then silently stops counting that kind's steps (a metrics-only drift, which no test pins and which review would not catch). Design-review principle 3 asks for shared mechanisms rather than copies; this is a one-line fix with zero behaviour change today.

Fix: if kind.samples() { self.metrics.model_step(prefill + generated.len() as u64); } and delete the seven-arm match. The same helper expresses the docs sentence added in this PR ("initialization, restore, vision, and snapshot graphs are not observed"), since !samples() is precisely that complement.

2. helios/src/server/protocol/encode.rs:80 — Timing.streaming duplicates Encoder.streaming

Encoder already carries streaming: bool (declared encode.rs:97, initialised false at :150, set only by set_logprobs at :190-193 from the streaming argument). The new per-request-metrics state adds a second copy inside Timing (encode.rs:80), set from the separate streaming argument of enable_request_metrics (:244-252):

_ => Some(RequestMetrics::Single(Timing { streaming, ..Timing::default() })),

and read by record_commit (:256-259) to decide whether to latch the commit instant at all.

Today they agree, because http.rs feeds both from decoded.stream (:349-353 encoder.set_logprobs(..., decoded.stream) and :363 encoder.enable_request_metrics(decoded.stream)). Nothing enforces it. set_logprobs is pub and is called directly from server/logprobs.rs:153 (not opened),557,575 (tests) without any call to enable_request_metrics, and enable_request_metrics is called directly by the new protocol tests (protocol/tests.rs:2380-2481) without set_logprobs. So the two flags are independently settable through public API, and a divergence makes record_commit drop instants the encoder would otherwise need (or retain them for a body that must not have them) — a silent null time_to_first_content_token_ms rather than an error.

Fix: drop Timing.streaming and read self.streaming in record_commit; enable_request_metrics then needs only protocol/include_usage/choice counts (and can keep returning whether the content instant applies). That also removes the ..Timing::default() struct-update that exists only to fill the duplicated field. Counts as a convention issue under principle 1 (keep Helios simple) as much as duplication: one struct, two answers to one question.


Nits

3. helios/src/server/metrics.rs:211-322 — the new Histogram/Buckets migration leaves the host-cache histograms behind

This PR introduces a general histogram mechanism — Buckets<const N> (metrics.rs:213-253) with REQUEST_SECONDS, TOKEN_SECONDS, TOKEN_COUNTS, PREEMPTION_COUNTS, CHOICE_COUNTS, and Histogram<const N> (:257-322) with observe/absorb/render — and converts exactly one of the two existing hand-rolled histogram families to it: latency.rs (FirstResponseSamples, observe at latency.rs:121, render_histogram at :101).

The other family keeps its own implementation verbatim: HOST_TIME_BUCKETS/HOST_TOKEN_BUCKETS (metrics.rs:199-209), the host_missing_tokens/host_transfer_ns/host_prefill_ns arrays, host_cost_sums: [AtomicU64; 3], Metrics::host_lookup_cost doing the same .position(|limit| value <= *limit).unwrap() scan, and the bespoke ~37-line render loop emitting _bucket/_count/_sum.

So two histogram implementations now coexist in one module, and the older one is the one with the unwrap() that Histogram::observe replaced with unwrap_or(N - 1). The earlier review of the stacked PR #548 raised exactly this conversion as a subtractive suggestion (~40 lines saved). Not blocking: the host histograms' exposed unit is nanoseconds/tokens against u64 bounds rather than the scale grid Buckets assumes, so the conversion needs scale: 1.0 (or u64/f64 bounds) for the time histograms — worth doing here only if the maintainer wants a single mechanism, otherwise the duplication is real and should be recorded as follow-up.

4. helios/src/server/config.rs:353-357 — the boolean parse duplicates history_drafts, and there is still no boolean() helper

per_request_metrics: match object.get("per_request_metrics") {
    None => false,
    Some(Value::Bool(value)) => *value,
    Some(_) => return Err("server configuration per_request_metrics must be a boolean".into()),
},

is the same three-arm match as history_drafts at config.rs:183-187, and observation.rs:78-84 (flag()) is the third instance. config.rs already has an integer helper (config.rs:56) and an optional_text helper (:303) precisely so that repeated key parsing lives in one place, but no boolean helper — and this PR adds the second boolean server key, so the third will copy again.

The error-string style does match the file ("server configuration must be …", the form used by optional_text and integer), so only the parse shape is duplicated. Suggested fix: add let boolean = |name: &str, default: bool| ... beside integer and use it for both history_drafts and per_request_metrics. Severity: nit.


Checked and conventional (no finding)

Open questions / not verified by execution