Skip to content

Commit 5fcbc31

Browse files
committed
fix: prevent task output loss when mixing sync and async tasks
Fixes #4137 When processing async tasks, `_process_async_tasks` returns a new list containing only async task outputs. The caller was replacing the existing `task_outputs` list instead of extending it, causing all previous sync task outputs to be silently lost. Changed assignment (`=`) to `extend()` at all affected locations: - `_execute_tasks()` lines 1155, 1169 - `_aexecute_tasks()` lines 960, 976 - `_handle_conditional_task()` line 1182 - `_ahandle_conditional_task()` line 990 This ensures sync task outputs accumulated before async tasks are preserved when async tasks are collected.
1 parent be70a04 commit 5fcbc31

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/crewai/src/crewai/crew.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,9 @@ async def _aexecute_tasks(
957957
pending_tasks.append((task, async_task, task_index))
958958
else:
959959
if pending_tasks:
960-
task_outputs = await self._aprocess_async_tasks(
960+
task_outputs.extend(await self._aprocess_async_tasks(
961961
pending_tasks, was_replayed
962-
)
962+
))
963963
pending_tasks.clear()
964964

965965
context = self._get_context(task, task_outputs)
@@ -973,7 +973,7 @@ async def _aexecute_tasks(
973973
self._store_execution_log(task, task_output, task_index, was_replayed)
974974

975975
if pending_tasks:
976-
task_outputs = await self._aprocess_async_tasks(pending_tasks, was_replayed)
976+
task_outputs.extend(await self._aprocess_async_tasks(pending_tasks, was_replayed))
977977

978978
return self._create_crew_output(task_outputs)
979979

@@ -987,7 +987,7 @@ async def _ahandle_conditional_task(
987987
) -> TaskOutput | None:
988988
"""Handle conditional task evaluation using native async."""
989989
if pending_tasks:
990-
task_outputs = await self._aprocess_async_tasks(pending_tasks, was_replayed)
990+
task_outputs.extend(await self._aprocess_async_tasks(pending_tasks, was_replayed))
991991
pending_tasks.clear()
992992

993993
return check_conditional_skip(
@@ -1152,7 +1152,7 @@ def _execute_tasks(
11521152
futures.append((task, future, task_index))
11531153
else:
11541154
if futures:
1155-
task_outputs = self._process_async_tasks(futures, was_replayed)
1155+
task_outputs.extend(self._process_async_tasks(futures, was_replayed))
11561156
futures.clear()
11571157

11581158
context = self._get_context(task, task_outputs)
@@ -1166,7 +1166,7 @@ def _execute_tasks(
11661166
self._store_execution_log(task, task_output, task_index, was_replayed)
11671167

11681168
if futures:
1169-
task_outputs = self._process_async_tasks(futures, was_replayed)
1169+
task_outputs.extend(self._process_async_tasks(futures, was_replayed))
11701170

11711171
return self._create_crew_output(task_outputs)
11721172

@@ -1179,7 +1179,7 @@ def _handle_conditional_task(
11791179
was_replayed: bool,
11801180
) -> TaskOutput | None:
11811181
if futures:
1182-
task_outputs = self._process_async_tasks(futures, was_replayed)
1182+
task_outputs.extend(self._process_async_tasks(futures, was_replayed))
11831183
futures.clear()
11841184

11851185
return check_conditional_skip(

0 commit comments

Comments
 (0)