Skip to content

common : fix XML tool calls with duplicate parameter keys#19753

Open
tomstokes wants to merge 1 commit intoggml-org:masterfrom
tomstokes:fix-dup-keys-in-xml-tool-calls
Open

common : fix XML tool calls with duplicate parameter keys#19753
tomstokes wants to merge 1 commit intoggml-org:masterfrom
tomstokes:fix-dup-keys-in-xml-tool-calls

Conversation

@tomstokes
Copy link

@tomstokes tomstokes commented Feb 20, 2026

Qwen3-Coder-Next can emit duplicate parameters in tool calls. The XML tool call parser stored parameters in an ordered_json object using operator[], which overwrites any previous values for the same key. This caused streaming diffs to fail when the duplicate key was partially streamed before the full duplicate was parsed.

This change replaces operator[] with .emplace_back() in the XML tool call parser logic, ensuring that the streamed JSON object only grows monotonically. Duplicate keys are preserved and accurately streamed to the output.

Fixes #19382

Qwen3-Coder-Next can emit duplicate parameters in tool calls. The XML
tool call parser stored parameters in an ordered_json object using
operator[], which overwrites any previous values for the same key. This
caused streaming diffs to fail when the duplicate key was partially
streamed before the full duplicate was parsed.

This change replaces operator[] with .emplace_back() in the XML tool
call parser logic, ensuring that the streamed JSON object only
grows monotonically. Duplicate keys are preserved and accurately
streamed to the output.

Signed-off-by: Tom Stokes <tomstokes@radixengineering.com>
@tomstokes tomstokes requested a review from ggerganov as a code owner February 20, 2026 06:56
@github-actions github-actions bot added the testing Everything test related label Feb 20, 2026
@aldehir
Copy link
Collaborator

aldehir commented Feb 20, 2026

Feels more like a grammar issue. It also doesn't appear relevant to the issue linked.

@tomstokes
Copy link
Author

Sorry, I linked the wrong issue. The correct issue is #19382 . I've updated the PR

I agree that the LLM output shouldn't contain multiple parameters with the same key, but if it does then llama.cpp should produce valid output when translating it from XML to JSON. The current parser breaks when this situation occurs, which breaks tool calls.

The (now correct) linked issue has several examples of people encountering the bug with Qwen3-Coder-Next. The output looks like this

{"content":"#include <iostream>\n\nint main() {\n    std::cout << \"Hello World!\";\n    std::cout << \"foo\";\n    return 0;\n}","filePath":"/data/dev/llmassist/src/helloworld.cpp","filePath"/data/dev/llmassist/src/helloworld.cpp"}.

The linked issue #19382 has several other examples. The reports from that thread that disabling streaming fixed the issue were the clue that helped me find the problem.

This PR would ensure correct streaming of XML tool calls and allow people to use Qwen3-Coder-Next with llama.cpp. It's a common complaint that Qwen3-Coder-Next and llama.cpp aren't working due to the intermittent failed tool calls from this problem.

@aldehir
Copy link
Collaborator

aldehir commented Feb 20, 2026

Give #19765 a try. It will also support duplicate keys, but they shouldn't appear if the grammar rules are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: Qwen3-Coder-Next produces invalid JSON tool calls

2 participants