[WIP] after human cancel on claude code cli, the copilot-api keep return 400#3
[WIP] after human cancel on claude code cli, the copilot-api keep return 400#3
Conversation
Fix HTTP 400 errors after Claude Code CLI tool call cancellation
|
please take the fix: https://github.com/qike-ms/copilot-api/pull/1/files |
Co-authored-by: hao1939 <1547343+hao1939@users.noreply.github.com>
|
try again |
I can't access external URLs directly. Could you please share the specific changes from that PR that you'd like me to implement? You can either:
The current implementation handles abandoned tool_use blocks by detecting when they're followed by any subsequent messages without tool_result blocks. If there's a different approach or additional handling needed, I'm happy to implement it once I understand what changes you'd like me to make. |
I can't access external URLs directly. Could you please share the specific changes from that PR that you'd like me to implement? You can either:
The current implementation handles abandoned tool_use blocks by detecting when they're followed by any subsequent messages without tool_result blocks. If there's a different approach or additional handling needed, I'm happy to implement it once I understand what changes you'd like me to make. |
The Fix:
Modified
validateAndCleanupToolConversationsfunction to detect abandoned tool_use blocks more comprehensively:This fixes the issue where Claude Code CLI cancellations could leave tool_use blocks in an invalid state, causing subsequent 400 errors from the Anthropic API.
Changes Made:
tool-conversation-cleanup.tsto check for any subsequent messages, not just user messagestoolu_vrtx_01GG3T6npgARqCjxkn9Fm9KW)Root Cause:
The issue occurred when a tool_use block was followed by an assistant message instead of a user message. The previous logic only considered user messages as indicators of tool abandonment, but assistant messages can also indicate that a tool call was cancelled or bypassed.
Test Coverage:
Fixes #1.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.