fix: process blank tool call ID in StreamFrameFlowBuilder.emitToolCallDelta#1915
Merged
Anastasiia Zarechneva (aozherelyeva) merged 1 commit intoApr 27, 2026
Conversation
Antonii (antoniibelyshev)
approved these changes
Apr 27, 2026
Antonii (antoniibelyshev)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thanks
510e6cf
into
develop
23 checks passed
This was referenced May 16, 2026
Anastasiia Zarechneva (aozherelyeva)
added a commit
that referenced
this pull request
Jun 1, 2026
) Closes #2002. ### Summary `StreamFrameFlowBuilder.emitToolCallDelta()` treated every chunk with a non-null tool-call `id` as a new tool call. This fix treats a repeated `id` as a continuation of the pending tool call, so OpenAI-compatible providers that repeat the same `id` on each streaming chunk no longer fragment one logical tool call into multiple premature `ToolCallComplete` frames. ### Fix A new tool call now begins only when a present `id` or `index` differs from the pending call, instead of whenever `id` is non-null. Before: ```kotlin val new: PendingToolCall = if (sanitizedId != null || index != previous?.index) { ``` After: ```kotlin val isNewToolCall = (sanitizedId != null && sanitizedId != previous?.id) || (index != null && index != previous?.index) val new: PendingToolCall = if (isNewToolCall) { ``` This follows the same id-change principle as `emitReasoningDelta`; absent or blank ids still continue the pending call (the blank case preserves the #1915 handling). The fix lives in the shared `StreamFrameFlowBuilder` because all streaming clients (OpenAI, OpenRouter, Mistral, Anthropic, DeepSeek, Ollama, Bedrock, Dashscope, Google) emit tool-call deltas through it. ### Tests Two regression tests in `StreamFrameFlowBuilderTest`: `testEmitToolCallDeltaWithRepeatedIdAppendsToExisting` (three chunks with the same `id` combine into one `ToolCallComplete`) and `testEmitToolCallDeltaWithRepeatedIdSeparatesDistinctToolCalls` (switching to a different `id` still starts a separate tool call). `:prompt:prompt-model:jvmTest` (20 tests, 0 failures), `wasmJsNodeTest`, and `ktlintCheck` all pass locally; the full `./gradlew build` (Android and browser targets) is left to CI, since this contributor environment lacks the Android SDK and a headless browser. --------- Co-authored-by: Anastasiia.Zarechneva <Anastasiia.Zarechneva@jetbrains.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.
Handle blank tool call IDs in emitToolCallDelta in StreamFrameFlowBuilder; add a corresponding test.
Closes #1900