fix: prevent IllegalStateException when ToolResponseMessage has no responses (GH-6197)#6213
Open
suryateja-g13 wants to merge 1 commit into
Open
Conversation
…sponses When ToolResponseMessage.getResponses() is empty or contains null IDs, the previous code attempted to build a ChatCompletionToolMessageParam without setting the required toolCallId field, causing the new OpenAI Java SDK to throw IllegalStateException at build time. Fix: stream responses, skip entries with null/empty IDs, and create a fresh builder per response to avoid builder state leaking across items. Fixes spring-projects#6197 Signed-off-by: Gorre Surya <suryateja.g13@gmail.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.
Problem
With the new OpenAI Java SDK,
ChatCompletionToolMessageParam.builder().build()now throwsIllegalStateException: toolCallId is requiredat build time iftoolCallIdis not set. The previous code had two bugs that trigger this:ToolResponseMessage.getResponses()is empty, the old code calledbuilder.build()without ever settingtoolCallId.builderinstance was shared across all responses in the stream, meaning state from a previous response (e.g. a null ID) could bleed into the next.The
ToolCallAdvisorintroduced in M7 auto-registers when tools are configured, changing the tool call flow and exposing both of these latent bugs.Fix
toolMessage.getResponses(), skipping entries whereidis null/empty.ChatCompletionToolMessageParam.Builderper response to eliminate builder-reuse state leakage.Tests
Three new unit tests added to
OpenAiChatModelTests:toolResponseMessageWithPopulatedResponses_mapsToOneParamPerResponse— verifies each response maps to one tool message param.toolResponseMessageWithEmptyResponses_producesNoMessages— verifies an emptyToolResponseMessageproduces zero tool-typed params.toolResponseMessageWithNullId_skipsResponse— verifies responses with null IDs are filtered out.Fixes #6197