langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Repeatedly run vertexes when use ConditionalRouterComponent

Open yangxikun opened this issue 10 months ago • 3 comments

Bug Description

Image

/api/v1/build/59fb2d26-14cb-410f-a599-75a5b3bf2413/flow?&start_component_id=ChatInput-vAd7W&log_builds=true api response:

{"event": "vertices_sorted", "data": {"ids": ["ChatInput-vAd7W"], "to_run": ["ConditionalRouter-zRRVB", "ChatInput-vAd7W", "ChatOutput-hFryt", "ChatOutput-5dYR6"]}}

{"event": "add_message", "data": {"timestamp": "2025-02-05T08:55:40", "sender": "User", "sender_name": "User", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "aaaa", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "921fc04c-1bb4-4336-90fa-43cbdce5abb2", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}}

{"event": "end_vertex", "data": {"build_data": {"id": "ChatInput-vAd7W", "inactivated_vertices": [], "next_vertices_ids": ["ConditionalRouter-zRRVB"], "top_level_vertices": ["ConditionalRouter-zRRVB"], "valid": true, "params": "- Files: []\n  Message: aaaa\n  Sender: User\n  Sender Name: User\n  Type: object\n", "data": {"results": {"message": {"text_key": "text", "data": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "User", "sender_name": "User", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "aaaa", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "921fc04c-1bb4-4336-90fa-43cbdce5abb2", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "default_value": "", "text": "aaaa", "sender": "User", "sender_name": "User", "files": [], "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "timestamp": "2025-02-05T08:55:40+00:00", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": []}}, "outputs": {"message": {"message": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "User", "sender_name": "User", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "aaaa", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "921fc04c-1bb4-4336-90fa-43cbdce5abb2", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "logs": {"message": []}, "message": {"message": "aaaa", "sender": "User", "sender_name": "User", "files": [], "type": "object"}, "artifacts": {"message": "aaaa", "sender": "User", "sender_name": "User", "files": [], "type": "object"}, "timedelta": 0.050034332991344854, "duration": "50 ms", "used_frozen_result": false}, "timestamp": "2025-02-05T08:55:40.683739Z"}}}

{"event": "end_vertex", "data": {"build_data": {"id": "ConditionalRouter-zRRVB", "inactivated_vertices": [], "next_vertices_ids": ["ChatInput-vAd7W", "ChatOutput-hFryt"], "top_level_vertices": ["ChatInput-vAd7W", "ChatOutput-hFryt"], "valid": true, "params": "None", "data": {"results": {}, "outputs": {"true_result": {"message": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}, "false_result": {"message": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}}, "logs": {"true_result": [], "false_result": []}, "message": {"true_result": {"repr": "{\n    \"content\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}, "false_result": {"repr": "{\n    \"text\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "artifacts": {"true_result": {"repr": "{\n    \"content\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}, "false_result": {"repr": "{\n    \"text\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "timedelta": 0.06202408400713466, "duration": "62 ms", "used_frozen_result": false}, "timestamp": "2025-02-05T08:55:40.755619Z"}}}

{"event": "end_vertex", "data": {"build_data": {"id": "ChatInput-vAd7W", "inactivated_vertices": [], "next_vertices_ids": ["ConditionalRouter-zRRVB"], "top_level_vertices": ["ConditionalRouter-zRRVB"], "valid": true, "params": "- Files: []\n  Message: aaaa\n  Sender: User\n  Sender Name: User\n  Type: object\n", "data": {"results": {"message": {"text_key": "text", "data": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "User", "sender_name": "User", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "aaaa", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "921fc04c-1bb4-4336-90fa-43cbdce5abb2", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "default_value": "", "text": "aaaa", "sender": "User", "sender_name": "User", "files": [], "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "timestamp": "2025-02-05T08:55:40+00:00", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": []}}, "outputs": {"message": {"message": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "User", "sender_name": "User", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "aaaa", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "921fc04c-1bb4-4336-90fa-43cbdce5abb2", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "logs": {"message": []}, "message": {"message": "aaaa", "sender": "User", "sender_name": "User", "files": [], "type": "object"}, "artifacts": {"message": "aaaa", "sender": "User", "sender_name": "User", "files": [], "type": "object"}, "timedelta": 0.01885970900184475, "duration": "19 ms", "used_frozen_result": false}, "timestamp": "2025-02-05T08:55:40.776553Z"}}}

{"event": "end_vertex", "data": {"build_data": {"id": "ConditionalRouter-zRRVB", "inactivated_vertices": [], "next_vertices_ids": [], "top_level_vertices": [], "valid": true, "params": "None", "data": {"results": {}, "outputs": {"true_result": {"message": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}, "false_result": {"message": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "object"}}, "logs": {"true_result": [], "false_result": []}, "message": {"true_result": {"repr": "{\n    \"content\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}, "false_result": {"repr": "{\n    \"text\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\",\n    \"sender\": \"Machine\",\n    \"sender_name\": \"AI\",\n    \"session_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "artifacts": {"true_result": {"repr": "{\n    \"content\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"content": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}, "false_result": {"repr": "{\n    \"text\": \"\",\n    \"files\": [],\n    \"timestamp\": \"2025-02-05 08:55:40 UTC\",\n    \"flow_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\",\n    \"sender\": \"Machine\",\n    \"sender_name\": \"AI\",\n    \"session_id\": \"59fb2d26-14cb-410f-a599-75a5b3bf2413\"\n}", "raw": {"text": "", "files": [], "timestamp": "2025-02-05 08:55:40 UTC", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "timedelta": 0.016741708997869864, "duration": "17 ms", "used_frozen_result": false}, "timestamp": "2025-02-05T08:55:40.849592Z"}}}

{"event": "add_message", "data": {"timestamp": "2025-02-05T08:55:40", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "ConditionalRouter-zRRVB", "display_name": "If-Else", "source": "If-Else"}, "icon": "split", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "e36fdf08-1f25-4ce4-93cf-214e8653a85c", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}}

{"event": "end_vertex", "data": {"build_data": {"id": "ChatOutput-hFryt", "inactivated_vertices": [], "next_vertices_ids": [], "top_level_vertices": [], "valid": true, "params": "- Files: []\n  Message: ''\n  Sender: Machine\n  Sender Name: AI\n  Type: object\n", "data": {"results": {"message": {"text_key": "text", "data": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "ConditionalRouter-zRRVB", "display_name": "If-Else", "source": "If-Else"}, "icon": "split", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "e36fdf08-1f25-4ce4-93cf-214e8653a85c", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "default_value": "", "text": "", "sender": "Machine", "sender_name": "AI", "files": [], "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "timestamp": "2025-02-05T08:55:40+00:00", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "ConditionalRouter-zRRVB", "display_name": "If-Else", "source": "If-Else"}, "icon": "split", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": []}}, "outputs": {"message": {"message": {"timestamp": "2025-02-05T08:55:40+00:00", "sender": "Machine", "sender_name": "AI", "session_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "ConditionalRouter-zRRVB", "display_name": "If-Else", "source": "If-Else"}, "icon": "split", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "e36fdf08-1f25-4ce4-93cf-214e8653a85c", "flow_id": "59fb2d26-14cb-410f-a599-75a5b3bf2413"}, "type": "message"}}, "logs": {"message": []}, "message": {"message": "", "sender": "Machine", "sender_name": "AI", "files": [], "type": "object"}, "artifacts": {"message": "", "sender": "Machine", "sender_name": "AI", "files": [], "type": "object"}, "timedelta": 0.09330516701447777, "duration": "93 ms", "used_frozen_result": false}, "timestamp": "2025-02-05T08:55:40.869920Z"}}}

{"event": "end", "data": {}}

ChatInput-vAd7W and ConditionalRouter-zRRVB run twice.

I found some clues. Should the mark_branch function create new edges from self.edges to discard the stop edge?

    def mark_branch(self, vertex_id: str, state: str, output_name: str | None = None) -> None:
        self._mark_branch(vertex_id=vertex_id, state=state, output_name=output_name)
        new_predecessor_map, _ = self.build_adjacency_maps(self.edges)
        self.run_manager.update_run_state(
            run_predecessors=new_predecessor_map,
            vertices_to_run=self.vertices_to_run,
        )

Or, if the vertex is INACTIVE, should it be excluded from being updated to next_runnable_vertices?

    def find_next_runnable_vertices(self, vertex_successors_ids: list[str]) -> list[str]:
        next_runnable_vertices = set()
        for v_id in sorted(vertex_successors_ids):
            if not self.is_vertex_runnable(v_id):
                next_runnable_vertices.update(self.find_runnable_predecessors_for_successor(v_id))
            else:
                next_runnable_vertices.add(v_id)

Reproduction

Send message to Playground.

Expected behavior

ChatInput-vAd7W and ConditionalRouter-zRRVB should run once.

Who can help?

@ogabrielluiz

Operating System

mac

Langflow Version

1.1.1 and main branch

Python Version

3.12

Screenshot

No response

Flow File

duplicated running vertexes.json

yangxikun avatar Feb 05 '25 09:02 yangxikun

The issue you're encountering with the ChatInput-vAd7W and ConditionalRouter-zRRVB vertices running twice could be related to how the flow execution is managed, particularly in the mark_branch and find_next_runnable_vertices functions.

  1. mark_branch Function: This function is responsible for marking a branch of the graph starting from a specified vertex. It updates the state of the vertices and adjusts the run state of the graph. If the stop edge is not properly discarded, it might cause vertices to be marked and executed multiple times. You might want to ensure that the mark_branch function correctly updates the adjacency maps and excludes any edges that should not lead to further execution [1].

  2. find_next_runnable_vertices Function: This function determines the next set of vertices that are ready to run. If a vertex is INACTIVE, it should indeed be excluded from being updated to next_runnable_vertices. This ensures that only active and runnable vertices are considered for execution, preventing unnecessary repeated runs [2].

To address the issue, you might consider:

  • Ensuring that the mark_branch function correctly updates the run state by discarding any edges that should not lead to further execution.
  • Modifying the find_next_runnable_vertices function to exclude INACTIVE vertices from being added to next_runnable_vertices.

These adjustments should help in ensuring that each vertex runs only once as expected.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

dosubot[bot] avatar Feb 05 '25 09:02 dosubot[bot]

@italojohnny could you please take a look at this issue

yangxikun avatar Feb 26 '25 04:02 yangxikun

Hi, @yangxikun. I'm Dosu, and I'm helping the langflow team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You reported a bug with the ChatInput-vAd7W vertex executing multiple times unexpectedly.
  • The issue seems related to the ConditionalRouterComponent.
  • I suggested looking into mark_branch and find_next_runnable_vertices functions for potential fixes.
  • You requested further assistance from italojohnny to investigate.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of langflow. If it is, feel free to comment to keep the discussion open.
  • If there is no further activity, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar May 29 '25 23:05 dosubot[bot]