Final review report · NVIDIA/hyperflare-inference #691

Raw Markdown for agents: https://autobot.eidonix.com/p/b045dc4d-660c-4e0a-aa17-8a4b8ffdfed1.md

Recommendation: Ready To Merge

PR #691 cleanly fixes #448 by carrying each request's finalized admission prefix-reuse count (u64) through the existing first_token oneshot channel and populating Encoder::usage[index].cached before Encoder::finish. The implementation is small (~110 production lines), preserves Prompt::output_event_capacity and ResponseLifecycle without adding a GenerationEvent variant, handles pre-token requeues, post-token preemption/readmission, reasoning-budget cuts, speculative grammar rollbacks, and multi-choice/multi-prompt Completions accurately, and adds solid Encoder and real Worker + RequestScheduler + HTTP streaming tests. Wait for CI to run on ef45ca9 before merging and coordinate merge order with open PRs touching the same regions (#692, #548, #560); no code blockers remain.

Merge Risk

Level: Low

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

None.

Subtract / Simplify

  1. Optional: drop pending_cached and Generation::has_pending_first_token for a direct step_by scan (helios/src/server/http.rs:406-413, 421, 510-523, helios/src/server/runtime.rs:166-168). For typical prompt counts, looping for i in (0..size).step_by(decoded.request.choices) inside if continuous_usage and calling generation.take_reused_prompt_tokens() (an immediate None check once consumed) mirrors Encoder::usage_value's exact index set (encode.rs:763-768) and removes the pending_cached Vec, the Chat clear(), the retain closure, and Generation::has_pending_first_token. Keep pending_cached only if very large multi-prompt Completions batches are expected to dominate per-token CPU time.
  2. Optional: centralize the repeated carried.reused_prompt_tokens.unwrap_or(...) helper (helios/src/server/runtime.rs:1475, 2012-2014, 2099-2102, 2297, 2402-2405, 2554). With this PR, six sites in runtime.rs resolve the locked-vs-live reused prompt token count inline. A small Carried::reused_prompt_tokens(&self, live: u64) -> u64 helper (used where live is already loaded) keeps that invariant in one place.
  3. Optional: deduplicate test setup boilerplate in helios/src/server/runtime/phase_tests.rs. The two new worker tests repeat the same 9-line ImageFeatureIndex | ImageFeatureSlot graph-input strip four times (:8476-8484, :8488-8496, :8879-8887, :8891-8899) alongside three small SSE data: parsers (:8453, :8791, :9062). Extracting a Fixture::text_only() helper and reusing one SSE parser would trim ~50 lines of test boilerplate.

Nits

  1. Generation::wait_for_first_token None => Ok(0) default (helios/src/server/runtime.rs:159-164): Unreachable today because Chat streaming (http.rs:418) is the sole caller and invokes it once before the event loop, but returning Err(self.failure()) (or debug_assert! + Err) on None would prevent silently fabricating 0 cached tokens if a future caller ever invoked it twice or after take_reused_prompt_tokens.
  2. Chat gating symmetry (helios/src/server/http.rs:420): encoder.report_cached_tokens(0, reused_prompt_tokens) runs unconditionally for streaming Chat rather than under if continuous_usage (unlike Completions at :509). This is completely benign because reused_prompt_tokens is the true finalized count and usage_value() is not emitted mid-stream when continuous_usage is false (encode.rs:313-315, http.rs:537-539), though gating it on continuous_usage makes the two paths symmetric.

Dropped on verification