You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this too. I had a longer session and was on the main branch in my repo. I had a few files staged and ran /rmslop (same as in opencode) and ran into this bug. I opened a new session and ran /rmslop and got the error again. The gist above is from the second session.
EDIT: realizing the way mine happened was different (no images uploaded) but the error was similar in case that's helpful. Otherwise we can mark this as unrelated.
Several of the calls outputted my entire files since it was diffing them, I obfuscated the file names & outputs. If those end up being required to debug this, I can find another way to share that.
I get this error many times so logged out and tried investigate with Opus. What I found.
(I posted this on other issue, but marked as off-topic - this issue is more related)
Tool Validation Error: Missing tool_result After Interruption
Root Cause
Client doesn't insert tool_result message after interruption before allowing model to continue.
When abort happens, client appends retry to the SAME assistant message instead of starting a new turn with tool_result in between.
Summary
Anthropic's Messages API rejects conversation history when an assistant message contains content (thinking/text) AFTER a tool_use block. The API expects tool_result immediately after tool_use, but when content appears in between, validation fails.
Error Message
messages.{N}: `tool_use` ids were found without `tool_result` blocks immediately after: {tool_id}.
Each `tool_use` block must have a corresponding `tool_result` block in the next message.
The Rule
All tool_use blocks must be contiguous at the END of the assistant message content.
Once a tool_use block appears, only more tool_use blocks can follow. Any other content (thinking, text) AFTER a tool_use is invalid.
prt_..5001 → step-start
prt_..7001 → reasoning: "The user wants me to create a markdown file..."
prt_..6001 → tool: write (ERROR, input: {}) ← ABORTED
prt_..b001 → reasoning: "The user wants me to create a markdown file..."
prt_..7001 → tool: write (COMPLETED)
prt_..c001 → step-finish
Same issue on latest OC 1.14.28
after running /compact there is a high chance the session will get corrupted with:
messages.2: tool_use ids were found without tool_result blocks immediately after: toolu_01FcmYRSCKCYMzixsRUwQbbt. Each tool_use block must have a corresponding tool_result block in the next message.
only workaround is to export session and reference it in a new one via @ to try and preserve the context
If the error you got is the "tool_use ids were found without tool_result blocks" 400, that's a pretty common one after an interrupted tool call, and attachment/image turns seem to trigger it too. I made a small plugin that prevents it and recovers from it automatically:
It cleans up dangling pending/running tool calls before each request, and if the 400 still happens it reverts the failed turn so you don't have to throw away the session (you can /unrevert it). It's a stopgap until opencode fixes it upstream. The approaches are from #8497 and #1662.
If your error turns out to be something else (like a tool-argument validation failure), ignore me, this one's only for the tool_use/tool_result pairing error.
Activity
github-actions commentedon Dec 18, 2025
This issue might be a duplicate of existing issues. Please check:
tool_useids were found withouttool_resultblocks immediately after #1662: AI_APICallError:tool_useids were found withouttool_resultblocks immediately aftertool_useids must be unique #1279: AI_APICallError: messages.1.content.2:tool_useids must be uniquetool_useids must be unique #1150: AI_APICallError:tool_useids must be uniqueFeel free to ignore if none of these address your specific case.
rekram1-node commentedon Dec 18, 2025
ill look into it
rekram1-node commentedon Dec 18, 2025
How do I replicate?
I saw ur description but I think this prolly has to do w/ ordering and whatnot
If u could export session:
opencode export > session.jsonit'd be amazingderiegle commentedon Dec 19, 2025
https://gist.github.com/deriegle/db117ea51f6f55e814e855541bcd47ee
I ran into this too. I had a longer session and was on the
mainbranch in my repo. I had a few files staged and ran/rmslop(same as in opencode) and ran into this bug. I opened a new session and ran/rmslopand got the error again. The gist above is from the second session.EDIT: realizing the way mine happened was different (no images uploaded) but the error was similar in case that's helpful. Otherwise we can mark this as unrelated.
rekram1-node commentedon Dec 19, 2025
@deriegle can u give me the raw json export tho?
opencode export > session.jsonderiegle commentedon Dec 19, 2025
Sorry about that. I've added the session.json into this gist: https://gist.github.com/deriegle/db117ea51f6f55e814e855541bcd47ee
Several of the calls outputted my entire files since it was diffing them, I obfuscated the file names & outputs. If those end up being required to debug this, I can find another way to share that.
Mishkun commentedon Dec 23, 2025
https://gist.github.com/Mishkun/02648359700010e559f7edf6bc8ac4dd
@rekram1-node I finally got this on a pet project, so I can share one in the full
westito commentedon Jan 8, 2026
I get this error many times so logged out and tried investigate with Opus. What I found.
(I posted this on other issue, but marked as off-topic - this issue is more related)
Tool Validation Error: Missing tool_result After Interruption
Root Cause
Client doesn't insert
tool_resultmessage after interruption before allowing model to continue.When abort happens, client appends retry to the SAME assistant message instead of starting a new turn with tool_result in between.
Summary
Anthropic's Messages API rejects conversation history when an assistant message contains content (thinking/text) AFTER a tool_use block. The API expects tool_result immediately after tool_use, but when content appears in between, validation fails.
Error Message
The Rule
All
tool_useblocks must be contiguous at the END of the assistant message content.Once a
tool_useblock appears, only moretool_useblocks can follow. Any other content (thinking, text) AFTER atool_useis invalid.Valid vs Invalid Patterns
Valid: Tools grouped at end
Valid: Separate turns per tool
Invalid: Content AFTER tool_use
Error:
tool_use ids were found without tool_result blocks immediately after: tool_AThe API sees content after
tool_use_Aand interprets it as: "tool_A should have gotten its result before the assistant generated more content."How This Happens
When a user aborts a tool mid-stream:
What should happen:
What actually happens:
The sequence:
thinking → tool_Athinking → tool_A (aborted)thinking → tool_B[thinking, tool_A, thinking, tool_B]- invalid patternOther causes:
Real-World Example
Saved message parts
Converted to API format:
{ "role": "assistant", "content": [ {"type": "thinking", "thinking": "..."}, {"type": "tool_use", "id": "toolu_01LiPBp", "name": "write", "input": {}}, {"type": "thinking", "thinking": "..."}, {"type": "tool_use", "id": "toolu_016rCwe", "name": "write", "input": {...}} ] }API Error:
Workaround
Before sending to API, restructure messages with interleaved content:
Option A - Split into separate turns:
Option B - Group tools at end (if results exist):
Note: Only works if the tool results are bundled together in the next message.
Test Results
[thinking, text, tool_A, tool_B]→[result_A, result_B][thinking, tool_A, thinking, tool_B]→[result_A, result_B][thinking, text, tool_A, thinking, text, tool_B]→[result_A, result_B][thinking, text, tool_A]→[result_A]→[thinking, text, tool_B]→[result_B]Minimal Reproduction
Expected error:
{ "type": "error", "error": { "type": "invalid_request_error", "message": "messages.1: `tool_use` ids were found without `tool_result` blocks immediately after: tool_1" } }prolific commentedon Feb 12, 2026
I am also getting this error way too many times. Makes the current session completely unusable.
ArchishmanSengupta commentedon Mar 26, 2026
is there any update on this? i can't use the session anymore after this error comes. this is very bad and customer facing issue.
XedinUnknown commentedon Apr 1, 2026
Same problem. #2214 seems to be a duplicate. I used Serena MCP when it did that.
faileon commentedon Apr 28, 2026
Same issue on latest OC
1.14.28after running /compact there is a high chance the session will get corrupted with:
only workaround is to export session and reference it in a new one via @ to try and preserve the context
viiqswim commentedon Jun 29, 2026
If the error you got is the "tool_use ids were found without tool_result blocks" 400, that's a pretty common one after an interrupted tool call, and attachment/image turns seem to trigger it too. I made a small plugin that prevents it and recovers from it automatically:
https://github.com/viiqswim/opencode-compaction-guard
One line in opencode.json:
It cleans up dangling pending/running tool calls before each request, and if the 400 still happens it reverts the failed turn so you don't have to throw away the session (you can /unrevert it). It's a stopgap until opencode fixes it upstream. The approaches are from #8497 and #1662.
If your error turns out to be something else (like a tool-argument validation failure), ignore me, this one's only for the tool_use/tool_result pairing error.
github-actions commentedon Aug 29, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.