Skip to content

fix: implement update_message() for guardrail redaction support#388

Open
notgitika wants to merge 4 commits intomainfrom
fix/update-message-guardrail-redaction
Open

fix: implement update_message() for guardrail redaction support#388
notgitika wants to merge 4 commits intomainfrom
fix/update-message-guardrail-redaction

Conversation

@notgitika
Copy link
Copy Markdown
Contributor

Summary

  • Implement update_message() in AgentCoreMemorySessionManager so that Strands' built-in guardrail redaction (redact_latest_message()) works out of the box
  • Since AgentCore Memory events are immutable, updates are performed via create-then-delete (same pattern as update_agent())
  • Handle the batch_size > 1 case by replacing messages in the send buffer before they are flushed

Context

When using Bedrock Guardrails with AgentCore Memory as the Strands session store, update_message() was a no-op. This meant guardrail-blocked user messages were persisted unredacted, creating a permanent dead-end conversation — on subsequent turns or reconnect, the guardrail would block again on the persisted offending message.

Test plan

  • test_update_message — verifies new event created + old event deleted for persisted messages
  • test_update_message_wrong_session — session ID mismatch raises SessionException
  • test_update_message_no_message_id — graceful skip when message has no event ID
  • test_update_message_create_fails — raises SessionException on create failure
  • test_update_message_delete_fails — raises SessionException on delete failure
  • test_update_buffered_message — in-buffer replacement when batch_size > 1
  • Full test suite passes (140/140)

@notgitika notgitika requested a review from a team April 2, 2026 05:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

✅ No Breaking Changes Detected

No public API breaking changes found in this PR.

Note: AgentCore Memory doesn't support updating events,
so this is primarily for validation and logging.
Since AgentCore Memory events are immutable, this method performs an update by
creating a new event with the updated content and deleting the old event.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a risk that anyone maintains a pointer/reference to the old eventId? My understanding is that recreating it will generate a completely different ID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added logic to update _latest_agent_message with the new eventId after a successful replacement, so it doesn't hold a reference to the deleted event

If create_message succeeds but delete_event fails, attempt to roll back
the newly created event to avoid leaving duplicate messages. Addresses
review comment about partial failure handling.
…essage

Prevents stale eventId references by updating the tracked latest message
with the new eventId after a successful create+delete replacement.
@notgitika notgitika force-pushed the fix/update-message-guardrail-redaction branch from 828699f to a6df5f4 Compare April 11, 2026 03:08
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.

3 participants