mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 07:13:00 +00:00
fix: populate task_id on task events and match in scope restore
Set task_id and task_name in _set_task_fingerprint so events carry task identity through serialization. Use task_id to find the correct task_started event when restoring the scope stack on checkpoint resume.
This commit is contained in:
@@ -426,10 +426,26 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
if state is None:
|
if state is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only restore the crew-level scope. Inner scopes (task, agent, llm)
|
# Restore crew scope and the in-progress task scope. Inner scopes
|
||||||
# are re-created by the normal execution flow on resume.
|
# (agent, llm, tool) are re-created by the executor on resume.
|
||||||
|
stack: list[tuple[str, str]] = []
|
||||||
if self._kickoff_event_id:
|
if self._kickoff_event_id:
|
||||||
restore_event_scope(((self._kickoff_event_id, "crew_kickoff_started"),))
|
stack.append((self._kickoff_event_id, "crew_kickoff_started"))
|
||||||
|
|
||||||
|
# Find the task_started event for the in-progress task (skipped on resume)
|
||||||
|
for task in self.tasks:
|
||||||
|
if task.output is None:
|
||||||
|
task_id_str = str(task.id)
|
||||||
|
for node in state.event_record.nodes.values():
|
||||||
|
if (
|
||||||
|
node.event.type == "task_started"
|
||||||
|
and node.event.task_id == task_id_str
|
||||||
|
):
|
||||||
|
stack.append((node.event.event_id, "task_started"))
|
||||||
|
break
|
||||||
|
break
|
||||||
|
|
||||||
|
restore_event_scope(tuple(stack))
|
||||||
|
|
||||||
# Set last_event_id to the most recent event in the record
|
# Set last_event_id to the most recent event in the record
|
||||||
last_event_id: str | None = None
|
last_event_id: str | None = None
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ from crewai.tasks.task_output import TaskOutput
|
|||||||
|
|
||||||
|
|
||||||
def _set_task_fingerprint(event: BaseEvent, task: Any) -> None:
|
def _set_task_fingerprint(event: BaseEvent, task: Any) -> None:
|
||||||
"""Set fingerprint data on an event from a task object."""
|
"""Set task identity and fingerprint data on an event."""
|
||||||
if task is not None and task.fingerprint:
|
if task is None:
|
||||||
|
return
|
||||||
|
task_id = getattr(task, "id", None)
|
||||||
|
if task_id is not None:
|
||||||
|
event.task_id = str(task_id)
|
||||||
|
task_name = getattr(task, "name", None) or getattr(task, "description", None)
|
||||||
|
if task_name:
|
||||||
|
event.task_name = task_name
|
||||||
|
if task.fingerprint:
|
||||||
event.source_fingerprint = task.fingerprint.uuid_str
|
event.source_fingerprint = task.fingerprint.uuid_str
|
||||||
event.source_type = "task"
|
event.source_type = "task"
|
||||||
if task.fingerprint.metadata:
|
if task.fingerprint.metadata:
|
||||||
|
|||||||
Reference in New Issue
Block a user