crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] Flow skips downstream router chains for earlier sibling outcomes

Open dakjdakd opened this issue 2 months ago • 4 comments

Description

When two routers listen to the same method and each returns a different outcome, both routers run. However, if those outcomes are consumed by another layer of routers, only the last sibling's downstream chain runs. The flow finishes without reporting that the other branch was skipped.

This matters for flows that split into independent decision paths, such as checking two different conditions before taking their respective follow-up actions. Reordering the sibling methods should not determine which follow-up path is reachable.

Steps to reproduce / Code snippet

No agents, model calls, tools, or external services are needed:

from crewai.flow import Flow, listen, router, start

calls = []

class SiblingRouterFlow(Flow):
    @start()
    def begin(self):
        return "input"

    @router(begin)
    def first_route(self):
        calls.append("first_route")
        return "left"

    @router(begin)
    def second_route(self):
        calls.append("second_route")
        return "right"

    @router("left")
    def left_route(self):
        calls.append("left_route")
        return "left_done"

    @router("right")
    def right_route(self):
        calls.append("right_route")
        return "right_done"

    @listen("left_done")
    def left_listener(self):
        calls.append("left_listener")

    @listen("right_done")
    def right_listener(self):
        calls.append("right_listener")

SiblingRouterFlow().kickoff()
print(calls)

Expected behavior

Both left_route / left_listener and right_route / right_listener run once.

Evidence

Actual output on main at 784aadde1d5cfd4e660d38aa2bd888fdf64eb45d:

['first_route', 'second_route', 'right_route', 'right_listener']

left_route and left_listener never run. Reproduced using the real public Flow API on Windows with Python 3.11.7 and CrewAI 1.15.22 from source. The three added regression cases also fail on the unchanged runtime; no Flow methods or routing behavior are mocked.

There is a related edge case: if the last sibling returns None, a previously emitted sibling outcome should still continue its own router chain.

Possible solution

In Flow._execute_listeners, the router phase updates a single current_trigger while iterating over all routers triggered by the same event. The next iteration therefore follows only the final outcome. Earlier outcomes are retained in router_results, but the later phase checks them with router_only=False, so it can activate ordinary listeners without recovering their downstream routers.

The proposed change is to retain every emitted outcome for the router phase, while keeping routers sequential and the existing normal-listener phase intact.

Environment

  • Operating system: Windows 11
  • Python: 3.11.7
  • CrewAI: 1.15.22 from source at the commit above
  • CrewAI Tools: not used
  • Virtual environment: isolated uv-created venv

Additional context

This is related to #2175 and its fix in #2231, but the missing step here is another @router, not an ordinary @listen. The existing multiple-router regression covers ordinary listeners; this example adds a second router layer. The chained human-feedback tests introduced in #4398 also do not exercise two sibling outcomes followed by separate router chains.

A focused fix and regression tests are ready. AI-assisted contribution; please apply the required llm-generated label. The author does not have permission to add labels in this repository.

dakjdakd avatar Sep 21 '26 17:09 dakjdakd

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 22 '26 12:10 github-actions[bot]

This still reproduces on current main (1.15.30, Windows 11, Python 3.12.12, no model calls). Running the snippet from the description prints:

['first_route', 'second_route', 'right_route', 'right_listener']

left_route and left_listener never run. #7696 was closed by the stale bot on 2026-10-21 without a human review, and the router phase in Flow._execute_listeners still keeps one current_trigger.

I have a small fix and tests ready: the router phase keeps a FIFO of pending outcomes instead of one variable. Single-chain flows behave as before; each sibling outcome continues its own router chain; a sibling that returns None no longer hides an earlier outcome; two siblings emitting the same outcome still run the downstream router once. Tests cover the reporter's flow, the None case and the shared-outcome case.

I plan to open a PR that references this issue. @dakjdakd, if you were going to reopen #7696, tell me and I will step aside. The patch is AI-assisted (Claude Code); I will say so in the PR, and since I cannot add labels, could a maintainer apply llm-generated to the PR?

Sonica-B avatar Oct 25 '26 09:10 Sonica-B

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 25 '26 12:11 github-actions[bot]

Still reproduces on main (77237ae, 2026-11-25; crewAI 1.15.45) with the script in the description: it runs ['first_route', 'second_route', 'right_route', 'right_listener'], so left_route and left_listener never run. PR #8562 is open for it.

cc @lucasgomide @joaomdmoura @vinibrsl @Vidit-Ostwal

yifanxiong272 avatar Nov 25 '26 22:11 yifanxiong272