mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #56] Anthropic API: mid-conversation "system" message crashes the chat template ("System message must be at the beginning") #31
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Nicolas0315 on GitHub (Sep 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/56
Summary
anthropic_to_messages(serve/frontend.py) passes messages withrole: "system"that appear insidemessages[]straight to the chat template, which raises:The request fails and the client connection is dropped (Claude Code shows
API Error: Connection dropped (ECONNRESET)).Who sends this
Claude Code (2.1.283) puts extra context (e.g. SessionStart hook output wrapped in
<system-reminder>) into the conversation as a{"role": "system", ...}entry after the first user message, in addition to the top-levelsystemfield. Captured request shape:Repro (commit
d551edf)→ TemplateError in the server log, no response.
Suggested fix
Only the first system message can go to the template, so convert later ones to
user(the content is already wrapped in<system-reminder>, so meaning is preserved). Minimal patch:Merging them into the leading system prompt would also work, but changes the prompt prefix and breaks KV reuse on every turn, so converting in place seems better.
Verified locally (Windows / RTX 4090 / IQ3_S, together with the query-string fix from the other issue): the repro returns 200 with the expected answer, and Claude Code completes a real edit-and-test task end to end (~94 s, prompt ~17-25k tokens, KV reuse working).
@Niko1221 commented on GitHub (Sep 28, 2026):
Thanks - fixed in v0.1.17 the way you suggested: a system message after the first one becomes a user message in place (the first stays the system prompt), so the prompt's start does not change and the conversation cache keeps reusing it. The same applies to the OpenAI API, where some clients send a late
developermessage. Tested with your request (and Claude Code's shape end to end on the real engine:?beta=true+ a mid-conversation system message answered correctly). Please reopen if you hit another shape it rejects.