Skip to content

fix: resolve Claude 4.6 assistant prefill compatibility issues#16900

Open
hsuanguo wants to merge 2 commits intoanomalyco:devfrom
hsuanguo:fix/claude-4.6-prefill-proper-fixes
Open

fix: resolve Claude 4.6 assistant prefill compatibility issues#16900
hsuanguo wants to merge 2 commits intoanomalyco:devfrom
hsuanguo:fix/claude-4.6-prefill-proper-fixes

Conversation

@hsuanguo
Copy link

Issue for this PR

Closes #13768

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:322 compared IDs: lastUser.id < lastAssistant.id. Since IDs embed timestamps (see id/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 at prompt.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:

  • 110 tests pass, 4 skip, 0 fail
  • All prompt-specific tests pass (4/4)

The changes are minimal (2 lines) and surgical, targeting only the specific issues.

Screenshots / recordings

N/A - This is a backend logic fix

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This model does not support assistant message prefill / Github Copilot with Opus 4.6

1 participant