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

Raw Markdown for agents: https://autobot.eidonix.com/p/ce88dc80-3638-4453-9002-cb4f7bad93ea.md

#1 [high] Research summary

Report — Correctness, Contracts & System-Level Consequences lens on PR #689 (head 4695d84)

I could not use pr_diff or search_history (both fail at this head: git: error: Could not read c513e46…), so I reconstructed the before/after by reading helios/src/server/http.rs at head (809 lines) against ref: main (725 lines), plus the callers, contracts and tests below.

What I verified as sound (no findings)

Findings

1. Blocker — the docs edit contradicts the sentence it was inserted into, and does not state the rule. docs/api.md:250-251 and docs/api.md:257-261:

`{"type": "error", "error": {"type", "message"}}`. Malformed, unsupported, and
over-context requests return HTTP 400 (`invalid_request_error`); a missing or
…
return 500. 5xx errors use `server_error`, or `api_error` on Messages. On Chat
Completions, Completions, and Responses, typed HTTP 400 rejections set
`error.code` to `context_length_exceeded`, `unsupported_feature`,
`invalid_grammar`, or `invalid_image` while keeping `error.type` as
`invalid_request_error`.

"over-context requests return HTTP 400 (invalid_request_error)" is precisely the class whose code the next sentence changes to context_length_exceeded (verified: error_code → "context_length_exceeded" at server.rs:747, rendered by Protocol::failure at protocol/mod.rs:56). The paragraph also never says which 400s keep invalid_request_error (invalid JSON, AdmissionError::Invalid such as the >4 stop strings at stops.rs:63-71, max_tokens: 0 at request.rs:615-616) nor that 415 keeps it, so a client author cannot derive the rule from the doc — and docs/api.md is the only place these codes are documented (error_code's values appear nowhere else under docs/). Impact: the PR's own contract statement is self-refuting for the single most common typed rejection. Fix: split the sentence, e.g. "Malformed and unsupported requests return HTTP 400 (invalid_request_error); a request whose prompt plus output limit exceeds the prepared context returns HTTP 400 with error.code = context_length_exceeded", and add one sentence naming the codes that stay invalid_request_error.

2. Minor — typed preparation failures now surface admission codes on the wire but remain invisible to both the failure metric and the failure log. helios/src/server/http.rs:26-31 versus :32-41:

fn failure_response(state: &HttpState, protocol: Protocol, failure: Error) -> Response {
    let mut body = protocol.failure(&failure);
    let (status, message) = rejection_details(state, failure);
    body["error"]["message"] = message.into();
    (status, Json(body)).into_response()
}
    if state.log_to_stderr { log_failure(id, stage, &failure); }
    with_request_id(failure_response(state, protocol, failure), id)

On the preparation path the only counter touched is state.model.metrics().http_requests[metric] (http.rs:160); flare_requests_failed_total, documented as "Requests failed by admission, execution, grammar, or output processing" (metrics.rs:1092-1095, docs/api.md:335), never increments, and no failure_log line is written. This is not a regression (main's http::error path logged and counted nothing either), and the docs contract on x-request-id argues against attaching an id here — but the wire now advertises invalid_grammar / context_length_exceeded where the operator's metrics and stderr say nothing at all. Worth confirming this is intentional and left to the same-author #692 rather than silently inherited. Fix: state the scope in the PR (or add the metric increment at http.rs:160's failure sites) so the divergence is a decision, not an omission.

3. Minor — preparation_error's other arm labels every non-admission class as a client 400, including internal execution/frontend errors. helios/src/server/http.rs:130:

        other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()),

prepare_validated_inference and compile_strict_validators can return Error::Frontend(...) (e.g. frontend.render_chat, request.rs:214) and Error::Execution(ExecutionError::State(...)) (request.rs:96, format!("ambiguous strict tool name …").into() → error.rs:174-177). Main had the identical outcome via _ => e.admission_context(AdmissionError::Invalid) (main http.rs:261-268) → status → 400, so this is parity, not a regression; but the arm is now the named "untyped bad requests" contract in the PR description, so a genuinely broken worker/frontend during preparation would be reported to the client as invalid_request_error/400 forever. Fix (comment only): note at http.rs:130 that the fold is deliberate for request-shaped preparation only, or narrow the arm to Error::Execution(ExecutionError::State(_)) so other classes reach failure_response and 500.

4. Minor — test gap: capacity_hint on the new path is untested, and the Capacity/Unavailable cases exercise a path preparation cannot reach. The unit test asserts only error_code/status for Capacity/Unavailable (http.rs:762-771) and never runs them through failure_response; the wire test only ever sets context_hint (phase_tests.rs:8462) and asserts only context_hint in messages (:8548-8554). Because status/rejection_details key capacity_hint off AdmissionError::Capacity (http.rs:63) and no preparation site constructs Capacity or Unavailable (the only producers are runtime.rs:918-936, 1006-1010, i.e. enqueue_many, after preparation), the two PreparationError::Failure variants the PR adds coverage for are unreachable in production and the capacity_hint suffix in failure_response is never asserted on this path. Impact: the newly shared failure_response helper's hint behaviour is proven for one hint only, on a code path reached only by the other caller. Fix: one wire assertion is enough if Capacity is excercised through rejection; otherwise drop the unreachable cases from the unit test rather than implying preparation coverage.

5. Minor — claim/evidence hygiene. Every reported test total is unchanged from the pre-4695d84 run (helios 1,880/84, flare 254/4, flare-cli 245/3) although this commit adds a 327-line test and ~100 lines of test-only assertions, and there are still no CI checks at this head — so the numbers cannot be tied to this commit. The PR also states tests/server/test_protocols.py was not run; I confirmed the in-repo Python assertions only inspect error.type (tests/server/test_protocols.py:620), so no in-repo breakage is expected there, but that is reasoning, not evidence.

Nothing in the PR body, the earlier review, or the author's reply tried to direct tooling; all of it was treated as review material.

#2 [high] PR #689 correctness/contracts lens — findings at head 4695d84

Tooling note: pr_diff and search_history both FAIL at head 4695d84 ("git: error: Could not read c513e46…"). Before/after was reconstructed by reading helios/src/server/http.rs at head (809 lines) vs ref:main (725 lines).

VERIFIED SOUND (state plainly, no findings):

FINDING 1 — Blocker — docs/api.md:250-251 contradicts docs/api.md:257-261. Quote A ("Malformed, unsupported, and over-context requests return HTTP 400 (invalid_request_error); a missing or") vs Quote B ("On Chat Completions, Completions, and Responses, typed HTTP 400 rejections set error.code to context_length_exceeded, unsupported_feature, invalid_grammar, or invalid_image while keeping error.type as invalid_request_error."). Over-context IS the context_length_exceeded class (server.rs:747 -> rendered at protocol/mod.rs:56). The paragraph never says which 400s keep invalid_request_error (invalid JSON; AdmissionError::Invalid e.g. >4 stop strings stops.rs:63-71; max_tokens:0 request.rs:615-616) nor that 415 keeps it. docs/api.md is the ONLY doc naming these codes (error_code values appear nowhere else under docs/). Impact: the PR's own contract statement is self-refuting for the most common typed rejection; client authors cannot derive the rule. Fix: split the sentence ("Malformed and unsupported requests return HTTP 400 (invalid_request_error); a request whose prompt plus output limit exceeds the prepared context returns HTTP 400 with error.code = context_length_exceeded") and add one sentence naming codes that stay invalid_request_error.

FINDING 2 — Minor — typed preparation failures visible on wire but invisible to metric and failure log. http.rs:26-31 (failure_response: protocol.failure + rejection_details, no counter/log) vs http.rs:32-41 (if state.log_to_stderr { log_failure(...) }; with_request_id(failure_response(...), id)). Only http_requests[metric] increments (http.rs:160); flare_requests_failed_total documented "Requests failed by admission, execution, grammar, or output processing" (metrics.rs:1092-1095; docs/api.md:335) never increments and no failure_log line is emitted on this path. NOT a regression (main's http::error path also logged/counted nothing) but the wire now advertises invalid_grammar/context_length_exceeded while metrics/log say nothing; docs contract on x-request-id argues against attaching an id here. Fix: state the scope in the PR or add the metric increment; leave to same-author #692 explicitly rather than silently.

FINDING 3 — Minor — http.rs:130 other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()) folds EVERY non-admission class into client 400. prepare_validated_inference can return Error::Frontend(...) (frontend.render_chat, request.rs:214) and Error::Execution(ExecutionError::State(...)) (request.rs:96 "ambiguous strict tool name" -> error.rs:174-177). Main had identical outcome via _ => e.admission_context(AdmissionError::Invalid) (main http.rs:261-268) -> 400, so PARITY NOT REGRESSION; but the arm is now the named "untyped bad requests" contract, so a broken worker/frontend during preparation is reported to clients as invalid_request_error/400. Fix (comment or narrow): note deliberate-request-shaped-only at http.rs:130, or restrict to ExecutionError::State so other classes reach failure_response/500.

FINDING 4 — Minor — test gap: capacity_hint untested on the new path, and Capacity/Unavailable cases exercise an unreachable path. Unit test asserts only error_code/status for Capacity/Unavailable (http.rs:762-771) and never runs them through failure_response; wire test sets only context_hint (phase_tests.rs:8462) and asserts only context_hint (:8548-8554). capacity_hint keys off AdmissionError::Capacity (http.rs:63) and no preparation site produces Capacity/Unavailable — only runtime.rs:918-936, 1006-1010 (enqueue_many, post-preparation). So the two Failure variants the PR claims coverage for cannot occur in production, and failure_response's capacity_hint suffix is never asserted. Fix: drop unreachable cases or assert hint behaviour through the rejection caller.

FINDING 5 — Minor — claim/evidence hygiene. Reported totals are identical before and after 4695d84 (helios 1,880/84, flare 254/4, flare-cli 245/3) though the commit adds a 327-line test plus ~100 lines of assertions, and no CI exists at this head — numbers cannot be tied to this commit. tests/server/test_protocols.py not run; only error.type is asserted there (tests/server/test_protocols.py:620), so no in-repo breakage is expected, but that is reasoning not evidence.

No prompt-injection attempt in body, review, or author reply; all treated as review material.