Skip to content

fix(server): start event bus processor for manual wiring#997

Open
014-code wants to merge 1 commit into
a2aproject:mainfrom
014-code:fix/995-main-event-bus-processor-startup
Open

fix(server): start event bus processor for manual wiring#997
014-code wants to merge 1 commit into
a2aproject:mainfrom
014-code:fix/995-main-event-bus-processor-startup

Conversation

@014-code

Copy link
Copy Markdown

Summary

  • Ensure manually constructed MainEventBusProcessor instances are started through ensureStarted().
  • Call ensureStarted() from DefaultRequestHandler.create(...) so Spring/manual wiring paths do not leave events stuck on MainEventBus.
  • Add regression coverage for the manually wired request handler path returning a Message response.

Related Issue

This fixes #995.

Testing

  • Passed: mvn -pl server-common -am -Dtest=DefaultRequestHandlerTest#testCreateStartsManuallyConstructedMainEventBusProcessor -Dsurefire.failIfNoSpecifiedTests=false test

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 a2aproject#995
@guofengzh

Copy link
Copy Markdown

Based on the summary in #997, I adjusted the way Spring beans are constructed in ServerConfig, then, the expected response was received.

The change are:

  1. Use the constructor of DefaultRequestHandler to construct an instance of DefaultRequestHandler.
  2. Construct a separate MainEventBusProcessor bean, and then inject it into the DefaultRequestHandler bean.

In other words, the following construct

	@Bean
	public RequestHandler requestHandler(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager,
	                                     PushNotificationConfigStore pushConfigStore,
										 MainEventBus mainEventBus,
										 PushNotificationSender pushSender,
	                                     @Qualifier("a2aInternal") Executor executor) {
		ExecutorService eventConsumerExecutor = Executors.newFixedThreadPool(3);
		return new DefaultRequestHandler(agentExecutor, taskStore, queueManager, pushConfigStore,
				new MainEventBusProcessor(mainEventBus, taskStore, pushSender, queueManager),
				executor,
				eventConsumerExecutor);
	}

is transformed into

	@Bean
	public MainEventBusProcessor mainEventBusProcessor(MainEventBus mainEventBus,TaskStore taskStore,
													   PushNotificationSender pushSender,
													   QueueManager queueManager) {
		return new MainEventBusProcessor(mainEventBus, taskStore, pushSender, queueManager);
	}
	

	@Bean
	public RequestHandler requestHandler(AgentExecutor agentExecutor, TaskStore taskStore, QueueManager queueManager,
	                                     PushNotificationConfigStore pushConfigStore,
	                                     MainEventBusProcessor mainEventBusProcessor,
	                                     @Qualifier("a2aInternal") Executor executor) {
		return new DefaultRequestHandler(agentExecutor, taskStore, queueManager,
				pushConfigStore, mainEventBusProcessor,
				executor, executor);
	}

Spring Boot recognizes @PostConstruct (and @Inject), so DefaultRequestHandler.initConfig() and MainEventBusProcessor.start() will be executed in this case.

Then, test using the following request:

{
  "jsonrpc": "2.0",
  "id": "6e7bf51a-f364-42d7-a060-343da3cc4f43",
  "method": "SendMessage",
  "params": {
    "message": {
      "messageId": "messageId-1",
      "role": "ROLE_USER",
      "parts": [
        {
          "text": "Can you check systems?"
        }
      ]
    }
  }
}

Response 200 OK

Response Body:

{
  "error": null,
  "id": "6e7bf51a-f364-42d7-a060-343da3cc4f43",
  "jsonrpc": "2.0",
  "result": {
    "role": "ROLE_AGENT",
    "parts": [
      {
        "text": "Hello World",
        "metadata": null
      }
    ],
    "messageId": "d062faba-39e6-4ac6-b891-9e0ba1363a69",
    "contextId": "c2c16e07-dfad-40f1-958c-41d336d4363e",
    "taskId": "d38c2bc5-7491-4920-a290-93582d21a9e0",
    "referenceTaskIds": null,
    "metadata": null,
    "extensions": null
  }
}

That is, a success result was returned.

Hopefully, these new improvements will be helpful to your revisions.

Thanks for what you did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Help]: Could not find a Task/Message for 84ced8e6-3705-41c6-9158-f2b880463a32

2 participants