Skip to content

Commit a6b42b3

Browse files
jmesnilclaude
andcommitted
fix: Apply historyLength from MessageSendConfiguration in SendMessage response
The onMessageSend() method was not applying the historyLength parameter from MessageSendConfiguration to the returned Task. When historyLength=0, the spec (CORE-HIST-003, Section 3.2.4) requires no history to be returned, but the full history was being included. The fix reuses the existing limitTaskHistory() method (already used by onGetTask) to filter the Task history before returning from onMessageSend(). This fixes a2aproject#816 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 215270c commit a6b42b3

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎server-common/src/main/java/org/a2aproject/sdk/server/requesthandlers/DefaultRequestHandler.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ public EventKind onMessageSend(MessageSendParams params, ServerCallContext conte
625625
});
626626
}
627627

628+
if (kind instanceof Task task) {
629+
Integer historyLength = params.configuration() != null ? params.configuration().historyLength() : null;
630+
kind = limitTaskHistory(task, historyLength);
631+
}
632+
628633
LOGGER.debug("Returning: {}", kind);
629634
return kind;
630635
}

‎tests/server-common/src/test/java/org/a2aproject/sdk/server/apps/common/AbstractA2AServerTest.java‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.a2aproject.sdk.spec.ListTaskPushNotificationConfigsResult;
7070
import org.a2aproject.sdk.spec.ListTasksParams;
7171
import org.a2aproject.sdk.spec.Message;
72+
import org.a2aproject.sdk.spec.MessageSendConfiguration;
7273
import org.a2aproject.sdk.spec.MessageSendParams;
7374
import org.a2aproject.sdk.spec.MethodNotFoundError;
7475
import org.a2aproject.sdk.spec.Part;
@@ -3022,4 +3023,66 @@ private String extractTextFromTask(Task task) {
30223023
.collect(Collectors.joining("\n"));
30233024
}
30243025

3026+
@Test
3027+
@Timeout(value = 30, unit = TimeUnit.SECONDS)
3028+
public void testSendMessageWithHistoryLengthZero() throws Exception {
3029+
AtomicReference<String> taskIdRef = new AtomicReference<>();
3030+
3031+
try {
3032+
Message initialMessage = Message.builder(MESSAGE)
3033+
.parts(new TextPart("input-required:Trigger INPUT_REQUIRED"))
3034+
.build();
3035+
3036+
CountDownLatch initialLatch = new CountDownLatch(1);
3037+
getNonStreamingClient().sendMessage(initialMessage, List.of((event, agentCard) -> {
3038+
if (event instanceof TaskEvent te) {
3039+
taskIdRef.set(te.getTask().id());
3040+
initialLatch.countDown();
3041+
} else if (event instanceof TaskUpdateEvent tue) {
3042+
if (tue.getUpdateEvent() instanceof TaskStatusUpdateEvent statusUpdate) {
3043+
taskIdRef.set(statusUpdate.taskId());
3044+
}
3045+
initialLatch.countDown();
3046+
}
3047+
}), null);
3048+
3049+
assertTrue(initialLatch.await(15, TimeUnit.SECONDS), "Initial sendMessage should complete");
3050+
String taskId = taskIdRef.get();
3051+
assertNotNull(taskId, "Should have captured task ID");
3052+
3053+
Message followUp = Message.builder(MESSAGE)
3054+
.taskId(taskId)
3055+
.parts(new TextPart("input-required:User input"))
3056+
.build();
3057+
3058+
MessageSendParams params = MessageSendParams.builder()
3059+
.message(followUp)
3060+
.configuration(MessageSendConfiguration.builder()
3061+
.historyLength(0)
3062+
.build())
3063+
.build();
3064+
3065+
CountDownLatch followUpLatch = new CountDownLatch(1);
3066+
AtomicReference<Task> resultTaskRef = new AtomicReference<>();
3067+
getNonStreamingClient().sendMessage(params, List.of((BiConsumer<ClientEvent, AgentCard>) (event, agentCard) -> {
3068+
if (event instanceof TaskEvent te) {
3069+
resultTaskRef.set(te.getTask());
3070+
followUpLatch.countDown();
3071+
}
3072+
}), null, null);
3073+
3074+
assertTrue(followUpLatch.await(15, TimeUnit.SECONDS), "Follow-up sendMessage should complete");
3075+
Task resultTask = resultTaskRef.get();
3076+
assertNotNull(resultTask, "Should have received a Task response");
3077+
assertTrue(resultTask.history() == null || resultTask.history().isEmpty(),
3078+
"historyLength=0 should return no history, but got " +
3079+
(resultTask.history() != null ? resultTask.history().size() : 0) + " messages");
3080+
} finally {
3081+
String taskId = taskIdRef.get();
3082+
if (taskId != null) {
3083+
deleteTaskInTaskStore(taskId);
3084+
}
3085+
}
3086+
}
3087+
30253088
}

0 commit comments

Comments
 (0)