This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new abfa7fadf784 CAMEL-28108: Preserve emitted A2A artifacts when
completing SendMessage tasks (#31358)
abfa7fadf784 is described below
commit abfa7fadf784534be371bce1f009aced9b91e01f
Author: Luigi De Masi <[email protected]>
AuthorDate: Fri Dec 4 14:45:22 2026 +0100
CAMEL-28108: Preserve emitted A2A artifacts when completing SendMessage
tasks (#31358)
A route could emit an artifact, then lose it when the consumer replaced the
running task with the final reply, so the blocking SendMessage reply and
later
GetTask calls missed the artifact.
Carry the artifacts from the running task into the final SendMessage
response
under the same store lock used by progress updates. Cover the blocking reply
and GetTask after blocking and asynchronous completion over JSON-RPC.
Co-authored-by: OpenAI Codex <[email protected]>
Signed-off-by: Luigi De Masi <[email protected]>
---
.../apache/camel/catalog/docs/a2a-consumer.adoc | 3 +
.../camel-a2a/src/main/docs/a2a-consumer.adoc | 3 +
.../apache/camel/component/a2a/A2AConsumer.java | 29 +++++++---
.../apache/camel/component/a2a/A2AProgress.java | 2 +-
.../a2a/A2AConsumerHttpIntegrationTest.java | 64 ++++++++++++++++++++--
5 files changed, 86 insertions(+), 15 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/a2a-consumer.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/a2a-consumer.adoc
index ee8118720688..59a2fd761ffe 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/a2a-consumer.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/a2a-consumer.adoc
@@ -517,6 +517,9 @@ Message msg = Message.builder()
A2AProgress.emitMessage(exchange, msg);
----
+Artifacts emitted during a blocking `SendMessage` are included in the
completed task returned to the caller.
+For both blocking and asynchronous `SendMessage`, clients can retrieve those
artifacts with `GetTask` after completion.
+
The consumer supports two SSE streaming patterns:
* *`SendStreamingMessage`* — The stream starts with the submitted `Task`,
followed by progress events from `A2AProgress` or `${a2a:emit()}`. When the
route completes, the body is emitted as the final message.
diff --git a/components/camel-ai/camel-a2a/src/main/docs/a2a-consumer.adoc
b/components/camel-ai/camel-a2a/src/main/docs/a2a-consumer.adoc
index ee8118720688..59a2fd761ffe 100644
--- a/components/camel-ai/camel-a2a/src/main/docs/a2a-consumer.adoc
+++ b/components/camel-ai/camel-a2a/src/main/docs/a2a-consumer.adoc
@@ -517,6 +517,9 @@ Message msg = Message.builder()
A2AProgress.emitMessage(exchange, msg);
----
+Artifacts emitted during a blocking `SendMessage` are included in the
completed task returned to the caller.
+For both blocking and asynchronous `SendMessage`, clients can retrieve those
artifacts with `GetTask` after completion.
+
The consumer supports two SSE streaming patterns:
* *`SendStreamingMessage`* — The stream starts with the submitted `Task`,
followed by progress events from `A2AProgress` or `${a2a:emit()}`. When the
route completes, the body is emitted as the final message.
diff --git
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AConsumer.java
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AConsumer.java
index 646a075b1f10..58ff0873c248 100644
---
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AConsumer.java
+++
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AConsumer.java
@@ -36,6 +36,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import org.apache.camel.Consumer;
@@ -1285,12 +1286,7 @@ public class A2AConsumer extends DefaultConsumer {
request.getConfiguration());
if (response.isTaskResponse()) {
- Task task = response.getTask();
- store.put(task.id(), task);
- if (task.status() != null) {
- store.notifySubscribers(task.id(),
- StreamResponse.ofStatusUpdate(buildStatusEvent(task)));
- }
+ response.setTask(storeTaskResponse(store, response.getTask()));
} else if (createdTask) {
store.delete(taskId);
forgetTaskOwner(taskId);
@@ -1299,6 +1295,24 @@ public class A2AConsumer extends DefaultConsumer {
return response;
}
+ private static Task storeTaskResponse(A2ATaskStore store, Task task) {
+ ReentrantLock lock = A2AProgress.lockFor(store);
+ lock.lock();
+ try {
+ Task current = store.get(task.id());
+ if (current != null && current.artifacts() != null) {
+ task =
Task.builder(task).artifacts(current.artifacts()).build();
+ }
+ store.put(task.id(), task);
+ } finally {
+ lock.unlock();
+ }
+ if (task.status() != null) {
+ store.notifySubscribers(task.id(),
StreamResponse.ofStatusUpdate(buildStatusEvent(task)));
+ }
+ return task;
+ }
+
private static void setTaskContext(Exchange exchange, String taskId,
String contextId, String operation) {
exchange.setProperty(A2AConstants.REQUEST_TASK_ID, taskId);
exchange.setProperty(A2AConstants.REQUEST_CONTEXT_ID, contextId);
@@ -1401,8 +1415,7 @@ public class A2AConsumer extends DefaultConsumer {
.id(taskId)
.contextId(contextId)
.build();
- store.put(taskId, completed);
- store.notifySubscribers(taskId,
StreamResponse.ofStatusUpdate(buildStatusEvent(completed)));
+ storeTaskResponse(store, completed);
}
} catch (Exception e) {
LOG.error("Async task processing failed for taskId={}",
taskId, e);
diff --git
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AProgress.java
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AProgress.java
index 540c97506fe6..aa59e1ea18e9 100644
---
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AProgress.java
+++
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/A2AProgress.java
@@ -50,7 +50,7 @@ public final class A2AProgress {
* returned so that callers coordinate with the store's lifecycle
operations. Otherwise, a per-store fallback lock
* is created and cached.
*/
- private static ReentrantLock lockFor(A2ATaskStore store) {
+ static ReentrantLock lockFor(A2ATaskStore store) {
if (store instanceof GuardedTaskStore guarded) {
return guarded.getLock();
}
diff --git
a/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/A2AConsumerHttpIntegrationTest.java
b/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/A2AConsumerHttpIntegrationTest.java
index 2b8e92658952..cf04e765d790 100644
---
a/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/A2AConsumerHttpIntegrationTest.java
+++
b/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/A2AConsumerHttpIntegrationTest.java
@@ -21,22 +21,31 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.a2a.model.Artifact;
+import org.apache.camel.component.a2a.model.Task;
+import org.apache.camel.component.a2a.model.TaskState;
+import org.apache.camel.component.a2a.model.TextPart;
import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer;
import
org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServerConfiguration;
import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.test.AvailablePortFinder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
class A2AConsumerHttpIntegrationTest {
@@ -44,13 +53,12 @@ class A2AConsumerHttpIntegrationTest {
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();
- private int port;
+ private VertxPlatformHttpServer server;
private CamelContext context;
private HttpClient http;
@BeforeEach
void setUp() {
- port = AvailablePortFinder.getNextAvailable();
http = HttpClient.newHttpClient();
}
@@ -63,17 +71,18 @@ class A2AConsumerHttpIntegrationTest {
private CamelContext createContext() throws Exception {
VertxPlatformHttpServerConfiguration conf = new
VertxPlatformHttpServerConfiguration();
- conf.setBindPort(port);
+ conf.setBindPort(0);
CamelContext ctx = new DefaultCamelContext();
ctx.getShutdownStrategy().setTimeout(5);
- ctx.addService(new VertxPlatformHttpServer(conf));
+ server = new VertxPlatformHttpServer(conf);
+ ctx.addService(server);
// Trigger platform-http component creation so RestConsumerFactory is
discoverable
ctx.getComponent("platform-http");
return ctx;
}
private String baseUrl() {
- return "http://localhost:" + port;
+ return "http://localhost:" + server.getPort();
}
private HttpResponse<String> get(String path) throws Exception {
@@ -291,6 +300,49 @@ class A2AConsumerHttpIntegrationTest {
assertThat(body.get("id").asString()).isEqualTo("req-1");
}
+ @ParameterizedTest
+ @ValueSource(booleans = { false, true })
+ void sendMessagePreservesEmittedArtifacts(boolean returnImmediately)
throws Exception {
+ Artifact stock =
Artifact.builder().artifactId("stock").parts(List.of(new TextPart("12
bottles"))).build();
+ context = createContext();
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("a2a:stock?protocolBinding=JSONRPC&validateAuth=false")
+ .process(exchange ->
A2AProgress.emitArtifact(exchange, stock, false, true))
+ .setBody(constant("Stock lookup complete"));
+ }
+ });
+ context.start();
+
+ String params = """
+
{"message":{"messageId":"lookup","role":"user","parts":[{"text":"Check
stock"}]},
+ "configuration":{"returnImmediately":%s}}
+ """.formatted(returnImmediately);
+ Task reply = MAPPER.treeToValue(jsonRpc("SendMessage",
params).get("task"), Task.class);
+ if (returnImmediately) {
+ assertThat(reply.status().state()).isEqualTo(TaskState.SUBMITTED);
+ } else {
+ assertThat(reply.status().state()).isEqualTo(TaskState.COMPLETED);
+ assertThat(reply.artifacts()).containsExactly(stock);
+ }
+
+ String taskParams = MAPPER.writeValueAsString(Map.of("id",
reply.id()));
+ Task completed = await().atMost(10, TimeUnit.SECONDS).until(
+ () -> MAPPER.treeToValue(jsonRpc("GetTask", taskParams),
Task.class),
+ task -> task.status().state() == TaskState.COMPLETED);
+ assertThat(completed.artifacts()).containsExactly(stock);
+ }
+
+ private JsonNode jsonRpc(String method, String params) throws Exception {
+ String request = """
+ {"jsonrpc":"2.0","id":"req-1","method":"%s","params":%s}
+ """.formatted(method, params);
+ HttpResponse<String> response = post("/", request,
A2AConstants.JSONRPC_CONTENT_TYPE);
+ assertThat(response.statusCode()).isEqualTo(200);
+ return MAPPER.readTree(response.body()).required("result");
+ }
+
@Test
void agentCardPublicWhenAuthEnabled() throws Exception {
context = createContext();