Skip to content

feat: wire execution-boundary interception points#6517

Draft
lucasgomide wants to merge 2 commits into
luzk/hooks-dispatcherfrom
luzk/hooks-exec-boundaries
Draft

feat: wire execution-boundary interception points#6517
lucasgomide wants to merge 2 commits into
luzk/hooks-dispatcherfrom
luzk/hooks-exec-boundaries

Conversation

@lucasgomide

@lucasgomide lucasgomide commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

With the dispatcher in place, the execution lifecycle still had no interception seams. This introduces the typed interception contexts and wires execution_start, input, output, and execution_end for both crews and flows: prepare_kickoff and Flow.kickoff_async let a hook rewrite resolved inputs before a run, while Crew._create_crew_output and the flow tail let the final result be observed or replaced. It closes the eight critical-path points the policy engine needs without touching the legacy hooks. Stacked on #6516; part of the OSS-86 interception-hook catalog.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a33c0110-f835-4d42-aa41-750e6fa7830a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch luzk/hooks-exec-boundaries

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.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 5 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 790bde5. Configure here.

Comment thread lib/crewai/src/crewai/crew.py
Comment thread lib/crewai/src/crewai/flow/runtime/__init__.py
Comment thread lib/crewai/src/crewai/crews/utils.py
Comment thread lib/crewai/src/crewai/flow/runtime/__init__.py
flow=self, output=final_output, payload=final_output
)
dispatch(InterceptionPoint.EXECUTION_END, end_ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

End hook after finished event

Medium Severity

EXECUTION_END is dispatched after FlowFinishedEvent and trace finalization. A HookAborted from that point still leaves listeners with a successful finished event while the caller sees an abort, and any returned payload replacement is ignored by the following return.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 790bde5. Configure here.

@lucasgomide lucasgomide force-pushed the luzk/hooks-exec-boundaries branch from 790bde5 to ea20c1a Compare July 11, 2026 17:16
@lucasgomide lucasgomide force-pushed the luzk/hooks-dispatcher branch from 8bc4fa2 to a85e100 Compare July 11, 2026 17:16
@lucasgomide lucasgomide marked this pull request as draft July 11, 2026 17:22
Adds the typed interception contexts (`crewai/hooks/contexts.py`) and wires
the `execution_start`, `input`, `output`, and `execution_end` points for both
crews and flows through the dispatcher. `prepare_kickoff` and
`Flow.kickoff_async` fire `execution_start`/`input` so a hook can rewrite
resolved inputs before the run, while `Crew._create_crew_output` and the flow
tail fire `output`/`execution_end` so the final result can be observed or
replaced. Closes the eight critical-path points without touching the legacy
hooks.
Reworks the crew and flow boundary seams flagged in review. `OUTPUT` and
`EXECUTION_END` now run before the completion event (`CrewKickoffCompletedEvent`
and `FlowFinishedEvent`) so a `HookAborted` no longer leaves a spurious
completed signal and a returned payload replacement is honored on the emitted
and returned result. Boundary contexts alias `inputs` to the same object as
`payload` instead of a fresh dict from `or`, so in-place edits survive
read-back. Flows re-publish the resolved inputs into `flow_inputs` baggage
after the `INPUT` hook so trigger-payload injection observes hook rewrites, and
a resumed flow now dispatches `OUTPUT`/`EXECUTION_END` on its completion path.
@lucasgomide lucasgomide force-pushed the luzk/hooks-exec-boundaries branch from ea20c1a to 73bdfaa Compare July 11, 2026 22:26
@github-actions github-actions Bot added size/L and removed size/M labels Jul 11, 2026
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.

1 participant