Files
UnbiasedStrata/patches/llama.cpp-qwen3-coder-any-argument-order.patch
Robert KarlandClaude Fable 5.1 8df8936dee Tool calls: accept arguments in any order; log a call the parser dropped
llama.cpp's Qwen3-Coder grammar takes a tool call's required arguments first and
the optional ones after. Qwen3.8 Flash-Next often writes the optional ones first
(limit, offset, path), and because the grammar's tool-call group is optional and
has no end anchor, such a call parsed as no call at all: no error, finish_reason
"stop", an empty answer. A coding agent sees its turn end after it announced the
call.

The grammar now accepts the arguments in any order; whether a required one is
missing is for the tool to report. The change is kept as a patch under patches/
that `make build` applies to the submodule. The front end logs the raw output
when it contains <tool_call> but no call was parsed, so the next case of this is
visible in the journal.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-08 15:54:15 -07:00

27 lines
1.8 KiB
Diff

diff --git a/common/parsers/qwen3-coder.cpp b/common/parsers/qwen3-coder.cpp
index 208f551..2d7c80f 100644
--- a/common/parsers/qwen3-coder.cpp
+++ b/common/parsers/qwen3-coder.cpp
@@ -139,12 +139,15 @@ common_chat_params common_chat_params_init_qwen3_coder(const common_chat_templat
(param.required ? required_args : optional_args).push_back(arg_rule);
});
- // Accept required arguments in any order, as Qwen does not always adhere to the
- // order provided.
- auto args = p.permute("tool-" + name + "-args", required_args);
- if (!optional_args.empty()) {
- args = args + p.zero_or_more(p.choice(optional_args));
- }
+ // Accept the arguments in any order, required and optional interleaved. The upstream rule
+ // took the required ones first and the optional ones after; Qwen3.8 Flash-Next often writes
+ // the optional ones first (limit, offset, path), and because the tool-call group below is
+ // optional and the grammar has no end anchor, such a call was dropped without any error:
+ // the client got finish_reason=stop and an empty answer. Whether every required argument
+ // is present is for the tool to report; a dropped call reports nothing.
+ std::vector<common_peg_parser> all_args = required_args;
+ all_args.insert(all_args.end(), optional_args.begin(), optional_args.end());
+ auto args = all_args.empty() ? p.eps() : p.zero_or_more(p.choice(all_args));
auto func = p.tool(p.tool_open("<function=" + p.tool_name(p.literal(name)) + ">\n") +
p.tool_args(args) +