Fix #5972: Allow multi-source OR listeners to re-fire in cyclic flows#5974
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Fix #5972: Allow multi-source OR listeners to re-fire in cyclic flows#5974devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
When a router emits a signal that should re-trigger an or_() listener that has already fired, the listener was permanently blocked by _fired_or_listeners. This created a catch-22: the clearing logic in _execute_single_listener (for cyclic re-execution) could never be reached because _find_triggered_methods blocked the listener first. Fix: Before processing router results as triggers, reset _fired_or_listeners entries for any OR listeners whose conditions match the router output signals. This preserves concurrent start-method protection (original trigger_method) while unblocking cyclic re-triggering through routers. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Fixes #5972 —
@listen(or_(A, B, C))multi-source OR listeners only fire once, blocking cyclic flow re-triggering.Root cause: When a multi-source OR listener fires, it's added to
_fired_or_listenersand permanently blocked by_find_triggered_methods. Although there's clearing logic in_execute_single_listener(for cyclic re-execution of already-completed methods), it can never be reached because_find_triggered_methodsblocks the listener from being found in the first place — a catch-22.Fix: Added
_reset_or_listeners_for_router_results()which is called in_execute_listenersbefore processing router results as triggers. It clears_fired_or_listenersentries for any OR listeners whose conditions match the router output signals. This:trigger_methodis still guarded)Review & Testing Checklist for Human
@listen(or_("SignalA", "SignalB"))where different router signals cycle back to re-trigger the OR listenertest_cyclic_flow_or_listeners_fire_every_iteration,test_cyclic_flow_multiple_or_listeners_fire_every_iteration,test_cyclic_flow_works_with_persist_and_id_input)test_or_condition_self_listen_fires_oncestill passes (self-listen guard preserved)Recommended test plan: Run
uv run pytest lib/crewai/tests/test_flow.py -xto verify all 69 flow tests pass (they do locally).Notes
The fix is minimal and targeted — a single new helper method (
_reset_or_listeners_for_router_results) and one call site in_execute_listeners. The two new tests cover both variants of the bug: different router signals triggering the OR listener across iterations, and the same signal repeated.Link to Devin session: https://app.devin.ai/sessions/633bab68f1d84198aabc677145227839