Repository navigation
fix(openai): avoid corrupting parallel streamed tool calls with repeated index - #758
Open
pcbeingused33 wants to merge 1 commit into
Open
pcbeingused33 wants to merge 1 commit into
pcbeingused33 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Root Cause
ActiveAgent::Providers::OpenAI::ChatProvider#hash_merge_delta(inherited byOllamaProvider,OpenRouterProviderandGeminiProvider) matches a streamedtool_callsdelta to an existing call purely byindex. Ollama's OpenAI-compatible endpoint (/v1/chat/completions) streams parallel tool calls as separate chunks that all carryindex: 0with distinctids, so the second call is merged into the first: the ids become"call_1call_2", the function names"get_weatherget_time"and the arguments{"city":"NYC"}{"tz":"EST"}, and the second call is lost. The same path also concatenatesidandfunction.namewhen a server repeats them on indexed continuation chunks.Fix
tool_call_target(renamed fromunindexed_tool_call_target) now resolves every streamedtool_callsdelta, indexed or not:idcontinues the call with thatid, or starts a new call when theidis unseen (even if itsindexcollides);indexcontinues the most recent call at thatindex;tool_call_fragment(renamed fromunindexed_tool_call_fragment) is applied to every continuation, so repeatedid,typeandfunction.nameare dropped instead of concatenated.Standard OpenAI streams (id on the first chunk, then index-only argument fragments) follow the same path as before.
Tests
New cases in
test/providers/open_ai/chat/streaming_tool_calls_test.rb(they fail onmain):index: 0with distinctids stay separate;index: 0continue the latest call at that index;id,typeandfunction.nameare not concatenated.Drafted with AI assistance and verified against the local test suite.