fix: multi-tool-call results incorrectly dropped causing LLM API 400#730
fix: multi-tool-call results incorrectly dropped causing LLM API 400#730yinwm merged 1 commit intosipeed:mainfrom
Conversation
…vider Walk backwards over preceding tool messages to find the nearest assistant with ToolCalls, instead of only checking the immediate predecessor. Add unit tests for sanitizeHistoryForProvider covering key edge cases.
|
This bug is more severe than it appears. Once a multi-tool-call turn exists in session history, all subsequent requests on that workspace will fail permanently — even after restartingpicoclaw. The session data on disk is correct, but The only recovery is manually deleting the session file. Users with no knowledge of the internal file structure are completely stuck. Trigger condition is simple: any LLM response with ≥2 parallel tool_calls (e.g. Reproduce |
|
this change fixes a critical edge case in sanitizeHistoryForProvider() — consecutive tool messages produced by multi-tool calls, which is common across providers and can break Anthropic/Claude validation. |
fix: multi-tool-call results incorrectly dropped causing LLM API 400
📝 Description
When an assistant message contains multiple tool calls (e.g. ToolCalls: ["A", "B"]), the second and subsequent tool results were incorrectly dropped by sanitizeHistoryForProvider. The old code only checked the immediate predecessor, which for the second tool result was another tool result — not the assistant message — causing it to be treated as orphaned and removed. This led to a mismatch between assistant tool calls and tool results, resulting in LLM API 400 errors.
The fix walks backwards over preceding tool messages to find the nearest assistant with ToolCalls. Added unit tests covering key edge cases.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
#704
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist