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
This is exactly the relevant file. Let's view the whole file.
Assistant
This one is more sophisticated (stateful token-by-token). Let's check llama_tool_parser's test file for streaming coverage and compare to other simpler parsers like deepseek/granite/nemotron for the same "re-emit all" bug.
Assistant
Now let's fix the ordering bug in both blocks (
<tool_call>and bare<function=) so that newly-completed calls are always checked and emitted before the incomplete-block suppression gate:Assistant
Now fix the same ordering issue in
llama_tool_parser.py(which I already patched but with the same wrong ordering):Assistant
Now let's re-verify the trailing return statement in llama parser is correct (should return
{"content": delta_text}at the end, notNone):Assistant
Good, that's correct. Now let's re-run the repro script to verify all scenarios pass, plus test hermes directly:
Assistant
All three scenarios now produce correct, non-dropped, non-duplicated results. Let's also verify the bare-Nemotron-XML branch in hermes (the
<function=without<tool_call>wrapper) has the same fix applied correctly, and check the postprocessor'sfinalize()fallback still works end-to-end through the full pipeline for both parsers.Assistant
Excellent — now both tool calls are recovered incrementally with a clean
finish_reason='tool_calls', no leaked XML, and no premature "stop". Now let's check "request tool selection must not alter recovery" — testing withtools_requested=Falseand differenttool_choicevalues.Assistant
All pass. Let's check if this ImportError is pre-existing (unrelated to our change) by checking on a clean checkout / verifying whether mlx is generally missing in this environment.
Assistant
Good — confirmed pre-existing environment limitation (mlx native lib unavailable, arm-only), unrelated to our change. Now let's run the full test suite to be safe.
Assistant
This is environment-related (docker-based integration test calling
exit(1)at import time, unrelated to our change). Let's exclude the integrations dir and run everything else.Assistant
Confirmed identical failure counts before and after our change (166 failed, 2937 passed, 178 skipped, 80 errors) — these are all pre-existing environment issues (missing native
mlxlib on this x86 Linux box, no network). Our changes introduce no new failures.Assistant
All directly relevant tool-call test suites pass. Now let's also test the malformed-markup / plain-text edge cases (should not create spurious calls or abort the stream) with the modified parsers.
Assistant
Now let's also test the full
StreamingPostProcessorwith the finalize fallback on malformed/incomplete markup at end of stream to make sure it doesn't crash or fabricate calls:Assistant
All still pass. Now let's re-run the full repro scripts once more end to end for a final sanity check, and view the diff.
Assistant
Everything works as expected. Let's view the final diff and clean up temp files.
Assistant
The diff looks clean and focused. Let's clean up temporary test files.
Assistant
Let's run the full relevant test suite one more time as a final check.
Assistant
That's the pre-existing mlx environment issue again, unrelated. Let's drop that one.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.