Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,31 @@ public void setPushNotificationExecutor(java.util.concurrent.Executor executor)

@SuppressWarnings("NullAway.Init")
@PostConstruct
void start() {
synchronized void start() {
if (processorThread != null && processorThread.isAlive()) {
LOGGER.debug("MainEventBusProcessor already started");
return;
}
running = true;
processorThread = new Thread(this, "MainEventBusProcessor");
processorThread.setDaemon(true); // Allow JVM to exit even if this thread is running
processorThread.start();
LOGGER.info("MainEventBusProcessor started");
}

/**
* No-op method to force CDI proxy resolution and ensure @PostConstruct has been called.
* Called by MainEventBusProcessorInitializer during application startup.
* Ensures the background processor thread has been started.
* <p>
* In CDI runtimes, this forces proxy resolution and {@link PostConstruct}. For manual
* wiring, this starts the processor directly.
* </p>
*/
public void ensureStarted() {
// Method intentionally empty - just forces proxy resolution
start();
}

@PreDestroy
void stop() {
synchronized void stop() {
LOGGER.info("MainEventBusProcessor stopping...");
running = false;
if (processorThread != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public DefaultRequestHandler(AgentExecutor agentExecutor, TaskStore taskStore,
// I am unsure about the correct scope.
// Also reworked to make a Supplier since otherwise the builder gets polluted with wrong tasks
this.requestContextBuilder = () -> new SimpleRequestContextBuilder(taskStore, false);
this.mainEventBusProcessor.ensureStarted();
}

@SuppressWarnings("NullAway.Init")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ public void sendMessage(List<Part<?>> parts, @Nullable Map<String, Object> metad
* Sends an existing Message object directly to the client.
* <p>
* Use this when you need to forward or echo an existing message without creating a new one.
* The message is enqueued as-is, preserving its messageId, metadata, and all other fields.
* The message is enqueued with this emitter's task and context IDs when they are missing,
* preserving its messageId, metadata, and all other fields.
* </p>
* <p>
* <b>Note:</b> This is typically used for forwarding user messages or preserving specific
Expand All @@ -518,7 +519,14 @@ public void sendMessage(Message message) {
LOGGER.error("Message contextId mismatch: expected={}, actual={}", contextId, message.contextId());
throw new IllegalArgumentException("Message contextId does not match the emitter's contextId");
}
eventQueue.enqueueEvent(message);
Message messageToSend = message;
if (message.taskId() == null || message.contextId() == null) {
messageToSend = Message.builder(message)
.taskId(taskId)
.contextId(contextId)
.build();
}
eventQueue.enqueueEvent(messageToSend);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,44 @@ void testInitConfigReadsBlockingTimeouts() {
assertEquals(7, handler.reconciliationTimeoutSeconds);
}

@Test
void testConstructorStartsManuallyConstructedMainEventBusProcessor() throws Exception {
InMemoryTaskStore manualTaskStore = new InMemoryTaskStore();
PushNotificationConfigStore manualPushConfigStore = new InMemoryPushNotificationConfigStore();
MainEventBus manualMainEventBus = new MainEventBus();
InMemoryQueueManager manualQueueManager = new InMemoryQueueManager(manualTaskStore, manualMainEventBus);
MainEventBusProcessor manualProcessor = new MainEventBusProcessor(
manualMainEventBus, manualTaskStore, NOOP_PUSHNOTIFICATION_SENDER, manualQueueManager);

try {
AgentExecutor manualAgentExecutor = new AgentExecutor() {
@Override
public void execute(RequestContext context, AgentEmitter agentEmitter) {
agentEmitter.sendMessage("manual lifecycle response");
}

@Override
public void cancel(RequestContext context, AgentEmitter agentEmitter) {
throw new AssertionError("Cancel should not be invoked");
}
};
DefaultRequestHandler manualRequestHandler = new DefaultRequestHandler(
manualAgentExecutor, manualTaskStore, manualQueueManager, manualPushConfigStore,
manualProcessor, internalExecutor, internalExecutor);
manualRequestHandler.agentCompletionTimeoutSeconds = 5;
manualRequestHandler.consumptionCompletionTimeoutSeconds = 2;
manualRequestHandler.reconciliationTimeoutSeconds = 1;

EventKind eventKind = manualRequestHandler.onMessageSend(
MessageSendParams.builder().message(MESSAGE).build(), NULL_CONTEXT);

assertInstanceOf(Message.class, eventKind);
assertEquals(Message.Role.ROLE_AGENT, ((Message) eventKind).role());
} finally {
EventQueueUtil.stop(manualProcessor);
}
}

/**
* Test 1: Non-streaming AUTH_REQUIRED returns immediately while agent continues.
* Verifies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@
@SuppressWarnings("deprecation")
@Test
public void testRequiresInputWithFinalTrue() throws Exception {
agentEmitter.requiresInput(true);

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17, multi-version)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17, multi-version)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / test-cloud-deployment

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 17)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 190 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (windows-latest, 17)

[removal] requiresInput(boolean) in AgentEmitter has been deprecated and marked for removal
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_INPUT_REQUIRED, null);
}

@SuppressWarnings("deprecation")
@Test
public void testRequiresInputWithMessageAndFinalTrue() throws Exception {
agentEmitter.requiresInput(SAMPLE_MESSAGE, true);

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17, multi-version)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17, multi-version)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / test-cloud-deployment

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 17)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 197 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (windows-latest, 17)

[removal] requiresInput(Message,boolean) in AgentEmitter has been deprecated and marked for removal
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_INPUT_REQUIRED, SAMPLE_MESSAGE);
}

Expand All @@ -213,14 +213,14 @@
@SuppressWarnings("deprecation")
@Test
public void testRequiresAuthWithFinalTrue() throws Exception {
agentEmitter.requiresAuth(true);

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17, multi-version)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17, multi-version)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / test-cloud-deployment

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 17)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 216 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (windows-latest, 17)

[removal] requiresAuth(boolean) in AgentEmitter has been deprecated and marked for removal
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_AUTH_REQUIRED, null);
}

@SuppressWarnings("deprecation")
@Test
public void testRequiresAuthWithMessageAndFinalTrue() throws Exception {
agentEmitter.requiresAuth(SAMPLE_MESSAGE, true);

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17, multi-version)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test (17)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / tck-test-0-3 (17, multi-version)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / test-cloud-deployment

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 17)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal

Check warning on line 223 in server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java

View workflow job for this annotation

GitHub Actions / build (windows-latest, 17)

[removal] requiresAuth(Message,boolean) in AgentEmitter has been deprecated and marked for removal
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_AUTH_REQUIRED, SAMPLE_MESSAGE);
}

Expand Down Expand Up @@ -461,6 +461,12 @@
EventQueueItem item = eventQueue.dequeueEventItem(WAIT_MILLI_SECONDS);
assertNotNull(item);
assertInstanceOf(Message.class, item.getEvent());
Message emittedMessage = (Message) item.getEvent();
assertEquals(TEST_TASK_ID, emittedMessage.taskId());
assertEquals(TEST_TASK_CONTEXT_ID, emittedMessage.contextId());
assertEquals(message.messageId(), emittedMessage.messageId());
assertEquals(message.role(), emittedMessage.role());
assertEquals(message.parts(), emittedMessage.parts());
}

@Test
Expand Down
Loading