Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #692

Raw Markdown for agents: https://autobot.eidonix.com/p/866dc6e7-066a-45ed-a84c-4aca1eedbe2e.md

#1 [high] Finding: requests_completed_total scope silently changes (docs/HELP mismatch)

VERIFIED in head pr/692.

  1. helios/src/server/metrics.rs:1077-1080 (unchanged by the PR) still promises model-generation semantics:
"requests_completed_total",
"Requests whose model generation completed successfully, including explicit token stops.",
&self.completed,

and docs/api.md:330 says | completed | Requests whose generation completed successfully | flare_requests_completed_total |. docs/api.md:332 is the failed line the PR cites.

  1. Under the new deferred machine, the same counter means two different things depending on the entry point:

So flare_requests_completed_total becomes "model generation finished and the HTTP consumer validated output" for HTTP/decisions traffic and "model generation finished" for in-process SDK callers, with neither HELP string nor docs/api.md:330 updated. Impact: operator dashboards/alerts built on completed/cancelled/failed ratios (and the #541 Grafana example) silently change definition; the PR's premise is that the metric HELP already described the fixed behaviour, which is true only of failed, not of completed/cancelled. Fix: update metrics.rs:1077-1089 HELP text and docs/api.md:328-332 to the end-to-end definition, or state that the deferral applies only where the reader is an HTTP/decisions output layer.

#2 [high] Finding: new outcome state machine unmodelled; conformance harness only covers defer_completion=false

VERIFIED in head pr/692.

docs/design-review.md:234-240: "Modifying the Helios scheduler, admission, speculation, cancellation, cache ownership, completion validation, readiness, or rank coordination without running—and updating when behavior, transitions, or supported bounds change—the applicable TLA+ models, Rust conformance fixtures, Kani harnesses, and scheduling simulator is a blocking design failure". And :241-246: "When a change adds protocol states ... update the model, conformance fixture, or Kani harness to cover the added domain rather than leaving it unverified."

The PR adds six protocol states OUTCOME_PENDING/GENERATED/READER_DROPPED/COMPLETED/CANCELLED/FAILED (helios/src/server/runtime.rs:109-114) and changes cancellation/completion transitions, but:

Impact: the deferred (HTTP/decisions) half of the new machine — the half the PR exists for — is outside the formal/conformance gate, which the doc calls "a blocking design failure, regardless of whether CPU unit tests pass". Fix: extend ResponseLifecycle.tla + the conformance harness to model the deferred terminal transitions (ideal: have the harness call emit_finished and a &mut Generation consumer op), and add mutation guards so the absorbing-state ordering is actually tested.

#3 [high] Research summary

Reviewed PR #692 against head pr/692 (base main; note pr_diff failed for every path — "Could not read c513e46" — so all verification was done by reading head files and main files side by side, not the diff itself).

The mechanism is sound in the areas I could verify: RequestOutcome's six states are genuinely absorbing (each of record_generated/record_completed/record_cancelled/record_failed/on_reader_drop CASes out of a restricted source set into a terminal state, and only the successful CAS increments a counter: helios/src/server/runtime.rs:138-296); fail_output() records FAILED before setting cancelled (runtime.rs:352-357), so the worker cannot re-classify it; emit_finished's reserve→record→send ordering (runtime.rs:553-582) closes the "completed despite overflow" hole; and all four worker cancellation sites now go through record_cancelled() (runtime.rs:1650, 1670, 1683, 1738). No unlocked head-of-line bottleneck, unbounded buffering, or extra copy is introduced — the new state is one Arc<AtomicU8> per request on a path that already allocates a channel, two oneshots and a semaphore permit (runtime.rs:1198-1245). The concurrency test (runtime.rs:4573-4649, 3×3 worker/consumer ops × both defer modes × 128 barrier-synchronised iterations asserting exactly one increment) and the terminal-overflow test (:4470-4571) are real and do cover the interleavings that matter. I found no double-count or decrement path.

Two high-severity issues, both saved to the scratchpad with citations, verbatim quotes, impact and fix: (1) flare_requests_completed_total / _cancelled_total silently change scope for HTTP and Decisions traffic (deferred completion means an un-validated reader drop now counts cancelled where the model generation completed) while metrics.rs:1077-1089 and docs/api.md:328-332 still document model-generation semantics — and the same counter now means two different things for generate_for_output vs generate/generate_many; (2) the PR adds six new protocol states and changes cancellation/completion transitions but extends no TLA+ model or conformance fixture for the deferred half, which docs/design-review.md:234-246 calls a blocking design failure — the existing response_lifecycle_tests.rs harness drives generate_many (defer=false) and emits the terminal event through Incoming::emit rather than the new emit_finished, so it structurally cannot observe the transition the PR adds.

Two further leads I could not fully confirm before the turn limit, recorded here for the next reader: (a) two pre-existing in-repo Python counter assertions now have ambiguous expected outcomes — tests/server/test_protocols.py:676 asserts flare_requests_cancelled_total rises on an n=4 streaming disconnect (that path may now land in GENERATED→completed if Finished was already consumed before the drop) and tests/server/test_decisions.py:257-261 requires cancelled to rise for a decision child whose reader is aborted mid-score() (that still lands in PENDING→cancelled, so it likely holds); the PR does not report running either suite. (b) emit_finished's Closed arm calls record_generated() unconditionally (runtime.rs:570-573), which for defer_completion = false increments completed even though no consumer ever received Finished — deliberately matching pre-PR behaviour for direct callers, but worth a maintainer's eye since it is the one place the "completion means someone saw it" invariant is not held.

#4 [high] Verified-sound areas and tool caveat (pr_diff unavailable)

VERIFIED in head pr/692. Record so the report does not over-claim defects in areas that are sound.

Environment caveat for the record: pr_diff failed on every path with git: error: Could not read c513e46a79f3b6ac510235aaf09bcf055b841958, so this review compared head files (ref: pr/692) against main files (ref: main) directly rather than reading the diff. Line numbers cited from head are from read_file output, not reconstructed.

#5 [medium] Leads: Python counter assertions unrun; emit_finished Closed arm records completed

Leads partially verified before turn limit; state them as leads, not confirmed defects.

(a) Two pre-existing in-repo Python counter assertions have ambiguous expected outcomes under deferred completion, and the PR does not report running either suite (its evidence lists only cargo tests and check.py):

(b) emit_finished's Closed arm calls record_generated() unconditionally (helios/src/server/runtime.rs:570-573):

Err(async_mpsc::error::TrySendError::Closed(())) => {
    self.cancelled.store(true, Ordering::Release);
    self.outcome.record_generated();
}

For defer_completion = false this transitions PENDING→COMPLETED and increments completed even though no consumer ever received Finished (the receiver is gone). That preserves pre-PR behaviour for direct generate/generate_many/test callers, so it is not a regression, but it is the one place the PR's "completion means the consumer settled it" invariant is deliberately not held, and it is not called out in the description. Fix: comment it as an intentional direct-caller compatibility path, or route it through READER_DROPPED so the state machine stays uniform.