Final review report · NVIDIA/hyperflare-inference #685

Raw Markdown for agents: https://autobot.eidonix.com/p/5e6f2bd5-3139-402b-a853-b6f6170dace0.md

Recommendation: Changes Requested

The core streaming mechanism in DsmlOutput (Call::publish with published_argument_bytes and literal deferral for string="false" values) is small, clean, and directly addresses the stalled-stream UX for multi-kilobyte DeepSeek tool calls while keeping strict-tool parking intact. However, this PR cannot merge as-is: it breaks four existing integration tests in helios/tests/ that were skipped because only --lib was run, leaves already-announced Messages/Responses tool blocks permanently unclosed (content_block_stop / response.output_item.done never emitted) when a call is truncated, and reverses reviewed pre-publication and retraction invariants without maintainer sign-off or explicit before/after disclosure in the PR description.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Four existing integration tests in helios/tests/ fail on head 2f0ed9d

    • helios/tests/deepseek_output.rs:476-512 (empty_and_duplicate_top_level_parameter_names_are_rejected), helios/tests/deepseek_output.rs:568-593, 596-619, 622-635 (parse_literal_parameters, called by tool_call_size_includes_retained_strings_and_closing_brace_in_either_order and literal_nesting_includes_the_enclosing_argument_object), and helios/tests/deepseek_requests.rs:652-687 (added_non_special_dsml_token_produces_tool_calls).
    • Verified behavior/impact: Because the PR only ran cargo test ... --lib, all integration tests in helios/tests/ were skipped, whereas CI (.github/workflows/native-serving.yml:63 (not opened),68) runs cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --features runtime-core,server:
      1. deepseek_output.rs:511 asserts assert!(published.is_empty()) when feeding char-by-char input with empty or duplicate parameter names; DsmlOutput::apply (dsml.rs:145-156) now emits Event::ToolBegin at ToolNameEnd before parameters are parsed, so published is non-empty and the assertion panics.
      2. deepseek_output.rs:576 asserts assert!(output.push(Input::Text(&header))?.is_empty()) on "{open}<|DSML|{s}invoke name=\"lookup\">", which now emits Event::ToolBegin and panics immediately (and :581 asserts .is_empty() across multi-parameter string="false" pushes even though the next parameter's ArgumentSeparator closes the previous literal and publishes on the next parameter key, breaking both tool_call_size_includes_retained_strings_and_closing_brace_in_either_order and literal_nesting_includes_the_enclosing_argument_object).
      3. deepseek_requests.rs:683-684 feeds "Berlin" one byte-token at a time via the zero-merge byte-level BPE fixture (:37-53) and evaluates serde_json::from_str::<Value>(text).unwrap() on each individual Event::ToolArguments event; the first fragment is "{\"location\": \"B", so .unwrap() panics.
    • Fix: Run the full helios release test suite (without --lib), plus flare and flare-cli per docs/design-review.md:180-185. Update deepseek_requests.rs:683-684 to concatenate Event::ToolArguments fragments (matching lines 875-882 in the same file), and update deepseek_output.rs:511, 568-593 once maintainers sign off on the relaxed pre-publication contract (see Should Fix #1).
  2. Truncating an announced tool call leaves Messages and Responses SSE streams with unclosed blocks/items

    • helios/src/server/output.rs:1720-1742, helios/src/server/protocol/encode.rs:409-415, 424-429, 430-434, 470-517, 677-684, 730-745, helios/src/server/http.rs:526-573.
    • Verified behavior/impact: When Event::ToolBegin arrives, Encoder::change immediately yields content_block_start (Messages, encode.rs:411-414) or response.output_item.added (Responses, encode.rs:431-434) over SSE (http.rs:571-573), followed by input_json_delta / response.function_call_arguments.delta frames. When OutputLimit, UserStop, Cancelled, or ExecutionError then triggers Encoder::finish, ResponseOutput::finish(cause) (output.rs:1730-1742) pops self.blocks and self.calls and sets self.open = None before calling self.close(&mut changes)?, returning an empty Vec<Change>. Encoder::finish therefore emits message_delta + message_stop (Messages) without content_block_stop, and response.incomplete/response.completed (Responses) with "output": [] without response.output_item.done (affecting both function tools and custom tools at encode.rs:366-386). On main, this path returned Err("incomplete emitted tool call") and emitted a terminal error frame (error / response.failed); converting it to a "successful" terminal stream without closing the opened block violates both SSE grammars. The new truncation tests (helios/src/server/protocol/tests.rs:3809-3891, 3964-4001) only assert !finished.is_empty() and encoder.response(), so they do not detect the missing close frames.
    • Fix: Emit the terminal per-block close frame before omitting the unfinished tool block from the final buffered body (e.g., an explicit Change::Abort(i) or closing before popping): emit content_block_stop { index: i } for Messages, and response.output_item.done with status: "incomplete" for Responses (bypassing the custom-tool JSON/grammar validation at encode.rs:475-485 for aborted calls so truncated custom-tool JSON does not turn an omission into a parse error). Add stream-framing assertions to protocol/tests.rs:3809-4001 (following messages_stream_reconstructs_ordered_buffered_blocks at :1098-1152 and :1195-1200) verifying every content_block_start has a matching content_block_stop and every response.output_item.added has a matching response.output_item.done.

Should Fix

  1. Obtain explicit maintainer sign-off and document the contract reversals in the PR description (AGENTS.md:88-93, 182-187, 204-207)
    • helios/src/server/output.rs:163-173, 1265-1274, helios/src/output/dsml.rs:191-205, docs/api.md:540-555, 570-572.
    • Streaming DSML calls before </|DSML|invoke> inherently reverses three previously tested guarantees:
      1. #364 (authored by @voipmonitor, reviewed by @yatesdr): the 1 MiB call-size check previously ran before emitting any tool event (docs/api.md:560 on main, helios/tests/deepseek_output.rs:596-619), whereas now earlier fragments are published before the oversized append fails (docs/api.md:570-572).
      2. validate_arguments (dsml.rs:202, 398-426) runs at ToolCallArgumentsEnd, so duplicate or empty parameter names now stream ToolBegin and partial ToolArguments before returning a delivery error (http.rs:575-579), breaking deepseek_output.rs:511.
      3. Truncating an already-announced call (OutputLimit, UserStop, Cancelled, ExecutionError) previously returned Err("incomplete emitted tool call") (server_error) as asserted by user_stop_cannot_retract_an_already_emitted_partial_tool_call (server/output.rs:1257-1271 on main), whereas now Accumulator::finish / ResponseOutput::finish succeed with a cause-derived finish_reason ("length", "stop", or "tool_calls" when an earlier call completed, encode.rs:690-696) while dropping the partial call from encoder.response() — meaning streaming Chat clients receive a tool_calls[0] header/fragment delta that the final buffered message omits.
    • Fix: Request explicit sign-off from @voipmonitor and @yatesdr on (a) relaxing #364's pre-publication 1 MiB and key-validation guarantees for streamed DSML calls, and (b) whether truncated streamed calls should omit-and-succeed vs error (and how Chat/Messages/Responses streaming vs buffered parity is defined). Update the PR description to state these before/after behavioral reversals explicitly, and rebase onto main so docs/api.md:543-547 accurately reflects #670's TAGGED_JSON parser (which buffers JSON objects rather than parameter syntax).

Subtract / Simplify

  1. Avoid the 8-file mechanical finish(Termination::Eos) sweep (AGENTS.md:188-193)
    • helios/src/server/output.rs:163-173, 1730-1742, helios/src/server/protocol/encode.rs:674-677, plus 21 one-token test edits across argument_tags.rs, chatml.rs, gemma_call.rs, minimax_xml.rs, pipeline.rs, xtml.rs, runtime_core/protobuf.rs, and server/runtime/phase_tests.rs.
    • Encoder::finish (encode.rs:675, 677) is the sole production caller that owns cause. Keeping Accumulator::finish(&self) and ResponseOutput::finish(&mut self) parameter-free and adding an explicit drop_unfinished_call / abort_unfinished_call method called from Encoder::finish (and test helper Presentation::finish) when cause.omits_unfinished_call() reverts all 8 unrelated files to zero diff and keeps finish() a pure invariant check.
  2. Unify drops_unfinished_call with TaggedTools::eos_decision
    • helios/src/server/output.rs:478-480 vs helios/src/output/tagged.rs:247-255 and helios/src/output.rs:51-58.
    • Termination has exactly five variants (Eos, OutputLimit, UserStop, Cancelled, ExecutionError), so cause != Termination::Eos (server/output.rs:479) and matches!(cause, Cancelled | ExecutionError | UserStop | OutputLimit) (tagged.rs:248-254) express the exact same policy in two modules with opposite polarities. Move the method onto Termination in helios/src/output.rs:58 (e.g., pub(crate) fn omits_unfinished_call(self) -> bool { self != Self::Eos }), use it in both tagged.rs:248 and server/output.rs, and delete server/output.rs:476-480 (which is currently unnecessarily pub(crate) for same-file callers).
  3. Delete the redundant call.check_size()? at helios/src/output/dsml.rs:191
    • helios/src/output/dsml.rs:191-192 vs helios/src/output/dsml.rs:218-220.
    • apply() writes into a local events Vec owned by push() (:359) or finish() (:387) that is discarded whenever apply() returns Err. call.publish (:192) does not mutate call.name or call.arguments, so :218-220 checks identical state and discards events on overflow identically. Delete :191 (keep :201 in ToolCallArgumentsEnd, where self.call.take() at :196 bypasses :218).
  4. Deduplicate docs/api.md finish-reason text
    • docs/api.md:547-551 duplicates the normative finish-reason mapping already defined at docs/api.md:580-589, and line 550-551 ("A client that received fragments of such a call has already seen a call that cannot complete") omits the concrete wire framing behavior clients must handle. Keep only the omission rule at :547-549, cross-reference :580-589 for finish reasons, and state the exact terminal SSE event behavior once Blocker #2 is fixed.

Nits

Dropped on verification