Subtraction, Simplicity & Conventions review — PR #685 fix(frontend): stream DeepSeek tool-call arguments
Key findings
The production change is small and idiomatic — DsmlOutput::publish is a six-line method with a correct guard, the Event::ToolBegin move is a net deletion, and no new flag, config knob, env var, trait, enum variant, or per-model branch is introduced (so no #267/#334 violation). The subtraction cost sits in the surrounding scaffolding:
- One termination rule is now spelled twice, in two modules, in two directions (high).
drops_unfinished_call(helios/src/server/output.rs:476-480) duplicates the four-armmatches!inTaggedTools::eos_decision(helios/src/output/tagged.rs:247-255);Terminationhas exactly those five variants (helios/src/output.rs:51-58), so the two are logically identical. - A mandatory
causeparameter swept eight unrelated dialect test modules for one production caller (high).Accumulator::finish(output.rs:163) andResponseOutput::finish(output.rs:1730) gainedcause; the only non-test call site isEncoder::finish(helios/src/server/protocol/encode.rs:675,677). - Two new tests exist twice under identical names, once at parser level and once at wire level (medium):
dsml.rs:940vsprotocol/tests.rs:3894, anddsml.rs:963vsprotocol/tests.rs:3964. docs/api.mdnow states the finish-reason mapping twice, and carries a design argument in a specification document (medium).- One added line is dead:
call.check_size()?atdsml.rs:191repeats the loop-tail check atdsml.rs:218-220(medium-low).
Nothing in the diff is speculative generality, an unreferenced fallback, or leftover dead code beyond item 5. Detail on each follows, with the exact lines to delete or replace.
1. One rule, two spellings: drops_unfinished_call vs eos_decision (high)
New helper, helios/src/server/output.rs:476-480:
/// Whether a termination cause drops a tool call that was announced but never
/// completed, instead of reporting it as an incomplete call.
pub(crate) fn drops_unfinished_call(cause: Termination) -> bool {
cause != Termination::Eos
}
The lower layer already classifies exactly the same cause set, helios/src/output/tagged.rs:247-255:
fn eos_decision(&self, cause: Termination) -> EosDecision {
if matches!(
cause,
Termination::Cancelled
| Termination::ExecutionError
| Termination::UserStop
| Termination::OutputLimit
) {
EosDecision::Omit
Termination has exactly those five variants — helios/src/output.rs:51-58: Eos, OutputLimit, UserStop, Cancelled, ExecutionError — so matches!(cause, Cancelled | ExecutionError | UserStop | OutputLimit) is cause != Termination::Eos. The PR now states one policy twice, in two modules, once as an inclusion list and once as an exclusion list. A sixth variant added later would silently change only one of them: eos_decision would fall through to its Reject branch while drops_unfinished_call would start dropping.
What to do: move the predicate down beside the enum, after the enum Termination block at helios/src/output.rs:51-58, as pub(crate) fn drops_unfinished_call(cause: Termination) -> bool; use it in tagged.rs as the first branch of eos_decision (if drops_unfinished_call(cause) { EosDecision::Omit } else if !self.confirmed || self.in_json_string { … }) and delete the four-arm matches!; delete the copy at server/output.rs:476-480. Net: one definition, no behaviour change.
Secondary, same note: both remaining uses of the helper are inside helios/src/server/output.rs (line 164 in finish, line 1731 in ResponseOutput::finish), so even if it stays put, pub(crate) is wider than needed — a private fn suffices today. Only the move to output.rs justifies crate visibility.
2. The finish(cause) parameter sweep: eight files of churn for one caller (high)
Accumulator::finish, helios/src/server/output.rs:163-173:
pub(crate) fn finish(&mut self, cause: Termination) -> Result<()> {
if drops_unfinished_call(cause)
&& self.calls.last().is_some_and(|call| !call.ended)
{
self.calls.pop();
}
if self.calls.iter().any(|call| !call.ended) {
return Err("incomplete emitted tool call".into());
}
Ok(())
}
and the parallel ResponseOutput::finish at helios/src/server/output.rs:1730 (Messages/Responses block emitter, same predicate, self.open cleared before close).
The only production caller is Encoder::finish, helios/src/server/protocol/encode.rs:674-677:
if self.protocol == Protocol::Chat {
self.chats[index].finish(cause)?;
}
for change in self.outputs[index].finish(cause)? {
Every other call site in the tree is a test passing the constant Termination::Eos. Eight of the thirteen changed files exist only so that argument can be threaded through unrelated dialect test modules:
helios/src/output/argument_tags.rs:212, 287, 334, 435, 490helios/src/output/chatml.rs:418, 650, 833, 1097(verified in diff:self.output.finish()→self.output.finish(Termination::Eos))helios/src/output/gemma_call.rs:265(not opened)helios/src/output/minimax_xml.rs:346helios/src/output/pipeline.rs:345, 492, 580, 685, 738(verified in diff: five identical one-token edits)helios/src/output/xtml.rs:464, 508helios/src/runtime_core/protobuf.rs:1160helios/src/server/runtime/phase_tests.rs:765, 973
That is roughly sixty call sites, none of which cares about cause, and every one of them now asserts "this call ended naturally" as a literal. AGENTS.md:188-193 is explicit: "Reject unsupported abstractions and churn… Unsolicited formatting, renaming, comment expansion, annotation sweeps, and file rearrangements are not contributions by themselves. Refactoring must directly support the requested behavior…"
What to do: keep finish() argument-free and add one explicit method per type — pub(crate) fn drop_unfinished_call(&mut self) on Accumulator holding exactly the pop now inlined at output.rs:164-168, and the equivalent on ResponseOutput at output.rs:1731-1738 — then in Encoder::finish:
if drops_unfinished_call(cause) {
if self.protocol == Protocol::Chat {
self.chats[index].drop_unfinished_call();
}
self.outputs[index].drop_unfinished_call();
}
This deletes the parameter threading, reverts the eight mechanical files to zero diff, and makes the state change explicit at the one place that actually owns the cause, instead of being a hidden side effect of finish(). The Err("incomplete emitted tool call") guard then stays a pure invariant check inside finish().
Honest counterweight: ModelOutput::finish and ReasoningParser/ToolCallParser::finish already take cause: Termination in the same crate (helios/src/output.rs:92, 97), so threading cause is stylistically consistent with the layer below and a reviewer may accept it. The objection is specifically the eight-file churn for a single production caller — the sweep is the cost, not the signature itself.
3. Two test functions duplicated under identical names (medium)
Two added tests exist twice, with the same name, once at parser level and once at wire level:
a_truncated_second_call_keeps_the_completed_first_call
helios/src/output/dsml.rs:939-960— parser +Accumulator, loopsOutputLimit/UserStop/ExecutionError, asserts reasoning preserved and one remaining call{"path": "a.txt"}.helios/src/server/protocol/tests.rs:3894-3961—Encoder+ all three protocols × three causes, asserts exactly the same one-call-survives contract per protocol, including Chatfinish_reason.
a_header_only_call_is_omitted_when_the_response_truncates
helios/src/output/dsml.rs:962-984— assertsToolBeginannounced,arguments(&events).is_empty(),message().get("tool_calls").is_none().helios/src/server/protocol/tests.rs:3964-4001— asserts the announcement frame count and the same empty-body outcome for Chat/Messages/Responses.
The wire-level copies strictly subsume the parser-level copies (they exercise the encoder, the finish-reason mapping, and all three protocols), and the parser-level truncation contract is already asserted by the third test, a_truncated_call_keeps_its_published_fragments_and_omits_the_stored_call (dsml.rs:916-937).
What to do: delete helios/src/output/dsml.rs:939-984 (~46 lines). Identical test names in two modules also make cargo test <name> run two tests and make a failure ambiguous about which layer broke.
Lower value, related: published_fragments_reconstruct_the_stored_arguments_at_every_split (dsml.rs:845-888) re-checks concatenation the new end-to-end dsml_arguments_reach_the_chat_wire_while_the_call_is_open (protocol/tests.rs:4004+) already checks, and a_call_opens_and_publishes_arguments_before_its_envelope_closes (dsml.rs:792-842) char-feeds the same fixture for a prefix assertion that the every-split test's tail also makes (dsml.rs:883-887). Merging those two would retain the coverage and drop most of ~100 lines; the streaming_tests module is ~285 lines of tests for a ~60-line production change. This is judgement, not a rule — leave it if the author values the parser-level locality.
4. docs/api.md: duplicated finish-reason rule plus a design argument (medium)
New text, docs/api.md:547-551:
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. A client that received fragments of such a
call has already seen a call that cannot complete. At natural completion,
restates the mapping already specified thirty lines later, docs/api.md:580-589:
The terminal event carries a termination cause, and each protocol maps the
cause to its finish reason. An output limit reports `length` on Chat
Completions and `max_tokens` on Messages, and `incomplete` with
`incomplete_details.reason` `max_output_tokens` on Responses, even when parsed
calls completed the answer.
Two statements of one finish-reason rule in one section will drift; the second paragraph is the normative one and names every protocol.
Second, docs/api.md:550-551 ("A client that received fragments of such a call has already seen a call that cannot complete.") is an argument for the design, not a statement of designed behaviour, and it omits the fact a client actually needs: the Messages content_block_start / Responses output_item.added already emitted for that abandoned call never receive their content_block_stop / output_item.done. AGENTS.md:52-60 requires that repository documents specify architecture or instruct agents, and forbids investigation logs and progress notes.
What to do: cut the new paragraph at docs/api.md:547-551 down to the new fact ("an announced call cut off before completion is omitted from a buffered response; only natural end-of-sequence reports it as an error"), move the finish-reason consequence next to the existing paragraph at docs/api.md:580-589 where stop/length/stop_reason are defined, and replace the persuasion sentence with the terminal event a client should expect for the abandoned block — or drop it.
Flag, not a simplification: docs/api.md:570-572 now documents the 1 MiB bound tripping after publication ("The bound is enforced on the append that crosses it, after the call name and earlier argument fragments were published and are not retracted"), the exact reverse of #364's reviewed property (bound checked before the first tool event). The text is honest; the concern is that it is presented as a new contract rather than a deliberate relaxation, which AGENTS.md:182-187 reserves for an explicit maintainer decision — @voipmonitor (author of #364) and @yatesdr (reviewer) are the people to ask.
5. One redundant line in the argument-text arm (medium-low)
helios/src/output/dsml.rs:189-193:
call.arguments.push_str(source);
}
call.check_size()?;
call.publish(self.calls, events);
}
call.check_size()? at dsml.rs:191 duplicates the check the loop already performs after every action, dsml.rs:218-220 (present on main, unchanged by this PR):
if let Some(call) = &self.call {
call.check_size()?;
}
Nothing between them mutates call.arguments or call.name — publish only reads arguments and writes published_argument_bytes — so both calls test identical state and return the identical error, and apply returns Err without emitting events, so the earlier position buys no "do not publish past the bound" guarantee anyway.
What to do: delete dsml.rs:191, keeping call.publish(self.calls, events) at 192. The other added check, dsml.rs:201, must stay: the ToolCallArgumentsEnd arm take()s the call at dsml.rs:195-198, so the trailing check at 218 no longer sees it.
What I checked and found already lean
Read in full or in the changed regions: helios/src/output/dsml.rs (production body 30-278 and 376-395, plus the new tests 785-1032), helios/src/server/output.rs (155-185, 460-495, ResponseOutput::finish at 1730), helios/src/server/protocol/encode.rs (540-720), helios/src/server/protocol/tests.rs (3885-4010), docs/api.md (528-596), all eight mechanical diffs, AGENTS.md, and the charter.
publish()is minimal and correct,helios/src/output/dsml.rs:49-62: six lines of body, one early return covering both "a literal may still be rewritten" and "nothing new", and it advances the cursor. No wrapper, no flag, no option.- The
Event::ToolBeginmove is a net deletion —dsml.rs:151-155adds one push and the old site atToolCallArgumentsEndloses its construction, so the PR removes more lines than it adds there. - No new generality. No trait, no enum variant, no
ToolCallParsermethod, no per-model branch; the streaming asymmetry is documented rather than branched on. The peer emitters that still publish atomically (tagged.rs:262-275 emit_calls,xtml.rs:205-216,tml.rs:357-368) remain the contract for their dialects, not dead code. - Strict-tool parking is untouched (
encode.rs:564-621), so the earlyToolBegincannot leak a frame ahead of schema validation — no new suppression branch was needed or added. drops_unfinished_callis not a per-dialect knob, consistent with the charter's no-per-model-branch rule (#267, #334). Its problem is duplication (finding 1), not proliferation.
Open questions
- Is the
finish(cause)shape deliberate consistency? It matchesModelOutput::finish(cause)(helios/src/output.rs:92,97), so if the author chose it to mirror the parser trait, the finding reduces to the eight-file churn rather than the signature. The author's answer should decide between finding 2's two options. - Has the truncation-semantics change been agreed with the owners? The inverted test (
user_stop_cannot_retract_an_already_emitted_partial_tool_call→user_stop_omits_an_already_emitted_partial_tool_call) and the reversed #364 bound are policy decisions no issue or review records; the natural reviewers (@voipmonitor, @yatesdr) have not engaged. - Is the duplicate-test deletion safe for the author's intent? The wire copies are strictly broader, but the author may want parser-level locality for future dialect work — worth asking rather than asserting.
- Nothing found on whether
flare/flare-clistill build (the changed signatures are crate-internal; the author did not build them), and no CI run corroborates the flaky-engram claim.