Subtraction & Simplicity audit — PR #685 (dfe38d4)
Verdict: the production diff is lean, and the streaming core is genuinely minimal. Call::publish (helios/src/output/dsml.rs:49-64) is 15 lines and does the whole feature; Event::ToolBegin at ToolNameEnd is 6 added lines (dsml.rs:153-157); the DSML ToolCallArgumentsEnd arm shrank on net (dsml.rs:195-205). No flag, config knob, trait, per-model branch or speculative abstraction is added anywhere in the diff. Everything worth flagging sits in the truncation bookkeeping split across two modules and in test scaffolding — which is where +428 (protocol/tests.rs) and +304 (output/dsml.rs) came from.
Citations are at head dfe38d4; nothing was executed, all statements are static reading of the diff and files.
1. Encoder adds a second, mark-then-clear copy of "this item is abandoned" — HIGH
helios/src/server/protocol/encode.rs:687-707:
let mut abandoned = false;
for change in self.outputs[index].finish(cause)? {
if self.protocol == Protocol::Responses
&& let Change::End(i) = &change
{
let truncated = self.outputs[index].is_abandoned(*i);
if truncated || cause == Termination::OutputLimit {
self.incomplete_item = Some(*i);
}
abandoned |= truncated;
}
frames.extend(self.change(change)?);
}
self.outputs[index].discard_abandoned();
// The buffered response is rendered after this returns, so the marking
// outlives the change that set it unless the item is gone.
if abandoned {
self.incomplete_item = None;
}
Two facts are tracked for the same block: incomplete_item (read later by item() at encode.rs:340-341 when the buffered body is rendered) and the local abandoned, which exists only to undo the first. The undo only exists because one field serves two renders, and abandoned |= plus the post-loop unset is treating a symptom of that: the restore is skipped for every end in the call, not just the last. change() already receives the index, so the abandoned flag can be passed down into item(i, complete) / change(change, abandoned) and incomplete_item left carrying only the OutputLimit case it carried before this PR (which is all encode.rs:695's || adds). That deletes abandoned, truncated, the trailing if abandoned and its three-line comment: ~8 lines and one piece of hidden state.
2. ResponseOutput.abandoned + is_abandoned + discard_abandoned is a channel where a return value would do — MEDIUM/HIGH
helios/src/server/output.rs:1735-1761:
pub fn finish(&mut self, cause: Termination) -> Result<Vec<Change>> {
let mut changes = vec![];
if drops_unfinished_call(cause)
&& let Some(index) = self.open
&& matches!(self.blocks[index], Block::Tool { ended: false, .. })
{
changes.push(Change::End(index));
self.abandoned = Some(index);
self.open = None;
}
self.close(&mut changes)?;
Ok(changes)
}
pub fn is_abandoned(&self, index: usize) -> bool { self.abandoned == Some(index) }
pub fn discard_abandoned(&mut self) {
if self.abandoned.take().is_some() {
self.blocks.pop();
self.calls.pop();
}
}
The index is already fully known inside finish; storing it in a field so the caller can re-read it through is_abandoned (called twice: encode.rs:471 and encode.rs:694) makes a three-method protocol for one value. finish returning (Vec<Change>, Option<usize>) and the caller holding it in a local across the loop removes abandoned, is_abandoned, and discard_abandoned's field entirely. Two concrete defects of the same design: (a) discard_abandoned discards the index it just took and pops positionally — correct only because an abandoned block is always last; let Some(index) = self.abandoned.take() + self.blocks.remove(index) / self.calls.remove(...) is the same line count and states the invariant instead of depending on it; (b) self.open = None; here duplicates the identical line close() executes three lines later (output.rs:1726-1731).
3. The 1 MiB check now runs twice per published fragment — MEDIUM
helios/src/output/dsml.rs:53-54:
fn publish(&mut self, index: usize, events: &mut Vec<Event>) -> Result<()> {
self.check_size()?;
and helios/src/output/dsml.rs:218-220, at the end of every action in apply:
if let Some(call) = &self.call {
call.check_size()?;
}
publish is reached only from the ToolCallArgumentsText arm (dsml.rs:193), whose every path has already run the loop-level check on the previous action and will run it again on this one — so the same inequality is evaluated three times per fragment. Round 4 deliberately moved the check into publish; the loop-level call could then be narrowed to actions that do not publish, or dropped for the text action. check_size is cheap, so this is a legibility item, not perf — but as written a reader has to work out which of two identical guards produces which error ordering (dsml.rs:202 validate precedes :203 publish).
4. custom tracked by a mutable flag, then re-derived anyway — LOW
encode.rs:472-476:
let mut custom = false;
if let Block::Tool { name, arguments, .. } = &self.outputs[0].blocks[i]
&& self.tool(name).is_some_and(|tool| tool.custom)
{
custom = true;
is one expression as matches!: matches!(self.outputs[0].blocks[i], Block::Tool { name, .. } if self.tool(name).is_some_and(|t| t.custom)), leaving arguments bound only inside the if !abandoned body. Five lines to one, no let mut.
5. Test scaffolding duplicates the helper it sits beside — LOW/MEDIUM
helios/src/server/protocol/tests.rs:56-74 re-lists all ten Encoder::new arguments verbatim from encoder_with_parallel (tests.rs:36-53), differing only in tools[0].custom = true; calling encoder_with_parallel(Protocol::Responses, tool_choice, true) and setting encoder.tools[0].custom = true removes ~14 duplicated lines. Same shape in dsml.rs: streaming_tests::config() (dsml.rs:757-763) and rejection_tests::parser() (dsml.rs:987-995) are the same OutputConfig differing only in start, and the two adjacent mods re-import the same five names (dsml.rs:751-755 vs :988-991); one config(start: OutputStart) in a shared #[cfg(test)] mod removes the pair.
6. Trailing blank line at EOF — NIT
helios/tests/deepseek_output.rs:834 — the diff's final hunk adds an empty line after the closing brace, leaving the file ending }\n\n.
Checked and already lean (do not re-raise)
drops_unfinished_call(cause) -> cause != Termination::Eos(output.rs:479-481) is a named predicate, not a boolean threaded through three signatures;Accumulator::finishkeepsmain's&selfshape (output.rs:163-168), so the earlierfinish(cause)churn is genuinely gone.Call::publish's single early return (dsml.rs:55) collapses "literal still open" and "nothing new" correctly;published_argument_bytesis oneusize, not a parallel fragment vector.- Strict tools reuse the existing
strictfield +pending_strict_calls(encode.rs:674-678) with no new flag. Changegained no variant;is_abandoned/discard_abandonedhave exactly the call sites listed above — no dead code, no unreachable branch, no new CLI/config surface (pr_files: 3 source files + 3 docs/tests).BUFFER_LIMIT(dsml.rs:22) is reused by both the call bound and the pending-buffer bound (dsml.rs:234-236) rather than gaining a second constant.
Bottom line: nothing blocks on simplicity grounds. Items 1 and 2 are the ones I would insist on — together they are ~20 lines of two-way bookkeeping (incomplete_item ↔ abandoned) that a single value passed down the change() path replaces, and discard_abandoned currently pops positionally while holding the index that says where to pop.