Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 20, 2025

Summary

Fixes Anthropic API validation error: messages.X: all messages must have non-empty content except for the optional final assistant message

Root Cause

Anthropic's Extended Thinking API requires thinking blocks to include a signature for replay. The Vercel AI SDK silently drops reasoning parts without providerOptions.anthropic.signature. When all parts of an assistant message are unsigned reasoning, the SDK drops them all, leaving an empty message that Anthropic rejects.

Changes

Core Fix

  • stripUnsendableReasoning() - Removes reasoning parts without signatures before API calls, preventing empty messages from reaching Anthropic

Signature Capture (for future reasoning replay)

  • Add signature and providerOptions fields to MuxReasoningPart
  • Add signature to ReasoningDeltaEventSchema for event transmission
  • Capture signatures from SDK stream events (signature_delta)
  • Store providerOptions.anthropic.signature for SDK compatibility

Debug Tooling

  • Add --workspace <id> flag to CLI for testing against existing workspaces

Testing

Verified against a corrupted workspace (e8dab40a78) with 286 empty assistant messages that previously caused consistent API failures. After fix:

  • Empty assistant messages filtered correctly
  • Unsigned reasoning stripped before API call
  • Request accepted by Anthropic, streaming succeeded

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high

@ammar-agent ammar-agent force-pushed the messages-vwm9 branch 2 times, most recently from 5835eb2 to aeda4c1 Compare December 21, 2025 01:27
Add defensive filter after convertToModelMessages to catch any
empty assistant messages that slip through. This is a final safety
net - if corrupted history produces empty ModelMessages, they are
filtered out before sending to the API.

Also adds integration tests that seed corrupted history and verify
the system self-heals.
@ammar-agent ammar-agent force-pushed the messages-vwm9 branch 2 times, most recently from 6931bcd to b373f93 Compare December 21, 2025 02:13
Root cause: Anthropic's Extended Thinking API requires thinking blocks to
include a signature for replay. The Vercel AI SDK silently drops reasoning
parts without providerOptions.anthropic.signature, which can leave assistant
messages empty and cause API rejection with 'all messages must have non-empty
content'.

Changes:
- Add signature field to MuxReasoningPart and ReasoningDeltaEvent
- Capture signatures from SDK stream events (signature_delta)
- Store providerOptions.anthropic.signature for SDK compatibility
- Add stripUnsendableReasoning() to remove reasoning without signatures
  before API calls, preventing empty messages
- Add --workspace flag to CLI for debugging existing workspaces
@ammario ammario merged commit ecc2e22 into main Dec 21, 2025
20 checks passed
@ammario ammario deleted the messages-vwm9 branch December 21, 2025 02:40
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.

2 participants