-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Group chat context injection creates consecutive user-role messages, breaking Anthropic API compatibility #83419
Copy link
Copy link
Closed
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.Channel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.Channel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Type
Fields
Priority
None yet
Description
OpenClaw's group chat message pipeline injects channel metadata (untrusted context block with sender info, channel topic, chat history) as a separate
{role: "user"}message object in the API request array, followed by the actual user message as another{role: "user"}object. This creates consecutive same-role messages on every turn, including the very first turn of a fresh session.The Anthropic API strictly requires role alternation (
user → assistant → user → ...) and rejects requests with consecutive same-role messages. OpenRouter proxies returnHTTP 500for these rejections instead of the upstream400, which triggers the OpenClaw failover cascade (see #83404).Impact
roles: {system: 1, user: 2}— the metadata context and the actual message as separate user entries.Reproduction
anthropic/claude-opus-4.6via OpenRouter)Intercepted request from a clean session (first turn ever):
{ "model": "anthropic/claude-opus-4.6", "messages": 3, "roles": {"system": 1, "user": 2}, "consecutiveSameRole": 1, "bodyBytes": 118715, "tools": 28, "systemMsgChars": 61151 }The two
usermessages contain:Conversation info (untrusted metadata): {"chat_id": "channel:...", "sender_id": "...", ...}@Graybeard say hello(the actual user message + channel metadata footer)Expected Behavior
The metadata context and actual message content should be merged into a single
{role: "user"}message before the request array is built. This ensures proper role alternation regardless of how many context blocks are injected.Alternatively, OpenClaw's provider adapter for Anthropic/OpenAI-compatible APIs should squash consecutive same-role messages before sending the request.
Environment
groupChat.visibleReplies: "automatic"messages.groupChat.historyLimitat defaultRelated