Skip to content

Commit 59520d4

Browse files
committed
fix(StateBasedAgent): catch aggregator execptions
1 parent 7b67e45 commit 59520d4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/rai_core/rai/agents/base_state_based_agent.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def process_aggregator(
136136
f"Running aggregator: {aggregator}(source={source}) on {len(aggregator.get_buffer())} messages"
137137
)
138138
ts = time.perf_counter()
139+
139140
output = aggregator.get()
141+
140142
self.logger.debug(
141143
f'Aggregator "{aggregator}(source={source})" done in {time.perf_counter() - ts:.2f}s'
142144
)
@@ -150,9 +152,15 @@ def process_aggregator(
150152
futures.append(future)
151153

152154
for future in as_completed(futures):
153-
source, output = future.result()
154-
if output is not None:
155-
self._aggregation_results[source] = output
155+
try:
156+
source, output = future.result()
157+
except Exception as e:
158+
self.logger.error(f"Aggregator crashed: {e}")
159+
continue
160+
161+
if output is None:
162+
continue
163+
self._aggregation_results[source] = output
156164

157165
def stop(self):
158166
"""Stop the agent's execution loop."""
@@ -164,7 +172,8 @@ def stop(self):
164172
if self._aggregation_thread is not None:
165173
self._aggregation_thread.join()
166174
self._aggregation_thread = None
175+
self._stop_event.clear()
167176
for callback_id in self._registered_callbacks:
168177
self._connector.unregister_callback(callback_id)
169-
self._stop_event.clear()
178+
self._connector.shutdown()
170179
self.logger.info("Agent stopped")

0 commit comments

Comments
 (0)