Review — PR #685 (fix(frontend): stream DeepSeek tool-call arguments), head b9864ab8243b2a54caf0d990f6759b1ddd9ec2db
Lens: Correctness, Contracts & System-Level Consequences. All findings are static reading of the diff at b9864ab and of its callers on that head (nothing executed; no CI run exists on any hash of this branch — noted where it matters). Line numbers are as read at the cited commit.
Key findings
- Blocker — a truncated
custom(grammar) tool call now fails the whole Responses request instead of being omitted:Encoder::finishrenders the abandoned block'sChange::Endthrough the custom-tool branch, whichserde_json::from_strs arguments that are partial JSON by construction (helios/src/server/protocol/encode.rs:475-483reached from:677-689). TheErrpropagates out offinish,helios/src/server/http.rs:575-580turns it into an error frame, anddrop_abandonednever runs. No test covers a custom tool. - Major — the abandoned item is reported as
status: "completed"with partialargumentsfor every non-output-limit cause (encode.rs:339-346,:381,:486,:513-516; onlyOutputLimitsetsincomplete_itemat:680-683), then disappears fromresponse.completed. - Blocker (authorization) — announce-and-stream now precede
validate_argumentsand the 1 MiB bound (helios/src/output/dsml.rs:145-156,:191-206vsmain:171-194), so rejected and oversized calls reach the client before the error; the tests that pinned the old "nothing published before validation" guarantee were rewritten to bless it (helios/tests/deepseek_output.rs:514-515,:572-601;helios/src/server/output.rs:1264-1274). Declared indocs/api.md:547-572, but no maintainer decision on record (AGENTS.md:182-187, 201-207). - Major (docs vs code) —
docs/api.md:547-549states an unconditional omission rule ("for every termination other than natural end-of-sequence") that the required/namedtool_choiceerror atencode.rs:690-694contradicts: the request still ends in an error frame. - Major (docs) —
docs/api.md:543-547is false againstmain: it claims the tagged parsers "build [arguments] from parameter syntax and the declared schemas rather than copying the model's text", butmainnow hashelios/src/output/tagged_json.rs:14-49,57which parses the model's own JSON object. This PR edits those exact lines, so the rebase lands false documentation. - Major/Minor (claim accuracy) — the PR body's "
ExecutionErrorincluded" describes a cause the server never passes toEncoder::finish(onlyUserStop/Eos/OutputLimitare forwarded,http.rs:534-540; errors takehttp.rs:562→failureat:576), and the reported test counts (1787/16,output:: 113,server::protocol 96) are stale for this head, which addsmod streaming_testsandmod rejection_testsindsml.rs:749-1033plus three protocol tests. - Clean, stated plainly: no new locks, channels, global state or blocking on the hot path; publication copies only newly appended bytes within the 1 MiB bound; TTFT/first-response sampling excludes tool-call deltas so the metric's span is unchanged; and the previously reported Messages/Responses unclosed-block framing bug is genuinely fixed (closing frames precede the terminal frame).
1. Correctness, safety & platform parity
F1 — BLOCKER: a truncated custom/grammar tool call errors the request instead of being omitted
helios/src/server/protocol/encode.rs:475-483:
if self.tool(name).is_some_and(|tool| tool.custom) {
let value: Value = serde_json::from_str(arguments)
.map_err(|e| format!("invalid custom tool arguments: {e}"))?;
if !value.get("input").is_some_and(Value::is_string) {
return Err("custom tool input must be text".into());
}
Reached for an abandoned block because Encoder::finish renders changes before dropping the block, helios/src/server/protocol/encode.rs:677-689:
let changes = self.outputs[index].finish(cause)?;
let abandoned = self.outputs[index].take_abandoned();
for change in changes {
...
frames.extend(self.change(change)?);
}
if let Some(block) = abandoned {
self.outputs[index].drop_abandoned(block);
}
ResponseOutput::finish produces that Change::End for the truncated call (helios/src/server/output.rs:1731-1744), and a truncated call's arguments are partial JSON by construction (the fragments were streamed by this very PR). The ? therefore propagates out of Encoder::finish; helios/src/server/http.rs:575-580 converts it:
Err(e) => {
let frame = encoder.failure(&e);
yield Delivery::Failed(e, frame);
return;
}
Impact: a client that has already received response.output_item.added (and argument deltas) for a custom tool gets an error frame and never response.completed/response.incomplete; drop_abandoned never executes, so the truncated call stays in blocks/calls. On main this path was unreachable because close() returned Err("incomplete emitted tool call") instead of emitting Change::End (helios/src/server/output.rs:1721-1730 keeps that behaviour only for EOS and non-tail calls). Custom tools are a real request surface (helios/src/server/inference.rs:68, selected by helios/src/server/protocol/decode.rs:959 (not opened), modelled by encode.rs:24,366,825). New protocol tests only use a plain function tool lookup (helios/src/server/protocol/tests.rs:3823-3827, :3992-3996), so nothing exercises it.
Fix: don't route an abandoned block's Change::End through the custom-tool validation — pass an "abandoned/closing-only" flag into change() and skip from_str/grammar validation, or validate custom input only when the block is ended.
F2 — MAJOR: response.output_item.done for a truncated call claims completed with partial arguments
helios/src/server/protocol/encode.rs:339-346:
let status = if self.incomplete_item == Some(index) {
"incomplete"
} else if complete {
"completed"
} else {
"in_progress"
};
incomplete_item is set only under cause == Termination::OutputLimit (encode.rs:680-683), while Change::End always renders self.item(i, true) (encode.rs:486) and the done frame (encode.rs:513-516), and function tools carry "arguments":if complete{arguments.as_str()}else{""} (encode.rs:381).
Impact: on UserStop, Cancelled or ExecutionError the client receives response.output_item.done with status:"completed" and truncated arguments for an item that then vanishes from response.completed — an item-level inconsistency surviving the (now correct) frame ordering. Fix: set the same incomplete marker for every drops_unfinished_call(cause) cause, or omit arguments/input on abandoned items.
F3 — BLOCKER (contract/authorization): announce-and-stream now precedes validation and the size bound
helios/src/output/dsml.rs:194-206:
OutputAction::ToolCallArgumentsEnd { closing_text } if !repeated => {
let mut call = self.call.take()...;
call.close_literal();
call.arguments.push_str(closing_text);
call.check_size()?;
validate_arguments(&call.arguments)?;
call.publish(self.calls, events);
events.push(Event::ToolEnd { index: self.calls });
Event::ToolBegin is already emitted at ToolNameEnd (dsml.rs:145-156), and fragments are published per text append after check_size (dsml.rs:191-192). On main:171-194 all three events were emitted only after validate_arguments. Consequently a call rejected for nonempty/unique argument names, and a call exceeding the 1 MiB bound, are announced and partly streamed before the request errors, and no byte is retracted.
The tests that pinned the old guarantee were inverted rather than extended:
helios/tests/deepseek_output.rs:514-515:
assert!(error.unwrap().to_string().contains("nonempty and unique"));
assert_eq!(parsed.ended, 0, "a rejected call reported an end");
(main:511 asserted nothing was published at all); helper helios/tests/deepseek_output.rs:572-601 now records events instead of asserting an empty push; helios/src/server/output.rs:1264-1274 renamed user_stop_cannot_retract_an_already_emitted_partial_tool_call (which on main:1262-1270 asserted Err("incomplete emitted tool call")) to user_stop_omits_an_already_emitted_partial_tool_call.
Impact: a wire-level contract change well beyond "stream the arguments" — the client can see a call that provably cannot complete, and the observable error surface for malformed model output moves from "no call" to "announced partial call + error frame". AGENTS.md:182-187 ("Do not remove validation, suppress errors…") and 201-207 ("Apply these criteria to documentation and test changes that would weaken the rules as well as code") make this a maintainer sign-off question; docs/api.md:547-555 declares the behaviour but no decision is on record anywhere in the tracker (cross-PR history in the dossier confirms: no issue, roadmap item, or maintainer request for tool-call streaming, and this reverses the publish-after-check property of merged #364).
Fix: obtain explicit sign-off recorded on the PR, or defer publication until validation completes (buffer, validate, then publish plus fragments).
Platform parity / races
No finding. The change touches no I/O, syscall, path, or threading surface: DsmlOutput, Accumulator/ResponseOutput and Encoder are per-request values built in helios/src/server/http.rs (encoder constructed per stream; DsmlOutput at helios/src/output/dsml.rs:81-95, ResponseOutput at helios/src/server/output.rs:1698-1704, Encoder at helios/src/server/protocol/encode.rs:122-159). No Unix/Windows divergence is introduced.
2. Unintended system-level consequences
F4 — CLEAN (verified, no defect)
- Locks/queues/HOL: no new mutex, channel or shared structure; every touched type is per-request, so no contention or serialization is added on the decode/emit path.
- Memory amplification:
Call::publishcopies only the newly appended slice (helios/src/output/dsml.rs:53-62) against the 1 MiB argument bound (dsml.rs:42-47); the extra cost is oneChange::Deltaper fragment and oneStringper published fragment — bounded by the same 1 MiB, i.e. no unbounded retention. - Failure blast radius: the only widened blast radius is F1 (one truncated custom call turns a truncated-but-valid response into a request-level error). It is per-request, so no cross-request or cross-choice poisoning.
- Metrics/rate span check:
stream_text(helios/src/server/latency.rs:114-142) samples only content/reasoning deltas (delta.content,delta.reasoning_content, text deltas), so tool-call argument frames do not shift first-response/TTFT sampling. Finish reasons and usage come from the accumulator, and a dropped call is simply not counted (encode.rs:695-708). - Ordering: fragments and
ToolEndare pushed into oneVec<Event>in decode order and replayed in order;content_block_stop(encode.rs:424-428) andresponse.output_item.done(:513-516) now precedemessage_stop(:735-739) /response.completed(:740-750) for truncated calls, asserted athelios/src/server/protocol/tests.rs:3861-3876. That earlier unclosed-block framing defect is genuinely fixed. - Known, intended cost (not a defect): SSE frame count is now linear in model fragments rather than in calls (author measured 566 frames / 2196 bytes for one
writeargument). Per-choice withn > 1/parallel_tool_calls, still linear in output bytes.
3. Architecture, contracts & charter compliance
F5 — MAJOR: docs/api.md "omitted for every termination other than EOS" is contradicted by the required/named tool-choice error
docs/api.md:547-549:
An announced call cut off before completion is omitted from a
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.
helios/src/server/protocol/encode.rs:690-694:
if matches!(self.tool_choice, ToolChoice::Required | ToolChoice::Named(_))
&& !self.outputs[index].has_tools()
{
return Err("required tool choice was not satisfied: the model did not produce a completed tool call".into());
}
After drop_abandoned (encode.rs:687-689) the call is gone, so has_tools() is false, the ? returns early, self.reasons[index] is never set (:702), no terminal frame is emitted (:709-752), and http.rs:575-580 yields an error frame. Impact: a streaming tool_choice:"required" request truncated by stop string/cancel/output limit still ends in server_error-style failure, not the documented truncated response — the doc overstates the change. Not a regression versus main (which failed one line earlier with "incomplete emitted tool call"), but it is a new false contract statement. Fix: qualify the sentence with the required/named tool-choice exception, or skip the required-tool error when drops_unfinished_call(cause).
F6 — MAJOR: the tagged-parser sentence this PR edits is false against main (TAGGED_JSON, #670)
docs/api.md:543-547:
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.
main contains helios/src/output/tagged_json.rs, which parses the model's own object and re-serializes it:
let value: Value = serde_json::from_str(trimmed)
.map_err(|error| format!("invalid tagged JSON tool call: {error}"))?;
...
Some(Value::Object(_)) => object["arguments"].to_string(),
(tagged_json.rs:17-18, :37; const JSON_BODY: bool = true; at :57). Impact: the sentence is factually wrong on the branch this PR merges into, and this PR is the one editing those lines (+25/−12 spans docs/api.md:540-575), so the merge lands incorrect documentation about which parsers copy model text. Fix: describe the tagged JSON dialect explicitly (envelope preserved, arguments copied from the model's object) or drop the generalization.
F7 — Charter/authority note (same as F3, recorded separately)
The behavioural change is now documented (docs/api.md:540-572) and tested, but per AGENTS.md:201-207 documenting and testing it does not substitute for a maintainer decision. docs/api.md:568-572 even records the reversal of #364's publish-after-check property in prose ("enforced on the append that crosses it, after the call name and earlier argument fragments were published and are not retracted"). Recommend the PR ask for explicit sign-off from the #364 reviewers rather than merging on the docs change.
4. Tests & claim accuracy
F8 — MAJOR: ExecutionError included describes an unreachable production path
helios/src/server/http.rs:534-540 forwards termination taken from GenerationEvent::Finished; the runtime only produces UserStop, Eos, OutputLimit (helios/src/runtime/…/runtime.rs:2366-2371). Generation errors take GenerationEvent::Error(e) => Err(e) (http.rs:562) → encoder.failure (:576), never finish. So drops_unfinished_call's ExecutionError arm (helios/src/server/output.rs:478-480) and the ExecutionError rows in the new tests (helios/src/server/protocol/tests.rs:3816, :3985) exercise a path the server does not take. Impact: the PR body's "ExecutionError included" overstates live coverage; a reviewer trusting it would think the error path is covered end to end when the error path actually bypasses the drop logic entirely (the client sees the error frame plus whatever fragments were already streamed, and the block is never closed). Fix: correct the claim, or route errors through finish-like cleanup so the accumulated state is discarded deterministically.
F9 — MINOR: stale, self-reported test evidence
The body reports "1787 passed and 16 failed", "output:: suite reports 113 passed", "server::protocol suite 96 passed" — the same numbers as the earlier head, although b9864ab adds mod streaming_tests (helios/src/output/dsml.rs:749-985), mod rejection_tests (dsml.rs:987-1033) and three protocol tests (helios/src/server/protocol/tests.rs:3809-4017). No CI run exists on any hash of the branch. Fix: refresh the numbers at this head and, per charter ("Bring real evidence"), attach a CI run.
F10 — MINOR: tests that should exist for the touched paths
- No test for a truncated custom/grammar tool call on Responses (would have caught F1); the new truncation rows use function tool
lookuponly. - No test for
tool_choice: Required|Named+ truncation (would have caught F5). - F2 (abandoned item status) is untested beyond
OutputLimit. The positive coverage is otherwise good: published-prefix-while-envelope-open, concatenation at every UTF-8 split, rewrittenstring="false"literal, EOS path, schema rejection after fragments, and a DSML→pipeline→Chat encoder end-to-end that reproduces the stored arguments from >2 pre-close frames.
Open questions / not verified
- Whether a truncated
customtool is reachable in the configurations NVIDIA actually serves (it needs acustom-declared tool plus stop-string/cancel/output-limit truncation). The code path is real; exposure is unmeasured. - Whether
Encoder::finish's earlyErrfor required tool choice (F5) or the custom-toolErr(F1) is ever caught upstream and converted into a partial response — I tracedhttp.rs:575-580only; no other caller ofEncoder::finishwas found in this reading. - The full text of the two prior flare-autobot reviews was not retrievable, so whether their "Should fix: 2" / "Subtract/Simplify: 2" items already cover F5/F9 is unknown; their three named blockers (test breakage, SSE framing,
incomplete emitted tool callreversal) are respectively fixed, fixed, and now F3/F7. - Nothing was executed: no test, no served request, no CI artefact. All of the above is static reading at
b9864ab; the author's 566-frame/2196-byte live measurement is taken from the PR body as self-reported. - Issue #347's body remains unreadable from this environment (tool rejected the request arguments), so whether that umbrella tracks the silent-tool-call symptom is unknown.