feat(pipeline): unified EventHandler protocol (#245 layer 1B)#247
Merged
miguelgfierro merged 1 commit intoMay 28, 2026
Merged
Conversation
Completes layer 1 by collapsing PipelineEventHandler + StatePipelineEventHandler into a single EventHandler protocol. The two old protocols stay as deprecated aliases for backward compatibility; the engine adapts to either via signature-inspection dispatch. New surface: - EventHandler protocol with the union of all callbacks (on_pipeline_start, on_node_start with visit, on_node_complete, on_node_error, on_node_skip, on_node_pause, on_pipeline_complete) — every method carries run_id. - PipelineEngine._dispatch(method_name, **kwargs) inspects each callback's signature once (cached) and passes only the parameters the method declares. That keeps legacy PipelineEventHandler implementations working unchanged — the engine silently drops run_id / visit when the method doesn't accept them. - PipelineEngine now emits on_pipeline_start at run() start (was only state-side). - _execute_node forwards run_id so on_node_start callbacks can correlate. - All previous direct event_handler method calls in engine.py go through _dispatch. Backward compatibility: - PipelineEventHandler and StatePipelineEventHandler stay in place with docstrings marking them legacy. Existing implementations of either continue to work without modification. - New code should implement EventHandler. Tests: 7 new in tests/unit/pipeline/test_pipeline_engine_event_dispatch.py covering unified handler (run_id + visit received), legacy handler (run_id dropped silently), mixed handler (some methods rich, some legacy), exception swallowing. Existing test_event_handler.py (legacy shape) still passes unchanged. Full suite: 1551 passed. Refs: #245
This was referenced May 28, 2026
ancongui
pushed a commit
that referenced
this pull request
May 31, 2026
…-handler feat(pipeline): unified EventHandler protocol (#245 layer 1B)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes layer 1 of the unification (#245) by collapsing `PipelineEventHandler` and `StatePipelineEventHandler` into a single `EventHandler` protocol. Stacked on top of #246 (the checkpoint/audit/resume PR) which is already merged into `issue-147-pipeline-evolution`.
What this lands
New: `EventHandler` protocol
One protocol that covers the full pipeline lifecycle across both modes:
```python
class EventHandler(Protocol):
async def on_pipeline_start(self, pipeline_name: str, run_id: str) -> None: ...
async def on_node_start(self, pipeline_name: str, run_id: str, node_id: str, visit: int) -> None: ...
async def on_node_complete(self, pipeline_name: str, run_id: str, node_id: str, latency_ms: float) -> None: ...
async def on_node_error(self, pipeline_name: str, run_id: str, node_id: str, error: str) -> None: ...
async def on_node_skip(self, pipeline_name: str, run_id: str, node_id: str, reason: str) -> None: ...
async def on_node_pause(self, pipeline_name: str, run_id: str, node_id: str, reason: str) -> None: ...
async def on_pipeline_complete(self, pipeline_name: str, run_id: str, success: bool, duration_ms: float) -> None: ...
```
Every callback carries `run_id` (for correlating across resumes and parallel runs) and `on_node_start` carries `visit` (re-entry counter — ready for cycles in a later layer).
Signature-inspection dispatch
`PipelineEngine._dispatch(method_name, **kwargs)` inspects each handler method's signature once (cached) and only passes parameters the method declares. This makes the unification non-breaking:
All engine event-emission paths now go through `_dispatch` — the previous direct `hasattr` + try/except scaffolding is gone.
Other engine changes
Backward compatibility
`PipelineEventHandler` and `StatePipelineEventHandler` stay in place with docstrings marking them legacy. Existing implementations (port-based with 2-arg `on_node_start`, state-based with 4-arg, etc.) keep working without modification. New code should implement `EventHandler`.
Public exports
`EventHandler` is re-exported from `fireflyframework_agentic.pipeline`.
Tests
7 new tests in `tests/unit/pipeline/test_pipeline_engine_event_dispatch.py`:
Existing `tests/unit/pipeline/test_event_handler.py` (which uses the legacy port-based shape) passes unchanged.
Full unit suite: 1551 passed, 21 warnings, 0 failures.
What's NOT in this PR
Refs