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
- Guaranteed Linux and Windows CI failure in
helios/tests/:.github/workflows/native-serving.yml:63 (not opened), 68run the fullheliostest target without--lib; four existing integration tests inhelios/tests/deepseek_output.rsandhelios/tests/deepseek_requests.rsassert pre-streaming DSML behavior and will fail. - SSE protocol-framing violation on streaming truncation:
ResponseOutput::finish(helios/src/server/output.rs:1730-1742) drops an openBlock::Toolbeforeclose(), so Messages and Responses streams sendmessage_stop/response.completed/response.incompletewhile a previously announcedcontent_block_startorresponse.output_item.addedremains permanently unclosed and vanishes fromresponse.output. - No runtime concurrency, memory amplification, or TTFT regressions: All modified state (
DsmlOutput,Accumulator,ResponseOutput,Encoder) is strictly per-request (helios/src/server/http.rs:451-600),Call::publishslices only newly appended bytes within the 1 MiB buffer (O(n) total allocation), strict-tool parking (helios/src/server/protocol/encode.rs:585-624) still withholds all frames until schema validation passes, andstream_text(helios/src/server/latency.rs:116-142) excludes tool-call deltas so TTFT metrics are unaffected.
Walkthrough
- Incremental DSML tool-call streaming (
helios/src/output/dsml.rs:38, 49-62, 145-156, 191-206): EmitsEvent::ToolBeginatOutputAction::ToolNameEnd, tracksCall::published_argument_bytesand publishesEvent::ToolArgumentsfragments after eachToolCallArgumentsTextappend (while withholdingstring="false"literals untilclose_literalsettles them), and flushes remaining bytes plusEvent::ToolEndaftervalidate_argumentsatToolCallArgumentsEnd. - Unfinished-call omission on non-EOS termination (
helios/src/server/output.rs:163-173, 476-480, 1730-1742,helios/src/server/protocol/encode.rs:674-677): Addsdrops_unfinished_call(cause) -> cause != Termination::Eosand threadscauseintoAccumulator::finishandResponseOutput::finishto pop an open trailing tool call instead of returningErr("incomplete emitted tool call"). - Mechanical test call-site churn and inverted retraction test (9 files): Updates
output.finish()→output.finish(Termination::Eos)acrosshelios/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,dsml.rs, andoutput.rs, and rewritesuser_stop_cannot_retract_an_already_emitted_partial_tool_callintouser_stop_omits_an_already_emitted_partial_tool_call(helios/src/server/output.rs:1265-1274). - New unit tests and API documentation (
helios/src/output/dsml.rs:749-1033,helios/src/server/protocol/tests.rs:3809-4073,docs/api.md:540-574): Adds DSML streaming/truncation/rejection tests and Chat/Messages/Responses buffered truncation tests plus an end-to-end DSML→Chat wire test, and updatesdocs/api.mdfor DSML streaming, non-EOS omission, and post-publication 1 MiB enforcement.
Pre-merge Checks
- [PASS] Security / malicious screen: No unsafe code, external I/O, or instruction-hijacking patterns; 1 MiB parser (
dsml.rs:22, 42-47, 234-236) and 8 MiB response (output.rs:119-121, 1817-1819) bounds remain enforced. - [WARN] Charter & value fit: Streaming DSML arguments directly serves the charter's coding-agent/heavy-tool-use vision with no per-model shared-layer branch, but no issue or maintainer request is linked, and the PR reverses reviewed error/pre-publication invariants (
user_stop_cannot_retract_an_already_emitted_partial_tool_calland#364) without maintainer sign-off (AGENTS.md:182-187, 201-207). - [WARN] Related / duplicate / conflict check: No duplicate PR and no textual merge conflict with
#670(itsdocs/api.mdedits begin at line 586 onmainand itsdsml.rsedits are ingrammar_envelope), but#670addedTAGGED_JSONafter the branch point, makingdocs/api.md:543-547factually false againstmain. - [WARN] Tests & verification evidence: Only
cargo test ... --libwas run (missing the 4 failing integration tests inhelios/tests/), 16 tests failed locally (6 missingFLARE_TEST_TEMPLATE_DIR, 10 parallel engram tests), andflare/flare-cliwere not built or tested (docs/design-review.md:180-185).
Blockers
-
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 inhelios/tests/. helios/tests/deepseek_output.rs:576, 581(parse_literal_parameters, used bytool_call_size_includes_retained_strings_and_closing_brace_in_either_orderat:596-619andliteral_nesting_includes_the_enclosing_argument_objectat:622-635): assertsoutput.push(Input::Text(&header))?.is_empty()andoutput.push(Input::Text(¶meter))?.is_empty().ToolNameEndnow emitsEvent::ToolBegin(helios/src/output/dsml.rs:145-156) and parameter key text emitsEvent::ToolArguments(dsml.rs:191-192), failing both assertions.helios/tests/deepseek_output.rs:510-511(empty_and_duplicate_top_level_parameter_names_are_rejected): assertspublished.is_empty()after duplicate/empty key rejection, butEvent::ToolBeginand early argument fragments are now emitted beforevalidate_argumentsruns atToolCallArgumentsEnd(dsml.rs:151-155, 192, 202).helios/tests/deepseek_requests.rs:683-684(added_non_special_dsml_token_produces_tool_calls): runsserde_json::from_str::<Value>(text).unwrap()on a singleEvent::ToolArgumentsevent, which panics now that individual events carry partial JSON fragments.- Fix: Update these four integration tests to match incremental DSML emission (collect/verify streamed
ToolBeginand concatenatedToolArguments, verify noToolEndis emitted on rejected/oversized calls) and verify with the full CI test commands acrosshelios,flare, andflare-cli(docs/design-review.md:180-185).
- CI runs
-
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::applyemitsChange::Start(i)onEvent::ToolBegin(output.rs:1792-1802), which sendscontent_block_starton Messages (encode.rs:409-415) andresponse.output_item.addedon Responses (encode.rs:430-434).- On non-EOS termination,
ResponseOutput::finish(output.rs:1730-1742) popsself.blocks, popsself.calls, and setsself.open = Nonebefore callingself.close(&mut changes)(output.rs:1720-1729), which is the sole producer ofChange::End(i)— andChange::End(i)is the sole producer ofcontent_block_stop(encode.rs:424-429) andresponse.output_item.done(encode.rs:470-517). Encoder::finish(encode.rs:730-745) then unconditionally sendsmessage_delta/message_stop(withstop_reason: "end_turn"/"max_tokens"/"stop_sequence") orresponse.incomplete/response.completed(whoseresponse.outputomits 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-4001miss this because they assert onlyencoder.response()and!finished.is_empty(), never the emitted frame sequence. - Fix: Do not emit terminal
message_stop/response.completed/response.incompleteframes while a previously announced block/item is unclosed. Either preserveErr("incomplete emitted tool call")(sohttp.rs:575-579terminates the stream withencoder.failure(&e)), or — for causes where omission from the final body is approved (e.g.,OutputLimit) — emit a valid closing frame (content_block_stopon Messages; on Responses,response.output_item.donewithstatus: "incomplete", skipping the complete-JSON custom-tool validation atencode.rs:475-485) before omitting the incomplete item from the final response. Add frame-sequence assertions tohelios/src/server/protocol/tests.rs:3810-4001.
-
Unapproved reversal of
Err("incomplete emitted tool call")forUserStop,Cancelled, andExecutionError(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) returnstruefor everyTerminationexceptEos, silently omitting an already-announced incomplete tool call across all parsers and all three wire protocols instead of returningErr("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) andCancelleddo flow throughEncoder::finish— and direct callers ofAccumulator/ResponseOutput/Encoder::finishwithExecutionErroralso now succeed withfinish_reason: "stop"/end_turn/completedand notool_callsafter 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 rewritesdocs/api.md:547-551without an explicit maintainer design decision, contraveningAGENTS.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 withmain'sdocs/api.md:542-543contract for output-limit truncation) and keepErr("incomplete emitted tool call")plususer_stop_cannot_retract_an_already_emitted_partial_tool_callforUserStop/Cancelled/ExecutionError, or obtain explicit maintainer sign-off before changing that contract.
Should Fix
-
docs/api.md:543-547is already factually inaccurate againstmain(#670TAGGED_JSON):docs/api.md:543-547claims 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,#670addedTAGGED_JSON(helios/src/output/tagged_json.rs:12-66onmain,docs/api.md:610-619onmain), which setsTRIM_NEWLINES = falseandJSON_BODY = true, parses the model's{"name": ..., "arguments": ...}JSON object directly without parameter syntax or schema coercion, and re-serializesobject["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 lines543-547with 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 lines550-551with the concrete wire-framing contract resolved in Blocker #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):#364intentionally enforced the 1 MiB combined name+arguments limit before emitting the first tool event (docs/api.md:560onmain: "Helios rejects a larger call before publishing it.").- Incremental streaming inherently relaxes this:
Event::ToolBeginand earlierEvent::ToolArgumentsfragments are emitted before a later append crosses 1 MiB (dsml.rs:191still rejects the crossing fragment beforepublishat:192, andhttp.rs:575-579terminates the stream with an error frame). - Fix: Call out this
#364contract relaxation explicitly in the PR description and get maintainer sign-off (@voipmonitor/@yatesdr) perAGENTS.md:201-207.
Subtract / Simplify
-
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: TerminationtoAccumulator::finishandResponseOutput::finishproduces mechanical+21/-21edits 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 indsml.rsandoutput.rs, for a single production caller (encode.rs:674-677). - Simplification: Keep
Accumulator::finish(&mut self)andResponseOutput::finish(&mut self)zero-argument, deletedrops_unfinished_call, and invoke an explicit truncation method (e.g.drop_unfinished/finish_truncated) only fromencode.rs:674-677for the approved truncation cause(s). This removes 8 files from the PR diff.
- Adding
-
Deduplicate new unit test structure in
helios/src/output/dsml.rs:940-1032:rejection_tests(dsml.rs:988-1032) duplicatesstreaming_tests's fixture/imports (dsml.rs:750-763) solely to passOutputStart::Content, andend_of_sequence_inside_an_announced_call_is_an_error(dsml.rs:1003-1011) overlapshelios/tests/deepseek_output.rs:387-421(incomplete_calls_do_not_finish_on_eos_and_can_be_cancelled_or_truncated) plusdsml.rs:793.a_truncated_second_call_keeps_the_completed_first_call(dsml.rs:940-960) anda_header_only_call_is_omitted_when_the_response_truncates(dsml.rs:963-984) reuse the exact names ofhelios/src/server/protocol/tests.rs:3894-3961, 3964-4001; theirAccumulatortruncation assertions repeatprotocol/tests.rs.- Simplification: Merge
rejection_testsintostreaming_tests(keepinga_rejected_argument_object_fails_after_its_fragments_are_published), removeend_of_sequence_inside_an_announced_call_is_an_error, and keepdsml.rsfocused onDsmlOutputevent assertions under distinct names rather than repeatingAccumulatortruncation checks.
Nits
ResponseOutput::finishdoes not checkended: false(helios/src/server/output.rs:1733):Accumulator::finish(:165) checks!call.endedandResponseOutput::close(:1722) checksBlock::Tool { ended: false, .. }, whereasResponseOutput::finish(:1733) matchesSome(Block::Tool { .. }). Currently unreachable becauseEvent::ToolEndimmediately callsclose()(:1842-1843), but matchingSome(Block::Tool { ended: false, .. })makes the invariant self-contained.- 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_opencurrently exercisesOutputPipeline→Encoderonly forProtocol::Chat; coveringProtocol::MessagesandProtocol::Responsesas well would pin incrementalinput_json_deltaandresponse.function_call_arguments.deltadelivery end-to-end.
Dropped on verification
- Subtraction candidate ("Delete duplicate
call.check_size()?;athelios/src/output/dsml.rs:191"): Dropped —:191runs beforecall.publish(self.calls, events)at:192. Removing it would allow:192to allocate up to ~1 MiB for the oversized suffix and mutatecall.published_argument_bytesbefore:218-220rejects the call; keeping:191prevents wasted allocation and state mutation on the error path at negligible cost. - Correctness candidate ("
ExecutionErroris the sharpest production path; agent loops cannot distinguish execution failure from empty output"): Dropped/corrected — verified inhelios/src/server/http.rs:562-579andhelios/src/server/runtime.rs:321-329, 2053-2070, 2351-2373that runtime execution errors arrive asGenerationEvent::Error(e)and terminate viaencoder.failure(&e), neverencoder.finish(..., Termination::ExecutionError, ...). Blocker #3 scopes the production impact accurately toUserStop/Cancelled(plus directfinishcallers passingExecutionError). - Correctness candidate ("Fix
#364reversal by reserve-and-check before appending/publishing" and "oversized calls leave the tool block unclosed per F1"): Dropped —dsml.rs:191already checks the size bound before publishing the crossing fragment at:192, and no incremental streaming parser can know ahead of time whether a later token will cross 1 MiB without buffering the full call; furthermore, whencheck_size()errors mid-stream,http.rs:575-579emitsencoder.failure(&e)rather than takingResponseOutput::finish. - Correctness candidate ("
docs/api.md:540-542overreaches by omittingstrict: truetools"): Dropped —docs/api.md:753-755already explicitly documents that Helios buffers strict tool calls until validated and never sends partial strict arguments in streaming responses. - Correctness candidate ("Test-count drift 1783/18 → 1787/16 across content-identical push"): Dropped as low-signal; the concrete verification gap is captured in Blocker #1 (4 failing
helios/tests/integration tests skipped by--lib) and Pre-merge Checks (unbuiltflare/flare-cli). - Subtraction candidate ("
dsml.rs:940, 963are pure duplicates ofprotocol/tests.rs:3894, 3964"): Partially corrected — thedsml.rstests exercise realDsmlOutputparsing rather than syntheticEvents, so only their colliding names and duplicatedAccumulatortruncation assertions were retained under Subtract / Simplify #2.