fix: use CopyOnWriteArrayList for thread-safe conversation history in InMemoryPersistenceFacade#3
Merged
rdobrik merged 4 commits intocodex/add-a2a-supportfrom Mar 18, 2026
Conversation
… InMemoryPersistenceFacade Co-authored-by: rdobrik <8812511+rdobrik@users.noreply.github.com>
… InMemoryPersistenceFacade Co-authored-by: rdobrik <8812511+rdobrik@users.noreply.github.com>
Co-authored-by: rdobrik <8812511+rdobrik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on A2A runtime integration implementation
fix: use CopyOnWriteArrayList for thread-safe conversation history in InMemoryPersistenceFacade
Mar 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the in-memory persistence implementation to use a thread-safe list type for storing per-conversation events, aligning InMemoryPersistenceFacade with concurrent access patterns in the agent runtime (including fallback-to-in-memory scenarios).
Changes:
- Replaced
ArrayListwithCopyOnWriteArrayListforconversationsevent storage inappendEvent().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Override | ||
| public void appendEvent(AgentEvent event, String idempotencyKey) { | ||
| conversations.computeIfAbsent(event.conversationId(), key -> new ArrayList<>()).add(event); | ||
| conversations.computeIfAbsent(event.conversationId(), key -> new CopyOnWriteArrayList<>()).add(event); |
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.
ConcurrentHashMapdoes not protect the values it stores — mutating a plainArrayListretrieved viacomputeIfAbsentis not thread-safe and can cause lost updates orConcurrentModificationExceptionunder concurrent load.Changes
InMemoryPersistenceFacade— replacenew ArrayList<>()withnew CopyOnWriteArrayList<>()for theconversationsmap values, making concurrent reads (loadConversation,listConversationIds,latestTimestamp) and writes (appendEvent) safe without external synchronizationNote: the originally flagged class (
AgentA2ATaskRepository) was removed in PR #1 and replaced byAgentA2ATaskAdapter, which delegates state management to the thread-safeA2ATaskService. This change addresses the same pattern in the surviving in-memory persistence layer.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.