Skip to content

Fold Claude Code's in-conversation system turns so Qwen accepts them - #77

Merged
Siddhesh2377 merged 1 commit into
mainfrom
siddhesh/shim-fold-system-messages
Sep 11, 2026
Merged

Fold Claude Code's in-conversation system turns so Qwen accepts them#77
Siddhesh2377 merged 1 commit into
mainfrom
siddhesh/shim-fold-system-messages

Conversation

@Siddhesh2377

@Siddhesh2377 Siddhesh2377 commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Claude Code on qwen3.8-27b fails every request through wally with 400 System message must be at the beginning. glm-5.3-flash and gemma-4 work.

Claude Code 2.1.268 sends a role: "system" turn inside messages (its environment block, after the first user turn), on top of the top-level system field. RequestToOpenAI passed roles through as-is, so the upstream got [system, user, system]. Qwen's chat template rejects a system message anywhere but first; the other two accept it.

The shim now folds every system turn into the one leading system message, in order, and leaves none in the conversation.

Found by capturing Claude Code's real requests through wally claude-code --serve on dev. The new unit test uses that captured shape.

Checks:

  • Break test: with the old translate.cpp the new test fails (a system message sits at index 2); with the fix it passes.
  • test_wally_unit --run-all: 43 passed.
  • Live on dev through the fixed binary: wally claude-code -p answers on qwen3.8-27b, glm-5.3-flash and gemma-4.

GLM and Gemma now get the environment text at the top of the system prompt instead of mid-conversation. Nothing else changes for them.

Summary by CodeRabbit

  • Bug Fixes
    • System instructions are now consolidated into a single leading message when requests are translated, preserving their original order.
    • Empty system instructions are ignored.
    • System messages no longer appear unexpectedly in the middle of conversations.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 75347927-d21e-4129-a62c-c8ca663287d2

📥 Commits

Reviewing files that changed from the base of the PR and between aa84dbf and 5397dc2.

📒 Files selected for processing (2)
  • src/anthropic/translate.cpp
  • tests/test_wally_unit.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

RequestToOpenAI now combines all non-empty Anthropic system turns into one leading OpenAI system message. A unit test verifies content order, message count, and conversation order.

Changes

System message translation

Layer / File(s) Summary
Fold system turns into the leading message
src/anthropic/translate.cpp, tests/test_wally_unit.cpp
RequestToOpenAI appends non-empty message-level system content to the leading system message and skips those turns during conversation translation. The new unit test verifies the combined content and resulting message order.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: sanchitmonga22

Merge Risk: ⚪ Minimal · up to 5397d

System turns are consolidated into one leading message and removed from the conversation as intended. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: folding Claude Code in-conversation system turns so Qwen accepts the translated requests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch siddhesh/shim-fold-system-messages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Siddhesh2377
Siddhesh2377 merged commit bc3a75e into main Sep 11, 2026
11 checks passed
@Siddhesh2377 Siddhesh2377 mentioned this pull request Sep 11, 2026
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