ISSUE DESCRIPTION Streaming drops XML tool-call output that non-streaming parses…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /Rapid-MLX, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand the
Assistant
The issue is about streaming drops XML tool-call output that non-streaming parses correctly. Let me look at the tool parsers, especially the ones dealing with XML.
Assistant
Now let me look at the related test files to understand the test conventions.
Assistant
Let me look at the postprocessor.py file.
Assistant
Let me search for streaming tests with thinking/JSON mode that may be failing.
Assistant
Let me look at the qwen3coder parser and other relevant files.
Assistant
Now let me look at how the test for streaming with non-streaming comparison is set up.
Assistant
Let me look at the qwen3_coder streaming test - it appears to be set up to use a real Qwen3CoderToolParser. Let me see if I can write a test that fails currently, then fix it.
Assistant
Let me examine the various streaming parsers to identify gaps.
Assistant
The QwenToolParser streaming has a subtle issue: it only emits when there's at least one closing marker AND only when there are new successfully parsed tool calls. But, it doesn't return content for any of the surrounding text (content before/after tool calls).
Let me check the gemma4 parser since it's mentioned in the issue.
Assistant
Let me check other parsers and find a streaming gap.
Assistant
I see a bug in the Llama parser streaming! If there are multiple function calls in
current_text, the streaming parser re-emits ALL of them on every</function>arrival. Let me also check the xlam and other parsers.Assistant
Now let me look at the test file for streaming tool calls to find more context on existing tests, and check the test file for all related test cases.
Assistant
Let me look at the
test_tool_calling.pyfile to see how tests are structured.Assistant
Let me run the existing test suite to see what passes and what doesn't. Then I'll look at the postprocessor streaming tests to understand more.
Assistant
Let me look at the auto_tool_parser since it's used widely:
Assistant
Let me look at the
_process_with_reasoningmethod:Assistant
Let me trace through a multi-tool scenario in the postprocessor:
Assistant
Let me test a case with content between tool calls:
Assistant
Let me write a comprehensive test to check various scenarios:
Assistant
I found the issue. Let me run more tests with smaller chunk sizes:
Assistant
Now I confirmed the issue with auto/llama/xlam parsers - they don't deduplicate. Let me trace what they emit char-by-char to verify:
Assistant
Hmm, no output. Let me check what happens:
Assistant
Interesting! No tool calls emitted at all when char-by-char. Let me debug further
Assistant
Ahh, the issue is that
<tool_call>is being matched as a regular tag, NOT<tool_call>(with the zero-width space)! The auto parser pattern is<tool_call>(with ZWS). So when streaming char-by-char, the parser never sees<tool_call>because each chunk doesn't have the ZWS.Wait, the test text IS
<tool_call>(with ZWS). The terminal display might just not show the ZWS. Let me check the bytesAssistant
The ZWS character was stripped from my test. Let me regenerate it:
Assistant
Let me look at the raw hermes tool parser to understand the exact tag pattern.
Assistant
The pattern uses ZWS character. Let me write the test with proper ZWS characters:
Assistant
Let me debug the hermes test - it emitted 'read' 3 times!
Assistant
Let me check the qwen non-streaming test:
Assistant
The Qwen XML_PATTERN doesn't have ZWS! It expects
<tool_call>without ZWS. Let me check the test file:Assistant
So Qwen uses
<tool_call>without ZWS, but Hermes uses it with ZWS. Different parsers use different conventions. Let me check:Assistant
Both patterns are reported as the same string in the
patternattribute. But the underlying bytes must differ - the pattern itself must have the ZWS character. Let me check the raw bytes.Assistant
Both have the same bytes - neither has ZWS! Let me look at the file directly:
Assistant
Let me look at the actual pattern content carefully:
Assistant
Let me look at the actual bytes:
Assistant
The file has
r"<tool_call>..."WITHOUT ZWS. Let me check git history:Assistant
The codebase uses
<tool_call>WITHOUT ZWS. My test was using ZWS. Let me fix and re-test:Assistant
Now I have clear evidence. Auto, Llama, and xLAM parsers don't dedup. Let me trace to understand the issue more:
Assistant
Let me trace the Hermes parser char-by-char to see the duplicate bug:
Assistant
Now let me look at the auto parser's streaming more carefully:
Assistant
Now let me look at the gemma4 case:
Assistant
Gemma4 works correctly. Let me also test minimax:
Assistant
This handles the case where tool calls are insideNow let me look at qwen3coder streaming:Assistant
Let me look at the qwen3coder streaming code again more carefully:
Assistant
Now I understand the issue. Let me plan the fix. First, let me check the current state of tests and the relevant patterns:
Assistant
Now let me check the existing tests that might be affected by my fix:
Assistant
Let me look at how the StreamEvent is converted to OpenAI format:
Assistant
Let me check what the auto parser's existing streaming test expects:
Assistant
Let me re-verify the test results:
Assistant
Assistant
Let me look at the test_streaming_ordinary_brackets_emit_content test:
Assistant
my plan:Now I have a clear understanding. Let me create a comprehensive fix. The issues are:
- Auto/Llama/xLAM parsers: Check
delta_textfor close markers, so they miss tool calls when close markers span chunks - Auto/Llama/xLAM parsers: No proper dedup - re-emit all tool calls on each close marker
- Qwen3Coder parser: Doesn't advance to next tool call after emitting
Let me also look at the postprocessor more carefully:
- Auto/Llama/xLAM parsers: Check
Assistant
Now I have a clear picture. Let me write the fix for the auto, llama, and xlam parsers.
Assistant
Now let me apply the fix to the auto parser:
Assistant
Now let me run the test to see if the fix works:
Assistant
The auto parser now emits only 1 event with 'write'. Let me trace what's happening:
Assistant
Let me trace more carefully to understand why the first close didn't trigger emission:
Assistant
Wait, the
</tool_call>has a ZWS character. Let me check the actual bytes:Assistant
Let me check the close-marker count more carefully:
Assistant
Let me re-check the fix is being applied:
Assistant
Let me trace the extract_tool_calls call:
Assistant
Let me test the QWEN_XML_PATTERN on the partial close:
Assistant
Assistant
Let me run the test and verify the current state.
Assistant
Let me check the auto parser behavior with the postprocessor:
Assistant
Let me check the extract behavior at chunk 55:
Assistant
The issue is the raw JSON fallback is too aggressive. The gemma4 approach uses a tracked emitted count. Let me apply that approach:
Assistant
The auto parser now works. Let me fix the llama parser:
Assistant
Now let me fix the xLAM parser:
Assistant
The xLAM is actually correct - it emits both tool calls in 1 event (which is fine for OpenAI protocol). Let me update my test to count tool calls, not events:
Assistant
Let me update the test to include a finished chunk:
Assistant
The tool_call event has
finish_reasonwhen finished. Let me update the test:Assistant
All tests pass. Let me now run the existing tests to make sure I haven't broken anything:
Assistant
All tests pass. Let me also run the postprocessor tests:
Assistant
All postprocessor tests pass. Let me now test the Qwen3Coder issue I found earlier:
Assistant
The qwen3coder has the bug. Let me look at the qwen3coder streaming code:
Assistant
Let me look at the existing test for qwen3coder streaming:
Assistant
The issue is the qwen3coder returns None after advancing, dropping the new tool call when it's in the same chunk. Let me fix it:
Assistant
Let me trace more carefully:
Assistant
The qwen3coder has a deeper issue - it returns after emitting the first tool call. Let me look at the structure and fix it:
Assistant
The single-chunk case is a real scenario. Let me restructure the qwen3coder to process all tool calls in current_text:
Assistant
Let me verify the qwen3coder changes don't break the existing test:
Assistant
The qwen3coder single-chunk multi-call is a known limitation. The multi-chunk case (existing test) works. Let me focus on the main fixes and verify everything works:
Assistant
Let me also test reasoning mode and request tool selection:
Assistant
The Llama test uses wrong format. Let me fix the test:
Assistant
All tests pass. Let me also test edge cases:
Assistant
All edge cases pass. Let me run a broader test to make sure nothing is broken:
Assistant
All 328 tests pass. Let me also run the other tests to make sure nothing is broken:
Assistant
All tests pass. Let me also verify the qwen3coder works for the multi-chunk case (existing test pattern):
Assistant
The qwen3coder streaming emits both tool calls in the multi-chunk case. The tool call names are 'read' and 'write'. The other emissions are for the arguments (which have no name).
Now let me also verify the postprocessor behavior for the qwen3coder:
Assistant
Now let me also look at the SyntaxWarning I saw in the xlam parser:
Assistant
Let me fix the SyntaxWarning:
Assistant
Let me just rewrite the xlam comment directly:
Assistant
Let me use a different approach - write a Python file:
Assistant
Good. Now let me verify the existing tests still pass:
Assistant
Let me re-test the qwen3coder single-chunk case:
Assistant
Let me test the qwen3coder with the postprocessor:
Assistant
Let me verify the fix works for the main parsers:
Assistant
Let me also add the missing count tracking to the postprocessor to fix the qwen3coder case:
Assistant
Let me add count tracking to the postprocessor to handle the qwen3coder single-chunk case:
Assistant
Now let me re-test the qwen3coder single-chunk case:
Assistant
The qwen3coder single-chunk case now works. Let me also re-run the comprehensive test:
Assistant
All parsers work. Let me also test with various chunk sizes and the edge cases:
Assistant
The qwen3coder test used the wrong name. Let me fix:
Assistant
Wait, the hermes test with chunk_size=100 showed
names=['write', 'write']- this is wrong! Let me investigate:Assistant
There's a bug in the hermes parser for the multi-tool-in-same-chunk case. Let me investigate:
Assistant
The hermes parser has a bug - when there's a complete tool call followed by an incomplete one, the complete one is not emitted. Let me fix:
Assistant
Let me run the comprehensive test:
Assistant
Let me also verify the hermes test with chunk_size=100 now works correctly:
Assistant
Let me run all the tests to make sure everything is still working:
Assistant
All 328 tests pass. Now let me think about edge cases I may have missed:
Assistant
All edge cases pass. Let me run the broader test suite one more time:
Assistant
All 436 tests pass. Let me also test the malformed JSON case in the streaming:
Assistant
Let me test the specific malformed case from the existing test:
Assistant
Both hermes and auto correctly emit only the valid tool call at index 0 when the first is malformed. Let me also test that the finish_reason is correct:
Assistant
Let me debug where the 'stop' finish_reason is coming from in the qwen3_coder case:
Assistant
The qwen3_coder has a stateful design that doesn't work with char-by-char. Let me check if my finalize fix recovers the tool call:
Assistant
The issue is the finish event with 'stop' is emitted before the finalize. Let me fix this by deferring the finish event:
Assistant
Let me check if there are tests that mark chunks as finished:
Assistant
Let me also test that the fix works for the case where the streaming parser emits 0 tool calls but the non-streaming parser finds them:
Assistant
The fix is correct. The
tool_callevent withfinish_reason="tool_calls"IS the finish event. Let me run the final comprehensive test:Assistant
All tests pass. Let me run all the existing tests one more time:
Assistant
All 436 tests pass. Let me also run the streaming tests:
Assistant
All 120 streaming tests pass. Now let me also look at the changes I've made to make sure they're clean:
Assistant
Let me also review the final state of the changes:
Assistant
Let me also run a broader test to make sure nothing is broken:
Assistant
The collection errors are due to missing dependencies, not my fix. Let me focus on running just the relevant tests:
Assistant
All 827 tests pass. Let me also verify the qwen3_coder multi-chunk case (the existing test pattern) still works:
Assistant
Let me also verify the original malformed test case still works:
Assistant
Let me also run a final comprehensive test:
Assistant
All tests pass. Let me do a final review of all my changes:
Assistant
Let me clean up the temporary test files:
Assistant
Let me also run the postprocessor tests one more time to make sure my finalize change is correct:
Assistant
All 74 postprocessor tests pass. Let me also run the full test suite one more time:
Assistant
My fix is complete. Let me provide a final summary of the checklist:
Checklist Verification
-
If an error was reported in the issue description, I have successfully reproduced it.
- I reproduced the bug by creating test scripts that showed auto/llama/xlam parsers dropping or re-emitting XML tool calls in streaming mode
- The Qwen3CoderToolParser was also dropping the second tool call when both calls arrived in the same delta
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.