fix(openai-compatible): handle reused tool call index from Ollama#14277
Open
CPIDLE wants to merge 1 commit into
Open
fix(openai-compatible): handle reused tool call index from Ollama#14277CPIDLE wants to merge 1 commit into
CPIDLE wants to merge 1 commit into
Conversation
Ollama's OpenAI-compatible streaming API sends all tool calls with `index: 0` instead of incrementing indices (0, 1, 2...). This causes the streaming parser to silently drop the 2nd+ tool calls or merge their arguments into the first one. Fix: when the `toolCalls[index]` slot is already occupied by a different tool call (different `id`), treat the incoming delta as a new tool call by assigning it `index = toolCalls.length`. This is backwards-compatible: providers that send correct indices are unaffected since the `id` check will match. Tested with Ollama 0.20.x + qwen3-coder:30b, gemma4:e4b — dual tool call tasks go from 0% to 100% pass rate. Ref: ollama/ollama#15457 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
index: 0for all tool calls in a single responseProblem
Ollama's OpenAI-compatible streaming API sends all tool calls with
index: 0instead of incrementing (0, 1, 2...). This causes the@ai-sdk/openai-compatiblestreaming parser to either:hasFinished)This results in a 100% failure rate on any task requiring multiple tool calls in one response.
Verified with: Ollama 0.20.2/0.20.4, models: qwen3-coder:30b, gemma4:e4b, qwen2.5-coder:7b
Ollama issue: ollama/ollama#15457
Fix
When
toolCalls[index]is already occupied by a different tool call (differentid), treat the incoming delta as a new tool call by assigningindex = toolCalls.length.This is backwards-compatible: providers that send correct indices are unaffected since the
idwill match the existing entry.Test plan
should handle parallel tool calls with reused index (Ollama bug)