Skip to content

fix(llm): treat empty tool call identity in stream deltas as absent - #40969

Closed
Curzibn wants to merge 1 commit into
anomalyco:devfrom
Curzibn:empty-tool-identity
Closed

fix(llm): treat empty tool call identity in stream deltas as absent#40969
Curzibn wants to merge 1 commit into
anomalyco:devfrom
Curzibn:empty-tool-identity

Conversation

@Curzibn

@Curzibn Curzibn commented Aug 7, 2026

Copy link
Copy Markdown

Problem

Streaming tool calls through an OpenAI-compatible endpoint fails with OpenAI Chat tool call delta is missing id or name on providers that send id as an empty string (instead of omitting it) on continuation deltas. Alibaba DashScope (*.maas.aliyuncs.com/compatible-mode/v1, also serving qwen3-max / deepseek models) does this. The session errors out mid-turn and the pending tool call is never resolved.

Actual chunks captured from DashScope (qwen3.8-max):

data: {"choices":[{"index":0,"delta":{"tool_calls":[{"id":"call_a1ad8367bde7444f82142e8e","type":"function","index":0,"function":{"name":"bash","arguments":""}}]}}]}
data: {"choices":[{"index":0,"delta":{"tool_calls":[{"id":"","type":"function","index":0,"function":{"arguments":"{\"command\": "}}]}}]}

The first delta carries the real identity. Continuation deltas carry id: "" with no function.name. In ToolStream.appendOrStart, delta.id ?? current?.id keeps the empty string (it is not nullish), so the fallback to the accumulated tool never happens and the truthiness guard reports the identity as missing.

Fix

Fall back on empty-string identity the same as on absent identity (|| instead of ??). A genuinely missing identity on the first delta for an index still errors as before.

Tests

Added a ToolStream regression test replicating the DashScope shape: identity on the first delta, id: "" on the continuation delta. bun test in packages/llm: 299 pass, 0 fail.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions github-actions Bot closed this Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant