Repository navigation
Conversation
…t overtake newer state With flush_interval_seconds set, the interval timer and the agent thread can flush at the same time. Without a lock, a slow or failed flush could write an older agent snapshot after a newer one, an agent state could be saved ahead of the messages it counts, a failed message flush reordered messages, and a partial agent-state failure re-sent agents that were already written.
This branch has not been deployed
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.
What
Serializes batched flushes in
AgentCoreMemorySessionManagerwith one lock, and fixes the retry paths that put buffered data back._flush_messages_only,_flush_agent_states_onlyand_flush_messagesrun under_flush_lock._flush_messagestakes the agent states before the messages, so a saved state never counts a message that wasn't saved.Why
With
flush_interval_secondsset, the timer thread and the agent thread can flush at the same time. Onmainand on #700 that causes four problems:read_agentrestores stale state.Stacked on #700. GitHub retargets this PR to
mainwhen #700 merges.How tested
TestConcurrentFlushes. Five fail without the fix. The threaded one passed 50 of 50 repeat runs.pytest tests/bedrock_agentcore/memory/: 790 passed.ruff checkandruff format --checkare clean.create_event:batch_size=3, the interval timer and Claude Haiku 4.5 restores the latest state and all 6 messages.v=1restored twice, statev=2with 1 stored message, stored order['m2', 'm1'], and a duplicateagent-aevent.