Skip to content

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

Closed

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)

Activity

  1. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If these are the same root cause, it would be helpful to consolidate discussion there. If your issue is distinct (e.g., specifically about empty-string deltas vs. missing fields), please note that in a comment.

  2. Garfier commented on Jul 20, 2026

    @Garfier
    Author

    Already fixed in v2 branch — upstream changed appendOrStart to prefer accumulated identity (current?.id ?? delta.id), which handles empty-string deltas correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions