Skip to content

server: fix Gemma-4 <channel|> swallowing answer body#39

Merged
kekzl merged 1 commit into
mainfrom
fix/gemma4-channel-marker-swallows-answer
Apr 23, 2026
Merged

server: fix Gemma-4 <channel|> swallowing answer body#39
kekzl merged 1 commit into
mainfrom
fix/gemma4-channel-marker-swallows-answer

Conversation

@kekzl
Copy link
Copy Markdown
Owner

@kekzl kekzl commented Apr 23, 2026

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).
  • Both the streaming path in handlers.cpp and the bulk strip_channel_headers helper used to scan-until-newline for both markers, eating the entire answer when no newline followed.
  • Fix: only <|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-streaming after that branch had already been merged via #36, so it never reached main. Re-opening on a fresh branch.

Test plan

  • Local 12-case behavior harness on strip_channel_headers (incl. regression close_no_nl_keeps_body)
  • imp:latest builds clean (full CUDA build via docker compose build imp-server)

`<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 kekzl enabled auto-merge (squash) April 23, 2026 23:19
@kekzl kekzl merged commit 1068074 into main Apr 23, 2026
2 checks passed
@kekzl kekzl deleted the fix/gemma4-channel-marker-swallows-answer branch April 30, 2026 18:57
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.

1 participant