Skip to content

fix(apicompat): omit empty tool name on streamed arguments deltas - #5632

Open
3219378872 wants to merge 1 commit into
Wei-Shaw:mainfrom
3219378872:fix/apicompat-streaming-tool-name-empty
Open

fix(apicompat): omit empty tool name on streamed arguments deltas#5632
3219378872 wants to merge 1 commit into
Wei-Shaw:mainfrom
3219378872:fix/apicompat-streaming-tool-name-empty

Conversation

@3219378872

Copy link
Copy Markdown

Closes #5631

问题

/v1/chat/completions 流式响应中,responses → chat 转换器在每个 function_call_arguments.delta 里重复输出 "name":""ChatFunctionCall.Name 缺少 omitempty)。OpenAI 兼容客户端从首个 delta 累积工具名,空串把名字覆盖,导致工具调用失败(Error: unknown tool "");空名历史还会让下一轮被上游拒绝(missing field 'name')。

改动

backend/internal/pkg/apicompat/types.goChatFunctionCall.Name 改为 json:"name,omitempty" —— 只有空名被省略,正常名字照常输出;参数增量不再携带 name 字段,与 OpenAI/上游原生流式行为一致。

新增回归测试 responses_to_chatcompletions_tool_name_test.go

  • 首个 output_item.added delta 保留 "name":"exec"
  • 后续 function_call_arguments.delta 的 JSON 不包含 "name" 字段。

验证

  • 修复前新测试失败("name":"" 出现在参数增量中),修复后通过。
  • go test ./internal/pkg/apicompat/...
  • go test ./internal/handler/ -run 'Chat|Responses|Stream'
  • 线上复现消除:流式 31 个 delta 仅首个带 name/v1/responses 客户端(Codex)路径不受影响(未触碰账户路由)。

影响面

仅影响流式 responses→chat 回程中"名字为空"的序列化;所有构造点中名字非空的场景输出逐字节不变。

The responses->chat streaming converter re-emits the tool name as an empty
string on every function_call_arguments.delta because ChatFunctionCall.Name
has no omitempty. OpenAI-compatible clients accumulate the name from the
first tool-call delta, so the trailing "name":"" overwrites it and the
call fails dispatch (unknown tool ""). Empty names also break the next
round-trip upstream (missing field 'name').

Fixes Wei-Shaw#5631
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@3219378872

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug][apicompat] 流式 chat/completions 参数增量重复输出 "name":"",覆盖工具名导致工具调用失败

1 participant