fix(bedrock): emit tool_call_end events for native tool streaming #10353
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 #10328
Fixes ROO-311: Write to File truncates filenames at special characters before file content
Problem
The Bedrock provider was not emitting
tool_call_endevents after tool use streaming, unlike other providers (e.g., OpenAI, Anthropic). TheNativeToolCallParserrequires these events to finalize tool calls and flush complete arguments. Without them, the parser would continue accumulating arguments in a buffer that never got finalized, causing filenames with special characters like parentheses to get truncated.Root Cause
Comparing to other providers like
base-openai-compatible-provider.ts(lines 186-193), they explicitly emittool_call_endevents when the stream indicates tool calls are complete. Bedrock was missing this logic entirely.Solution
contentBlockStopevent type to theStreamEventinterfacecontentBlockStartreceives a tool use blocktool_call_endwhencontentBlockStopis received for a tracked tool use blocktool_call_endas a fallback onmessageStopwithstopReason: tool_usefor any remaining active tool callsTesting
Added 4 new tests for native tool streaming support:
tool_call_endemission whencontentBlockStopis receivedtool_call_endemission viamessageStopfallback whencontentBlockStopis missingtool_call_endevents for parallel tool callstool_call_endwhenstopReasonis nottool_useAll 58 bedrock.spec.ts tests pass ✅