Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.6-27B· alibabaHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Streaming drops XML tool-call output that non-streaming parses…

  1. 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. Qwen Assistant

    Let me start by exploring the repository structure to understand the codebase and then focus on the issue about streaming dropping XML tool-call output that non-streaming parses correctly.

    The issue is about:

    1. Streaming must emit the same recovered XML tool calls as non-streaming
    2. Calls split across chunks and multiple calls should be handled
    3. Finish with tool_calls
    4. Reasoning mode and request tool selection must not alter recovery
    5. Plain text or malformed markup must not create calls or abort the stream

    Let me explore the repository first.

  3. Qwen Assistant

    Let me look at the streaming-related files since the issue is about streaming dropping XML tool-call output.

  4. Qwen Assistant

    The streaming.py file is about JSON encoding for SSE responses, but the issue is about XML tool-call parsing. Let me look at the tool_calling.py and related files.

  5. Qwen Assistant

    The output was truncated. Let me see the full file to understand the tool call parsing.

  6. Qwen Assistant

    Now let me search for XML tool-call related code. The issue mentions "XML tool-call output" specifically. Let me search for XML patterns in the codebase:

  7. Qwen Assistant

    Now I see there's a tool_parsers directory. Let me explore it more:

  8. Qwen Assistant

    Let me look at the abstract tool parser first to understand the interface, especially streaming:

  9. Qwen Assistant

    Now let me look at the tests to understand the issue better:

  10. Qwen Assistant

    Now let me look at the streaming tests specifically and the postprocessor to understand how streaming interacts with tool calls:

  11. Qwen Assistant

    Now let me look at the QwenToolParser specifically since it handles XML tool calls in streaming:

  12. Qwen Assistant

    Now let me look at the test_streaming.py file to understand the expected behavior better:

  13. Qwen Assistant

    Let me look at the chat streaming tests:

  14. Qwen Assistant

    Let me search for how tool calls are actually emitted in the server streaming path:

  15. Qwen Assistant

    Now let me run the existing tests to understand what's passing and failing:

  16. Qwen Assistant

    Let me look more closely at how tool calls are handled in streaming vs non-streaming. Let me examine the HermesToolParser since it handles XML formats:

  17. Qwen Assistant

    Now let me understand the issue better. Let me look at how the server handles the streaming finish to see what's happening with tool calls:

  18. Qwen Assistant

    Now let me look at the tests for the chat streaming spec more closely to understand the bug scenarios:

  19. Qwen Assistant

    Let me focus on understanding the flow better without MLX:

  20. Qwen Assistant

    Interesting! The Unicode characters aren't being used properly. Let me use the actual XML characters:

  21. Qwen Assistant

    I see! The pattern in the source code uses the actual special characters. Let me check what characters are actually in the regex:

  22. Qwen Assistant

    Now I understand! The pattern uses `

  23. Qwen Assistant

    The XML tags are causing shell issues. Let me use a script file instead:

  24. Qwen Assistant

    Let me try a different approach with base64 encoding to avoid shell interpretation issues:

  25. Qwen Assistant

    Let me write the test script using base64-encoded tags:

  26. Qwen Assistant

    Good, that works for Qwen parser. Let me now test the issue described - what happens when tool calls are dropped in streaming but parsed correctly in non-streaming. Let me test with different parsers:

  27. Qwen Assistant

    The Qwen parser is working correctly for the XML format. Now let me check the issue more broadly - maybe it's about the auto parser or specific edge cases. Let me look at what the issue description says more carefully:

    The issue says:

    1. "Streaming drops XML tool-call output that non-streaming parses correctly"
    2. "calls split across chunks and multiple calls"
    3. "finish with tool_calls"
    4. "Reasoning mode and request tool selection must not alter recovery"
    5. "Plain text or malformed markup must not create calls or abort the stream"

    Let me test the AutoToolParser:

  28. Qwen Assistant

    Found it! The AutoToolParser has a bug! When processing the second tool call, it's re-emitting BOTH tool calls (read and write) instead of just the new one (write). This results in 3 tool calls being emitted instead of 2.

    Let me look at the AutoToolParser's streaming implementation:

  29. Qwen Assistant

    Now I can see the issue clearly. The extract_tool_calls_streaming method in AutoToolParser (lines 286-328) has a bug:

    1. When a completion marker (`
  30. Qwen Assistant

    The bug is clear now. The extract_tool_calls_streaming method in AutoToolParser:

    1. Does NOT deduplicate already-emitted tool calls
    2. Every time it sees a completion marker in delta_text, it returns ALL tool calls from current_text, not just the new ones

    Compare this to QwenToolParser.extract_tool_calls_streaming which properly:

    1. Counts close markers in previous_text vs current_text
    2. Uses prev_close_count as the offset to only emit NEW tool calls
    3. Skips already-emitted ones by slicing result.tool_calls[prev_emitted:]

    Let me also check if there are similar issues in other parsers. Let me check the HermesToolParser:

  31. Qwen Assistant

    Good, the HermesToolParser has proper deduplication using tag counting. The bug is specifically in AutoToolParser.

    Now let me fix the AutoToolParser.extract_tool_calls_streaming method. The fix needs to:

    1. Track how many tool calls were already emitted (using close marker counts)
    2. Only emit NEW tool calls (those after the previously emitted ones)
    3. Handle the case where the stream finishes without a closing marker (return content)
  32. Qwen Assistant

    Now I understand the full picture. Let me fix the extract_tool_calls_streaming method. The fix needs to:

    1. Track the number of completed tool calls in previous_text vs current_text using close markers
    2. Only emit NEW tool calls (deduplication)
    3. Handle incomplete tool calls (suppress output while inside a tool call block)
    4. Pass through content after all tool calls are complete
    5. Handle multiple formats (XML, bracket, etc.)
  33. Qwen Assistant

    The edit went wrong - it seems the file got corrupted. Let me check the current state and restore it:

  34. Qwen Assistant

    Now let me write the fix properly. I need to replace the extract_tool_calls_streaming method:

  35. Qwen Assistant

    Now I understand the full method. The issue is that the method doesn't deduplicate tool calls. Let me create a proper replacement:

  36. Qwen Assistant

    The edit deleted the method entirely. Let me restore and try again with the correct format:

  37. Qwen Assistant

    Now let me use the proper heredoc syntax for the edit:

  38. Qwen Assistant

    The XML tags are causing shell interpretation issues. Let me write the fix to a temporary Python script and use it to generate the replacement content, avoiding direct shell interpretation of the XML tags.

  39. Qwen Assistant

    The XML tags `

  40. Qwen Assistant

    The problem is that the closing tag `

  41. Qwen Assistant

    I see - the closing tag is < + /tool_call>. Let me write a Python script that will generate the new file content and then overwrite it:

  42. Qwen Assistant

    The XML closing tag is still causing issues. Let me try a completely different approach - use Python to write the file directly without involving the heredoc:

  43. Qwen Assistant

    Let me write the complete fix script to a file:

  44. Qwen Assistant

    The closing tag `

  45. Qwen Assistant

    The XML closing tag keeps causing shell interpretation issues. Let me encode the entire fix script in base64:

  46. Qwen Assistant

    Let me take a simpler approach - write the entire fix script to a file using Python to avoid any shell interpretation:

  47. Qwen Assistant

    Let me encode the entire fix script as base64 and decode it on the other end:

  48. Qwen Assistant

    The shell is still trying to interpret </...> even inside Python comments. Let me try a different approach - use a Python script file to generate the fix:

  49. Qwen Assistant

    Now I can use chr() to build the tags. Let me write the full fix script this way:

  50. Qwen Assistant

    The fix was applied but there's a minor error in the print statement. Let me verify the file was actually modified:

  51. Qwen Assistant

    The method was written with each character on a separate line! The repr() conversion created individual characters. Let me restore and try a different approach:

  52. Qwen Assistant

    Let me write the fix script properly using Python to build and write the new method:

  53. Qwen Assistant

    The NL variable wasn't included in the fix script. Let me fix it:

  54. Qwen Assistant

    The fix was applied. Let me verify the file looks correct:

  55. Qwen Assistant

    Wait, the method uses open_tag, close_tag, and close_func_tag as local variables, but they need to be defined inside the method or be accessible. Looking at the QwenToolParser and HermesToolParser, they use the literal strings directly in the method. Let me check how those parsers handle it:

  56. Qwen Assistant

    I see - in the QwenToolParser, the XML markers are used as class attributes (regex patterns) and literal strings. In my fix, open_tag, close_tag, and close_func_tag are referenced but not defined. I need to either:

    1. Define them as class attributes, or
    2. Use the literal strings directly in the method

    Let me check how the QwenToolParser's streaming method handles the markers:

  57. Qwen Assistant

    I see - the QwenToolParser uses literal strings like `"

  58. Qwen Assistant

    The escaping is getting too complex. Let me take a completely different approach - write the new method to a separate file and then use Python to do the replacement:

  59. Qwen Assistant

    The method looks correct. Now I need to add proper indentation (4 spaces at the beginning of each line). Let me fix the indentation and write the replacement script:

  60. Qwen Assistant

    Let me verify the file:

  61. Qwen Assistant

    Now let me test the fix by running the test that reproduced the bug:

  62. Qwen Assistant

    The fix is working. Now the streaming parser correctly:

    1. Emits only 2 tool calls (not 3)
    2. Uses correct indices (0, 1) instead of re-emitting all calls with wrong indices

    Let me now run the full test suite to make sure nothing is broken:

  63. Qwen Assistant

    All 134 tests pass. Now let me also verify the diff shows exactly the changes I intended:

  64. Qwen Assistant

    The diff looks correct. Let me now also run a more comprehensive test to verify edge cases:

  65. Qwen Assistant

    Let me also test some additional edge cases to make sure the fix is robust:

  66. Qwen Assistant

    All tests pass. Let me also run the existing streaming tests to make sure nothing is broken:

  67. Qwen Assistant

    All tests pass. Now let me verify my fix handles all the requirements from the issue:

    1. "Streaming must emit the same recovered XML tool calls as non-streaming" - ✅ Fixed: Now uses deduplication to emit each tool call exactly once, matching non-streaming behavior.

    2. "calls split across chunks and multiple calls" - ✅ Fixed: The close-marker counting handles calls split across chunks and multiple sequential calls.

    3. "finish with tool_calls" - ✅ The existing finalize() in StreamingPostProcessor handles this.

    4. "Reasoning mode and request tool selection must not alter recovery" - ✅ The fix passes request to extract_tool_calls() call.

    5. "Plain text or malformed markup must not create calls or abort the stream" - ✅ Plain text returns content passthrough, incomplete tool calls are suppressed (return None).

    Let me also run a broader test to make sure no other tests are affected:

  68. Qwen Assistant

    All 160 tests pass (134 tool parser tests + 26 streaming tests). Let me view the final diff one more time:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.