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
Now let's write the simulator script.
Assistant
Looks fine, no special chars. Let me open the file and use
editwith explicit line numbers instead.Assistant
Now update
reset():Assistant
Now let's find and update
_detect_tool_calls:Assistant
I have a duplicate block. Let me fix lines 539-550.
Assistant
Good, that's fixed now. Let's verify the whole file compiles and re-check surrounding context.
Assistant
Now let's also check the
_fallback_textcomputation still works fine, and view the whole file end to confirm no leftover duplication elsewhere.Assistant
There's a leftover dead line
return {"content": tool_result.get("content", "")}from the old code. Let's remove it.Assistant
Now let's verify syntax and run existing postprocessor tests.
Assistant
All existing tests pass. Now let's re-run my repro script to verify the leak is fixed.
Assistant
Duplicate leftover lines 627-628. Let's remove them.
Assistant
Now let's verify syntax and run tests + repros.
Assistant
Now let's re-test.
Assistant
All parsers now show zero leaked content with correct tool_calls recovered. Let's also test edge cases: plain text with
</[that's not a tool call (false positive), malformed JSON inside tags, and multiple tool calls / reasoning mode.Assistant
Now let's run the test suite and repro again.
Assistant
All pass. Now re-run the repro6 comprehensive scenario checks.
Assistant
Now let's syntax-check chat.py and run relevant tests (skip mlx-dependent ones since they can't run here).
Assistant
All runnable tests pass. Let's run the entire tool_parsers/postprocessor/api_utils related test files together plus a broader sanity sweep of all tests that can import without mlx.
Assistant
Now let's run all these runnable tests together to check for regressions.
Assistant
Good, sanitize_output tests pass individually too. Let's confirm those "166 failed" tests aren't affected by test-order pollution and are truly identical (diff the two runs precisely) for extra safety.
Assistant
Confirmed byte-for-byte identical failure sets — these are pre-existing environment/test-isolation issues unrelated to my changes, and no regressions were introduced.
Now let's run ruff (or similar linter) if available, to keep code style consistent.
Assistant
Just a formatting nit. Let's apply ruff format.
Assistant
Let's re-run the full targeted test suite once more to be safe after formatting.
Assistant
All good. Let's also verify request tool-selection (
tools_requested) doesn't alter recovery, and check the_MAX_AMBIGUOUS_HOLD_LEN/cap edge cases (adversarial long unresolved<chain) don't hang or blow up memory.Assistant
Excellent — all edge cases pass, and content reconstruction is exact even under adversarial input, with no performance blow-up. Let's clean up temp scripts and do a final review of the diff.
Assistant
This diff looks clean and complete. Let's do one final full test pass on the core test files plus a broader integration-style check.
Assistant
All tests pass. Now let's go through the checklist.
Assistant
Everything is clean. Let's do one last comprehensive summary run and then submit.
Assistant
Summary
Root cause: In
StreamingPostProcessor._detect_tool_calls(vllm_mlx/service/postprocessor.py), each per-modelToolParser.extract_tool_calls_streaming()only recognizes an opening tag (<tool_call>,<minimax:tool_call>,[TOOL_CALLS],<|tool▁calls▁begin|>, etc.) once the complete literal has accumulated. When a real streaming engine splits that literal across multiple deltas/tokens (the normal case — token boundaries rarely align with tag boundaries), the parser reports the partial fragment ("<to","ol_","cal", …) as ordinary content before it can recognize and suppress the completed tag. This leaked raw tool-call markup into the visiblecontentstream instead of cleanly hiding it and emittingtool_calls, unlike non-streamingextract_tool_calls()which sees the whole text at once and never leaks markup. A few parsers (DeepSeek V3.1's two-marker wrapper, Seed-OSS's single-delta-only literal check) never suppressed at all under chunked input, leaking the whole tag.Fix:
- Added a generic, parser-agnostic holdback (
_split_pending_tag/_parser_flags_pending) inStreamingPostProcessorthat buffers an ambiguous trailing<...>/[...]-shaped fragment instead of emitting it immediately, releasing it once it's provably safe (closed and not flagged pending by the parser's ownhas_pending_tool_call) or bounded caps are hit — with a fallback flush infinalize()so genuinely-plain text (false positives likea < b) is never silently dropped, and true tool calls recovered by the existing non-stream fallback correctly discard the buffered fragment instead of double-emitting it. - Fixed
sanitize_output()(vllm_mlx/api/utils.py) to only.strip()when its regex actually removed something — it was unconditionally stripping per-delta chunks that merely contained</[, silently eating legitimate whitespace at chunk boundaries. - Updated
stream_chat_completion(vllm_mlx/routes/chat.py) to forward the new trailingcontentevents fromfinalize()(previously onlytool_callevents were forwarded).
Verified against real parsers (hermes, qwen, llama, mistral, minimax, kimi, glm47, seed_oss, deepseek_v31, xlam) with char-by-char chunking: zero leaked markup, correct multi-call recovery, correct
finish_reason="tool_calls", reasoning-mode andtools_requesteddon't affect recovery, malformed/false-positive markup produces no spurious calls and doesn't crash, and adversarial unbounded input is bounded/fast. Full relevant test suite (and a before/after diff of all mlx-independent tests) shows zero regressions.- Added a generic, parser-agnostic holdback (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →