From 963fa54f8cd8f47a85eb1966e89c040a7fa45f91 Mon Sep 17 00:00:00 2001 From: citizen204 Date: Tue, 30 Jun 2026 18:14:37 +0930 Subject: [PATCH] fix(memory): guard against integer message_id in update_message Fixes #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: , valid types: 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. --- .../memory/integrations/strands/session_manager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bedrock_agentcore/memory/integrations/strands/session_manager.py b/src/bedrock_agentcore/memory/integrations/strands/session_manager.py index c4fe8540..d5da48d2 100644 --- a/src/bedrock_agentcore/memory/integrations/strands/session_manager.py +++ b/src/bedrock_agentcore/memory/integrations/strands/session_manager.py @@ -686,6 +686,19 @@ def update_message(self, session_id: str, agent_id: str, session_message: Sessio logger.debug("Message has no event ID and was not found in buffer - skipping update") return + # Strands' RepositorySessionManager.initialize_agent passes SessionMessage objects + # whose message_id is a sequential integer index (0, 1, 2 …), not an AWS eventId + # string (e.g. "4#abc123f"). Passing an integer to delete_event causes a + # ParamValidationError at the botocore layer. Skip the update — the event + # cannot be located by a positional index alone. + if isinstance(old_message_id, int): + logger.warning( + "update_message: message_id %r is a Strands positional integer index, not an " + "AWS eventId string — skipping delete of old event (see issue #556)", + old_message_id, + ) + return + # Create a new event with the updated message content try: updated_message = SessionMessage(