Skip to content

Tool call streaming fails with 'missing id or name' on OpenAI-compatible APIs that send empty-string deltas #37841

Description

@Garfier

Description

When using an OpenAI-compatible API (DashScope token-plan endpoint with GLM-5.2), tool calls fail with:

OpenAI Chat tool call delta is missing id or name

The root cause is that some OpenAI-compatible APIs send empty strings ("") for id and function.name on subsequent tool call deltas instead of omitting them or sending null. For example:

delta 1: {"id":"call_8c1f...","function":{"name":"calculator","arguments":"{"}}
delta 2: {"id":"","function":{"name":"","arguments":"\"expression\": "}}
delta 3: {"id":"","function":{"name":"","arguments":"\"2"}}

In ToolStream.appendOrStart, the nullish coalescing operator (??) does not treat "" as absent, so the fallback to accumulated values never triggers. The !id check then fails on the empty string.

OpenCode version

v2 branch (also affects published opencode2 next builds)

Steps to reproduce

  1. Configure an OpenAI-compatible provider pointing to DashScope token-plan endpoint (token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1)
  2. Add a model like glm-5.2 with tool_call: true
  3. Send a prompt that triggers a tool call
  4. The streaming response fails on the second tool call delta

Operating System

Linux (x86_64)

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions