Skip to content

fix: use CopyOnWriteArrayList for thread-safe conversation history in InMemoryPersistenceFacade#3

Merged
rdobrik merged 4 commits intocodex/add-a2a-supportfrom
copilot/sub-pr-1-again
Mar 18, 2026
Merged

fix: use CopyOnWriteArrayList for thread-safe conversation history in InMemoryPersistenceFacade#3
rdobrik merged 4 commits intocodex/add-a2a-supportfrom
copilot/sub-pr-1-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

ConcurrentHashMap does not protect the values it stores — mutating a plain ArrayList retrieved via computeIfAbsent is not thread-safe and can cause lost updates or ConcurrentModificationException under concurrent load.

Changes

  • InMemoryPersistenceFacade — replace new ArrayList<>() with new CopyOnWriteArrayList<>() for the conversations map values, making concurrent reads (loadConversation, listConversationIds, latestTimestamp) and writes (appendEvent) safe without external synchronization
// before
conversations.computeIfAbsent(event.conversationId(), key -> new ArrayList<>()).add(event);

// after
conversations.computeIfAbsent(event.conversationId(), key -> new CopyOnWriteArrayList<>()).add(event);

Note: the originally flagged class (AgentA2ATaskRepository) was removed in PR #1 and replaced by AgentA2ATaskAdapter, which delegates state management to the thread-safe A2ATaskService. 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.

Copilot AI and others added 3 commits March 17, 2026 19:45
… 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
Copilot AI requested a review from rdobrik March 17, 2026 19:48
@rdobrik rdobrik marked this pull request as ready for review March 18, 2026 16:09
Copilot AI review requested due to automatic review settings March 18, 2026 16:09
@rdobrik rdobrik merged commit 4b35fe8 into codex/add-a2a-support Mar 18, 2026
1 check passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ArrayList with CopyOnWriteArrayList for conversations event storage in appendEvent().

💡 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);
@rdobrik rdobrik deleted the copilot/sub-pr-1-again branch March 18, 2026 16:29
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