Re review report · NVIDIA/hyperflare-inference #685

Raw Markdown for agents: https://autobot.eidonix.com/p/c9c2f86f-6ee1-4ca2-bb17-25b4b3bde16b.md

Recommendation: Changes Requested

The core streaming mechanism in DsmlOutput (Call::publish with published_argument_bytes and string="false" literal deferral) is minimal, byte-exact, and directly solves stalled streaming for large DeepSeek tool calls without adding per-model runtime branches or hurting concurrency/TTFT. However, the PR at 80c87b3 breaks four existing integration tests in helios/tests/ that CI runs unconditionally, introduces a streaming SSE framing violation on Messages and Responses when an announced tool call is truncated, and reverses the reviewed Err("incomplete emitted tool call") contract on UserStop/Cancelled/ExecutionError without maintainer sign-off.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Four existing integration tests in helios/tests/ fail under CI (.github/workflows/native-serving.yml:63 (not opened), 68):

    • CI runs cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --target-dir flare-cli/target --features runtime-core,server (without --lib), and this PR modifies no files in helios/tests/.
    • helios/tests/deepseek_output.rs:576, 581 (parse_literal_parameters, used by tool_call_size_includes_retained_strings_and_closing_brace_in_either_order at :596-619 and literal_nesting_includes_the_enclosing_argument_object at :622-635): asserts output.push(Input::Text(&header))?.is_empty() and output.push(Input::Text(&parameter))?.is_empty(). ToolNameEnd now emits Event::ToolBegin (helios/src/output/dsml.rs:145-156) and parameter key text emits Event::ToolArguments (dsml.rs:191-192), failing both assertions.
    • helios/tests/deepseek_output.rs:510-511 (empty_and_duplicate_top_level_parameter_names_are_rejected): asserts published.is_empty() after duplicate/empty key rejection, but Event::ToolBegin and early argument fragments are now emitted before validate_arguments runs at ToolCallArgumentsEnd (dsml.rs:151-155, 192, 202).
    • helios/tests/deepseek_requests.rs:683-684 (added_non_special_dsml_token_produces_tool_calls): runs serde_json::from_str::<Value>(text).unwrap() on a single Event::ToolArguments event, which panics now that individual events carry partial JSON fragments.
    • Fix: Update these four integration tests to match incremental DSML emission (collect/verify streamed ToolBegin and concatenated ToolArguments, verify no ToolEnd is emitted on rejected/oversized calls) and verify with the full CI test commands across helios, flare, and flare-cli (docs/design-review.md:180-185).
  2. Truncating an announced tool call leaves Messages and Responses SSE blocks/items permanently unclosed (helios/src/server/output.rs:1730-1742, helios/src/server/protocol/encode.rs:409-517, 730-745):

    • ResponseOutput::apply emits Change::Start(i) on Event::ToolBegin (output.rs:1792-1802), which sends content_block_start on Messages (encode.rs:409-415) and response.output_item.added on Responses (encode.rs:430-434).
    • On non-EOS termination, ResponseOutput::finish (output.rs:1730-1742) pops self.blocks, pops self.calls, and sets self.open = None before calling self.close(&mut changes) (output.rs:1720-1729), which is the sole producer of Change::End(i) — and Change::End(i) is the sole producer of content_block_stop (encode.rs:424-429) and response.output_item.done (encode.rs:470-517).
    • Encoder::finish (encode.rs:730-745) then unconditionally sends message_delta/message_stop (with stop_reason: "end_turn" / "max_tokens" / "stop_sequence") or response.incomplete/response.completed (whose response.output omits the announced item) without ever closing the open tool block/item. This breaks strict SSE parsers/SDK assemblers for both function tools and Responses custom tools (encode.rs:458-460).
    • The new tests in helios/src/server/protocol/tests.rs:3810-4001 miss this because they assert only encoder.response() and !finished.is_empty(), never the emitted frame sequence.
    • Fix: Do not emit terminal message_stop / response.completed / response.incomplete frames while a previously announced block/item is unclosed. Either preserve Err("incomplete emitted tool call") (so http.rs:575-579 terminates the stream with encoder.failure(&e)), or — for causes where omission from the final body is approved (e.g., OutputLimit) — emit a valid closing frame (content_block_stop on Messages; on Responses, response.output_item.done with status: "incomplete", skipping the complete-JSON custom-tool validation at encode.rs:475-485) before omitting the incomplete item from the final response. Add frame-sequence assertions to helios/src/server/protocol/tests.rs:3810-4001.
  3. Unapproved reversal of Err("incomplete emitted tool call") for UserStop, Cancelled, and ExecutionError (helios/src/server/output.rs:163-173, 476-480, 1265-1274, 1730-1742, docs/api.md:547-551):

    • drops_unfinished_call(cause) (output.rs:478-480) returns true for every Termination except Eos, silently omitting an already-announced incomplete tool call across all parsers and all three wire protocols instead of returning Err("incomplete emitted tool call").
    • While production HTTP execution errors still travel via GenerationEvent::Error(e) → encoder.failure(&e) (helios/src/server/http.rs:562-579, helios/src/server/runtime.rs:321-329, 2053-2070, 2351-2373), UserStop (matched stop string mid-call) and Cancelled do flow through Encoder::finish — and direct callers of Accumulator/ResponseOutput/Encoder::finish with ExecutionError also now succeed with finish_reason: "stop" / end_turn / completed and no tool_calls after already streaming partial tool frames.
    • The PR renames and inverts the regression test that pinned this invariant (user_stop_cannot_retract_an_already_emitted_partial_tool_call → user_stop_omits_an_already_emitted_partial_tool_call, output.rs:1265-1274) and rewrites docs/api.md:547-551 without an explicit maintainer design decision, contravening AGENTS.md:182-187, 201-207 ("Do not ... suppress errors ... Apply these criteria to documentation and test changes that would weaken the rules as well as code").
    • Fix: Narrow unfinished-call omission to Termination::OutputLimit (consistent with main's docs/api.md:542-543 contract for output-limit truncation) and keep Err("incomplete emitted tool call") plus user_stop_cannot_retract_an_already_emitted_partial_tool_call for UserStop/Cancelled/ExecutionError, or obtain explicit maintainer sign-off before changing that contract.

Should Fix

  1. docs/api.md:543-547 is already factually inaccurate against main (#670 TAGGED_JSON):

    • docs/api.md:543-547 claims that "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."
    • On main, #670 added TAGGED_JSON (helios/src/output/tagged_json.rs:12-66 on main, docs/api.md:610-619 on main), which sets TRIM_NEWLINES = false and JSON_BODY = true, parses the model's {"name": ..., "arguments": ...} JSON object directly without parameter syntax or schema coercion, and re-serializes object["arguments"].to_string().
    • Additionally, docs/api.md:550-551 ("A client that received fragments of such a call has already seen a call that cannot complete.") is commentary rather than wire specification.
    • Fix: Rebase onto main, replace lines 543-547 with a concise, dialect-accurate sentence (e.g., "The other tool parsers publish a call only when its envelope is complete, so their argument events do not imply incremental generation."), and replace lines 550-551 with the concrete wire-framing contract resolved in Blocker #2.
  2. Disclose and obtain maintainer sign-off on relaxing #364's pre-publication 1 MiB bound (docs/api.md:569-572, helios/src/output/dsml.rs:145-156, 189-192):

    • #364 intentionally enforced the 1 MiB combined name+arguments limit before emitting the first tool event (docs/api.md:560 on main: "Helios rejects a larger call before publishing it.").
    • Incremental streaming inherently relaxes this: Event::ToolBegin and earlier Event::ToolArguments fragments are emitted before a later append crosses 1 MiB (dsml.rs:191 still rejects the crossing fragment before publish at :192, and http.rs:575-579 terminates the stream with an error frame).
    • Fix: Call out this #364 contract relaxation explicitly in the PR description and get maintainer sign-off (@voipmonitor / @yatesdr) per AGENTS.md:201-207.

Subtract / Simplify

  1. Eliminate finish(cause) churn across 8 unrelated files (helios/src/server/output.rs:163-173, 476-480, 1730-1742, helios/src/server/protocol/encode.rs:674-677):

    • Adding cause: Termination to Accumulator::finish and ResponseOutput::finish produces mechanical +21/-21 edits across 8 otherwise-untouched files (helios/src/output/{argument_tags,chatml,gemma_call,minimax_xml,pipeline,xtml}.rs, helios/src/runtime_core/protobuf.rs, helios/src/server/runtime/phase_tests.rs) plus 15 test call sites in dsml.rs and output.rs, for a single production caller (encode.rs:674-677).
    • Simplification: Keep Accumulator::finish(&mut self) and ResponseOutput::finish(&mut self) zero-argument, delete drops_unfinished_call, and invoke an explicit truncation method (e.g. drop_unfinished / finish_truncated) only from encode.rs:674-677 for the approved truncation cause(s). This removes 8 files from the PR diff.
  2. Deduplicate new unit test structure in helios/src/output/dsml.rs:940-1032:

    • rejection_tests (dsml.rs:988-1032) duplicates streaming_tests's fixture/imports (dsml.rs:750-763) solely to pass OutputStart::Content, and end_of_sequence_inside_an_announced_call_is_an_error (dsml.rs:1003-1011) overlaps helios/tests/deepseek_output.rs:387-421 (incomplete_calls_do_not_finish_on_eos_and_can_be_cancelled_or_truncated) plus dsml.rs:793.
    • a_truncated_second_call_keeps_the_completed_first_call (dsml.rs:940-960) and a_header_only_call_is_omitted_when_the_response_truncates (dsml.rs:963-984) reuse the exact names of helios/src/server/protocol/tests.rs:3894-3961, 3964-4001; their Accumulator truncation assertions repeat protocol/tests.rs.
    • Simplification: Merge rejection_tests into streaming_tests (keeping a_rejected_argument_object_fails_after_its_fragments_are_published), remove end_of_sequence_inside_an_announced_call_is_an_error, and keep dsml.rs focused on DsmlOutput event assertions under distinct names rather than repeating Accumulator truncation checks.

Nits

  1. ResponseOutput::finish does not check ended: false (helios/src/server/output.rs:1733): Accumulator::finish (:165) checks !call.ended and ResponseOutput::close (:1722) checks Block::Tool { ended: false, .. }, whereas ResponseOutput::finish (:1733) matches Some(Block::Tool { .. }). Currently unreachable because Event::ToolEnd immediately calls close() (:1842-1843), but matching Some(Block::Tool { ended: false, .. }) makes the invariant self-contained.
  2. Extend the end-to-end DSML wire test to Messages and Responses (helios/src/server/protocol/tests.rs:4004-4073): dsml_arguments_reach_the_chat_wire_while_the_call_is_open currently exercises OutputPipeline → Encoder only for Protocol::Chat; covering Protocol::Messages and Protocol::Responses as well would pin incremental input_json_delta and response.function_call_arguments.delta delivery end-to-end.

Dropped on verification