Final review report · NVIDIA/hyperflare-inference #692

Raw Markdown for agents: https://autobot.eidonix.com/p/87479e88-166f-425f-9132-51a20ed046ab.md

Recommendation: Changes Requested

The core fix for #679 is technically sound: the shared RequestOutcome atomic state machine cleanly eliminates mid-stream cancellation misattribution, post-generation output-rejection misattribution, and event-budget double-counting with zero lock contention and strong unit, 2-thread concurrency, and HTTP-to-Worker integration tests. No correctness or concurrency blockers were found. However, before merge the PR should (1) update the Prometheus # HELP strings and API docs for requests_completed_total and requests_cancelled_total so they match the new deferred end-to-end semantics, (2) route the ResponseLifecycle conformance harness's terminal emission through the new emit_finished entry point instead of raw emit, and (3) get CI green on head 348c06c (and simplify the ~160 lines of duplicated CAS loops in RequestOutcome).

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Update metric # HELP strings and API docs for the shifted completed / cancelled contract (helios/src/server/metrics.rs:1076-1090, docs/api.md:330).
    • metrics.rs:1077-1079 still documents requests_completed_total as "Requests whose model generation completed successfully, including explicit token stops." and metrics.rs:1087-1089 documents requests_cancelled_total as "Queued or active model requests cancelled before completion." (docs/api.md:330 mirrors completed).
    • Under generate_for_output (defer_completion = true), HTTP and Decisions requests whose model generation completed successfully no longer increment completed until output decoding/validation succeeds, and requests whose reader drops after worker completion (no longer queued or active) now increment cancelled (explicitly tested at helios/src/server/runtime/phase_tests.rs:8983-9020).
    • Fix: Update the # HELP descriptions in helios/src/server/metrics.rs:1076-1090 and the table in docs/api.md:330 (and add a cancelled row if missing) to reflect validated output completion and unread/unvalidated disconnects for served HTTP/Decisions traffic (noting in-process ModelRuntime::generate* retains model-generation completion semantics).
  2. Exercise Incoming::emit_finished in the ResponseLifecycle conformance tests (helios/src/server/runtime/response_lifecycle_tests.rs:155, 372).
    • Production worker completion now goes through Incoming::emit_finished (helios/src/server/runtime.rs:2297, 2594), which uses try_reserve() and suppresses Finished after a prior failure. Both response_lifecycle_tests.rs:155 (action 3 in the TLA+ observed-edge harness) and response_lifecycle_tests.rs:372 (the HTTP terminal-frame retention test) still call raw emit(GenerationEvent::Finished { ... }), bypassing the new production entry point (docs/design-review.md:215-218).
    • Fix: Switch both call sites to .emit_finished(GenerationEvent::Finished { ... }). This preserves the exact ResponseLifecycle.tla projection without adding TLA+ state-space blowup while keeping the harness on the production terminal path.

Subtract / Simplify

  1. Collapse the five duplicated CAS loops in RequestOutcome into one transition helper (helios/src/server/runtime.rs:138-295).
    • record_generated, record_completed, record_cancelled, record_failed, and on_reader_drop repeat the same ~20-line load(Acquire) / compare_exchange_weak(AcqRel, Acquire) / fetch_add(Relaxed) loop across ~160 lines.
    • Replace with one monomorphized helper:
      fn transition(&self, next: impl Fn(u8) -> Option<(u8, Option<&AtomicU64>)>) {
          let mut current = self.state.load(Ordering::Acquire);
          while let Some((target, counter)) = next(current) {
              match self.state.compare_exchange_weak(
                  current,
                  target,
                  Ordering::AcqRel,
                  Ordering::Acquire,
              ) {
                  Ok(_) => {
                      if let Some(counter) = counter {
                          counter.fetch_add(1, Ordering::Relaxed);
                      }
                      return;
                  }
                  Err(actual) => current = actual,
              }
          }
      }
      
      Each of the five methods then becomes a 3–8 line transition table, cutting ~100 lines while keeping identical memory ordering and zero runtime overhead.
  2. Deduplicate the event-budget overflow arm (helios/src/server/runtime.rs:574-580 vs :626-634).
    • emit_finished and emit contain byte-identical TrySendError::Full handlers (same ExecutionError::Completion error string and cancelled.store(true, Ordering::Release)). Extract a single Incoming::event_budget_exceeded(&self) helper called by both.

Nits

Dropped on verification