Skip to content

fix(common): tolerate dangling Gemma 4 channel prefix after tool responses#25100

Open
rodboev wants to merge 1 commit into
ggml-org:masterfrom
rodboev:pr/25072-gemma4-tool-call-peg-parse
Open

fix(common): tolerate dangling Gemma 4 channel prefix after tool responses#25100
rodboev wants to merge 1 commit into
ggml-org:masterfrom
rodboev:pr/25072-gemma4-tool-call-peg-parse

Conversation

@rodboev

@rodboev rodboev commented Jun 28, 2026

Copy link
Copy Markdown

Overview

Gemma 4 tool-calling turns can end on a bare <|channel> prefix with optional trailing whitespace. On current master, that fragment is treated as invalid peg-gemma4 output, so llama-server returns a 500 with:

The model produced output that does not match the expected peg-gemma4 format

This change keeps the fix in the shared Gemma 4 parse path. It tolerates only the exact final dangling <|channel> prefix with trailing whitespace, preserves any already parsed assistant state, keeps the existing tolerated trailing marker cases, and still rejects malformed non-whitespace tails after parsed prefixes.

Closes #25072

Additional information

The live issue log shows the final unparsed fragment as:

<|channel> 

The non-tool Gemma 4 path already has narrow tolerance for trailing channel-marker noise. The tool-enabled path did not have an equivalent final-parse escape hatch, which is why the shared parser escalated this exact fragment into a 500.

Focused validation for the implemented diff stayed on the parser surfaces:

test-chat.exe --template google-gemma-4-31B-it.jinja --detailed
ctest --test-dir build-target1-msvc-nofatal -R "^test-chat$" --output-on-failure --timeout 900
ctest --test-dir build-target1-msvc-nofatal -R "^test-chat-peg-parser$" --output-on-failure --timeout 900

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI assisted with local issue triage, patch planning, and test planning.

@rodboev rodboev requested review from a team and pwilkin as code owners June 28, 2026 12:43
@github-actions github-actions Bot added the testing Everything test related label Jun 28, 2026
@pwilkin pwilkin requested a review from aldehir June 28, 2026 14:50

@aldehir aldehir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, but we do not indiscriminately apply fixes to code that impacts all models. Gemma 4 has a dedicated parser which should encode this edge case, iff it exists with a well-behaved client.

First and foremost, due diligence should be done to ensure the reporter is using a proper client that sends back reasoning content. The absence of reasoning content from tool calls leads to model hallucinations and is the source of many parsing problems.

@rodboev

rodboev commented Jun 28, 2026

Copy link
Copy Markdown
Author

That makes sense. I see you already asked, so we we should have more details about the tool responses soon. In the meantime I'm moving the fix into the dedicated Gemma 4 grammar rather than the shared parser path.

@rodboev rodboev force-pushed the pr/25072-gemma4-tool-call-peg-parse branch from f409532 to 3106c25 Compare June 28, 2026 18:19
@magicmaaaaan

Copy link
Copy Markdown

This is probably from a bug in the chat template, and it should be noted that there's a slew of upcoming fixes in https://huggingface.co/google/gemma-4-31B-it/discussions/118. I believe "fix: restore model turn + thinking cue after tool responses" is the relevant fix to this particular issue.

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: Gemma 4 tool calling fails with "The model produced output that does not match the expected peg-gemma4 format"

3 participants