You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start a long-running conversation (80+ messages over multiple days)
Trigger specialist tool timeouts or interruptions that leave orphaned tool_use blocks in conversation history
Allow conversation to grow until context window trimming is needed
Context trimming fails repeatedly (24+ attempts) due to inability to find valid trim points with orphaned blocks
On next user message, RepositorySessionManager.initialize() calls _fix_broken_tool_use()
The repair logic adds synthetic toolResult blocks but incorrectly assigns tool_use blocks to user role messages
Bedrock Converse API rejects the request with ValidationException
Expected Behavior
When _fix_broken_tool_use() repairs orphaned tool_use blocks by adding synthetic toolResult blocks, it should ensure tool_use blocks remain in assistant messages only (per AWS Bedrock API specification).
Actual Behavior
The repair logic creates malformed message history where tool_use blocks appear in user role messages, causing AWS Bedrock to reject the request with:
An error occurred (ValidationException) when calling the Converse operation: User messages cannot contain tool uses. Please remove the tool uses and try again.
Observed in production on 2026-04-27 in a conversation that accumulated 80 messages over 5 days
Preceded by log message: Session message history has an orphaned toolUse with no toolResult. Adding toolResult content blocks to create valid conversation
Root cause: Orphaned tool blocks + context window overflow + failed trimming created the conditions for this bug
Only 1 conversation affected out of entire system over a 7-day period (isolated but reproducible)
AWS Bedrock API specification requires tool_use blocks ONLY in assistant messages, never user messages
Logs Showing the Issue
2026-04-27T17:13:59.958095Z Session message history has an orphaned toolUse with no toolResult. Adding toolResult content blocks to create valid conversation.
2026-04-27T17:14:01Z botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: User messages cannot contain tool uses. Please remove the tool uses and try again.
Possible Solution
Modify _fix_broken_tool_use() in src/strands/session/repository_session_manager.py to ensure that when adding synthetic toolResult blocks, tool_use blocks remain assigned to assistant role messages. Specifically:
When detecting orphaned tool_use blocks, verify they are in assistant messages
When adding toolResult blocks, add them to the same assistant message that contains the tool_use
Never create or modify user messages to contain tool_use blocks
Add validation before returning from _fix_broken_tool_use() to assert no user messages contain tool_use blocks
Alternative simpler fix: Instead of adding synthetic toolResult blocks, strip orphaned tool_use blocks entirely from message history (trade-off: loses incomplete tool invocation context).
Repro Steps
tool_useblocks in conversation historyRepositorySessionManager.initialize()calls_fix_broken_tool_use()toolResultblocks but incorrectly assignstool_useblocks to user role messagesValidationExceptionExpected Behavior
When
_fix_broken_tool_use()repairs orphanedtool_useblocks by adding synthetictoolResultblocks, it should ensuretool_useblocks remain in assistant messages only (per AWS Bedrock API specification).Actual Behavior
The repair logic creates malformed message history where
tool_useblocks appear in user role messages, causing AWS Bedrock to reject the request with:Additional Context
417ebea), first shipped in v1.15.0 (2025-11-04)Session message history has an orphaned toolUse with no toolResult. Adding toolResult content blocks to create valid conversationtool_useblocks ONLY in assistant messages, never user messagesLogs Showing the Issue
Possible Solution
Modify
_fix_broken_tool_use()insrc/strands/session/repository_session_manager.pyto ensure that when adding synthetictoolResultblocks,tool_useblocks remain assigned to assistant role messages. Specifically:tool_useblocks, verify they are in assistant messagestoolResultblocks, add them to the same assistant message that contains thetool_usetool_useblocks_fix_broken_tool_use()to assert no user messages containtool_useblocksAlternative simpler fix: Instead of adding synthetic
toolResultblocks, strip orphanedtool_useblocks entirely from message history (trade-off: loses incomplete tool invocation context).Related