Skip to content

fix: sync kickoff-completed event with OUTPUT hook result#6571

Merged
lucasgomide merged 2 commits into
mainfrom
luzk/crew-output-hook-event
Jul 16, 2026
Merged

fix: sync kickoff-completed event with OUTPUT hook result#6571
lucasgomide merged 2 commits into
mainfrom
luzk/crew-output-hook-event

Conversation

@lucasgomide

@lucasgomide lucasgomide commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Crew OUTPUT hooks already mutated the returned CrewOutput, but CrewKickoffCompletedEvent still emitted the pre-hook TaskOutput, so AMP/OTEL never showed those changes even though Flow already honors post-hook results via FlowFinishedEvent. This syncs final_task_output.raw from 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 raw field on the existing final task output before event emission.

Overview
Crew OUTPUT hooks could change the CrewOutput returned from kickoff(), but CrewKickoffCompletedEvent still carried the pre-hook final TaskOutput, so telemetry listeners (e.g. AMP/OTEL) did not see hook edits.

After OUTPUT and EXECUTION_END interception, _create_crew_output now copies the post-hook crew_output.raw onto final_task_output before emitting the kickoff-completed event, so event subscribers see the same text as the returned crew output.

A conformance test asserts that an OUTPUT hook that appends to raw is reflected in both crew.kickoff() and CrewKickoffCompletedEvent.output.raw.

Reviewed by Cursor Bugbot for commit d0fc106. Bugbot is set up for automated code reviews on this repo. Configure here.

`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`.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Crew._create_crew_output now propagates post-interception raw output changes to the final task output. A new test verifies that the kickoff result and CrewKickoffCompletedEvent contain the mutated output.

Changes

Crew output synchronization

Layer / File(s) Summary
Synchronize intercepted output and validate kickoff event
lib/crewai/src/crewai/crew.py, lib/crewai/tests/hooks/test_interception_conformance.py
The crew flow copies mutated crew_output.raw into final_task_output.raw before emitting the completion event. The conformance test applies an OUTPUT hook and verifies the mutation in both the kickoff result and captured event.

Suggested reviewers: vinibrsl

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: syncing the kickoff-completed event with OUTPUT hook results.
Description check ✅ Passed The description directly matches the code changes and explains the event/output synchronization fix and added test.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch luzk/crew-output-hook-event

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/crewai/src/crewai/crew.py (1)

1931-1935: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider synchronizing structured output fields as well.

While synchronizing .raw ensures text-based mutations are propagated to the event listeners, any mutations made by hooks to .pydantic or .json_dict will currently be missed by CrewKickoffCompletedEvent. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5dba2ef and d8740b2.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/crew.py
  • lib/crewai/tests/hooks/test_interception_conformance.py

@lucasgomide
lucasgomide merged commit 9a49af0 into main Jul 16, 2026
54 checks passed
@lucasgomide
lucasgomide deleted the luzk/crew-output-hook-event branch July 16, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants