openclaw - 💡(How to fix) Fix systemEvent causes SWW when session conversation ends with assistant turn (Anthropic provider) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#72226Fetched 2026-04-27 05:33:02
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

When a cron systemEvent fires into a main session and the most recent turn in that session is an assistant turn, the embedded agent call immediately fails with a 400 from the Anthropic API.

Error Message

Error (from gateway.err.log)

error=LLM request rejected: This model does not support assistant message prefill. The conversation must end with a user message. rawError=400 {"type":"error","error":{"type":"invalid_request_error","message":"This model does not support assistant message prefill. The conversation must end with a user message."}}

  • Failover chain exhausted: all fallback models hit billing cooldown after the format error on the primary model

Root Cause

OpenClaw injects the systemEvent into the current conversation context as-is. When the last turn is an assistant turn, the resulting message array sent to the Anthropic API ends with an assistant message — which Anthropic treats as "assistant prefill" and rejects with 400.

Note: this is not a claude-cli issue — provider=anthropic (direct API) is confirmed in the log.

Code Example

[agent/embedded] embedded run agent end:
  model=claude-sonnet-4-6 provider=anthropic
  error=LLM request rejected: This model does not support assistant message prefill. The conversation must end with a user message.
  rawError=400 {"type":"error","error":{"type":"invalid_request_error","message":"This model does not support assistant message prefill. The conversation must end with a user message."}}

[model-fallback/decision] model fallback decision:
  decision=candidate_failed reason=format
  next=anthropic/claude-haiku-4-5

Embedded agent failed before reply: All models failed (6): ...
RAW_BUFFERClick to expand / collapse

Summary

When a cron systemEvent fires into a main session and the most recent turn in that session is an assistant turn, the embedded agent call immediately fails with a 400 from the Anthropic API.

Version

OpenClaw 2026.4.25-beta.4 (6ecae22)

Reproduction

  1. Start a main session using anthropic/claude-* model
  2. Have the assistant reply (conversation ends on an assistant turn)
  3. Trigger a systemEvent cron job targeting sessionTarget: "main"
  4. → SWW occurs every time

Error (from gateway.err.log)

[agent/embedded] embedded run agent end:
  model=claude-sonnet-4-6 provider=anthropic
  error=LLM request rejected: This model does not support assistant message prefill. The conversation must end with a user message.
  rawError=400 {"type":"error","error":{"type":"invalid_request_error","message":"This model does not support assistant message prefill. The conversation must end with a user message."}}

[model-fallback/decision] model fallback decision:
  decision=candidate_failed reason=format
  next=anthropic/claude-haiku-4-5

Embedded agent failed before reply: All models failed (6): ...

Root Cause

OpenClaw injects the systemEvent into the current conversation context as-is. When the last turn is an assistant turn, the resulting message array sent to the Anthropic API ends with an assistant message — which Anthropic treats as "assistant prefill" and rejects with 400.

Note: this is not a claude-cli issue — provider=anthropic (direct API) is confirmed in the log.

Suggested Fix

Before building the LLM request for a systemEvent injection, check if the conversation tail ends with an assistant turn. If so, either:

  • Insert a placeholder user turn (e.g. [system event]) before the injected content, or
  • Restructure the systemEvent as a new user turn rather than continuing the existing thread

Notes

  • Reproducible 100% when assistant turn is last
  • Works correctly when a user turn precedes the systemEvent (confirmed by current test)
  • Failover chain exhausted: all fallback models hit billing cooldown after the format error on the primary model

extent analysis

TL;DR

Insert a placeholder user turn before the systemEvent injection to prevent Anthropic API rejection.

Guidance

  • Check the conversation context before injecting the systemEvent to determine if the last turn is an assistant turn.
  • If the last turn is an assistant turn, insert a placeholder user turn (e.g., [system event]) before the injected content to avoid Anthropic API rejection.
  • Alternatively, consider restructuring the systemEvent as a new user turn rather than continuing the existing thread.
  • Verify the fix by triggering the systemEvent cron job and checking the gateway logs for successful embedded agent runs.

Example

if last_turn_is_assistant:
    conversation_context.append("[system event]")
    # Proceed with systemEvent injection

Notes

This fix assumes that inserting a placeholder user turn or restructuring the systemEvent will resolve the Anthropic API rejection issue. However, the effectiveness of this fix may depend on the specific requirements of the Anthropic API and the OpenClaw implementation.

Recommendation

Apply the workaround by inserting a placeholder user turn before the systemEvent injection, as this is a straightforward and targeted solution to the identified issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING