Run branches in parallel will cause some problem. #6504

Closed
opened 2026-02-21 18:16:02 -05:00 by yindo · 5 comments
Owner

Originally created by @Hope1u on GitHub (Nov 1, 2024).

Originally assigned to: @laipz8200 on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.10.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

The normal situation is as follows
1

The error conditions are as follows:
When I add any more node before merging the two branches, after the other branches are completed, the merged node will be taken.
iShot_2024-11-01_18 17 16

✔️ Expected Behavior

There are 3 branches. The entire process should end after completing branch 1.

Actual Behavior

There are three branches, branch 1, branch 2 and branch 3. Branch 2 and branch 3 are merged. Normally, it should be over after taking branch 1. However, before branch 2 and branch 3 are merged, if there is any more node, it will As a result, after branch 1 ends, it will automatically jump to the merge node and continue.

Originally created by @Hope1u on GitHub (Nov 1, 2024). Originally assigned to: @laipz8200 on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.10.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce The normal situation is as follows ![1](https://github.com/user-attachments/assets/81dfeddd-e4fd-4c11-a02e-f5a2037ed2c3) The error conditions are as follows: When I add any more node before merging the two branches, after the other branches are completed, the merged node will be taken. ![iShot_2024-11-01_18 17 16](https://github.com/user-attachments/assets/21a48f88-d94d-49fb-8b3f-2a9db9fee66f) ### ✔️ Expected Behavior There are 3 branches. The entire process should end after completing branch 1. ### ❌ Actual Behavior There are three branches, branch 1, branch 2 and branch 3. Branch 2 and branch 3 are merged. Normally, it should be over after taking branch 1. However, before branch 2 and branch 3 are merged, if there is any more node, it will As a result, after branch 1 ends, it will automatically jump to the merge node and continue.
yindo closed this issue 2026-02-21 18:16:02 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 1, 2024):

@Hope1u Hello there! I'm here to help you with any bugs, questions, or contributions you might have. Let's squash those bugs together!

To resolve the issue where adding a node before merging branches causes the process to continue after branch 1 ends, ensure that the graph correctly identifies and handles the end of branches. The key is in managing duplicate_end_node_ids and branches_merge_node_ids to handle merging branches properly. This logic checks for duplicate end nodes and manages the merging of branches:

duplicate_end_node_ids = {}
for node_id, branch_node_ids in merge_branch_node_ids.items():
    for node_id2, branch_node_ids2 in merge_branch_node_ids.items():
        if node_id != node_id2 and set(branch_node_ids) == set(branch_node_ids2):
            if (node_id, node_id2) not in duplicate_end_node_ids and (
                node_id2,
                node_id,
            ) not in duplicate_end_node_ids:
                duplicate_end_node_ids[(node_id, node_id2)] = branch_node_ids

for (node_id, node_id2), branch_node_ids in duplicate_end_node_ids.items():
    # check which node is after
    if cls._is_node2_after_node1(node1_id=node_id, node2_id=node_id2, edge_mapping=edge_mapping):
        if node_id in merge_branch_node_ids:
            del merge_branch_node_ids[node_id2]
    elif cls._is_node2_after_node1(node1_id=node_id2, node2_id=node_id, edge_mapping=edge_mapping):
        if node_id2 in merge_branch_node_ids:
            del merge_branch_node_ids[node_id]

This code ensures that when branches are merged, the graph correctly identifies which nodes are duplicates and removes them from the merge list, preventing the process from continuing unexpectedly. Make sure this logic is correctly implemented and that your graph configuration accurately reflects the intended workflow [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 1, 2024): <!-- Greeting --> @Hope1u Hello there! I'm here to help you with any bugs, questions, or contributions you might have. Let's squash those bugs together! <!-- Answer --> To resolve the issue where adding a node before merging branches causes the process to continue after branch 1 ends, ensure that the graph correctly identifies and handles the end of branches. The key is in managing `duplicate_end_node_ids` and `branches_merge_node_ids` to handle merging branches properly. This logic checks for duplicate end nodes and manages the merging of branches: ```python duplicate_end_node_ids = {} for node_id, branch_node_ids in merge_branch_node_ids.items(): for node_id2, branch_node_ids2 in merge_branch_node_ids.items(): if node_id != node_id2 and set(branch_node_ids) == set(branch_node_ids2): if (node_id, node_id2) not in duplicate_end_node_ids and ( node_id2, node_id, ) not in duplicate_end_node_ids: duplicate_end_node_ids[(node_id, node_id2)] = branch_node_ids for (node_id, node_id2), branch_node_ids in duplicate_end_node_ids.items(): # check which node is after if cls._is_node2_after_node1(node1_id=node_id, node2_id=node_id2, edge_mapping=edge_mapping): if node_id in merge_branch_node_ids: del merge_branch_node_ids[node_id2] elif cls._is_node2_after_node1(node1_id=node_id2, node2_id=node_id, edge_mapping=edge_mapping): if node_id2 in merge_branch_node_ids: del merge_branch_node_ids[node_id] ``` This code ensures that when branches are merged, the graph correctly identifies which nodes are duplicates and removes them from the merge list, preventing the process from continuing unexpectedly. Make sure this logic is correctly implemented and that your graph configuration accurately reflects the intended workflow <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/graph_engine/entities/graph.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Nov 1, 2024):

See this https://github.com/langgenius/dify/issues/10162
It's a designed behavior.

@crazywoola commented on GitHub (Nov 1, 2024): See this https://github.com/langgenius/dify/issues/10162 It's a designed behavior.
Author
Owner

@Hope1u commented on GitHub (Nov 3, 2024):

You seem to have misunderstood the meaning. It has nothing to do with the variable aggregator. This problem will occur when any other nodes are added before merging two branches, as follows:
There are three parameters. When test1 is not empty, branch 1 is taken. When q is not empty, branch 2 is taken. When w is not empty, branch 3 is taken. Branch 2 and branch 3 are merged. When testing, I assign test1 to 1, and the q and w parameters are not assigned values.
When there are no redundant nodes before merging nodes, the entire process ends after branch 1 is completed, as follows:
image

When there is an additional node before the merge node, after completing branch 1, the merge node will continue to be taken, as follows:
image

As long as you add any more nodes before merging them, this will happen:
For example, there are no redundant nodes before merging nodes.
image
image

There are redundant nodes
image
In fact, when I assign test1 to 1, branch 1 should be taken. At the same time, q and w are empty, then branch 2 and branch 3, these two conditional judgments should be over, so branch 1 is completed, and the entire process It should all end.

@Hope1u commented on GitHub (Nov 3, 2024): You seem to have misunderstood the meaning. It has nothing to do with the variable aggregator. This problem will occur when any other nodes are added before merging two branches, as follows: There are three parameters. When test1 is not empty, branch 1 is taken. When q is not empty, branch 2 is taken. When w is not empty, branch 3 is taken. Branch 2 and branch 3 are merged. When testing, I assign test1 to 1, and the q and w parameters are not assigned values. When there are no redundant nodes before merging nodes, the entire process ends after branch 1 is completed, as follows: ![image](https://github.com/user-attachments/assets/ea17c911-2c21-40ea-b218-c7d7a666c193) When there is an additional node before the merge node, after completing branch 1, the merge node will continue to be taken, as follows: ![image](https://github.com/user-attachments/assets/a73d46a2-98ac-47ac-aef5-dde08021344b) As long as you add any more nodes before merging them, this will happen: For example, there are no redundant nodes before merging nodes. ![image](https://github.com/user-attachments/assets/5f472eb6-7664-46ac-aaf2-40aac6220908) ![image](https://github.com/user-attachments/assets/2d1ab3e4-39ec-41da-8c27-50a68f515fb8) There are redundant nodes ![image](https://github.com/user-attachments/assets/ba95cf5c-b635-4d7b-8c98-6650c2e20e1c) In fact, when I assign test1 to 1, branch 1 should be taken. At the same time, q and w are empty, then branch 2 and branch 3, these two conditional judgments should be over, so branch 1 is completed, and the entire process It should all end.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 12, 2024):

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

Issue Summary

  • Reported issue with branching logic in version 0.10.2 of a self-hosted Docker setup.
  • Process incorrectly continues to a merge node after completing branch 1 if any additional node is added before merging branches 2 and 3.
  • I suggested checking logic for handling duplicate end nodes and merging branches.
  • You clarified the issue occurs when any node is added before the merge, not related to variable aggregation.
  • Crazywoola mentioned this might be a designed behavior, referencing another issue for context.

Next Steps

  • Please confirm if this issue is still relevant to the latest version of the Dify repository. If so, you can keep the discussion open by commenting on the issue.
  • Otherwise, the issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 12, 2024): Hi, @Hope1u. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary** - Reported issue with branching logic in version 0.10.2 of a self-hosted Docker setup. - Process incorrectly continues to a merge node after completing branch 1 if any additional node is added before merging branches 2 and 3. - I suggested checking logic for handling duplicate end nodes and merging branches. - You clarified the issue occurs when any node is added before the merge, not related to variable aggregation. - Crazywoola mentioned this might be a designed behavior, referencing another issue for context. **Next Steps** - Please confirm if this issue is still relevant to the latest version of the Dify repository. If so, you can keep the discussion open by commenting on the issue. - Otherwise, the issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Author
Owner

@yihong0618 commented on GitHub (Dec 20, 2024):

can you offer your dsl?

@yihong0618 commented on GitHub (Dec 20, 2024): can you offer your dsl?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6504