fix(sanitizer): drop tool_calls key when all calls deduped, not set empty array - #70781
Closed
yanjingr119 wants to merge 1 commit into
Closed
fix(sanitizer): drop tool_calls key when all calls deduped, not set empty array#70781yanjingr119 wants to merge 1 commit into
yanjingr119 wants to merge 1 commit into
Conversation
…mpty array When deduplicating tool_call_ids, if every call is a duplicate (kept_tcs is empty), the current code sets tool_calls: [] on the message dict. Strict providers (DeepSeek v4) reject this with HTTP 400: Invalid 'messages[N].tool_calls': empty array. Expected an array with minimum length 1, but got an empty array instead. The existing pre-API chokepoint (lines 2738-2770) that drops empty tool_calls arrays runs *before* the dedup pass and cannot see arrays emptied here. Drop the key entirely at the dedup site instead, and supply a placeholder content string when dropping the key would leave the message body empty.
Collaborator
Duplicate of #64345. It already implements the same dedup-output drop-key repair with focused regression coverage; this patch's placeholder-content edge case is the only material delta. |
Author
This was referenced Aug 3, 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.
Problem
When
sanitize_api_messagesdeduplicatestool_call_ids, if all calls in a message are duplicates, the current code setstool_calls: []on the message dict. Strict providers (DeepSeek v4) reject this with HTTP 400:The existing pre-API chokepoint (lines 2738-2770) that drops empty/invalid
tool_callsarrays runs before the dedup pass and cannot see arrays emptied here.Root Cause
Fix
When
kept_tcsis empty (all calls were duplicates), drop thetool_callskey entirely instead of preserving an empty array. If dropping the key would leave the message body empty (edge case: host-fed/merged histories from WebUI sidecar), supply a placeholder content string.Testing