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
The issue is about streaming dropping XML tool-call output that non-streaming parses correctly. Let me start by understanding the repository structure and finding the relevant code.
Let me explore the repository first.
Assistant
Let me explore the repository structure more to find relevant code for streaming and XML tool calls.
Assistant
Let me combine these into a single command.
Assistant
Let me look more specifically at the vllm_mlx directory which seems to be the main source code.
Assistant
Let me look at the key files related to streaming and tool calling.
Assistant
Let me also look at the output collector and tool calling files
Assistant
Let me look at the tool_calling.py and the server.py files to understand how XML tool calls are parsed.
Assistant
Let me see the full tool_calling.py file, particularly the XML-related parts:
Assistant
Let me read the file in sections to understand the full content.
Assistant
Let me read the beginning of tool_calling.py to see the full tool call parsing functions
Assistant
Let me search for XML-related patterns and understand how streaming works.
Assistant
Let me look at the key files - the postprocessor and tool parsers:
Assistant
Let me look at the tool parser files, especially the base and auto parser.
Assistant
Let me look at the abstract tool parser and the auto_tool_parser.
Assistant
Now let me look at the auto_tool_parser and qwen3coder_tool_parser.
Assistant
Let me also check the qwen3coder_tool_parser for its streaming implementation
Assistant
Let me find tests related to streaming tool calls to understand the expected
Assistant
Let me look at the test_tool_parsers.py to see what tests exist for streaming tool calls.
Assistant
Let me look at the QwenToolParser for its streaming implementation.
Assistant
Let me look at the model auto config and check how tool call parsers are assigned.
Assistant
Let me look at the NemotronToolParser.
Assistant
Let me look more carefully at the
_process_with_reasoningmethod and try to reproduce the issue.Assistant
Let me read the
_process_with_reasoningmethod more carefully.Assistant
Let me look at how the server handles streaming with tool calls. Let me search for where the streaming output is formatted.
Assistant
Let me look at the StreamEvent domain, and the server streaming code.
Assistant
Let me look at how the streaming chat completion works in the server.
Assistant
The grep didn't find anything? Let me try differently.
Assistant
Let me look at the service helpers for streaming formatting.
Assistant
Let me look at the server.py for the streaming chat completion flow.
Assistant
Let me search for the route files where the streaming happens.
Assistant
Let me look at the chat route file.
Assistant
Let me look at the streaming loop in the chat route more carefully, especially around tool call handling
Assistant
Let me continue reading the streaming loop section.
Assistant
Let me look at
_parse_tool_calls_with_parserin helpers.Assistant
Let me read that function.
Assistant
Let me create a reproduction script to verify the issues
Assistant
Let me add more debugging to understand the discrepancy.
Assistant
Let me look at existing test files to understand what behavior is expected.
Assistant
Let me look at the test_chat_streaming_spec.py which seems to test the streaming tool fallback.
Assistant
Now I have a clear understanding of the issues. Let me summarize what I found:
-
Content after tool calls is dropped in streaming mode via
StreamingPostProcessor. The non-streaming path correctly preserves content after tool calls incleaned_text, but streaming suppresses everything after the first tool call. -
The
_process_standardand_process_with_reasoningmethods unconditionally drop all content aftertool_calls_detectedis set to True. -
The parsers'
extract_tool_calls_streamingreturnNonefor content after tool calls because they still see the start marker (<tool_call>) in the accumulated text even after the tool call is complete.
Let me now implement the fix. I'll focus on:
- Modifying the PostProcessor to allow content through after tool calls are detected, when that content is not tool markup.
- Modifying the parsers to properly detect when tool calls are complete and pass through subsequent content.
Let me start with the PostProcessor changes, and then fix the parsers.
-
Assistant
Now I have a thorough understanding of the bugs. Let me implement the fix. The core issues are:
-
PostProcessor suppresses all content after
tool_calls_detected: In_process_standard,_process_with_reasoning, and_process_channel_routed, after tool calls are detected, ALL subsequent content is dropped. Content after the last</tool_call>should be emitted. -
Parsers'
extract_tool_calls_streamingreturnNonefor content after complete tool calls: Becausehas_markerchecks the entirecurrent_textwhich still contains<tool_call>from earlier. Content after all balanced tool call tags should be passed through.
Let me fix all the
-
Assistant
Let me now implement the fix. I'll edit the PostProcessor first
Assistant
Let me use the heredoc syntax for the edit
Assistant
Let me use a different approach - write a script to apply the changes.
Assistant
Let me verify the changes and run the reproduction test
Assistant
I see the issue - my fix is too simplistic. The
_delta_opens_tool_callcheck can't distinguish between "content inside a tool call" and "content after all tool calls". I need to fix the parsers to properly detect when tool calls are complete and pass through subsequent content.Let me fix the QwenToolParser first
Assistant
Now fix the AutoToolParser similarly
Assistant
Now fix the NemotronToolParser
Assistant
Let me check which other parsers have streaming implementations that might need fixing
Assistant
I need to refine the PostProcessor fix. The
_delta_opens_tool_callapproach is too aggressive and can leak internal tool call content. With the parser fixes, the parsers will correctly return content when tags are balanced. Let me simplify the PostProcessor fix - just remove the_delta_opens_tool_calloverride and keep theand not contentconditionAssistant
Let me run the reproduction tests again
Assistant
I see the issue - my balanced-tag check in QwenToolParser runs before the close-count check, causing
</tool_call>to be returned as content instead of triggering tool call parsing. Let me fix the order.Assistant
Fix the AutoToolParser with the same ordering fix
Assistant
Now let me run the reproduction tests again
Assistant
The tests look much better now. Let me run the existing test suite to check for regressions.
Assistant
Let me run without --timeout.
Assistant
All 134 tests pass. Let me run the other related tests too.
Assistant
Let me run the other tests that don't need MLX.
Assistant
Let me run all tests that don't require MLX.
Assistant
Let me just run tests without any timeout argument.
Assistant
Let me run the specific test files that we know can run
Assistant
Let me just run the key tests that are most relevant.
Assistant
Let me verify the PostProcessor changes are correct for all three
_process_*methodsAssistant
Let me check the NemotronToolParser fix has the correct order.
Assistant
The NemotronToolParser also has the ordering issue - the balanced check comes before the close marker check. Let me fix it.
Assistant
Let me check the HermesToolParser streaming implementation since it's a commonly used parser.
Assistant
Let me read the full HermesToolParser streaming method.
Assistant
Let me write a more comprehensive test to verify all edge cases work correctly
Assistant
All tests pass. Let me run the full test suite one more time to confirm everything is good.
Assistant
All 354 tests pass. Let me review the final diff of my changes.
Assistant
Let me verify the
_process_channel_routedchange is correct by looking at its context.Assistant
Let me test a case where content and tool call opening are in the same chunk
Assistant
There's also a pre-existing issue where content before
<tool_call>in the same chunk is dropped. Let me fix that too.Assistant
Let me test the content-before-marker fix
Assistant
Let me add the same content-before-marker fix to AutoToolParser
Assistant
And to NemotronTool
Assistant
Now let me run the comprehensive tests and the existing test suite to verify everything works.
Assistant
All tests pass. Let me run the comprehensive test again to verify everything still works.
Assistant
The content-before-marker fix is too aggressive. It should only apply when
previous_texthad no markers. Let me fix this.Assistant
Let me run all tests again.
Assistant
All tests pass. Let me do a final review of the complete diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.