fix(prompt): Don't start a new tool call on repeated tool call id#2052
Merged
Anastasiia Zarechneva (aozherelyeva) merged 2 commits intoJun 1, 2026
Conversation
`emitToolCallDelta()` started a new tool call whenever the chunk `id` was non-null. Some OpenAI-compatible providers repeat the same `id` on every streaming chunk, so a single tool call was fragmented into multiple early `ToolCallComplete` frames. Detect a new tool call only when a present `id`/`index` signal differs from the pending call, matching the existing logic in `emitReasoningDelta`.
Maria Tigina (tiginamaria)
approved these changes
Jun 1, 2026
Maria Tigina (tiginamaria)
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for the fix! Looks good!
Anastasiia Zarechneva (aozherelyeva)
approved these changes
Jun 1, 2026
Anastasiia Zarechneva (aozherelyeva)
left a comment
Contributor
There was a problem hiding this comment.
Thank you!
581d6af
into
JetBrains:develop
22 checks passed
Contributor
Author
|
Thanks for the review and for landing the OpenTelemetry test fix on top to unblock CI — really appreciated. |
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.
Closes #2002.
Summary
StreamFrameFlowBuilder.emitToolCallDelta()treated every chunk with a non-null tool-callidas a new tool call. This fix treats a repeatedidas a continuation of the pending tool call, so OpenAI-compatible providers that repeat the sameidon each streaming chunk no longer fragment one logical tool call into multiple prematureToolCallCompleteframes.Fix
A new tool call now begins only when a present
idorindexdiffers from the pending call, instead of wheneveridis non-null.Before:
After:
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 sharedStreamFrameFlowBuilderbecause 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 sameidcombine into oneToolCallComplete) andtestEmitToolCallDeltaWithRepeatedIdSeparatesDistinctToolCalls(switching to a differentidstill starts a separate tool call).:prompt:prompt-model:jvmTest(20 tests, 0 failures),wasmJsNodeTest, andktlintCheckall 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.