fix(bedrock): take last 9 chars in normalizeToolCallId to preserve entropy#16406
Open
zhsj0089944 wants to merge 1 commit into
Open
fix(bedrock): take last 9 chars in normalizeToolCallId to preserve entropy#16406zhsj0089944 wants to merge 1 commit into
zhsj0089944 wants to merge 1 commit into
Conversation
…tropy The previous implementation took the first 9 alphanumeric characters, but since Bedrock IDs always start with 'tooluse' (7 fixed chars), only 2 variable characters survived. This caused collisions when multiple tool calls were made in parallel. Take the last 9 characters instead, preserving more entropy from the random suffix and reducing collision risk. Fixes vercel#16182
|
|
||
| it('should handle IDs with various special characters', () => { | ||
| expect(normalizeToolCallId('tool-use_123ABC456', true)).toBe('tooluse12'); | ||
| expect(normalizeToolCallId('tool-use_123ABC456', true)).toBe('oluse123A'); |
Contributor
There was a problem hiding this comment.
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
normalizeToolCallId()takes the first 9 alphanumeric characters, but since Bedrock IDs always start withtooluse_(7 fixed chars), only 2 variable characters survive. This causes collisions when multiple tool calls are made in parallel.Example with 8 parallel tool calls:
Note
tooluseAcappears twice → BedrockValidationException: duplicate Ids.Fix
Take the last 9 alphanumeric characters instead of the first 9, preserving more entropy from the random suffix:
For
tooluse_bpe71yCfRu2b5i-nKGDr5g:toolusebp(2 variable chars)b5inKGDr5g(9 variable chars, ~62⁹ possible values)Fixes #16182