Conventions report · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/e8b4596f-52ac-4e96-89b6-d930fb1f61e9.md

Conventions and duplication review — PR #548 (head 6624592, 9 files, +1008/−51)

Re-verified at head 6624592; search_history shows no commits after it (top three: 6624592 / 055663a / 49373bc). No reviews, no CI checks. Every changed file was read in its surrounding code, and each finding below was re-checked line by line at this head (metrics.rs:195-330, :1170-1220, :1544-1560, :1640-1660; latency.rs:28-130; server.rs:655-680; http.rs:400-412, :520-540, :600-620; server/protocol/encode.rs:50-62, :685-700).

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

Should fix 1 — metrics.rs now holds THREE Prometheus-histogram implementations that disagree within one scrape

New in this PR: Buckets<const N> (metrics.rs:213-216) with shared unit constants REQUEST_SECONDS :218-224, TOKEN_SECONDS :226-232, TOKEN_COUNTS :234-240, PREEMPTION_COUNTS :244-247, CHOICE_COUNTS :250-253; and Histogram<const N> :257-260 (observe :272-283, absorb :286-295, render :297-321). Its render emits # HELP flare_{name} + # TYPE (:298-301), then buckets, then _sum (:315-319) before _count (:320).

Untouched host-cost histograms: HOST_TIME_BUCKETS / HOST_TOKEN_BUCKETS as [u64; 8] ending u64::MAX (:199-209); host_cost_sums (:475); observed at :819-841 with limits.iter().position(|limit| value <= *limit).unwrap() (:838); rendered :1178-1214 with # TYPE only — no # HELP (:1198) — and _count (:1209) before _sum (:1210-1213).

Untouched retirement buckets: field :468, filled :854-860, rendered :1000-1025 with no # HELP, +Inf bound scaled at render (*ms as f64 / 1000.0, :1008), _count (:1020) before _sum (:1021-1025).

Why it matters: the disagreement is scrape-visible — HELP presence, _sum/_count ordering and integer-vs-float bound encoding differ between series emitted by the same module, and the bucket-index loop is the same algorithm three times (:276-281, :836-840, :854-860). docs/design-review.md:74 requires the design to account for duplicate representations; AGENTS.md:188-193 rejects adding an abstraction without retiring what it supersedes.

Fix: rebuild the host-cost and retirement histograms on Histogram<8>/Buckets<8> — removes :199-209, host_cost_sums (:475), the loop :836-840, render :1178-1214, and for retirement :468, :854-860, :1000-1025. Behaviour-preserving: u64::MAX terminates the bound array so position(..).unwrap() cannot panic, and existing tests already pin every affected series (metrics.rs:2035, :2403-2405). If the consolidation is deferred, the PR description should name the deferred sites; it currently names none.

Should fix 2 — the two HTTP-observed histograms added by this PR have different owners and render paths

flare_request_e2e_seconds: private Metrics field request_e2e: Histogram<21> (metrics.rs:406), observed only through Metrics::response_completed (:608-618, observation at :609), called from http.rs:606-612, rendered by the generic histogram table loop (metrics.rs:1548-1552).

flare_time_to_first_response_seconds: lives outside the registry — FirstResponseSamples { window: Mutex<Samples>, histogram: super::metrics::Histogram<21> } (latency.rs:33-37), observed inside FirstResponse::output (latency.rs:121-124), rendered by its own forwarder render_histogram (latency.rs:101-108) which the /metrics route calls out of band at helios/src/server.rs:671.

Why it matters: a reader of Metrics cannot discover the TTFR series exists; it is the only histogram in the scrape that is neither a Metrics field nor emitted through metrics::metric (metrics.rs:1834-1839, used at server.rs:666, :673). The scrape body is assembled in four stages — metrics().render() (server.rs:660), first-response gauges/median (:661-670), TTFR histogram (:671), input + HTTP gauges (:672-708) — with no stated rule for which series belong where. Two series that share one observation layer and one unit (REQUEST_SECONDS at latency.rs:106 and metrics.rs:609) should not need two mechanisms (charter line 12; docs/design-review.md:74).

Fix: move the TTFR histogram onto Metrics, observe from FirstResponse::output through the existing metrics_handle(), delete render_histogram (latency.rs:101-108) and the server.rs:671 call — or state the ownership rule in Metrics::render. Only the asymmetry is the finding: keeping a rolling window and an all-time histogram side by side is defensible and documented in docs/api.md:302-389.

Nits

Nit 1 — per-choice generated-token counts stored and grouped twice. http.rs:407 declares let mut generated = vec![0u32; size];, filled at :530 from the same GenerationEvent::Finished payload, duplicating the encoder's Usage { generated: u32 } (server/protocol/encode.rs:56-58), which is set from that same event (:630-634) and incremented by observe_generated_token (:217-219, called at http.rs:498). The encoder already groups by prompt via choices_per_prompt (:94, .step_by(self.choices_per_prompt) at :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; they diverge the first time either path changes (zero-budget choices finished at http.rs:442 never set generated). Fix: expose the encoder's per-choice counts and observe from that single source.

Nit 2 — flare_admission_rejections_total bypasses the file's labelled-counter loop. metrics.rs:1643-1656 hand-rolls the literal array ["http_slots", "generation_capacity", "request_queue"] (:1647) zipped positionally against &self.admission_rejections (:1649), duplicating AdmissionLimit's variant order (:378-385) with nothing linking the two (admission_rejected indexes limit as usize, :685). The established pattern is metrics.rs:1143-1177 (for (name, labels, counters) → # TYPE flare_{name} counter → one line per label). Fix: give AdmissionLimit a name() / ALL and feed that loop.

Observation (not raised as a finding): the output budget sum is now spelled three times — Prompt::output_event_capacity (runtime.rs:62-67), the new record.max_tokens stamp (runtime.rs:1568-1569) and a test (phase_tests.rs:3987). Kept low because the two production sites serve different purposes (event-capacity sizing in u64 vs. the histogram's u32 limit); docs/api.md:346-349 defines flare_request_max_tokens from the second.

Resolved at this head (not findings)

Verified non-findings (checked and dropped)

Open questions / not verifiable from code

Link: https://github.com/NVIDIA/hyperflare-inference/pull/548