crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

crew.replay() emits CrewKickoffCompletedEvent without a matching CrewKickoffStartedEvent

Open Wilson0511 opened this issue 1 month ago • 0 comments

Description

crew.replay() skips prepare_kickoff entirely, but its execution tail still emits a CrewKickoffCompletedEvent built with started_event_id=self._kickoff_event_id (crew.py, _create_crew_output). The only place a CrewKickoffStartedEvent is emitted is prepare_kickoff (crews/utils.py), which replay never calls.

Two user-visible consequences on every replay:

  1. The event bus warns:
    [CrewAIEventsBus] Warning: Ending event 'crew_kickoff_completed' emitted with empty scope stack. Missing starting event?
    
  2. The replay's completion event points at the original kickoff's start event id — two completions reference one start, corrupting event pairing / trace causality for any listener (telemetry, tracing, custom observability).

Reproduction

Reproducible on current main with a 2-task crew using mocked Task.execute_sync: register listeners for both event types, kickoff(), then replay(task_id):

events during kickoff: start-count=1 completed-count=1
--- calling crew.replay() ---
[CrewAIEventsBus] Warning: Ending event 'crew_kickoff_completed' emitted with empty scope stack. Missing starting event?
events during replay: starts=0
BUG: replay emitted NO CrewKickoffStartedEvent
replay completed.started_event_id == first kickoff's start id: True

Expected behavior

replay() emits its own CrewKickoffStartedEvent (with the replay inputs) before executing tasks, so the completion event pairs with a fresh start id — mirroring what prepare_kickoff does for kickoff().

Suggested fix

In replay(), after _interpolate_inputs and before task execution, emit CrewKickoffStartedEvent(crew_name=self.name, inputs=replay_inputs), store its event_id in self._kickoff_event_id, and wait for the emit future like prepare_kickoff does.

Happy to submit a PR with a regression test if the approach sounds right.

Wilson0511 avatar Oct 21 '26 12:10 Wilson0511