Skip to content

reproduction: BUG: openai-compatible: empty toolcalls: array in every delta - #20251

Closed
ai-sdk-factory[bot] wants to merge 1 commit into
mainfrom
bug-reproduction-20203-20260902213734420341
Closed

ai-sdk-factory[bot] wants to merge 1 commit into
mainfrom
bug-reproduction-20203-20260902213734420341

Conversation

@ai-sdk-factory

@ai-sdk-factory ai-sdk-factory Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Bug

[BUG]: openai-compatible: empty tool_calls: [] array in every delta fragments reasoning into one reasoning-start/end cycle per chunk

Reproduction

  • packages/openai-compatible/package.json is version 3.0.43, and the reported APIs and response fields exist on main; no package-version or configuration mismatch explains the behavior.
  • packages/openai-compatible/src/chat/openai-compatible-chat-language-model.ts closes active reasoning whenever delta.tool_calls != null, so an empty array incorrectly triggers a reasoning lifecycle transition.
  • examples/ai-functions/src/reproduction/openai-compatible-empty-tool-calls-reasoning.ts replayed two consecutive reasoning deltas containing tool_calls: [] and observed two reasoning-start/end cycles instead of the expected single contiguous reasoning block.
  • packages/openai-compatible/src/chat/__fixtures__/issue-20203-empty-tool-calls.chunks.txt records the reported stream shape, and the regression test added to packages/openai-compatible/src/chat/openai-compatible-chat-language-model.test.ts fails because two reasoning starts are emitted instead of one.
  • The fragmentation is user-visible to consumers that create a reasoning part for each reasoning-start event.

Relevant Documentation

Related Issues

Reproduces #20203

Co-authored-by: Gregor Martynus <[email protected]>

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Empty tool_calls: [] arrays in stream deltas prematurely end the active reasoning block every chunk, fragmenting a single reasoning block into many reasoning-start/reasoning-end pairs.

Fix on Vercel

@gr2m gr2m closed this in #20253 Sep 3, 2026
pull Bot pushed a commit to Hawthorne001/ai that referenced this pull request Sep 3, 2026
…e reasoning streams (vercel#20253)

## Background

OpenAI-compatible gateways that attach `tool_calls: []` to reasoning
deltas caused one logical reasoning span to be emitted as multiple
user-visible reasoning blocks.

## Root Cause

The stream transform treated any non-null `tool_calls` array as active
tool output. The immutable reproduction and regression test confirmed
that empty arrays closed reasoning after each delta, producing two
start/end cycles instead of one.

## Summary

Reasoning now ends for tool calls only when the streamed `tool_calls`
array contains entries. Added a patch changeset and removed
reproduction-only artifacts.

## Testing

Added a regression test verifying consecutive reasoning deltas with
empty tool-call arrays remain within one reasoning lifecycle.

## End-to-end Validation

- `pnpm -C packages/openai-compatible build` completed successfully.
- Immutable reproduction replay completed successfully with one
contiguous reasoning block and no original failure signal.

## Related Issues

Fixes vercel#20203

Closes vercel#20251

---------

Co-authored-by: ai-sdk-factory <[email protected]>
Co-authored-by: Gregor Martynus <[email protected]>
Co-authored-by: WuJunkai2004 <[email protected]>
gr2m added a commit that referenced this pull request Sep 9, 2026
…e reasoning streams (#20537)

## Background

OpenAI-compatible gateways that attach `tool_calls: []` to reasoning
deltas caused one logical reasoning span to be emitted as multiple
user-visible reasoning blocks.

## Root Cause

The stream transform treated any non-null `tool_calls` array as active
tool output. The immutable reproduction and regression test confirmed
that empty arrays closed reasoning after each delta, producing two
start/end cycles instead of one.

## Summary

Reasoning now ends for tool calls only when the streamed `tool_calls`
array contains entries. Added a patch changeset and removed
reproduction-only artifacts.

## Testing

Added a regression test verifying consecutive reasoning deltas with
empty tool-call arrays remain within one reasoning lifecycle.

## End-to-end Validation

- `pnpm -C packages/openai-compatible build` completed successfully.
- Immutable reproduction replay completed successfully with one
contiguous reasoning block and no original failure signal.

## Related Issues

Fixes #20203

Closes #20251

Co-authored-by: ai-sdk-factory[bot] <305873210+ai-sdk-factory[bot]@users.noreply.github.com>
Co-authored-by: ai-sdk-factory <[email protected]>
Co-authored-by: WuJunkai2004 <[email protected]>
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