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

Raw Markdown for agents: https://autobot.eidonix.com/p/b0ab5286-4cb8-4ccf-b278-c4d5e88d72d9.md

Review — PR #685 (fix(frontend): stream DeepSeek tool-call arguments), head b9864ab8243b2a54caf0d990f6759b1ddd9ec2db

Lens: Correctness, Contracts & System-Level Consequences. All findings are static reading of the diff at b9864ab and of its callers on that head (nothing executed; no CI run exists on any hash of this branch — noted where it matters). Line numbers are as read at the cited commit.

Key findings

  1. Blocker — a truncated custom (grammar) tool call now fails the whole Responses request instead of being omitted: Encoder::finish renders the abandoned block's Change::End through the custom-tool branch, which serde_json::from_strs arguments that are partial JSON by construction (helios/src/server/protocol/encode.rs:475-483 reached from :677-689). The Err propagates out of finish, helios/src/server/http.rs:575-580 turns it into an error frame, and drop_abandoned never runs. No test covers a custom tool.
  2. Major — the abandoned item is reported as status: "completed" with partial arguments for every non-output-limit cause (encode.rs:339-346, :381, :486, :513-516; only OutputLimit sets incomplete_item at :680-683), then disappears from response.completed.
  3. Blocker (authorization) — announce-and-stream now precede validate_arguments and the 1 MiB bound (helios/src/output/dsml.rs:145-156, :191-206 vs main:171-194), so rejected and oversized calls reach the client before the error; the tests that pinned the old "nothing published before validation" guarantee were rewritten to bless it (helios/tests/deepseek_output.rs:514-515, :572-601; helios/src/server/output.rs:1264-1274). Declared in docs/api.md:547-572, but no maintainer decision on record (AGENTS.md:182-187, 201-207).
  4. Major (docs vs code) — docs/api.md:547-549 states an unconditional omission rule ("for every termination other than natural end-of-sequence") that the required/named tool_choice error at encode.rs:690-694 contradicts: the request still ends in an error frame.
  5. Major (docs) — docs/api.md:543-547 is false against main: it claims the tagged parsers "build [arguments] from parameter syntax and the declared schemas rather than copying the model's text", but main now has helios/src/output/tagged_json.rs:14-49,57 which parses the model's own JSON object. This PR edits those exact lines, so the rebase lands false documentation.
  6. Major/Minor (claim accuracy) — the PR body's "ExecutionError included" describes a cause the server never passes to Encoder::finish (only UserStop/Eos/OutputLimit are forwarded, http.rs:534-540; errors take http.rs:562 → failure at :576), and the reported test counts (1787/16, output:: 113, server::protocol 96) are stale for this head, which adds mod streaming_tests and mod rejection_tests in dsml.rs:749-1033 plus three protocol tests.
  7. Clean, stated plainly: no new locks, channels, global state or blocking on the hot path; publication copies only newly appended bytes within the 1 MiB bound; TTFT/first-response sampling excludes tool-call deltas so the metric's span is unchanged; and the previously reported Messages/Responses unclosed-block framing bug is genuinely fixed (closing frames precede the terminal frame).

1. Correctness, safety & platform parity

F1 — BLOCKER: a truncated custom/grammar tool call errors the request instead of being omitted

helios/src/server/protocol/encode.rs:475-483:

if self.tool(name).is_some_and(|tool| tool.custom) {
    let value: Value = serde_json::from_str(arguments)
        .map_err(|e| format!("invalid custom tool arguments: {e}"))?;
    if !value.get("input").is_some_and(Value::is_string) {
        return Err("custom tool input must be text".into());
    }

Reached for an abandoned block because Encoder::finish renders changes before dropping the block, helios/src/server/protocol/encode.rs:677-689:

let changes = self.outputs[index].finish(cause)?;
let abandoned = self.outputs[index].take_abandoned();
for change in changes {
    ...
    frames.extend(self.change(change)?);
}
if let Some(block) = abandoned {
    self.outputs[index].drop_abandoned(block);
}

ResponseOutput::finish produces that Change::End for the truncated call (helios/src/server/output.rs:1731-1744), and a truncated call's arguments are partial JSON by construction (the fragments were streamed by this very PR). The ? therefore propagates out of Encoder::finish; helios/src/server/http.rs:575-580 converts it:

Err(e) => {
    let frame = encoder.failure(&e);
    yield Delivery::Failed(e, frame);
    return;
}

Impact: a client that has already received response.output_item.added (and argument deltas) for a custom tool gets an error frame and never response.completed/response.incomplete; drop_abandoned never executes, so the truncated call stays in blocks/calls. On main this path was unreachable because close() returned Err("incomplete emitted tool call") instead of emitting Change::End (helios/src/server/output.rs:1721-1730 keeps that behaviour only for EOS and non-tail calls). Custom tools are a real request surface (helios/src/server/inference.rs:68, selected by helios/src/server/protocol/decode.rs:959 (not opened), modelled by encode.rs:24,366,825). New protocol tests only use a plain function tool lookup (helios/src/server/protocol/tests.rs:3823-3827, :3992-3996), so nothing exercises it.

Fix: don't route an abandoned block's Change::End through the custom-tool validation — pass an "abandoned/closing-only" flag into change() and skip from_str/grammar validation, or validate custom input only when the block is ended.

F2 — MAJOR: response.output_item.done for a truncated call claims completed with partial arguments

helios/src/server/protocol/encode.rs:339-346:

let status = if self.incomplete_item == Some(index) {
    "incomplete"
} else if complete {
    "completed"
} else {
    "in_progress"
};

incomplete_item is set only under cause == Termination::OutputLimit (encode.rs:680-683), while Change::End always renders self.item(i, true) (encode.rs:486) and the done frame (encode.rs:513-516), and function tools carry "arguments":if complete{arguments.as_str()}else{""} (encode.rs:381).

Impact: on UserStop, Cancelled or ExecutionError the client receives response.output_item.done with status:"completed" and truncated arguments for an item that then vanishes from response.completed — an item-level inconsistency surviving the (now correct) frame ordering. Fix: set the same incomplete marker for every drops_unfinished_call(cause) cause, or omit arguments/input on abandoned items.

F3 — BLOCKER (contract/authorization): announce-and-stream now precedes validation and the size bound

helios/src/output/dsml.rs:194-206:

OutputAction::ToolCallArgumentsEnd { closing_text } if !repeated => {
    let mut call = self.call.take()...;
    call.close_literal();
    call.arguments.push_str(closing_text);
    call.check_size()?;
    validate_arguments(&call.arguments)?;
    call.publish(self.calls, events);
    events.push(Event::ToolEnd { index: self.calls });

Event::ToolBegin is already emitted at ToolNameEnd (dsml.rs:145-156), and fragments are published per text append after check_size (dsml.rs:191-192). On main:171-194 all three events were emitted only after validate_arguments. Consequently a call rejected for nonempty/unique argument names, and a call exceeding the 1 MiB bound, are announced and partly streamed before the request errors, and no byte is retracted.

The tests that pinned the old guarantee were inverted rather than extended:

helios/tests/deepseek_output.rs:514-515:

assert!(error.unwrap().to_string().contains("nonempty and unique"));
assert_eq!(parsed.ended, 0, "a rejected call reported an end");

(main:511 asserted nothing was published at all); helper helios/tests/deepseek_output.rs:572-601 now records events instead of asserting an empty push; helios/src/server/output.rs:1264-1274 renamed user_stop_cannot_retract_an_already_emitted_partial_tool_call (which on main:1262-1270 asserted Err("incomplete emitted tool call")) to user_stop_omits_an_already_emitted_partial_tool_call.

Impact: a wire-level contract change well beyond "stream the arguments" — the client can see a call that provably cannot complete, and the observable error surface for malformed model output moves from "no call" to "announced partial call + error frame". AGENTS.md:182-187 ("Do not remove validation, suppress errors…") and 201-207 ("Apply these criteria to documentation and test changes that would weaken the rules as well as code") make this a maintainer sign-off question; docs/api.md:547-555 declares the behaviour but no decision is on record anywhere in the tracker (cross-PR history in the dossier confirms: no issue, roadmap item, or maintainer request for tool-call streaming, and this reverses the publish-after-check property of merged #364).

Fix: obtain explicit sign-off recorded on the PR, or defer publication until validation completes (buffer, validate, then publish plus fragments).

Platform parity / races

No finding. The change touches no I/O, syscall, path, or threading surface: DsmlOutput, Accumulator/ResponseOutput and Encoder are per-request values built in helios/src/server/http.rs (encoder constructed per stream; DsmlOutput at helios/src/output/dsml.rs:81-95, ResponseOutput at helios/src/server/output.rs:1698-1704, Encoder at helios/src/server/protocol/encode.rs:122-159). No Unix/Windows divergence is introduced.

2. Unintended system-level consequences

F4 — CLEAN (verified, no defect)

3. Architecture, contracts & charter compliance

F5 — MAJOR: docs/api.md "omitted for every termination other than EOS" is contradicted by the required/named tool-choice error

docs/api.md:547-549:

An announced call cut off before completion is omitted from a
buffered response for every termination other than natural end-of-sequence, and
the response reports that termination's finish reason; only an output-limit
termination reports the output limit.

helios/src/server/protocol/encode.rs:690-694:

if matches!(self.tool_choice, ToolChoice::Required | ToolChoice::Named(_))
    && !self.outputs[index].has_tools()
{
    return Err("required tool choice was not satisfied: the model did not produce a completed tool call".into());
}

After drop_abandoned (encode.rs:687-689) the call is gone, so has_tools() is false, the ? returns early, self.reasons[index] is never set (:702), no terminal frame is emitted (:709-752), and http.rs:575-580 yields an error frame. Impact: a streaming tool_choice:"required" request truncated by stop string/cancel/output limit still ends in server_error-style failure, not the documented truncated response — the doc overstates the change. Not a regression versus main (which failed one line earlier with "incomplete emitted tool call"), but it is a new false contract statement. Fix: qualify the sentence with the required/named tool-choice exception, or skip the required-tool error when drops_unfinished_call(cause).

F6 — MAJOR: the tagged-parser sentence this PR edits is false against main (TAGGED_JSON, #670)

docs/api.md:543-547:

The tagged tool parsers publish a call only when its envelope is
complete, because they build its arguments from parameter syntax and the
declared schemas rather than copying the model's text: values are coerced to
declared types, strict container parameters are parsed, and wrapping newlines
are trimmed.

main contains helios/src/output/tagged_json.rs, which parses the model's own object and re-serializes it:

let value: Value = serde_json::from_str(trimmed)
    .map_err(|error| format!("invalid tagged JSON tool call: {error}"))?;
...
Some(Value::Object(_)) => object["arguments"].to_string(),

(tagged_json.rs:17-18, :37; const JSON_BODY: bool = true; at :57). Impact: the sentence is factually wrong on the branch this PR merges into, and this PR is the one editing those lines (+25/−12 spans docs/api.md:540-575), so the merge lands incorrect documentation about which parsers copy model text. Fix: describe the tagged JSON dialect explicitly (envelope preserved, arguments copied from the model's object) or drop the generalization.

F7 — Charter/authority note (same as F3, recorded separately)

The behavioural change is now documented (docs/api.md:540-572) and tested, but per AGENTS.md:201-207 documenting and testing it does not substitute for a maintainer decision. docs/api.md:568-572 even records the reversal of #364's publish-after-check property in prose ("enforced on the append that crosses it, after the call name and earlier argument fragments were published and are not retracted"). Recommend the PR ask for explicit sign-off from the #364 reviewers rather than merging on the docs change.

4. Tests & claim accuracy

F8 — MAJOR: ExecutionError included describes an unreachable production path

helios/src/server/http.rs:534-540 forwards termination taken from GenerationEvent::Finished; the runtime only produces UserStop, Eos, OutputLimit (helios/src/runtime/…/runtime.rs:2366-2371). Generation errors take GenerationEvent::Error(e) => Err(e) (http.rs:562) → encoder.failure (:576), never finish. So drops_unfinished_call's ExecutionError arm (helios/src/server/output.rs:478-480) and the ExecutionError rows in the new tests (helios/src/server/protocol/tests.rs:3816, :3985) exercise a path the server does not take. Impact: the PR body's "ExecutionError included" overstates live coverage; a reviewer trusting it would think the error path is covered end to end when the error path actually bypasses the drop logic entirely (the client sees the error frame plus whatever fragments were already streamed, and the block is never closed). Fix: correct the claim, or route errors through finish-like cleanup so the accumulated state is discarded deterministically.

F9 — MINOR: stale, self-reported test evidence

The body reports "1787 passed and 16 failed", "output:: suite reports 113 passed", "server::protocol suite 96 passed" — the same numbers as the earlier head, although b9864ab adds mod streaming_tests (helios/src/output/dsml.rs:749-985), mod rejection_tests (dsml.rs:987-1033) and three protocol tests (helios/src/server/protocol/tests.rs:3809-4017). No CI run exists on any hash of the branch. Fix: refresh the numbers at this head and, per charter ("Bring real evidence"), attach a CI run.

F10 — MINOR: tests that should exist for the touched paths


Open questions / not verified