-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
Getting a repeated error when using Roo-Code with the Anthropic API:
LLM request rejected: messages.98.content.1: unexpected tool_use_id found in tool_result blocks: toolu_0114eUeLnM3d16LHL9X69Y92. Each tool_result block must have a corresponding tool_use block in the previous message.
The error persists across retries with the same tool_use_id, suggesting the conversation history is replayed with the same corrupted state.
Expected Behavior
The conversation should continue without API validation errors.
Likely Cause
A tool_result block in the conversation history references a tool_use_id that no longer has a matching tool_use block in the preceding assistant message. This can happen when conversation history is truncated or summarized — if the assistant message containing the tool_use is removed but the following user message with the tool_result is kept, the pairing breaks.
Suggested Fix
- Treat
tool_use/tool_resultpairs as atomic units when trimming conversation context — never remove one without the other. - Validate the message array before sending to the API to ensure every
tool_result.tool_use_idhas a correspondingtool_useblock in the immediately preceding assistant message.
Environment
- API: Anthropic (Claude)
- The error occurs at message index 98, suggesting it happens in longer conversations after context management kicks in.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Triage