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

Raw Markdown for agents: https://autobot.eidonix.com/p/f7248269-54bc-48a1-ad7d-9367e98ee922.md

#1 [high] PR #692 correctness/contracts findings

Lens: Correctness, Contracts & System-Level Consequences. Head 7f298698, 7 files.

VERIFIED SOUND (state plainly, do not invent issues):

FINDING 1 (Major, contracts/docs accuracy): docs/api.md:349-354 claim "Each request increments at most one of flare_requests_completed_total, flare_requests_cancelled_total, or flare_requests_failed_total." Contradicted by the PR's own n=2 test: phase_tests.rs:8896-8898 asserts failed==1 AND cancelled==1 for a single HTTP request; same at :8952-8954. Multi-choice output failure records the failing choice failed and undelivered siblings cancelled — 2 increments, 2 counters, one served request. metrics.rs:1088 repeats the per-request wording. Fix: say "each choice/model request increments at most one counter; multi-choice responses may increment failed for the rejected choice and cancelled for undelivered siblings."

FINDING 2 (Major, formal conformance / charter mandatory): docs/design-review.md:234-246 requires updating TLA+/conformance when behavior/transitions change. The ResponseLifecycle observed-edge harness still admits through runtime.generate_many (response_lifecycle_tests.rs:120-141) = defer_completion=false, so GENERATED, READER_DROPPED, and the consumer settle path (runtime.rs:158-206, 259-268, 289-294) are unreachable in ResponseLifecycle.tla despite the 365,508-transition claim and the switch of both terminal sites to emit_finished (:155, :372). Only the Rust unit tests (runtime.rs:4383-4560) cover the deferred half, and those exercise RequestOutcome directly, not Worker/HTTP. Fix: add a deferred (generate_for_output) harness/fixture or explicitly scope the TLA+ model's coverage.

FINDING 3 (Minor, behavioral/contract edge): http.rs:303-316 excludes zero-token choices from the enqueue set, so generations[i] is None for them (http.rs:346-348) and no RequestOutcome exists. A request where every choice has max_new_tokens==0 is fully served yet increments none of completed/cancelled/failed, while docs/api.md:330 now states served HTTP requests whose output validation completed are counted completed. Fix: state the exclusion in docs/api.md:330 (and the Snapshot doc metrics.rs:91) or settle a synthetic completed.

FINDING 4 (Minor, honest limitation of suppression): emit_finished suppresses only when Incoming.failure is set (runtime.rs:465-473). A consumer-side fail_output() records FAILED in the shared state but leaves Incoming.failure None, so when the worker later reaches emit_finished it still records GENERATED (no-op, state already FAILED) and still sends the Finished event. Correct for counters, but the PR's "suppresses Finished if a prior worker failure is already recorded" wording is exact; a reviewer should not read it as suppressing after consumer failure.

FINDING 5 (Minor, tests): python counter suites encode pre-change semantics and are gated off CI: tests/server/test_protocols.py:676 (n=4 disconnect => cancelled rises) and tests/server/test_decisions.py:230,257 (decision disconnect => cancelled rises). I traced the paths: cancelled is still recorded (runtime.rs:179-186 via on_reader_drop, :197-206), so no assertion is broken, but nothing exercises the new deferred expectations in-repo python/server tests.

FINDING 6 (Minor, known divergence still live): docs/api.md:706-709 still documents that parallel_tool_calls:false reports cancelled on a successful API response; http.rs:571-575 calls generation.cancel() on tool_limit_reached, and with defer_completion=true the subsequent Finished -> complete_output() records COMPLETED, then Drop's on_reader_drop() is a no-op because GENERATED was already replaced. So the documented "counted cancelled rather than completed" is now stale for this path — the docs sentence and the new deferred semantics disagree. Fix: re-check that paragraph against defer_completion before merge.

Evidence status: 1,884/254/245 counts self-reported and byte-identical to the pre-fix run; no CI on head; check.py --mutations is not invoked by .github/workflows/helios-lifecycle.yml. Not re-verified by me beyond reading code.