From 94de7f199f86b39bdb7cce6e9800eb05008a8953 Mon Sep 17 00:00:00 2001 From: Maciej Szwaja Date: Wed, 18 Mar 2026 09:37:12 -0700 Subject: [PATCH] fix: Use ConcurrentHashMap in InvocationReplayState fixes #1009 PiperOrigin-RevId: 885641755 --- .../java/com/google/adk/plugins/InvocationReplayState.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev/src/main/java/com/google/adk/plugins/InvocationReplayState.java b/dev/src/main/java/com/google/adk/plugins/InvocationReplayState.java index 7d70a0efb..eab293de0 100644 --- a/dev/src/main/java/com/google/adk/plugins/InvocationReplayState.java +++ b/dev/src/main/java/com/google/adk/plugins/InvocationReplayState.java @@ -16,8 +16,8 @@ package com.google.adk.plugins; import com.google.adk.plugins.recordings.Recordings; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** Per-invocation replay state to isolate concurrent runs. */ class InvocationReplayState { @@ -33,7 +33,7 @@ public InvocationReplayState(String testCasePath, int userMessageIndex, Recordin this.testCasePath = testCasePath; this.userMessageIndex = userMessageIndex; this.recordings = recordings; - this.agentReplayIndices = new HashMap<>(); + this.agentReplayIndices = new ConcurrentHashMap<>(); } public String getTestCasePath() { @@ -57,7 +57,6 @@ public void setAgentReplayIndex(String agentName, int index) { } public void incrementAgentReplayIndex(String agentName) { - int currentIndex = getAgentReplayIndex(agentName); - setAgentReplayIndex(agentName, currentIndex + 1); + agentReplayIndices.merge(agentName, 1, Integer::sum); } }