Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): handle empty event bus subscription gracefully

Steven Enamakel58650b9a59fd
diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.ts
index 4e3bf8d006..8d8d23fd12 100644
--- a/app/src/services/chatService.ts
+++ b/app/src/services/chatService.ts
@@ -1173,6 +1173,46 @@ export function subscribeChatEvents(listeners: ChatEventListeners): () => void {
handlers.push([EVENTS.planReviewRequest, cb]);
}
+ if (listeners.onThreadTodosChanged) {
+ const cb = (payload: unknown) => {
+ const e = payload as ChatThreadTodosChangedEvent;
+ chatLog('%s thread_id=%s count=%d', EVENTS.threadTodosChanged, e.thread_id, e.todos?.length ?? 0);
+ listeners.onThreadTodosChanged?.(e);
+ };
+ socket.on(EVENTS.threadTodosChanged, cb);
+ handlers.push([EVENTS.threadTodosChanged, cb]);
+ }
+
+ if (listeners.onThreadGoalUpdated) {
+ const cb = (payload: unknown) => {
+ const e = payload as ChatThreadGoalUpdatedEvent;
+ chatLog('%s thread_id=%s status=%s', EVENTS.threadGoalUpdated, e.thread_id, e.goal?.status);
+ listeners.onThreadGoalUpdated?.(e);
+ };
+ socket.on(EVENTS.threadGoalUpdated, cb);
+ handlers.push([EVENTS.threadGoalUpdated, cb]);
+ }
+
+ if (listeners.onThreadGoalCleared) {
+ const cb = (payload: unknown) => {
+ const e = payload as ChatThreadGoalClearedEvent;
+ chatLog('%s thread_id=%s', EVENTS.threadGoalCleared, e.thread_id);
+ listeners.onThreadGoalCleared?.(e);
+ };
+ socket.on(EVENTS.threadGoalCleared, cb);
+ handlers.push([EVENTS.threadGoalCleared, cb]);
+ }
+
+ if (listeners.onRunModeChanged) {
+ const cb = (payload: unknown) => {
+ const e = payload as ChatRunModeChangedEvent;
+ chatLog('%s thread_id=%s mode=%s', EVENTS.runModeChanged, e.thread_id, e.mode);
+ listeners.onRunModeChanged?.(e);
+ };
+ socket.on(EVENTS.runModeChanged, cb);
+ handlers.push([EVENTS.runModeChanged, cb]);
+ }
+
// Artifact lifecycle events (#2779). The Rust subscriber in
// `web_chat::ArtifactSurfaceSubscriber` packs the
// artifact payload into the generic `args` field of the wire
diff --git a/crates/openhuman-core/src/web_chat/event_bus.rs b/crates/openhuman-core/src/web_chat/event_bus.rs
index 008d6b7863..b567a1657e 100644
--- a/crates/openhuman-core/src/web_chat/event_bus.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus.rs
@@ -157,6 +157,18 @@ impl EventHandler<DomainEvent> for AgentSurfaceSubscriber {
..Default::default()
});
}
+ DomainEvent::ThreadRunModeChanged { thread_id, mode } => {
+ log::debug!(
+ "[web-channel] agent-surface emitting run_mode_changed thread_id={thread_id} mode={mode}"
+ );
+ publish_web_channel_event(WebChannelEvent {
+ event: "run_mode_changed".to_string(),
+ client_id: String::new(),
+ thread_id: thread_id.clone(),
+ message: Some(mode.clone()),
+ ..Default::default()
+ });
+ }
DomainEvent::RunQueueMessageQueued {
thread_id,
item_id,