fix: normalize a tool call name sent as null (#29690)

Some endpoints stream a tool call whose function name is JSON null instead of a string. Nothing normalized it, so the null stayed on the tool call, was written into the stored message, and was sent back to the endpoint in the assistant message on the next turn, where a null is not a valid function name.

The delta accumulator now replaces a null name with an empty string, at the same point it already normalizes the arguments field. The call still fails as an unknown tool, which is the right outcome for a call that has no name, so the result is one failed tool call instead of a follow-up request the endpoint has to reject.

This is done where the delta enters the accumulator rather than at the consumers, because the name is emitted to the client and persisted while the response is still streaming, before anything downstream could clean it up.

Checked against 1261 streaming delta sequences: behaviour is unchanged except where the delta that creates the tool call carries a null name.

Seen in #29686 with a custom sglang build.
This commit is contained in:
Classic298 2026-09-06 23:00:03 +02:00 committed by GitHub
parent 3361a972b3
commit 66e021a926
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5008,7 +5008,8 @@ async def streaming_chat_response_handler(response, ctx):
if current_response_tool_call is None:
# Add the new tool call
delta_tool_call.setdefault('function', {})
delta_tool_call['function'].setdefault('name', '')
if delta_tool_call['function'].get('name') is None:
delta_tool_call['function']['name'] = ''
delta_tool_call['id'] = delta_tool_call.get('id') or output_id('fc')
delta_arguments = delta_tool_call['function'].get('arguments')
if not isinstance(delta_arguments, str):