Skip to content

fix(memory): guard against integer message_id in update_message#558

Open
citizen204 wants to merge 1 commit into
aws:mainfrom
citizen204:fix-556-update-message-integer-message-id
Open

fix(memory): guard against integer message_id in update_message#558
citizen204 wants to merge 1 commit into
aws:mainfrom
citizen204:fix-556-update-message-integer-message-id

Conversation

@citizen204

Copy link
Copy Markdown
Contributor

Summary

update_message crashes with a ParamValidationError when session_message.message_id is a Strands positional integer index (e.g. 4) rather than an AWS eventId string (e.g. "4#abc123f").

This happens because RepositorySessionManager.initialize_agent populates _latest_agent_message with SessionMessage objects that carry a sequential integer message_id. When redact_latest_message is subsequently called it reads _latest_agent_message[agent_id] and passes that message to update_message, which then calls delete_event(eventId=4). botocore rejects the integer:

Parameter validation failed: Invalid type for parameter eventId,
value: 4, type: <class 'int'>, valid types: <class 'str'>

Fixes #556

Changes

  • src/bedrock_agentcore/memory/integrations/strands/session_manager.py: add an isinstance(old_message_id, int) guard immediately after the existing None check in update_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 the ParamValidationError.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] update_message fails with parameter validation error when SessionMessage.message_id is a Strands positional integer index

1 participant