fix: resolve Claude 4.6 assistant prefill compatibility issues#16900
Open
hsuanguo wants to merge 2 commits intoanomalyco:devfrom
Open
fix: resolve Claude 4.6 assistant prefill compatibility issues#16900hsuanguo wants to merge 2 commits intoanomalyco:devfrom
hsuanguo wants to merge 2 commits intoanomalyco:devfrom
Conversation
This commit addresses two root causes of the 'This model does not support assistant message prefill' error that occurs with Claude Opus 4.6 and Sonnet 4.6 models: 1. Max steps message role (prompt.ts:670) - Changed from assistant to user role for MAX_STEPS instruction - Claude 4.6 rejects conversations ending with assistant messages - User role maintains instruction delivery while ensuring compatibility 2. Agentic loop exit condition (prompt.ts:322) - Replaced timestamp-based ID comparison with explicit parentID check - Previous: lastUser.id < lastAssistant.id (vulnerable to clock skew) - Fixed: lastAssistant.parentID === lastUser.id (clock-skew resistant) - Prevents extra assistant messages when client/server clocks differ Fixes anomalyco#13768
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #13768
Type of change
What does this PR do?
This PR fixes the "This model does not support assistant message prefill" error that occurs with Claude Opus 4.6 and Sonnet 4.6 models.
Root Cause 1: Max steps message ends with assistant role
When the agentic loop reaches max steps, opencode appends a message with MAX_STEPS instructions using role "assistant". Claude 4.6 rejects any conversation array ending with an assistant message.
Fix 1: Changed the role from "assistant" to "user" in
prompt.ts:670. The instruction still reaches the model but now complies with Claude 4.6's requirements.Root Cause 2: Loop exit condition vulnerable to clock skew
The loop exit check at
prompt.ts:322compared IDs:lastUser.id < lastAssistant.id. Since IDs embed timestamps (seeid/id.ts:55-74), when the client clock runs ahead of the server clock, this comparison fails. The loop doesn't exit properly and creates an extra assistant message that becomes the last message.Fix 2: Replaced ID comparison with explicit parent-child relationship check:
lastAssistant.parentID === lastUser.id. This uses the existing parentID field (set atprompt.ts:571) which tracks which user message an assistant is responding to. This is clock-skew resistant and semantically correct.Credit to @nguquen for identifying the clock-skew issue.
How did you verify your code works?
Ran the full session test suite:
The changes are minimal (2 lines) and surgical, targeting only the specific issues.
Screenshots / recordings
N/A - This is a backend logic fix
Checklist