fix(memory): guard against integer message_id in update_message#558
Open
citizen204 wants to merge 1 commit into
Open
fix(memory): guard against integer message_id in update_message#558citizen204 wants to merge 1 commit into
citizen204 wants to merge 1 commit into
Conversation
Fixes aws#556 Strands' RepositorySessionManager.initialize_agent populates _latest_agent_message with SessionMessage objects whose message_id is a sequential integer index (e.g. 4), not an AWS eventId string (e.g. "4#abc123f"). When redact_latest_message subsequently calls update_message, it passes one of these integer-id messages to delete_event, which botocore rejects with: Parameter validation failed: Invalid type for parameter eventId, value: 4, type: <class 'int'>, valid types: <class 'str'> Add an isinstance(old_message_id, int) guard immediately after the existing None check so that integer positional indices are detected early and the method returns without attempting the delete, preventing the ParamValidationError.
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
update_messagecrashes with aParamValidationErrorwhensession_message.message_idis a Strands positional integer index (e.g.4) rather than an AWS eventId string (e.g."4#abc123f").This happens because
RepositorySessionManager.initialize_agentpopulates_latest_agent_messagewithSessionMessageobjects that carry a sequential integermessage_id. Whenredact_latest_messageis subsequently called it reads_latest_agent_message[agent_id]and passes that message toupdate_message, which then callsdelete_event(eventId=4). botocore rejects the integer:Fixes #556
Changes
src/bedrock_agentcore/memory/integrations/strands/session_manager.py: add anisinstance(old_message_id, int)guard immediately after the existingNonecheck inupdate_message. Integer positional indices cannot be mapped to AWS eventId strings without an extra API call, so the method logs a warning and returns early, preventing theParamValidationError.