fix(server): collapse system messages on anthropic /messages path (Claude Code + strict templates)#132
Open
yanalialiuk wants to merge 1 commit into
Conversation
…aude Code + strict templates)
pull Bot
pushed a commit
to TheTechOddBug/Atomic-Chat
that referenced
this pull request
Jul 3, 2026
Claude Code can emit more than one system-role message after the Anthropic→OpenAI conversion (it mixes its own system prompt with developer/system content items). Strict chat templates such as AtomicChat/ornith-9b and Qwen3-family GGUFs reject any non-leading or repeated system role with: System message must be at the beginning The same fix was already applied on the Codex /responses path via merge_system_messages in responses_shim.rs. This commit: * Makes merge_system_messages pub(crate) so proxy.rs can call it. * Calls it in transform_anthropic_to_openai right after convert_messages, collapsing all system/developer messages into a single leading system message before forwarding to the llama.cpp backend. Fixes: ATO-249 See also: PR AtomicBot-ai#132 Co-authored-by: Mike <Vect0rM@users.noreply.github.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.
Summary
/messagesproxy path (same behavior already used on the Codex/responsesshim).merge_system_messagesfromresponses_shim.rsinproxy.rsso Claude Code requests that combine system prompts with developer/system items no longer fail strict chat templates (e.g. AtomicChat/ornith-9b, Qwen3-family GGUFs) with "System message must be at the beginning".Context
Claude Code can emit more than one system message after Anthropic→OpenAI conversion. Strict templates reject non-leading or duplicate system roles, which surfaces during llama.cpp tool-call parser generation.
Test plan
/messagesendpoint against a strict-template model/responsespath behavior is unchangedMade with Cursor