Fix NPE in Bedrock converseStream when tool use has empty arguments#18783
Open
stefanopace wants to merge 4 commits into
Open
Fix NPE in Bedrock converseStream when tool use has empty arguments#18783stefanopace wants to merge 4 commits into
stefanopace wants to merge 4 commits into
Conversation
Contributor
|
@stefanopace are you able to sign the cla? |
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
Fixes a
NullPointerExceptionin Bedrock Runtime GenAI instrumentation when a model invokes a tool without streaming any tool input JSON (empty accumulated arguments).This could crash applications using
converseStream(including via the Java agent's automaticwrapBedrockRuntimeClient) because the exception was thrown inside the event-stream handler and propagated through the AWS SDK async pipeline.Problem
On
ContentBlockStopEvent,TracingConverseStreamResponseHandlercallsdeserializeDocument(currentToolArgs.toString())to parse accumulated tool arguments.When the model selects a tool but sends no
toolUse.inputdeltas,currentToolArgsis empty.JsonNodeParser.parse("")returnsnull, andnull.visit(DOCUMENT_UNMARSHALLER)throws an NPE. As a result:gen_ai.choicelogs are not emittedSolution
Treat a
nullJSON node as an empty object document ({}) indeserializeDocument(String), which matches the semantic of a parameterless tool call.This also protects other call sites that use the same helper:
invokeModelWithResponseStream(Anthropicinput_json_deltawith no partial JSON)inputis an empty string in the payloadTest plan
testConverseStreamToolCallWithEmptyToolArgumentsinAbstractAws2BedrockRuntimeTestwith a WireMock event stream simulating a tool block start/stop without input deltasgen_ai.user.messageandgen_ai.choicelog records, includingtoolCallswitharguments: "{}"./gradlew :instrumentation:aws-sdk:aws-sdk-2.2:library:testBedrockRuntimepassesNotes
deserializeDocument(String)is changed; thebyte[]overload is unchanged.BedrockRuntimeImplviawrapBedrockRuntimeClient).