Re review report · NVIDIA/hyperflare-inference #685

Raw Markdown for agents: https://autobot.eidonix.com/p/4b200085-ecf2-4469-9d69-45c78eff5562.md

Recommendation: Changes Requested

The incremental DSML streaming core (DsmlOutput::apply + Call::publish with published_argument_bytes and string="false" literal deferral) is clean, byte-exact, and avoids per-model shared-layer branches, concurrency hazards, or TTFT regressions, and b9864ab fixes the four previously broken helios/tests/ integration tests and the Messages closing-frame order. However, the new Change::End-before-drop path in b9864ab introduces a concrete regression that fails Responses requests (both streaming and non-streaming) whenever a custom tool call is truncated, and the PR still reverses reviewed pre-publication (#364) and non-EOS incomplete-call error contracts across code, tests, and docs without explicit maintainer sign-off (AGENTS.md:182-187, 201-207).

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Truncated custom tool calls on Responses now fail the entire request instead of being omitted (helios/src/server/protocol/encode.rs:470-485, 502-505, 677-689; helios/src/server/output.rs:1731-1744).

    • Verified behavior & impact: When a custom tool call (tool.custom == true) is truncated by OutputLimit or UserStop, ResponseOutput::finish(cause) emits Change::End(last) before drop_abandoned pops the block. Encoder::finish renders that Change::End through Encoder::change (encode.rs:685), which executes serde_json::from_str(arguments)? (:476-477), checks value.get("input").is_some_and(Value::is_string) (:478-480), runs grammar.validate(...) (:481-483), and checks item["input"].is_string() (:503-505). Because an abandoned call's arguments are empty or partial JSON by construction, Encoder::finish returns Err("invalid custom tool arguments: ..."), drop_abandoned never runs, streaming Responses requests fail with response.failed (helios/src/server/http.rs:575-580), and non-streaming Responses requests return an HTTP error (http.rs:639). This is a direct regression against main, where DsmlOutput buffered and discarded incomplete calls so both streaming and buffered Responses requests succeeded cleanly as incomplete/completed.
    • Fix: Pass whether Change::End(i) is closing an abandoned block into Encoder::change (or check abandoned == Some(i)), skip custom-tool JSON/grammar validation and response.custom_tool_call_input.{delta,done} emission for abandoned blocks, and emit only the closing response.output_item.done with "status": "incomplete" before discarding the block. Add a Responses protocol test covering a truncated custom tool call for both streaming frames and buffered response().
  2. Reversal of reviewed pre-publication, size-bound, and non-EOS error invariants without maintainer sign-off (helios/src/output/dsml.rs:145-156, 191-206; helios/src/server/output.rs:163-173, 478-480, 1265-1274; helios/tests/deepseek_output.rs:514-515; docs/api.md:547-551, 568-572).

    • Verified behavior & impact: Streaming DSML arguments before ToolCallArgumentsEnd inherently publishes ToolBegin and ToolArguments fragments before validate_arguments and before subsequent appends cross #364's 1 MiB bound (main docs/api.md:560 and helios/tests/deepseek_output.rs:511 pinned "nothing published before validation/size check"; b9864ab weakens :515 to assert_eq!(parsed.ended, 0)). Separately, drops_unfinished_call replaces main's non-EOS Err("incomplete emitted tool call") (pinned by main helios/src/server/output.rs:1257-1271, user_stop_cannot_retract_an_already_emitted_partial_tool_call, rewritten here to assert omission) across all tool parsers and wire protocols. Under AGENTS.md:182-187, 201-207, weakening existing validation/error guarantees — including via accompanying doc and test rewrites — requires an explicit maintainer design decision on record before merging.
    • Fix: Obtain explicit maintainer sign-off (e.g., from @yatesdr / @voipmonitor, who reviewed/authored #364 and the retraction semantics) recorded on this PR confirming (a) post-publication validation/1 MiB enforcement for streaming DSML calls and (b) non-EOS unfinished-call omission across protocols.

Should Fix

  1. Responses response.output_item.done reports status: "completed" with partial JSON arguments for non-OutputLimit truncated calls (helios/src/server/protocol/encode.rs:339-346, 381, 486, 509, 513-516, 680-685).

    • self.incomplete_item = Some(i) is set only when cause == Termination::OutputLimit (encode.rs:680-684). On UserStop (or Cancelled), Change::End renders self.item(i, true) with "status": "completed" and partial JSON in both response.function_call_arguments.done and response.output_item.done, right before drop_abandoned deletes that item from response.completed's output.
    • Fix: Set self.incomplete_item = Some(i) whenever abandoned == Some(i) (not only on OutputLimit), clear self.incomplete_item = None after the for change in changes loop, and extend the Responses truncation test to assert status == "incomplete" for all non-EOS causes.
  2. docs/api.md:547-550 states an unconditional truncation-omission rule contradicted by tool_choice: Required | Named (helios/src/server/protocol/encode.rs:690-694).

    • docs/api.md:547-550 claims an announced call cut off before completion is omitted and the response reports that termination's finish reason for every non-EOS termination. However, after drop_abandoned, if no completed tool call remains and tool_choice is Required or Named(_), encode.rs:690-694 returns Err("required tool choice was not satisfied: ..."), ending the request in an error frame / HTTP error.
    • Fix: Qualify docs/api.md:547-550 to note that tool_choice: "required" or a named tool still errors when omitting the truncated call leaves no completed tool call (and add a test pinning the intended behavior).
  3. docs/api.md:543-547 is factually false against main after #670 (TAGGED_JSON).

    • docs/api.md:543-547 states that all tagged tool parsers buffer "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." On main, TAGGED_JSON (helios/src/output/tagged_json.rs:14-49, 57, JSON_BODY = true, TRIM_NEWLINES = false) parses the model's JSON object directly without parameter syntax, schema coercion, or newline trimming.
    • Fix: Delete the over-generalized "because ... trimmed." clause so line 543-544 states simply: "The tagged tool parsers publish a call only when its envelope is complete." (The per-dialect details are already documented at docs/api.md:601-638 on main.)

Subtract / Simplify

  1. Restore Accumulator::finish(&self) and remove 8 files of mechanical test churn (helios/src/server/output.rs:163-173; helios/src/server/protocol/encode.rs:674-676; 8 test-only files).

    • Accumulator::finish(&mut self, cause: Termination) uses cause only to evaluate drops_unfinished_call(cause), forcing ~25 call sites across argument_tags.rs, chatml.rs, gemma_call.rs, minimax_xml.rs, pipeline.rs, xtml.rs, runtime_core/protobuf.rs, server/runtime/phase_tests.rs, dsml.rs, and server/output.rs to pass Termination::Eos.
    • Simplification: Keep Accumulator::finish(&self) -> Result<()> unchanged from main, add pub(crate) fn discard_unfinished_call(&mut self) (4 lines), and call it before finish() at the single production site (encode.rs:674-676, plus Presentation::finish at output.rs:501-505). This deletes 8 entire files from the diff.
  2. Collapse take_abandoned + drop_abandoned(index) into discard_abandoned(&mut self) (helios/src/server/output.rs:1745-1755; helios/src/server/protocol/encode.rs:678, 687-689).

    • ResponseOutput::finish always sets self.abandoned = Some(self.blocks.len() - 1) and rendering changes never mutates self.blocks, so round-tripping index: usize out through take_abandoned and back into drop_abandoned with the unreachable if index + 1 == self.blocks.len() guard adds surface area without value. Replace take_abandoned/drop_abandoned(index) with a read accessor is_abandoned(&self, index: usize) -> bool (needed for Blocker #1 / Should Fix #1) plus a single pub fn discard_abandoned(&mut self) that pops blocks and calls when self.abandoned.take().is_some().
  3. Fold the duplicated header-only vs mid-argument truncation matrix tests (helios/src/server/protocol/tests.rs:3809-3907, 3979-4017; helios/src/output/dsml.rs:917-937, 962-984).

    • Both pairs repeat the same loop/assertion body differing only in whether argument fragments were pushed, and protocol/tests.rs:3982-3986 already drifted by omitting Termination::Cancelled and the closing-frame assertions (:3861-3876). Parameterizing each pair over empty vs non-empty fragments removes ~70 lines and keeps one authoritative cause list.

Nits

Dropped on verification