Streaming drops XML tool-call output that non-streaming parses correctly Streaming must…
- User
Streaming drops XML tool-call output that non-streaming parses correctly
Streaming must emit the same recovered XML tool calls as non-streaming, including calls split across chunks and multiple calls, and finish with
tool_calls. Reasoning mode and request tool selection must not alter recovery. Plain text or malformed markup must not create calls or abort the stream.Interface
No new interfaces are introduced.
- Assistant
I'll investigate how XML tool-call recovery differs between streaming and non-streaming paths in the codebase.
- Assistant
Identifying the issue: several XML parsers only detect closing tags in
delta_text, so split</tool_call>chunks are missed; Hermes also slices by close-marker count instead of parsed tool-call count. I'll add a shared close-marker helper and update the affected parsers. - Assistant
The root cause is false-positive parses on incomplete XML; I'll track emitted count in parser state instead of re-parsing
previous_text. - Assistant
The test reused parser state across chunk sizes; I'll reset the parser between iterations.
- Assistant
Fixed streaming XML tool-call recovery so it matches non-streaming behavior.
Root cause
Several XML parsers only looked for closing tags inside the current
delta_text. When</tool_call>or</function>was split across chunks, completion was never detected and tool calls were dropped.A second issue: deduping by re-parsing
previous_textfailed when parsers with fallback patterns (Hermes, Auto) false-positively parsed incomplete markup before the close tag arrived, so the real completion was treated as already emitted.Fix
Added a shared helper on
ToolParser:_streaming_emit_new_close_completed_tool_calls— detects completion by comparing close-marker counts betweenprevious_textandcurrent_text(works when tags span chunks)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.