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:
Greyson LaLonde
2026-04-06 21:17:33 +08:00
parent b55e86ac8c
commit 61422be7cf
2 changed files with 29 additions and 5 deletions

View File

@@ -426,10 +426,26 @@ class Crew(FlowTrackable, BaseModel):
if state is None:
return
# Only restore the crew-level scope. Inner scopes (task, agent, llm)
# are re-created by the normal execution flow on resume.
# Restore crew scope and the in-progress task scope. Inner scopes
# (agent, llm, tool) are re-created by the executor on resume.
stack: list[tuple[str, str]] = []
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
last_event_id: str | None = None

View File

@@ -5,8 +5,16 @@ from crewai.tasks.task_output import TaskOutput
def _set_task_fingerprint(event: BaseEvent, task: Any) -> None:
"""Set fingerprint data on an event from a task object."""
if task is not None and task.fingerprint:
"""Set task identity and fingerprint data on an event."""
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_type = "task"
if task.fingerprint.metadata: