Repository navigation
fix(gemma4 tool calls): block the bare <|channel> token before a tool call (#886) - #908
Merged
Merged
Conversation
… call (#886) With thinking off, only the two-token opener <|channel>thought was excluded from the free text before a call. The model could still sample <|channel> alone and use it in place of <|tool_call>, leaking the call into content or running away. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #886.
Problem
With
gemma4-it:12b, tools in the request and thinking off, the model often opened a tool call with the bare<|channel>token instead of<|tool_call>. The grammar only excluded the two-token reasoning opener<|channel>thoughtfrom the free text before a call, so<|channel>alone could still be sampled. The call then leaked intocontentwithfinish_reason: stop, or the model ran on untilmax_tokens.Change
src/common/chat/chat_grammar.cpp: for the GEMMA4 format only, the free-text exclusion before an auto tool call also blocks<|channel>.reasoning_startis untouched, so reasoning-block detection and the reasoning prefix are unchanged. Other chat formats are unaffected.Test
Built from this branch (rebased on main at 0ce8a71), using the script from the issue (
max_tokens512, n=5 per prompt, 3 for thinking on):Not tested: multi-turn requests,
tool_choice: required, bolt-dflash, Windows. No unit test added.🤖 Generated with Claude Code