Correctness and contracts report · NVIDIA/hyperflare-inference #637

Raw Markdown for agents: https://autobot.eidonix.com/p/cdaa8e90-cd8d-4687-9c37-5facf0968055.md

Correctness, Contracts & System-Level Consequences review — PR #637

Key findings


1. Correctness, Safety & Platform Parity

1.1 The close() / apply() reorder is correct and strictly better — no finding

helios/src/server/output.rs:1714-1723:

    fn close(&mut self, changes: &mut Vec<Change>) -> Result<()> {
        if let Some(index) = self.open {
            if let Block::Tool { ended: false, .. } = &self.blocks[index] {
                return Err("incomplete emitted tool call".into());
            }
            self.open = None;
            changes.push(Change::End(index));
        }
        Ok(())
    }

Previously self.open.take() ran before the check, so a rejected unclosed-tool close() silently dropped self.open and the subsequent ToolArguments/ToolEnd for that block became unreachable. Now the error path leaves self.open pointing at the still-unclosed tool, so recovery via ToolArguments/ToolEnd still works (covered by the test at output.rs:1656-1670). Same for apply, where validation now precedes self.close(&mut changes)? (output.rs:1768-1777):

                let id = id.unwrap_or_else(|| synthesize_tool_call_id(request_id, index));
                if id.is_empty()
                    || self
                        .blocks
                        .iter()
                        .any(|b| matches!(b, Block::Tool { id: existing, .. } if existing == &id))
                {
                    return Err("tool IDs must be unique and nonempty".into());
                }
                self.close(&mut changes)?;

Note the behavioral delta this introduces: finish() after a failed apply is now retryable rather than permanently wedged. That is an improvement, but it is beyond "ID formatting" and is not described as a behavior change in the PR body.

1.2 Length guarantee rests on a tautology, not on production assertions — Minor

helios/src/server/output.rs:20-22:

const MAX_SYNTHESIZED_TOOL_CALL_ID_LEN: usize = 40;
const SYNTHESIZED_TOOL_CALL_ID_LEN: usize = 37;
const _: () = assert!(SYNTHESIZED_TOOL_CALL_ID_LEN <= MAX_SYNTHESIZED_TOOL_CALL_ID_LEN);

and output.rs:46-47:

    debug_assert_eq!(id.len(), SYNTHESIZED_TOOL_CALL_ID_LEN);
    debug_assert!(id.len() <= MAX_SYNTHESIZED_TOOL_CALL_ID_LEN);

37 <= 40 cannot fail for any implementation; it documents, it does not guard. The only executable check of the emitted string is a debug_assert!, which is compiled out under cargo test --release — the mode the PR's entire evidence section uses. In practice the length is structural (5 + 16×2 = 37 at output.rs:41-45), and the test helpers do assert it (output.rs:1296-1308, protocol/tests.rs:2666-2682), so real-world risk is low.

Fix: drop the tautological const assert and make the length structural — e.g. build from a fixed-size hex table into a [u8; 37], or promote debug_assert_eq! to assert_eq! (one compare on a path already doing a SHA-256).

1.3 Platform parity — no finding

The change adds no platform-specific code: sha2 is a portable pure-Rust/asm crate already in the dependency graph for server builds (helios/Cargo.toml:22-25,53; helios/src/lib.rs:29-30 gates pub mod server), the hash uses only to_le_bytes (endianness-explicit), and no path, FFI, or signal handling is touched. The x86_64/Windows risk is build-level only, and that is where CI is red (§4.1) — unexplained, not diagnosable from the diff.

1.4 Collision semantics — noted, not a finding

The doc comment at output.rs:28-30 claims the encoding is "injective", which is true of the input encoding but not of the 128-bit truncated output. In the astronomically improbable collision case the behavior is a hard per-response error via the uniqueness checks at output.rs:102-104 and 1769-1776, not a silent duplicate — the right failure mode. Worth one sentence in the doc comment, nothing more.


2. Unintended System-Level Consequences

I traced the change through the request path (http.rs:317-327 → Encoder::new at encode.rs:130-131 → Accumulator::apply / ResponseOutput::apply) and found no system-level regression.


3. Architecture, Contracts & Charter Compliance

3.1 A provider limit is promoted to a documented project contract without evidence — Major

New text, docs/api.md:443-451:

parser supplies no tool-call identifier, Helios synthesizes a deterministic
37-character ASCII identifier (`call_` followed by 32 lowercase hexadecimal
digits hashed from the request identifier—which embeds a random per-server-start
run ID and monotonic counter—together with the choice index on Chat Completions
and the call index). This format stays within the 40-character OpenAI Chat
Completions maximum and the `[a-zA-Z0-9_-]+` character set accepted across Chat
Completions, Responses, and Messages, keeping synthesized identifiers distinct
across calls, choices, requests, server restarts, and hosts.

New comment, helios/src/server/output.rs:17-19:

/// OpenAI Chat Completions enforces a 40-character maximum on `tool_calls[].id`,
/// the strictest limit among Chat Completions (40), Responses (64), and
/// Anthropic Messages (64).

The maintainer's standing objection on #447 (yatesdr, 2026-11-21 18:38), still unanswered:

"Every parser leaves ids to Flare, so all models get synthesized ids. Flare documents no length limit, and the only limit cited is a third-party report of Azure OpenAI rejecting 41 characters, so the client contract this should meet is not established yet."

The only source anywhere is https://github.com/BerriAI/litellm/issues/11392, named in #447's own suggested fix. No OpenAI/Azure schema reference, no captured string_above_max_length 400, no in-repo doc. The numbers "Responses (64)" and "Messages (64)" are likewise uncited — and note that nothing in the charter or repo previously stated them.

Impact: two ways. (a) The repo's client-facing contract document now asserts a limit the project has not verified; if the real limit differs (higher, or applied to a different field), the documentation is wrong in a way clients will code against. (b) A second, subtler lock-in: publishing "deterministic 37-character call_<32 hex>" makes the hash format itself a permanent external guarantee, when it is an internal workaround for a length problem. Any future change to the derivation becomes a breaking docs change.

Fix: either supply primary evidence (Azure/OpenAI request-schema maxLength, or a live 400 capture) in the PR and keep the text as-is, or reword to what is actually known — "synthesized identifiers are fixed-length (call_ + 32 hex, 37 characters), so they do not grow with the request counter" — and drop the specific 40/64 maxima and the [a-zA-Z0-9_-]+ claim until a primary source is attached.

3.2 Tool-call IDs become opaque: an undeclared observability regression — Major

Before (removed line in the diff):

-                    let id = id.unwrap_or_else(|| format!("call_{}_{}", self.id, index));

After, helios/src/server/output.rs:101:

                    let id = id.unwrap_or_else(|| synthesize_tool_call_id(&self.id, index));

with output.rs:34-45 reducing the scope to 16 digest bytes, while the request id itself stays human-readable at http.rs:323-327:

    let id = format!(
        "{prefix}-{:016x}-{}",
        state.run,
        state.ids.fetch_add(1, Ordering::Relaxed)
    );

Impact: the run+counter prefix used to be readable out of every tool-call ID, which is exactly the correlation #176 and docs/core-design.md:1120 (not opened) ("responses carry an x-request-id header matching failure logs") are built around. A user reporting "tool call call_chatcmpl-3f9a…-1042_0_0 failed" gave support a run ID and a request counter; after this change the same report gives 32 opaque hex characters. The PR body lists this in neither "What Changed" nor "Compatibility". This is the kind of consequence the charter's evidence rule targets: an accepted, user-visible loss of diagnosability traded for an unverified length limit.

Fix: state the change explicitly in the PR body under compatibility, and optionally log the mapping once per synthesized ID at debug level (scope id + produced id) so the correlation is recoverable from logs without widening the wire format.

3.3 Wrong-layer placement — no finding

The change sits in the shared Helios protocol layer (helios/src/server/output.rs), touches no parser, no per-model branch, and no protobuf/ModelContract/core format. That is the correct layer per the charter ("Keep the runtime small and model-agnostic"; "no per-model special cases").

3.4 A sibling unbounded ID is left alone — Minor, part of 4.2

Responses item.id (encode.rs:268-270) still concatenates the request id and index, so it still grows with the counter — the very defect this PR fixes for tool-call IDs. The PR neither changes it nor tracks it.


4. Tests & Claim Accuracy

4.1 CI is red on head while the description reports everything green — Minor (evidence integrity)

.github/workflows/native-serving.yml:18-21 (not opened) sets the matrix to ubuntu-24.04 (x86_64) and windows-2022, and both legs run:

        - name: Test native runtime on Linux
…
          run: |
            ulimit -l
            sudo prlimit --pid $$ --memlock=67108864:67108864
            cargo test --locked --release --manifest-path helios/Cargo.toml --target-dir flare-cli/target --features runtime-core,server
        - name: Test native runtime on Windows
…
          run: cargo test --locked --release --manifest-path helios/Cargo.toml --target-dir flare-cli/target --features runtime-core,server

(lines 63 and 68). These are exactly the legs the PR says "were not executed locally", and CI failed on d150811 with no explanation in the PR or on #447. The aarch64 result (1803 passed) cannot be reconciled with red CI from the PR body alone.

Fix: paste the failing job name and the first failing assertion into the PR; if it is pre-existing/unrelated, say so and cite the commit where it started.

4.2 Claim-accuracy corrections — Minor

(a) Parser count. The PR says "all nine native tool-call parsers in helios/src/output/" emit id: None. Verified sites — 8, in 7 files: argument_tags.rs:596 (not opened), dsml.rs:185 (not opened), recipient.rs:186 (not opened), recipient.rs:279 (not opened), tagged.rs:269 (not opened), tml.rs:361 (not opened), tml.rs:488 (not opened), xtml.rs:209 (not opened).

(b) seq = 0 is unreachable. New tests iterate for seq in [0u64, 99_999, 100_000, u64::MAX] (output.rs:1320), but production starts the counter at 1 — helios/src/server.rs:325: ids: AtomicU64::new(1),. Harmless (it only widens coverage), but the description's "from 0 through u64::MAX" describes a domain production cannot produce.

(c) The item_id figure does not follow. PR text: "Responses item_id values (<= 54 characters up to seq = u64::MAX…)". Actual code, unchanged by this PR:

    fn item_id(&self, index: usize) -> String {
        format!("item_{}_{index}", self.id)
    }

(encode.rs:268-270). With self.id = resp-<16 hex>-<20 digits> = 42 characters, that is 5 + 42 + 1 + digits(index) = 49 at index 0; 54 would need a five-digit index. No test asserts the bound, and the 64-character Responses limit it is compared against is uncited in-repo.

Fix: correct all three numbers, or state them as "unreachable in production" / "not asserted".

4.3 Tests that are missing

4.4 Claims that are accurate


Open questions / not found

  1. Why is CI red on d150811? Not explained in the PR or on #447. The x86_64/Windows legs are the likely candidates but that is inference, not evidence.
  2. Is the 40-character limit real, and is it OpenAI's or Azure's, on Chat Completions or on the request echo? No primary source in the repo or the PR; yatesdr asked for exactly this before the change was written.
  3. Who decided #176's run-embedded uniqueness may become a truncated digest? Cross-restart/cross-host collision probability (≈2⁻⁶⁴ per pair) is fine, but no one has stated that this trade is accepted, and the PR never cites #176 (cc696a6b), whose format it re-encodes.
  4. Should item_id (encode.rs:268-270) be bounded too? It has the same unbounded-growth defect this PR fixes elsewhere; no issue tracks it and the description mis-states its bound.
  5. Merge interaction with #638, which edits the same docs/api.md region and appends to the same tail of protocol/tests.rs; no stacking order is declared.