Uh oh!
There was an error while loading. Please reload this page.
Fix: Each tool_use block must have a corresponding tool_result block in the next message - #3243
Fix: Each tool_use block must have a corresponding tool_result block in the next message#3243i-m-sid wants to merge 1 commit into
Conversation
…in the next message
rekram1-node
commented
Oct 17, 2025
Is it possible to save them in correct format instead, seems weird that for every request we need to reorder all the messages |
i-m-sid
commented
Oct 17, 2025
The API itself returns them out of order. It's pretty complicated to save them in correct format while streaming. This replaces .flat() method which I believe is also O(n), so there is no performance hit IMO. |
so the api returns them in an invalid order to send back to api? Hmm are you sure this isnt a bug with pruning tool calls on the opencode side? I need to look into that api thing but i havent heard that before, Im not saying you are wrong but could you reference the documentation for that here? ill also look into it tho |
rekram1-node
commented
Oct 20, 2025
ahh i just found: anthropics/claude-code#473 |
i-m-sid
commented
Oct 24, 2025
@rekram1-node so what do you think? |
@i-m-sid let me read over the code and test it i wish i had a session to read to verify that isnt anything we can solve for in simplier fashion |
i-m-sid
commented
Oct 25, 2025
Sure, will see if I can find a session to test |
i-m-sid
commented
Nov 3, 2025
I wasn't able to find any session. We use forked version of opencode in our platform ideavo.ai , and we made this fix more than a month ago. We haven't received the Bad Request issue after that point, which implies it's working. |
rekram1-node
commented
Nov 3, 2025
@i-m-sid I managed to get a session of it, someone sent it to me. It is so funny this is actually still an issue in claude code, but yeah your solution makes sense. |
f1dc981 to
3e15a39Comparef8ee907 to
6a9856dComparef1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
In rare cases, the ordering of tool calls doesn't match the expected Anthropic API contract. Fixed this by manually ordering the tool calls in expected format.
#2214
#3230
#2720