Skip to content

Commit e8fd7f2

Browse files
authored
fix: flaky testInputRequiredWorkflow test (#671)
1 parent 8946760 commit e8fd7f2

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

tests/server-common/src/test/java/io/a2a/server/apps/common/AbstractA2AServerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ private boolean awaitChildQueueCountStable(String taskId, int expectedCount, lon
15381538
@Timeout(value = 1, unit = TimeUnit.MINUTES)
15391539
public void testInputRequiredWorkflow() throws Exception {
15401540
String inputRequiredTaskId = "input-required-test-" + java.util.UUID.randomUUID();
1541+
boolean taskCreated = false;
15411542
try {
15421543
// 1. Send initial message - AgentExecutor will transition task to INPUT_REQUIRED
15431544
Message initialMessage = Message.builder(MESSAGE)
@@ -1572,6 +1573,7 @@ public void testInputRequiredWorkflow() throws Exception {
15721573
assertTrue(initialLatch.await(10, TimeUnit.SECONDS));
15731574
assertFalse(initialUnexpectedEvent.get());
15741575
assertEquals(TaskState.TASK_STATE_INPUT_REQUIRED, initialState.get());
1576+
taskCreated = true;
15751577

15761578
// 2. Send input message - AgentExecutor will complete the task
15771579
Message inputMessage = Message.builder(MESSAGE)
@@ -1608,7 +1610,9 @@ public void testInputRequiredWorkflow() throws Exception {
16081610
assertEquals(TaskState.TASK_STATE_COMPLETED, completedState.get());
16091611

16101612
} finally {
1611-
deleteTaskInTaskStore(inputRequiredTaskId);
1613+
if (taskCreated) {
1614+
deleteTaskInTaskStore(inputRequiredTaskId);
1615+
}
16121616
}
16131617
}
16141618

tests/server-common/src/test/java/io/a2a/server/apps/common/AgentExecutorProducer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public void execute(RequestContext context, AgentEmitter agentEmitter) throws A2
7979
if (taskId != null && taskId.startsWith("input-required-test")) {
8080
// First call: context.getTask() == null (new task)
8181
if (context.getTask() == null) {
82-
agentEmitter.startWork();
82+
// Go directly to INPUT_REQUIRED without intermediate WORKING state
83+
// This avoids race condition where blocking call interrupts on WORKING
84+
// before INPUT_REQUIRED is persisted to TaskStore
8385
agentEmitter.requiresInput(agentEmitter.newAgentMessage(
8486
List.of(new TextPart("Please provide additional information")),
8587
context.getMessage().metadata()));
@@ -91,7 +93,8 @@ public void execute(RequestContext context, AgentEmitter agentEmitter) throws A2
9193
throw new InvalidParamsError("We didn't get the expected input");
9294
}
9395
// Second call: context.getTask() != null (input provided)
94-
agentEmitter.startWork();
96+
// Go directly to COMPLETED without intermediate WORKING state
97+
// This avoids the same race condition as the first call
9598
agentEmitter.complete();
9699
return;
97100
}

0 commit comments

Comments
 (0)