Uh oh!
There was an error while loading. Please reload this page.
fix: disable assistant prefill for Claude 4.6 models - #14772
Conversation
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
adlternative
commented
Feb 28, 2026
@hsuanguo Has this been fixed yet? This feature is very important to me. |
hsuanguo
commented
Feb 28, 2026
I haven't seen the error in the last couple of days so I assume it fixes it. |
coygeek
commented
Mar 2, 2026
I validated PR #14772 locally against issue #13768 by testing it side-by-side with other candidate fixes and replaying the real failing session exports shared in the issue discussion. To make sure the result was not specific to one path, I used separate worktrees for each approach: the PR branch itself ( For replay validation, I used the two exported sessions attached in issue comments by The alternatives were informative but incomplete: both the loop-guard variant and the Copilot-adapter-only variant had passing tests, but replay still showed a trailing Based on these comparisons, PR #14772 is the correct fix for #13768. It addresses the issue at the transport normalization layer ( |
adlternative
commented
Mar 26, 2026
nobody merge this? |
klondenberg-bioptimus
commented
Mar 27, 2026
I tried this, it also fixed the issue for me ( both Claude Opus 4.6 on Bedrock and on Github Copilot ) |
hulk-ilmtec
commented
Mar 28, 2026
Please prioritize merging this PR. This bug makes Claude 4.6 models (Opus and Sonnet) essentially unreliable on AWS Bedrock, which is the primary provider for enterprise users. Impact
Why this PR specifically
Our situationWe run OpenCode headless on a server with Bedrock Opus 4.6, accessed via web UI, Desktop app, and Slack. This bug forced us to build from this PR branch ourselves. We'd much rather track stable releases. |
…aude 4.x prefill error (GH#17790) Adds prefill-guard.mjs to opencode-aidevops plugin and composes it into the experimental.chat.messages.transform hook after the existing TTSR hook. The guard strips trailing assistant messages from the outgoing LLM payload when safe — preserving messages with finish=tool-calls or active tool parts so legitimate tool-call flows are untouched. Session DB is never modified. Fixes the mobile webui error 'This model does not support assistant message prefill' on Claude Opus/Sonnet 4.x. Mirrors upstream PRs anomalyco/opencode#14772, marcusquinn#16921, and marcusquinn#18091 which add the same logic in provider/transform.ts but are not yet merged in opencode v1.3.17 / v1.4.0. Fixesmarcusquinn#17790
…aude 4.x prefill error (GH#17790) Adds prefill-guard.mjs to opencode-aidevops plugin and composes it into the experimental.chat.messages.transform hook after the existing TTSR hook. The guard strips trailing assistant messages from the outgoing LLM payload when safe — preserving messages with finish=tool-calls or active tool parts so legitimate tool-call flows are untouched. Session DB is never modified. Fixes the mobile webui error 'This model does not support assistant message prefill' on Claude Opus/Sonnet 4.x. Mirrors upstream PRs anomalyco/opencode#14772, marcusquinn#16921, and marcusquinn#18091 which add the same logic in provider/transform.ts but are not yet merged in opencode v1.3.17 / v1.4.0. Fixesmarcusquinn#17790
J-Light
commented
Apr 20, 2026
@hulk-ilmtec any guidance on how to build and replace the stable version. I was successful in building but it would not re-use the existing sessions. Since I need them I have downgraded would like to be current if possible. |
Claude models version 4.6 and later do not support assistant message prefill across all providers (Anthropic, GitHub Copilot, OpenRouter, Bedrock, etc), causing errors when a conversation ends with an assistant message (e.g. from max steps or aborted turns). Instead of maintaining a hard-coded list of specific model names, this uses version extraction from the model API ID to detect any Claude model >= 4.6, making it forward-compatible with future model releases. Changes: - Add claudeVersion() to extract [major, minor] from any Claude model ID - Add supportsAssistantPrefill() using version comparison (>= 4.6) - Add stripTrailingAssistant() in normalizeMessages() to strip trailing assistant messages for models that don't support prefill - Add comprehensive tests covering version detection across providers Fixesanomalyco#13768
3bbe13e to
d25ea6eCompare
Issue for this PR
Closes#13768
Type of change
What does this PR do?
Problem:
Claude Opus 4.6 and Sonnet 4.6 models reject requests where the last message in the conversation is an assistant message, returning: "This model does not support assistant message prefill. The conversation must end with a user message."
This happens in at least two scenarios:
The issue affects these models across all providers — native Anthropic API, GitHub Copilot, OpenRouter, etc.
Fix:
Added
stripTrailingAssistant()insidenormalizeMessages()inprovider/transform.ts. SincenormalizeMessagesis called from the singleProviderTransform.message()choke point used for all outgoing requests, this covers every code path rather than patching individual call sites.For models that don't support prefill (detected via
supportsAssistantPrefill()), any trailing assistant messages are stripped before the request is sent. For all other models, nothing changes.How did you verify your code works?
Confirmed the root cause using logs from a live session that reproduced the error:
providerID=anthropic,modelID=claude-opus-4-6, URLhttps://api.anthropic.com/v1/messagesrole: assistantfrom a prior interrupted turn — not a max steps prefillAdded integration tests in
ProviderTransform.message - strip trailing assistant for Claude 4.6that verify:Screenshots / recordings
Not applicable - backend logic fix
Checklist