jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Anthropic 400: tool_use without tool_result immediately after, when results were saved late

Open SiavZ opened this issue 2 months ago • 0 comments

What happens

A session gets stuck: every request to Anthropic fails with 400 "tool_use ids were found without tool_result blocks immediately after". Retrying does not help. The tool results do exist in the saved history, but they were written later, after another assistant turn (for example a scheduled wake-up) had already been added. The request formatter leaves them where they are, so the tool_use is never followed directly by its result.

Steps to reproduce

  1. The assistant makes one or more tool calls.
  2. Before those results are saved, another assistant message and more turns get written (a second batch of tool calls that finishes first, or a scheduled task waking the session).
  3. The first results are then saved at the end of the history.
  4. Send any new message. Anthropic returns the 400 above, every time.

Expected

Results that exist later in history should be moved up to sit right after the call that made them, so the session keeps working.

SiavZ avatar Sep 29 '26 13:09 SiavZ