Skip to content

fix(server): collapse system messages on anthropic /messages path (Claude Code + strict templates)#132

Open
yanalialiuk wants to merge 1 commit into
AtomicBot-ai:mainfrom
yanalialiuk:fix/anthropic-system-message-collapse
Open

fix(server): collapse system messages on anthropic /messages path (Claude Code + strict templates)#132
yanalialiuk wants to merge 1 commit into
AtomicBot-ai:mainfrom
yanalialiuk:fix/anthropic-system-message-collapse

Conversation

@yanalialiuk

Copy link
Copy Markdown
Contributor

Summary

  • Collapse multiple system messages into a single leading system message on the Anthropic /messages proxy path (same behavior already used on the Codex /responses shim).
  • Reuse merge_system_messages from responses_shim.rs in proxy.rs so 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

  • Send a Claude Code request through Atomic Chat's Anthropic /messages endpoint against a strict-template model
  • Confirm tool-call / streaming responses succeed without "System message must be at the beginning"
  • Verify Codex /responses path behavior is unchanged

Made with Cursor

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>
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.

2 participants