Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Router does not stop correctly #4490

Open
9n opened this issue Nov 11, 2024 · 3 comments
Open

Conditional Router does not stop correctly #4490

9n opened this issue Nov 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@9n
Copy link
Contributor

9n commented Nov 11, 2024

Bug Description

Conditional Router does not stop correctly. The input message display twice, followed by a error message: "Error parsing message".
It's not reproduced every time, try more times.

Screenshot 2024-11-11 at 17-16-33 Langflow

Reproduction

  1. import the flow file
  2. input hello in the playground
  3. it's not reproduced every time, try more times.

Expected behavior

return hi, there I'm a robot directly and no error message

Who can help?

No response

Operating System

manjaro

Langflow Version

v1.0.19.post2

Python Version

None

Screenshot

Screenshot 2024-11-11 at 17-17-52 Langflow

Flow File

Simple Conditional Router.json

@9n 9n added the bug Something isn't working label Nov 11, 2024
Copy link

dosubot bot commented Nov 11, 2024

The issue with the Conditional Router not stopping correctly and causing the input message to display twice, followed by an "Error parsing message," is likely due to a problem in the iterate_and_stop_once method. The method is supposed to stop the opposite route when the maximum number of iterations is reached, but it seems to be incorrectly implemented.

Here's the relevant part of the code:

def iterate_and_stop_once(self, route_to_stop: str):
    if not self.__iteration_updated:
        self.update_ctx({f"{self._id}_iteration": self.ctx.get(f"{self._id}_iteration", 0) + 1})
        self.__iteration_updated = True
        if self.ctx.get(f"{self._id}_iteration", 0) >= self.max_iterations and route_to_stop == self.default_route:
            # We need to stop the other route
            route_to_stop = "true_result" if route_to_stop == "false_result" else "false_result"
        self.stop(route_to_stop)

The problem arises because the route_to_stop is being reassigned to the opposite route when the maximum iterations are reached, but the stop method is still called with the original route_to_stop value. This means that the intended route to stop is not being stopped, leading to the message being processed twice.

To fix this, the stop method should be called with the updated route_to_stop value:

def iterate_and_stop_once(self, route_to_stop: str):
    if not self.__iteration_updated:
        self.update_ctx({f"{self._id}_iteration": self.ctx.get(f"{self._id}_iteration", 0) + 1})
        self.__iteration_updated = True
        if self.ctx.get(f"{self._id}_iteration", 0) >= self.max_iterations and route_to_stop == self.default_route:
            # We need to stop the other route
            route_to_stop = "true_result" if route_to_stop == "false_result" else "false_result"
        self.stop(route_to_stop)  # Ensure this uses the updated route_to_stop

This change ensures that the correct route is stopped, preventing the message from being processed twice and avoiding the "Error parsing message" [1].

To continue talking to Dosu, mention @dosu.

@ChunJen
Copy link

ChunJen commented Nov 14, 2024

Hi, I have the same question.
It happened in both of version 1.0.17 and 1.1.0

I change the conditional Router with self.stop('method_name'), but the components of the subsequent process will still be executed.

    def true_response(self) -> Message:
        result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive)
        if result:
            return self.message
        else:
            self.stop('true_response')

With the workflow:

[python 3.12.3, langflow 1.0.17]

20241114_debug_conditional_router.json
20241114_debug_conditional_router_v2.json

Test Case

1.input=A, expected_output=A, real_output=A None None

image

2.input=B, expected_output=B, real_output=None B None

  • in this situation will cause 2 user messages to be generated

image

[python 3.12.3, langflow 1.1.0]

Still not work in this version:
20241114_debug_conditional_router_v2_使用langflow1.1.0版本.json

@irshadmb
Copy link
Contributor

@joaoguilhermeS - I have given the details.

#4590 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants