Repository navigation
fix(bedrock): sanitize tool names to the Converse pattern in specs and replayed history - #90016
Open
liuhao1024 wants to merge 1 commit into
Open
liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…d replayed history
Bedrock's Converse/ConverseStream APIs validate toolSpec.name and
toolUse.name against ^[a-zA-Z0-9_-]{1,64}$. Tool names sourced from MCP
servers, plugins, or aliases can carry dots, slashes, or unicode, and a
single offending toolUse block in the conversation history is replayed
(and re-validated) on EVERY subsequent request — after one bad call the
session fails permanently, even for a plain 'hi' (NousResearch#90008).
Fold non-conforming characters to underscores (truncate to 64, empty
fallback 'tool') identically at both emission sites — the toolSpec
definitions and the replayed toolUse history blocks — so the name the
model's earlier calls are recorded under matches the spec it is offered.
toolResult blocks pair by toolUseId, not by name, so tool results are
unaffected by the rename.
Author
|
The failing checks here are a pre-existing main regression, not caused by this diff: the failing test is the FAL catalog all-off upscale invariant ( Main has since resolved it on its own (the catalog entry was fixed and the invariant test was dropped in 00888e8), so this failure should disappear on the next rebase. This PR's changes don't touch the image-generation catalog or its tests. Not re-running CI since the failing slice is unrelated to the change under review. |
This was referenced Sep 25, 2026
This branch has not been deployed
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.
What does this PR do?
Fixes #90008: after a single tool call whose name violates Bedrock's Converse pattern, every subsequent ConverseStream request in the session fails with a ValidationException — including a plain "hi" — because the offending
toolUseblock sits in the replayed history and is re-validated on every request.Bedrock validates
toolSpec.name/toolUse.nameagainst^[a-zA-Z0-9_-]{1,64}$. Tool names sourced from MCP servers, plugins, or aliases can carry dots, slashes, or unicode (the report's flow hits it after a tool-search invocation). The adapter passed both sites through verbatim.This adds
_sanitize_bedrock_tool_name(): non-conforming characters fold to underscores, the result is truncated to 64, and an empty result falls back totool. It is applied identically at both emission sites — thetoolSpecdefinitions (convert_tools_to_converse) and the replayedtoolUsehistory blocks (convert_messages_to_converse) — so the name the model's earlier calls are recorded under matches the spec it is offered.toolResultblocks pair bytoolUseId, not by name, so tool results are unaffected by the rename.Related Issue
Fixes #90008
Type of Change
Changes Made
agent/bedrock_adapter.py: new_BEDROCK_TOOL_NAME_RE+_sanitize_bedrock_tool_name(); applied at the toolSpec name and the replayed toolUse name.How to Test
pytest tests/agent/test_bedrock_adapter.py -q— 71 passed (5 new tests inTestBedrockToolNameSanitization).test_bedrock_adapter,test_bedrock_empty_text_blocks,test_bedrock_1m_context): 76 passed.mcp.github.search_repos/v2·xbecomesmcp_github_search_repos_v2_xin both the spec and the replayed history; conforming names (includingmcp__server__tool) pass through unchanged.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A