-
Notifications
You must be signed in to change notification settings - Fork 161
fix(server): start event bus processor for manual wiring #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo this change |
||
| } | ||
|
|
||
| @PreDestroy | ||
| void stop() { | ||
| synchronized void stop() { | ||
| LOGGER.info("MainEventBusProcessor stopping..."); | ||
| running = false; | ||
| if (processorThread != null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just call mainEventBusProcessor.start() if we have to. |
||
| } | ||
|
|
||
| @SuppressWarnings("NullAway.Init") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude thinks: The null-ID backfill in AgentEmitter (lines 522-528 of the diff) is unrelated to the event bus processor startup fix. |
||
| messageToSend = Message.builder(message) | ||
| .taskId(taskId) | ||
| .contextId(contextId) | ||
| .build(); | ||
| } | ||
| eventQueue.enqueueEvent(messageToSend); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just make this public synchronized