fix: sync kickoff-completed event with OUTPUT hook result#6571
Conversation
`CrewKickoffCompletedEvent` still carried the pre-hook `TaskOutput`, so AMP/OTEL consumers never saw `OUTPUT` mutations even though the returned `CrewOutput` was updated. Sync `final_task_output.raw` from the post-hook payload before emit, matching `FlowFinishedEvent`.
📝 WalkthroughWalkthrough
ChangesCrew output synchronization
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/crewai/src/crewai/crew.py (1)
1931-1935: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winConsider synchronizing structured output fields as well.
While synchronizing
.rawensures text-based mutations are propagated to the event listeners, any mutations made by hooks to.pydanticor.json_dictwill currently be missed byCrewKickoffCompletedEvent. To ensure complete alignment between the returned output and the event payload for structured outputs, consider syncing these fields as well.♻️ Proposed refactor
# Keep KickoffCompletedEvent in sync with post-hook output so AMP / # OTEL consumers see OUTPUT mutations (mirrors FlowFinishedEvent). if isinstance(crew_output, CrewOutput): final_task_output.raw = crew_output.raw + final_task_output.pydantic = crew_output.pydantic + final_task_output.json_dict = crew_output.json_dict🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai/src/crewai/crew.py` around lines 1931 - 1935, Update the CrewOutput synchronization in the kickoff completion flow so final_task_output matches crew_output for raw, pydantic, and json_dict fields. Preserve the existing CrewOutput type guard and ensure CrewKickoffCompletedEvent receives all post-hook structured-output mutations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/crewai/src/crewai/crew.py`:
- Around line 1931-1935: Update the CrewOutput synchronization in the kickoff
completion flow so final_task_output matches crew_output for raw, pydantic, and
json_dict fields. Preserve the existing CrewOutput type guard and ensure
CrewKickoffCompletedEvent receives all post-hook structured-output mutations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2aaa825e-665a-41a7-a4a6-5c84d3c26d64
📒 Files selected for processing (2)
lib/crewai/src/crewai/crew.pylib/crewai/tests/hooks/test_interception_conformance.py
Crew
OUTPUThooks already mutated the returnedCrewOutput, butCrewKickoffCompletedEventstill emitted the pre-hookTaskOutput, so AMP/OTEL never showed those changes even though Flow already honors post-hook results viaFlowFinishedEvent. This syncsfinal_task_output.rawfrom the post-hook payload before the completed event is emitted so crew OUTPUT mutations surface the same way.Note
Low Risk
Small, targeted change at crew completion; only syncs the
rawfield on the existing final task output before event emission.Overview
Crew
OUTPUThooks could change theCrewOutputreturned fromkickoff(), butCrewKickoffCompletedEventstill carried the pre-hook finalTaskOutput, so telemetry listeners (e.g. AMP/OTEL) did not see hook edits.After
OUTPUTandEXECUTION_ENDinterception,_create_crew_outputnow copies the post-hookcrew_output.rawontofinal_task_outputbefore emitting the kickoff-completed event, so event subscribers see the same text as the returned crew output.A conformance test asserts that an
OUTPUThook that appends torawis reflected in bothcrew.kickoff()andCrewKickoffCompletedEvent.output.raw.Reviewed by Cursor Bugbot for commit d0fc106. Bugbot is set up for automated code reviews on this repo. Configure here.