openclaw - 💡(How to fix) Fix [Bug]: Trailing assistant turn causes silent provider failover on every first Anthropic request in persisted sessions [2 comments, 2 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#75193Fetched 2026-05-01 05:37:03
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
2
Author
Timeline (top)
commented ×2closed ×1labeled ×1mentioned ×1

Gateway heartbeat carries the prior session's trailing assistant turn into the next provider call without appending a synthetic user event. Anthropic claude-opus-4-* enforces strict role ordering and 400s with:

"This model does not support assistant message prefill. The conversation must end with a user message."

Gateway falls through to next provider in the chain (e.g. OpenAI), which doesn't enforce the rule, so the call succeeds and the provider switch is invisible to the caller. Net effect on a long-lived heartbeat session pinned to an Anthropic primary: every fire silently hits the fallback provider.

Error Message

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

Root Cause

Gateway heartbeat carries the prior session's trailing assistant turn into the next provider call without appending a synthetic user event. Anthropic claude-opus-4-* enforces strict role ordering and 400s with:

"This model does not support assistant message prefill. The conversation must end with a user message."

Gateway falls through to next provider in the chain (e.g. OpenAI), which doesn't enforce the rule, so the call succeeds and the provider switch is invisible to the caller. Net effect on a long-lived heartbeat session pinned to an Anthropic primary: every fire silently hits the fallback provider.

RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Gateway heartbeat carries the prior session's trailing assistant turn into the next provider call without appending a synthetic user event. Anthropic claude-opus-4-* enforces strict role ordering and 400s with:

"This model does not support assistant message prefill. The conversation must end with a user message."

Gateway falls through to next provider in the chain (e.g. OpenAI), which doesn't enforce the rule, so the call succeeds and the provider switch is invisible to the caller. Net effect on a long-lived heartbeat session pinned to an Anthropic primary: every fire silently hits the fallback provider.

Steps to reproduce

  1. Long-lived agent session with heartbeat enabled and an Anthropic model as primary.
  2. Let one heartbeat fire and persist its assistant reply (HEARTBEAT_OK or any single-turn output).
  3. On the next heartbeat fire, the provider call goes out with trailing assistant. Anthropic 400s. Fallback chain takes over.

Expected behavior

Either:

  • (a) The heartbeat runner appends a synthetic user turn (the heartbeat event/prompt) AS A USER MESSAGE before sending, or
  • (b) The Anthropic adapter normalizes the messages array, stripping or repairing trailing-assistant turns before send.

Actual behavior

Provider call goes out with the trailing assistant turn intact. Anthropic returns:

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."}} Gateway immediately invokes the fallback chain (model_fallback_decision: candidate_failed, reason=format). The session file repair fires afterward (session file repaired: rewrote 1 assistant message(s)) but the bad request has already gone out. The user receives a response from the fallback provider with no indication the primary failed.

OpenClaw version

openclaw 2026.4.25 (aa36ee6)

Operating system

MacOS 26.3.1

Install method

npm global

Model

anthropic/claude-sonnet-4-6 (primary); anthropic/claude-opus-4-7 (same-provider fallback)

Provider / routing chain

openclaw -> anthropic (direct, no proxy)

Additional provider/model setup details

Anthropic plugin enabled via openclaw.json (plugins.entries.anthropic.enabled: true). Auth via api_key profile in agents/main/agent/auth-profiles.json. models.providers.anthropic.api: "anthropic-messages" required to prevent auth-profile schema rejection on load.

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The issue can be fixed by modifying the heartbeat runner to append a synthetic user turn before sending the provider call or by normalizing the messages array in the Anthropic adapter to strip trailing assistant turns.

Guidance

  • Verify that the Anthropic adapter is correctly configured and enabled in the openclaw.json file.
  • Check the agents/main/agent/auth-profiles.json file to ensure the api_key profile is correctly set up for the Anthropic plugin.
  • Consider modifying the heartbeat runner to append a synthetic user turn (e.g., the heartbeat event/prompt) as a user message before sending the provider call.
  • Alternatively, update the Anthropic adapter to normalize the messages array and strip or repair trailing assistant turns before sending the provider call.

Example

No code snippet is provided as the issue does not contain sufficient information about the specific implementation.

Notes

The issue seems to be specific to the Anthropic plugin and its strict role ordering enforcement. The provided information does not contain enough details about the implementation to provide a concrete code fix.

Recommendation

Apply a workaround by modifying the heartbeat runner or the Anthropic adapter to handle trailing assistant turns correctly, as upgrading to a fixed version is not mentioned in the 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…

FAQ

Expected behavior

Either:

  • (a) The heartbeat runner appends a synthetic user turn (the heartbeat event/prompt) AS A USER MESSAGE before sending, or
  • (b) The Anthropic adapter normalizes the messages array, stripping or repairing trailing-assistant turns before send.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: Trailing assistant turn causes silent provider failover on every first Anthropic request in persisted sessions [2 comments, 2 participants]