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
I'll start by exploring the repository to understand its structure and locate relevant files.
- Assistant
Let me understand the repository structure better. The issue is about streaming dropping XML tool-call output that non-streaming parses correctly. Let me look for relevant files.
- Assistant
Let me look at the main package directory and find relevant streaming code.
- Assistant
Let me understand the issue better. The issue says "Streaming drops XML tool-call output that non-streaming parses correctly." So I need to find where streaming is handled, and where XML tool calls are parsed. Let me look at the relevant files.
- Assistant
Let me look at the streaming code and the test files related to this issue.
- Assistant
Now let me look at the tool calling module and find where streaming handles tool calls.
- Assistant
Let me see the full tool_calling.py file and look for XML-related parsing:
- Assistant
Let me look at the test files related to streaming and tool calls to understand what's expected.
- Assistant
Let me look at the existing tests for tool calling and streaming to understand the expected behavior.
- Assistant
Now let me look at the test files that are specifically related to streaming tool calls:
- Assistant
Let me look at the chat route or server file to understand how streaming and non-streaming handle tool calls:
- Assistant
Let me look at the routes/chat.py file to see how streaming and non-streaming handle tool calls:
- Assistant
Let me look at the full chat.py file to understand the streaming flow better:
- Assistant
Let me look at the StreamingPostProcessor class to understand how it handles tool calls during streaming:
- Assistant
Let me continue exploring the codebase to understand the issue.
- Assistant
Let me look at the abstract tool parser and the specific XML-based parsers:
- Assistant
Let me look at the existing tests for streaming tool calls:
- Assistant
Now let me look at the existing tests for tool call parsing and understand the issue better:
- Assistant
Let me look for the specific test file that tests streaming tool call handling:
- Assistant
Let me look at the test files that are specifically about streaming and tool calls:
- Assistant
Let me search for specific test files about XML tool calls in streaming:
- Assistant
Let me look at the test_postprocessor.py file to understand the issue better:
- Assistant
Let me look at the Qwen tool parser to understand how it handles XML tool calls:
- Assistant
Now let me look at the qwen3coder tool parser:
- Assistant
Let me look for test files that might be related to this specific issue:
- Assistant
Let me search for test files that might be testing streaming XML tool calls:
- Assistant
Let me look at the test file for the issue:
- Assistant
Let me now look for any test files that might be related to the issue:
- Assistant
Let me now run the existing tests to see if there are any failures related to this issue:
- Assistant
Let me run the tool parser tests to see if there are any failures:
- Assistant
Let me now look at the test files that might be testing the streaming tool call issue:
- Assistant
Let me look at the postprocessor more carefully and how it handles tool calls:
- Assistant
Let me look at the chat_streaming_spec.py file more carefully for the specific test that tests tool calls:
- Assistant
Let me look at the test that tests the tool fallback:
- Assistant
Let me continue reading this test file:
- Assistant
Let me now run all the tests to see if there are any failures:
- Assistant
Let me look at the test files that don't require the full engine:
- Assistant
Let me now look at the postprocessor test file to understand how it handles tool calls:
- Assistant
Let me look at the full streaming flow to understand the issue. Let me look at the stream_chat_completion function in chat.py more carefully:
- Assistant
Now let me look at the full tool_calling.py file to understand how parse_tool_calls works for non-streaming:
- Assistant
Let me look at the parse_tool_calls function:
- Assistant
Now let me look at the parse_tool_calls function:
- Assistant
Now let me look for the specific test file that tests the streaming tool call issue. Let me search for a test file that might have been created for this issue:
- Assistant
Now let me understand the issue better. Let me look at the test file that tests streaming with tool parsers:
- Assistant
Let me look at the specific tests for streaming with XML tool calls:
- Assistant
Let me look at the full test to understand the expected behavior:
- Assistant
Now let me look at the hermes tool parser to understand how it handles XML tool calls:
- Assistant
Now let me understand the issue better by looking at the test files that might be related to this specific issue:
- Assistant
Let me create a test script to reproduce the issue:' parser = HermesToolParser() result = parser.extract_tool_calls(text) print('Non-streaming result:', result.tools_called, result.tool_calls)
Test streaming: might fail
chunks = [ '', ] accumulated = '' prev = '' for chunk in chunks: prev = accumulated accumulated += chunk r = parser.extract_tool_calls_streaming( previous_text=prev, current_text=accumulated, delta_text=chunk, ) print(f'Chunk: {repr(chunk)}, Result: {r}') " </tool_call>
- Assistant
' chunks1 = [ '', ] test_parser("Hermes-QwenXML", HermesToolParser(), text1, chunks1)
Test 2: Qwen XML with text around it
text2 = 'Here is the tool call: and done.' chunks2 = [ 'Here is the tool call: ', '', ' and done.', ] test_parser("Hermes-QwenXML-with-text", HermesToolParser(), text2, chunks2)
Test 3: Nemotron XML format
text3 = '' chunks3 = [ '', ] test_parser("Hermes-NemotronXML", HermesToolParser(), text3, chunks3)
Test 4: Multiple XML tool calls
text4 = '' chunks4 = [ '', '', ] test_parser("Hermes-MultiXML", HermesToolParser(), text4, chunks4)
Test 5: QwenToolParser with bracket format
text5 = '[Calling tool: get_weather({"city": "NYC"})]' chunks5 = [ '[Calling tool: ', 'get_weather', '({"city": "NYC"})', ']', ] test_parser("Qwen-Bracket", QwenToolParser(), text5, chunks5)
Test 6: Qwen XML format with QwenToolParser
text6 = '' chunks6 = [ '
- Assistant
Let me create a test script to reproduce the issue:' chunks1 = [''] test_parser('Hermes-QwenXML', HermesToolParser(), text1, chunks1)
Test 2: Qwen XML with text around it
text2 = 'Here is the tool call: and done.' chunks2 = ['Here is the tool call: ', '', ' and done.'] test_parser('Hermes-QwenXML-with-text', HermesToolParser(), text2, chunks2)
Test 3: Nemotron XML format
text3 = '' chunks3 = [''] test_parser('Hermes-NemotronXML', HermesToolParser(), text3, chunks3)
Test 4: QwenToolParser with bracket format
text4 = '[Calling tool: get_weather({"city": "NYC"})]' chunks4 = ['[Calling tool: ', 'get_weather', '({"city": "NYC"})', ']'] test_parser('Qwen-Bracket', QwenToolParser(), text4, chunks4)
Test 5: QwenToolParser XML format
text5 = '' chunks5 = ['
- Assistant
Let me create a test script file first:' chunks1 = [ '' ] test_parser("Hermes-QwenXML-single-chunk", HermesToolParser(), text1, chunks1)
Test 1b: Split across chunks
chunks1b = [ '' ] test_parser("Hermes-QwenXML-split", HermesToolParser(), text1, chunks1b)
Test 2: Qwen XML with text around it
text2 = 'Here is the tool call: and done.' chunks2 = [ 'Here is the tool call: ', '', ' and done.', ] test_parser("Hermes-QwenXML-with-text", HermesToolParser(), text2, chunks2)
- Assistant
I need to write the test script to a file to avoid the tool call parsing issue in my responses. Let me use heredoc:
- Assistant
Good, the individual parsers seem to work. Now let me test the full StreamingPostProcessor flow:
- Assistant
The basic cases pass. Let me look more deeply at the non-streaming vs streaming path more carefully, especially
_parse_tool_calls_with_parser: - Assistant
Let me see the full function:
- Assistant
Let me see the full function:
- Assistant
Let me look more carefully at the
_process_with_reasoningpath in the postprocessor: - Assistant
Let me search for tests that specifically test the streaming vs non-streaming XML tool call parity:
- Assistant
Let me look at the test_fallback_tool_detection_on_finalize test:
- Assistant
Let me run all the tests to see what's failing:
- Assistant
Let me run only the tests that don't require mlx:
- Assistant
Let me run just the tests that work:
- Assistant
Let me now create a targeted test to understand the specific scenario where streaming drops XML tool calls:
- Assistant
" as reasoning, and then the remaining text (XML tool call) becomes content. The
_process_with_reasoningpath checks for tool call markers in reasoning, but the XML content is incontent, not inreasoning. The MiniMax redirect only redirects from reasoning → content, not from content → tool parsing.Wait, looking at the code again:
python# Tool call detection if self.tool_parser and content: result = self._detect_tool_calls(content)In Scenario 2,
self.tool_parseris None because no tool parser was configured! That's why the XML content leaks through. - Assistant
Now I see the issue clearly! Let me trace the key gaps:
-
No tool parser configured:
tool_parserisNone, so_detect_tool_calls()is never called, andfinalize()requiresself.tool_parserto be non-None. XML tool calls are completely lost. -
Reasoning parser active without tool parser: Content with XML tool calls leaks through because there's no tool parser to intercept it.
-
accumulated_textis not tracked in_process_standard: Even if we add a fallback infinalize(), there's no text to parse.
Let me now look at the
_process_standardmethod to understand exactly what needs to change: -
- Assistant
Let me look at the
sanitize_outputfunction to understand what it does with XML: - Assistant
Let me check what sanitize_output does:
- Assistant
Let me look at what
_FINAL_SANITIZERstrips: - Assistant
Let me look at
_FINAL_SANITIZER: - Assistant
Let me see more of this sanitizer:
- Assistant
and</tool_call>patterns, but NOT - Assistant
Let me search for accumulated_text usage properly:
- Assistant
Now I understand the full picture. Let me now implement the fix. I need to:
- Track
accumulated_textin_process_standardand_process_channel_routed - In
finalize(), add a fallback toparse_tool_calls()whentool_parseris None buttools_requestedis True
- Track
- Assistant
Now let me look at the
_process_channel_routedmethod: - Assistant
Now let me see the full finalize method:
- Assistant
Now I have a clear picture. Let me implement the fix:
- Assistant
Now let me make the first change - track
accumulated_textin_process_standard: - Assistant
Now let me implement the fix. First, add text accumulation in
_process_standard: - Assistant
The special characters in comments are causing issues. Let me use sed:
- Assistant
Let me verify the change:
- Assistant
Good. Now let me add the same tracking in
_process_channel_routed: - Assistant
Let me add the accumulation in
_process_channel_routed: - Assistant
Let me verify:
- Assistant
Good. Now let me modify the
finalize()method. Let me find it: - Assistant
Let me see the full finalize method:
- Assistant
Now let me modify the
finalize()method to add the fallback: - Assistant
The em-dashes in the comments don't match. Let me look at the actual content:
- Assistant
The file uses Unicode em dashes. Let me take a different approach and use a Python script to patch the file properly:
- Assistant
Let me verify the change looks correct:
- Assistant
Good, the patch looks correct. Now let me run the tests to verify everything still passes:
- Assistant
I see, there's a test that now fails because
accumulated_textis now being tracked. Let me adjust the approach - only trackaccumulated_textin_process_standardwhen there's no tool parser but tools were requested: - Assistant
Let me fix the code to only track accumulated_text when needed:
- Assistant
The
/in the comment is interfering with sed. Let me use a different approach. - Assistant
Now let me also fix the channel_routed path to only track when needed:
- Assistant
Let me check the actual content:
- Assistant
The indentation of
if output.channel == "reasoning":is wrong - it has 8 spaces. Let me fix this: - Assistant
Let me verify the changes:
- Assistant
Good. Now let me verify the _process_standard change:
- Assistant
Good, the changes look correct. Now let me run the tests again to verify everything passes:
- Assistant
All 274 tests pass. Now let me run my reproduction test to see if the fix works:
- Assistant
All scenarios pass! Now let me run all the existing tests to make sure nothing is broken:
- Assistant
The streaming_pipeline_integration test requires mlx. Let me run only the tests that don't need mlx:
- Assistant
All 308 tests pass! Let me also run any other relevant tests:
- Assistant
Some tests need mlx. Let me run the ones that don't:
- Assistant
All 102 tests pass. Let me also verify the full change looks clean:
- Assistant
The diff looks clean and correct. Let me also verify with the broader test suite:
- Assistant
Let me run only the tests that can run:
- Assistant
All 425 tests pass. Let me also run a comprehensive edge case test:
- Assistant
All 22 comprehensive edge case tests pass! Let me clean up the temporary test files and run the final test suite:
- Assistant
Now let me run the final comprehensive test suite:
- Assistant
All 425 tests pass. Let me review the final diff one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.