server: fix Gemma-4 <channel|> swallowing answer body#39
Merged
Conversation
`<channel|>` is a channel-switch marker, not a header opener. Q5_K_M sometimes emits the final answer directly after it with no trailing newline (observed: "<|channel>thought\n<channel|>5 + 3 = 8"), but both the streaming path in handlers.cpp and the bulk strip_channel_headers helper treated it symmetrically with `<|channel>` — scan until newline, which ate the entire answer when none followed. Fix: only `<|channel>` enters scan-until-newline mode; `<channel|>` drops just the marker and falls through to body. If a `<|channel>` header is truncated (no newline), we also drop just the marker now, instead of discarding everything to EOS. Covered by a local behavior harness (12 cases incl. the regression); imp:latest builds clean.
kekzl
added a commit
that referenced
this pull request
Apr 30, 2026
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.
Summary
<channel|>is the channel-switch marker, not a header opener — Q5_K_M sometimes emits the final answer directly after it with no trailing newline (observed:<|channel>thought\n<channel|>5 + 3 = 8).handlers.cppand the bulkstrip_channel_headershelper used to scan-until-newline for both markers, eating the entire answer when no newline followed.<|channel>enters scan-until-newline mode;<channel|>drops just the marker and falls through to body. Truncated<|channel>(no newline) also drops just the marker now, instead of discarding everything to EOS.Note
This commit was originally pushed to
feat/anthropic-messages-streamingafter that branch had already been merged via #36, so it never reached main. Re-opening on a fresh branch.Test plan
strip_channel_headers(incl. regressionclose_no_nl_keeps_body)imp:latestbuilds clean (full CUDA build viadocker compose build imp-server)