Skip to content

fix(cli): restore the Gemma 4 thought opener after a tool response - #1672

Merged
RemiliaForever (RemiliaForever) merged 1 commit into
qualcomm:mainfrom
jefgen:fix/gemma4-thought-opener
Nov 24, 2026
Merged

RemiliaForever (RemiliaForever) merged 1 commit into
qualcomm:mainfrom
jefgen:fix/gemma4-thought-opener

Conversation

@jefgen

@jefgen Erin Genovy (jefgen) commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Thank you RichardDong1225 for your comment on #1660, and thank you RemiliaForever (@RemiliaForever) for the RestoreOpener fix in 209be3d! 😊

I was able to get GenieX building from source on Windows ARM64, and wanted to help out. This PR is my attempt to contribute back a fix for #1660.


This only changes RestoreOpener in cli/internal/thinkfsm, and its test.

After a tool response, Gemma 4's chat template ends the prompt with <|channel>thought\n, so the model starts inside the thought channel and only generates the closing <channel|>. The splitter enters thinking only on the <|channel>, thought and \n tokens it sees, so the thinking goes to content, ending in a stray <channel|>, and reasoning_content stays empty. RestoreOpener already covers prompts that end in <think>; this extends it to Gemma 4's opener.

Summary

  • RestoreOpener also replays <|channel>, thought and \n, as the three tokens the splitter matches, when the prompt ends with <|channel>thought\n.
  • TestRestoreOpener gains that case.
  • With reasoning_format: none, content after a tool response now starts with the opener, as it already does after a user message.

Test plan

  • The new test case fails without the fix (nothing replayed, every token content) and passes with it.
  • Ran CI's Windows Go tests locally, bazelisk test //cli/... //bindings/go/... --//sdk:sdk_type=local --test_output=errors --test_summary=terse -- -//cli/release/...: 18 pass, and the 10 _posix tests are skipped, as on Windows CI.
  • Live on a Snapdragon X2 Elite NPU with qualcomm-ai-hub-community/Gemma-4-E4B-it-Hi-Fi-fraQtl:Q4_K_M: sent the Gemma 4: thinking leaks into content after a tool response, ending in a stray <channel|> #1660 request, and the same with text beside the tool call, blocking and streaming. On v0.11.0 all four replies leaked; on this branch all four split, with no <channel|> in content. A user-message request split on both.
  • Used this build with Gemma 4 E4B in a terminal editing agent harness: its thinking after tool calls arrives as reasoning_content.

Fixes #1660

Co-authored by Copilot + Human.

@jefgen

Copy link
Copy Markdown
Contributor Author

Thank you so much for reviewing!

I took a quick look at the failing CI build and I wonder if this might be related to the path limit.

Build SDK (Windows) failed while compiling the Rust tokenizer dependency.

LINK : fatal error LNK1104: cannot open file 'C:/a/GenieX/GenieX/sdk/build-arm64-windows-snapdragon-release/third-party/geniex-qairt/third-party/geniex-proc/third-party/tokenizers-cpp\release\build\macro_rules_attribute-proc_macro/caca7729a5ec11c9\out\macro_rules_attribute_proc_macro-caca7729a5ec11c9.dll.lib'

The output path exceeds the Windows 260-character limit.

A possible fix might be to move Cargo's target directory to a shorter path, such as C:\cargo-target.

After a tool response, Gemma 4's chat template ends the prompt with
<|channel>thought\n, so the model starts inside the thought channel and
only emits <channel|>. thinkfsm never entered thinking: the reasoning
leaked into content with a stray <channel|>, and reasoning_content was
empty.

Replay the opener as the three tokens the Splitter matches, as
RestoreOpener already does for <think>, so the Splitter and
reasoning_format=none see the same thought channel as after a user
message.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Erin Genovy <29107334+jefgen@users.noreply.github.com>
Signed-off-by: RemiliaForever <remilia@koumakan.cc>
@RemiliaForever
RemiliaForever (RemiliaForever) merged commit cbc93b3 into qualcomm:main Nov 24, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemma 4: thinking leaks into content after a tool response, ending in a stray <channel|>

2 participants