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 intoanomalyco:devfrom
Conversation
…in the next message
|
Is it possible to save them in correct format instead, seems weird that for every request we need to reorder all the messages |
|
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 |
|
ahh i just found: anthropics/claude-code#473 |
|
@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 |
|
Sure, will see if I can find a session to test |
|
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. |
|
@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. |
772b621 to
eb855e1
Compare
f1dc981 to
3e15a39
Compare
f8ee907 to
6a9856d
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Closing 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