Skip to content

Commit f8f2512

Browse files
committed
Review fixes
1 parent 333e326 commit f8f2512

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,18 @@ public EventKind onMessageSend(MessageSendParams params, ServerCallContext conte
307307

308308
// Step 4: Fetch the final task state from TaskStore (all events have been processed)
309309
Task updatedTask = taskStore.get(taskId);
310-
if (updatedTask != null) {
311-
if (failed && !updatedTask.getStatus().state().isFinal()) {
312-
// If we had exceptions above, update the Task to reflect that
313-
Message msg = new Message.Builder()
314-
.role(Message.Role.AGENT)
310+
Message errorMessage = failed ?
311+
new Message.Builder()
312+
.role(Message.Role.AGENT) // System seems more accurate for this
315313
.parts(Collections.singletonList(new TextPart(error)))
316314
.contextId(mss.requestContext.getContextId())
317315
.taskId(taskId)
318-
.build();
319-
316+
.build() : null;
317+
if (updatedTask != null) {
318+
if (failed && !updatedTask.getStatus().state().isFinal()) {
319+
// If we had exceptions above, update the Task to reflect that
320320
updatedTask = new Task.Builder(updatedTask)
321-
.status(new TaskStatus(TaskState.FAILED, msg, null))
321+
.status(new TaskStatus(TaskState.FAILED, errorMessage, null))
322322
.build();
323323
taskStore.save(updatedTask);
324324
}
@@ -328,6 +328,11 @@ public EventKind onMessageSend(MessageSendParams params, ServerCallContext conte
328328
taskId, updatedTask.getStatus().state(),
329329
updatedTask.getArtifacts().size());
330330
}
331+
332+
} else if (failed) {
333+
// No Task but return an error to the user
334+
LOGGER.warn("Task {} not found in store, but a failure occurred: {}", taskId, error);
335+
kind = errorMessage; // Return the error message as the EventKind
331336
}
332337
}
333338
if (kind instanceof Task taskResult && !taskId.equals(taskResult.getId())) {

0 commit comments

Comments
 (0)