GenieX: chat template mishandles empty-thought boundary tokens and occasionally drops `tool_calls` entirely after a tool-error correction turn (Gemma-4-26B GGUF, NPU backend)
Describe the bug
Serving google/gemma-4-26B-A4B-it-qat-q4_0-gguf:Q4_0 via GenieX's /v1/chat/completions shows three defects:
- Empty-thought tokens leak into content. With
enable_think: true, when the model produces no actual thinking for a turn, the chat template still emits the literal tokens<|channel>thought/<channel|>as plaincontent, right before an otherwise validtool_callspayload. The tool call itself still parses (finish_reason: "tool_calls") — only the visible text is polluted. Reproduced 6/6 in isolated testing (streaming and non-streaming). - Tool call occasionally degrades entirely into text. On the turn immediately following a tool-call validation error (the model's "correction" attempt), the response sometimes comes back as unparsed plain text instead:
finish_reason: "stop", with raw<|tool_call|>/<|channel|>tokens embedded incontent, no usabletool_calls. Observed in 3 independent real multi-turn sessions (two Android-automation tasks via one custom tool, one web-search task via an unrelated tool), always at this same position. 10 isolated single-request attempts to reproduce it did not succeed — the trigger likely needs the fuller real conversation context, or has a probabilistic component. grammar_string(GBNF constrained decoding) is a no-op. A grammar forcing literal"YES"output had no effect on a request asking an unrelated question — the model answered the question normally, ignoring the constraint. Possibly not wired up for the NPU/QAIRT backend.
To Reproduce
Issue 1 (6/6 reproducible):
- POST to
/v1/chat/completionswith this model,enable_think: true, atoolsarray with one function tool, and a message history ending in:assistantmessage containing atool_callsentry →toolmessage whose content is a validation-error string for that call. - Send the request (works with
stream: falseorstream: true). - Observe
<|channel>thought/<channel|>rendered as literal text before an otherwise validtool_callsarray.
Issue 2 (intermittent, real sessions only):
- Run a multi-tool agent session against this model with a full production system prompt/tool set.
- Have the model hit a tool-call validation error, then attempt to self-correct on the next turn.
- On some fraction of such turns, the response is
finish_reason: "stop"with raw unparsed special tokens incontentinstead of atool_callsarray.
Issue 3:
- POST a chat completion with
grammar_string: "root ::= \"YES\""and an unrelated prompt, e.g."What is 2+2? Answer with just the number.". - Observe the model answers the actual question (
"4") instead of being constrained to"YES".
Expected behavior
- Empty thinking content should suppress the boundary tokens entirely, not render them as text.
- A tool-calling turn should always end as either a valid
tool_callsarray or clean plain text — never a garbled mix of leaked tokens with no usable tool call. grammar_stringshould either constrain generation as requested, or the API should return an explicit error when it's unsupported for the model/backend, rather than silently ignoring it.
Screenshots
Not applicable — API-level defect, not a UI issue.
Desktop (please complete the following information):
- OS: Windows 11 Enterprise (client); GenieX server runs on an internal NPU/QAIRT inference host
- Browser: N/A — reproduced via direct HTTP requests and via the Pi Agent CLI's
openai-completionsclient - Version: GenieX server at
10.92.139.252:18181; modelgoogle/gemma-4-26B-A4B-it-qat-q4_0-gguf:Q4_0;compute=npu
Smartphone (please complete the following information):
Not applicable — this is in the server's chat-template/tool-call handling, independent of any client device.
Additional context
For issue 2, three alternative explanations were tested and ruled out: client-side conversation-history truncation (no such code path exists in the Pi Agent CLI's request-building logic); a mismatch between the model's client-declared context window and the server's actual one (disproved — a 9018-token prompt was accepted with no error); and server-side prompt/KV-cache reuse causing token-count under-reporting (disproved — resending an identical long prompt three times showed cached_tokens: 0 and unchanged latency every time). None of these explain issue 2; it appears to be a genuine chat-template/parsing defect specific to the correction-turn position.
Source: qualcomm/GenieX