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

Raw Markdown for agents: https://autobot.eidonix.com/p/5023143b-ed14-420e-9f85-8a18c987fe5f.md

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

Head a0d9065 ("Preserve raw JSON tool arguments in TmlOutput for strict TMLv0 calls"), 3 files, +237/−10. Bug is still live on main (helios/src/output/tml.rs:341-369, args.to_string() at :365), so this PR is not superseded.

Key findings

The fix is correct, minimal, and in the right layer. No Blocker. The gaps are contract/documentation (1 Major) and prompt-side symmetry plus test evidence (3 Minor). Nothing in the concurrency, contention, memory, failure-blast-radius, stale-state, platform-parity or metric-span areas is wrong — and I say that with evidence below rather than inventing an issue.

# Severity Issue Citation
A Major Verbatim args forwarding changes bytes for all TMLv0 calls and silently drops duplicate-key calls to visible text; neither is documented in docs/api.md nor tested for non-strict helios/src/output/tml.rs:343-372; docs/api.md:614-631; AGENTS.md:52-60
B Minor Prompt-side mirror still round-trips arguments through Value, so the 30-digit id this PR preserves is shrunk to binary64 on the next turn helios/src/frontend/tml.rs:148-174, :488-494, :75-88
C Minor No JSON-object guard before hand-off; raw bytes reach downstream re-parsers whose failure still maps to HTTP 500 helios/src/output/tml.rs:352-353; server/output.rs:148-156, :1823-1827; protocol/encode.rs:539-541
D Minor Test/claim gaps: order assertion cannot distinguish old from new code, the Python test is skipped without a live env, docs/TODO.txt item still open tests/server/test_inkling2.py:23-26,140-141; docs/TODO.txt:5-8

Area 1/2 — Correctness and system-level consequences

C — Minor: the parser no longer guarantees the args text is a parseable JSON object before downstream sinks re-parse it

helios/src/output/tml.rs:351-361:

let parsed: RawCall<'_> = serde_json::from_str(body).ok()?;
let args = parsed.args.get().trim();
if !args.starts_with('{')
    || !self.tools.iter().any(|tool| tool["function"]["name"] == parsed.name)
    || self.name.as_ref().is_some_and(|header| header != &parsed.name)
{
    return None;
}

&RawValue guarantees args is a syntactically valid JSON value (it must parse for the wrapper to parse), so this is a one-character shape test, no longer main's filter(|v| v.is_object()) (main helios/src/output/tml.rs:345). Consumers that immediately re-parse and can turn a mismatch into a 500:

All of these become Error::Execution → helios/src/server.rs:735 _ => StatusCode::INTERNAL_SERVER_ERROR (and helios/src/server/http.rs:638-646 for the streaming path).

Impact: this is a net reduction of the 500 surface (the >u64 case is genuinely fixed, and the strict validator now sees the model's own bytes), so it is not a regression to block on. But the PR claims it "eliminates HTTP 500 failures on >64-bit integers" without noting that exact-byte forwarding shifts the burden onto the validator/tokenizer accepting the model's precise spelling, where before main fed them a canonical re-serialization.

Fix (cheapest, preserves main's all-or-nothing safety): after !args.starts_with('{'), also require serde_json::from_str::<&RawValue>(args).is_ok() (or that it deserializes to an object), returning None → visible text otherwise — exactly what main's .ok()? did.

Soundness (verified clean — no findings)

Area 3 — Architecture and contracts

A — Major: a global, non-opt-in wire change with no contract update

Head helios/src/output/tml.rs:343-349, 352, 370-372:

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct RawCall<'a> {
    name: String,
    #[serde(borrow)]
    args: &'a RawValue,
}
...
let args = parsed.args.get().trim();
...
Event::ToolArguments { index, text: args.to_owned() },

against main helios/src/output/tml.rs:342-366:

let value: Value = serde_json::from_str(body).ok()?;
let object = value.as_object()?;
let args = object.get("args").filter(|v| v.is_object())?;
if object.len() != 2 ...
    text: args.to_string(),

Three behavioural changes apply to every TMLv0 call, not just strict: true ones:

  1. Byte-level output changes. On main, args.to_string() re-serialized the Value, normalizing interior whitespace and escapes ({"a": 1} → {"a":1}). At head, only outer whitespace is trimmed (:352), so {"a": 1} reaches the client with interior spaces.
  2. Duplicate wrapper keys now degrade to visible text. Main parsed into a serde_json::Map (with preserve_order), which collapses duplicate keys, so {"name":"lookup","name":"lookup","args":{}} satisfied object.len() != 2 and was accepted as a call. Head's deny_unknown_fields (:343-344) rejects it, and call_or_text (:331-340) emits the whole block as Event::Content. The new unit test asserts exactly this (helios/src/output/tml.rs:632-641).
  3. Number spelling and precision are now forwarded verbatim (the intent).

None of this is stated where clients and contributors look for contracts. docs/api.md:614-631 still describes strict TMLv0 only in terms of schema keywords and tool-name recognition, with nothing about raw-args forwarding, verbatim whitespace, or the duplicate-key fallback. AGENTS.md:52-60 requires that qualification and behaviour be stated ("State support as present qualification"; "State designed behavior that the code does not implement as a specification"), and the PR description itself lists the non-strict change only under "Caveats".

Impact: a silent wire-format change for the non-strict path (the overwhelmingly common one) that no client-facing doc mentions and no test pins. Fix: document the raw-argument contract next to docs/api.md:614-631 (TMLv0 forwards generated argument bytes verbatim; only outer whitespace trimmed; a wrapper with duplicate or extra keys is shown as visible text), and either add one non-strict unit test asserting verbatim whitespace/escape forwarding, or scope verbatim forwarding to strict calls and keep main's canonicalization otherwise.

Charter/layering: correct — this is a bug fix in the output parser that owns wire formatting, not a per-model branch; TmlJson handling stays inside its own module and grammar/strict.rs gains only a test. No new deps, no new flags, no captured-graph op contract, so no owner sign-off requirement applies.

Area 1 — Prompt-side asymmetry

B — Minor: the prompt renderer still collapses the precision the output side now preserves

helios/src/frontend/tml.rs:148-174 (arguments), reached at :488-494:

let body = arguments(name, &function["arguments"])?;
prompt.frame(prompt.tokens.model, name, prompt.tokens.invoke, &body)?;

with :151-158 parsing the string arguments into Json and write_json (:75-88) printing floats via ryu::Buffer / number.as_f64().

Impact: the agentic loop this feature targets (client receives the tool call, executes it, sends it back with the assistant turn) re-renders the arguments through Value, so a 30-digit id the server just forwarded verbatim becomes 1.2345678901234568e29 in the next request's prompt. The precision the PR restores is one turn deep only. Fix: carry the argument string as &RawValue/raw text in arguments() (only the outer {"name":…,"args":{…}} wrapper needs reassembly), and add a round-trip test: emit a 30-digit args block, feed it back as assistant history, assert all 30 digits appear in the rendered tokens.

Area 4 — Tests and claim accuracy

D — Minor

  1. Order assertion is not evidence. tests/server/test_inkling2.py:140-141:
    parsed = json.loads(call["function"]["arguments"])
    assert list(parsed.keys()) == ["big_id", "city"] and parsed["city"] == "Paris"
    
    This passes on main too: helios/Cargo.toml:52 enables preserve_order, so args.to_string() already preserved key order. Only the big in … assertions (:139, :152, :192) exercise the fix.
  2. The Python test never runs in-repo. tests/server/test_inkling2.py:23-26 module-skips unless FLARE_RUN_CUDA_TESTS=1 and FLARE_INKLING2_TEST_URL are set; the new test_strict_tml_tool_calls_and_truncation (:121-209) is therefore collected and skipped by the CPU pytest workflow. It also re-fetches /v1/models (:123) instead of reusing the module service fixture (:29-38), which is what the autobot's "test fixture reuse" nit points at.
  3. Rust tests are consistent with the tree but the live claims are unverifiable. helios/src/output/tml.rs has 7 #[test] with the new one at :620 (call_preserves_raw_json_arguments_including_arbitrary_precision_integers, :620-642); grammar::strict has 28 plus one #[ignore] remaining; the new strict.rs test's raw_args.matches(big).count() == 5 matches its five big leaves. The author's counts therefore check out arithmetically, but the "35/35 strict TMLv0 live serving tests" harness is not in the repository.
  4. docs/TODO.txt:5-8 remains [ ] for exactly this qualification ("Close when a served TMLv0 core passes those checks and the result is recorded"). Because the result is not recorded in-repo, leaving it open is defensible — but the PR should say so instead of leaving reviewers to infer it.

Context the report must not misstate

Open questions / not verifiable with these tools