fix(ai-proxy): don't abort Anthropic response on bad tool_call arguments#13599
Open
AlinsRan wants to merge 4 commits into
Open
fix(ai-proxy): don't abort Anthropic response on bad tool_call arguments#13599AlinsRan wants to merge 4 commits into
AlinsRan wants to merge 4 commits into
Conversation
When an OpenAI-compatible upstream returns tool_call arguments that are not valid JSON (or not a JSON object), convert_response previously returned `nil, err`, aborting the entire non-streaming response conversion and dropping any already-collected text/thinking content -- the client received nothing. Fall back to an empty input object and log a warning instead, so the rest of the message (text, other tool calls) is still delivered. Anthropic tool_use input must be an object, so non-object decoded values are treated the same way. Signed-off-by: AlinsRan <alinsran@apache.org>
…rter-toolcall-decode Signed-off-by: AlinsRan <alinsran@apache.org> # Conflicts: # t/plugin/ai-proxy-anthropic.t
Add TEST 55 exercising tool_call arguments that are valid JSON but decode to a non-object value (e.g. "123"), covering the "not a JSON object" fallback branch where err is nil. Signed-off-by: AlinsRan <alinsran@apache.org>
TEST 55 now also verifies already-collected text content survives the empty-object fallback, symmetric with TEST 54. Signed-off-by: AlinsRan <alinsran@apache.org>
nic-6443
approved these changes
Jun 24, 2026
membphis
approved these changes
Jun 24, 2026
shreemaan-abhishek
approved these changes
Jun 24, 2026
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.
Description
In the Anthropic-messages → OpenAI-chat converter, when an OpenAI-compatible upstream returns
tool_callarguments that are not valid JSON (or decode to a non-object such as a number/string),convert_responsedidreturn nil, "invalid tool_call arguments: ...". This aborts the entire non-streaming response conversion and drops any already-collected text/thinking content — the client receives nothing instead of a partial-but-usable message.This patch falls back to an empty input object (
{}) and logs a warning, so the rest of the message (text, other tool calls) is still delivered. Anthropic'stool_use.inputmust be an object, so non-object decoded values are handled the same way as a decode failure.Added
t/plugin/ai-proxy-anthropic.tTEST 52 covering malformedarguments: conversion still returns, text content is preserved,tool_use.inputis an empty object, and a warning is logged.Checklist