#1478·GenieX

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)

Author: EurusZhangCreated Sep 22, 2026Updated Sep 24, 2026

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:

  1. 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 plain content, right before an otherwise valid tool_calls payload. 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).
  2. 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 in content, no usable tool_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.
  3. 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):

  1. POST to /v1/chat/completions with this model, enable_think: true, a tools array with one function tool, and a message history ending in: assistant message containing a tool_calls entry → tool message whose content is a validation-error string for that call.
  2. Send the request (works with stream: false or stream: true).
  3. Observe <|channel>thought / <channel|> rendered as literal text before an otherwise valid tool_calls array.

Issue 2 (intermittent, real sessions only):

  1. Run a multi-tool agent session against this model with a full production system prompt/tool set.
  2. Have the model hit a tool-call validation error, then attempt to self-correct on the next turn.
  3. On some fraction of such turns, the response is finish_reason: "stop" with raw unparsed special tokens in content instead of a tool_calls array.

Issue 3:

  1. POST a chat completion with grammar_string: "root ::= \"YES\"" and an unrelated prompt, e.g. "What is 2+2? Answer with just the number.".
  2. Observe the model answers the actual question ("4") instead of being constrained to "YES".

Expected behavior

  1. Empty thinking content should suppress the boundary tokens entirely, not render them as text.
  2. A tool-calling turn should always end as either a valid tool_calls array or clean plain text — never a garbled mix of leaked tokens with no usable tool call.
  3. grammar_string should 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-completions client
  • Version: GenieX server at 10.92.139.252:18181; model google/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.