Skip to content

Commit d58f5a8

Browse files
committed
fix(server): start event bus processor for manual wiring
Ensure MainEventBusProcessor.ensureStarted() starts manually constructed processors, and call it from DefaultRequestHandler.create(...). This prevents manually wired integrations from leaving events stuck on the main event bus. Add a regression test for the manual wiring path that returns a Message response. This fixes #995
1 parent 45c6be6 commit d58f5a8

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎server-common/src/main/java/org/a2aproject/sdk/server/events/MainEventBusProcessor.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,31 @@ public void setPushNotificationExecutor(java.util.concurrent.Executor executor)
137137

138138
@SuppressWarnings("NullAway.Init")
139139
@PostConstruct
140-
void start() {
140+
synchronized void start() {
141+
if (processorThread != null) {
142+
LOGGER.debug("MainEventBusProcessor already started");
143+
return;
144+
}
145+
running = true;
141146
processorThread = new Thread(this, "MainEventBusProcessor");
142147
processorThread.setDaemon(true); // Allow JVM to exit even if this thread is running
143148
processorThread.start();
144149
LOGGER.info("MainEventBusProcessor started");
145150
}
146151

147152
/**
148-
* No-op method to force CDI proxy resolution and ensure @PostConstruct has been called.
149-
* Called by MainEventBusProcessorInitializer during application startup.
153+
* Ensures the background processor thread has been started.
154+
* <p>
155+
* In CDI runtimes, this forces proxy resolution and {@link PostConstruct}. For manual
156+
* wiring, this starts the processor directly.
157+
* </p>
150158
*/
151159
public void ensureStarted() {
152-
// Method intentionally empty - just forces proxy resolution
160+
start();
153161
}
154162

155163
@PreDestroy
156-
void stop() {
164+
synchronized void stop() {
157165
LOGGER.info("MainEventBusProcessor stopping...");
158166
running = false;
159167
if (processorThread != null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public static DefaultRequestHandler create(AgentExecutor agentExecutor, TaskStor
309309
handler.agentCompletionTimeoutSeconds = 5;
310310
handler.consumptionCompletionTimeoutSeconds = 2;
311311
handler.reconciliationTimeoutSeconds = 1;
312+
handler.mainEventBusProcessor.ensureStarted();
312313

313314
return handler;
314315
}

‎server-common/src/test/java/org/a2aproject/sdk/server/requesthandlers/DefaultRequestHandlerTest.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,41 @@ void testInitConfigReadsBlockingTimeouts() {
165165
assertEquals(7, handler.reconciliationTimeoutSeconds);
166166
}
167167

168+
@Test
169+
void testCreateStartsManuallyConstructedMainEventBusProcessor() throws Exception {
170+
InMemoryTaskStore manualTaskStore = new InMemoryTaskStore();
171+
PushNotificationConfigStore manualPushConfigStore = new InMemoryPushNotificationConfigStore();
172+
MainEventBus manualMainEventBus = new MainEventBus();
173+
InMemoryQueueManager manualQueueManager = new InMemoryQueueManager(manualTaskStore, manualMainEventBus);
174+
MainEventBusProcessor manualProcessor = new MainEventBusProcessor(
175+
manualMainEventBus, manualTaskStore, NOOP_PUSHNOTIFICATION_SENDER, manualQueueManager);
176+
177+
try {
178+
AgentExecutor manualAgentExecutor = new AgentExecutor() {
179+
@Override
180+
public void execute(RequestContext context, AgentEmitter agentEmitter) {
181+
agentEmitter.sendMessage("manual lifecycle response");
182+
}
183+
184+
@Override
185+
public void cancel(RequestContext context, AgentEmitter agentEmitter) {
186+
throw new AssertionError("Cancel should not be invoked");
187+
}
188+
};
189+
RequestHandler manualRequestHandler = DefaultRequestHandler.create(
190+
manualAgentExecutor, manualTaskStore, manualQueueManager, manualPushConfigStore,
191+
manualProcessor, internalExecutor, internalExecutor);
192+
193+
EventKind eventKind = manualRequestHandler.onMessageSend(
194+
MessageSendParams.builder().message(MESSAGE).build(), NULL_CONTEXT);
195+
196+
assertInstanceOf(Message.class, eventKind);
197+
assertEquals(Message.Role.ROLE_AGENT, ((Message) eventKind).role());
198+
} finally {
199+
EventQueueUtil.stop(manualProcessor);
200+
}
201+
}
202+
168203
/**
169204
* Test 1: Non-streaming AUTH_REQUIRED returns immediately while agent continues.
170205
* Verifies:

0 commit comments

Comments
 (0)