fix(agent): prevent empty tool_calls arrays after dedup for DeepSeek V4 - #65211
Closed
ajzrva-sys wants to merge 1 commit into
Closed
fix(agent): prevent empty tool_calls arrays after dedup for DeepSeek V4#65211ajzrva-sys wants to merge 1 commit into
ajzrva-sys wants to merge 1 commit into
Conversation
When deduplicating tool_call_ids, if all tool calls in an assistant message are removed as duplicates, the code previously reassigned msg['tool_calls'] = [] — which DeepSeek V4 (and other strict OpenAI-compatible providers) reject with HTTP 400 'empty array'. Now if kept_tcs is empty after dedup, the tool_calls key is removed entirely instead of being set to []. Fixes the 'empty array' 400 error seen during long DeepSeek sessions with history corruption / retry artifacts. Ref: NousResearch#64843
Collaborator
Contributor
Author
|
Duplicate of #64843 by rommy2017 — same fix, already open. |
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
DeepSeek V4 (and other strict OpenAI-compatible providers) reject API requests with HTTP 400 when any message contains
tool_calls: [](empty array).The existing
sanitize_api_messagesalready stripstool_calls: []from assistant messages (lines 2508-2541), but the deduplication block at lines 2652-2666 can re-introduce an empty array: if every tool call in an assistant message is identified as a duplicate and removed,kept_tcsends up empty but the code still doesmsg = {**msg, "tool_calls": kept_tcs}which produces[].This hits long-running sessions where history corruption, retry artifacts, or compression re-emits cause duplicate tool_call_ids.
Fix
In the dedup block: when
kept_tcsis empty after removing duplicates, delete thetool_callskey from the message dict instead of setting it to[].Changed file
agent/agent_runtime_helpers.py— 4 lines added, 1 removedRelated
Verification
hermes chatwith DeepSeek V4 after a long session with Ctrl+C interruptions — no more 400 errors