When session history contains an assistant message with tool calls but
missing results (e.g., due to branching, interruption, or crash), the
API rejects the request. Previously, we tried to repair this by
inserting synthetic error results, but this approach was fragile and
could lead to confusing conversation states.
New approach: truncate history before the first incomplete tool call
sequence. This is simpler and always produces valid history:
- Agent continues working (just with less context)
- No confusing synthetic error results
- User may need to repeat their last request
The truncation is logged with details about which tool call IDs were
missing, helping track and diagnose the root cause.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>