Repository navigation
fix: repair Anthropic tool-call pairing to clear upstream 11148 - #13
Merged
Merged
Conversation
Claude Code and CC Switch send legal Anthropic histories whose tool
results are not adjacent to the declaring assistant tool_calls:
parallel tool_use blocks answered in later turns, duplicated
tool_result blocks, and orphan results. _convert_anthropic_message()
only translated blocks, so the CodeBuddy backend rejected those
histories with HTTP 400 code 11148 ("tool calls and tool results do
not match"). The Responses path already had this repair (6274044);
the Anthropic path did not, which is why the errors only appeared
under protocol=anthropic.
Apply _sanitize_tool_pairing() to the converted messages: defer
interleaved messages until their tool group completes, and drop
orphan/duplicate results plus unanswered tool calls while keeping the
assistant text. Add regression tests covering the reported 59-message
agentic history and the individual malformed shapes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Some agent clients submit malformed or nonstandard Anthropic tool histories that the CodeBuddy Chat backend rejects as HTTP 400 / 11148 (
tool calls and tool results do not match). The Responses adapter already had a pairing repair, but the Anthropic adapter did not.Changes
tool_pairing.pynormalizer.detail.code=invalid_tool_historywhen a tool call has no result, IDs are duplicated/reused, or repeated results contradict one another. This prevents silently erasing potentially side-effecting executions. Such requests are not forwarded upstream./v1/messagesand/v1/responsesHTTP routes.Validation
Operational note
If the proxy returns 422, verify whether an unacknowledged tool may already have performed its side effect before retrying. Direct
/v1/chat/completionstraffic is not normalized by these adapters.