Skip to content

fix: condition node incorrectly executes nodes on unfulfilled branches with multiple edges#6539

Open
joo9906 wants to merge 2 commits into
FlowiseAI:mainfrom
joo9906:main
Open

fix: condition node incorrectly executes nodes on unfulfilled branches with multiple edges#6539
joo9906 wants to merge 2 commits into
FlowiseAI:mainfrom
joo9906:main

Conversation

@joo9906

@joo9906 joo9906 commented Jun 22, 2026

Copy link
Copy Markdown

Problem

In determineNodesToIgnore (buildAgentflow.ts), the code used edges.find() to locate edges belonging to unfulfilled condition branches. Since find() returns only the first match, when a single condition branch had more than one edge connected (multiple targets on the same output handle), only the first target node was added to ignoreNodeIds. The remaining target nodes were not ignored and would execute unintentionally.

Example:

  • Branch 0 (unfulfilled): 2 edges → NodeA, NodeB
  • Branch 1 (fulfilled): 1 edge → NodeC
  • Branch 2 (unfulfilled): 1 edge → NodeD

Before fix: NodeA, NodeD ignored → NodeB executes alongsi
After fix: NodeA, NodeB, NodeD all ignored → only NodeC executes (correct)

Root Cause

// Before — only first matching edge captured
const ignoreEdge = edges.find((edge) => edge.source === nodeId && edge.sourceHandle === ${nodeId}-output-${index})
if (ignoreEdge) {
ignoreNodeIds.push(ignoreEdge.target)
}

Fix

// After — all matching edges captured
const ignoreEdges = edges.filter((edge) => edge.source == === ${nodeId}-output-${index})
for (const ignoreEdge of ignoreEdges) {
ignoreNodeIds.push(ignoreEdge.target)
}

Files Changed

  • packages/server/src/utils/buildAgentflow.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the node filtering logic in buildAgentflow.ts to handle multiple matching edges instead of just the first one by replacing edges.find with edges.filter. The reviewer provided a valuable optimization suggestion to reduce the time complexity from O(N * M) to O(N + M) by pre-computing the unfulfilled source handles in a Set and filtering the edges in a single pass.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 832 to 838
for (const index of unfulfilledIndexes) {
const ignoreEdge = edges.find((edge) => edge.source === nodeId && edge.sourceHandle === `${nodeId}-output-${index}`)
const ignoreEdges = edges.filter((edge) => edge.source === nodeId && edge.sourceHandle === `${nodeId}-output-${index}`)

if (ignoreEdge) {
for (const ignoreEdge of ignoreEdges) {
ignoreNodeIds.push(ignoreEdge.target)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Improvement Opportunity

Currently, edges.filter is called inside a loop over unfulfilledIndexes. This results in $O(N \times M)$ complexity, where $N$ is the number of edges and $M$ is the number of unfulfilled indexes.

We can optimize this to $O(N + M)$ by pre-computing the unfulfilled source handles in a Set and filtering the edges array in a single pass.

        const unfulfilledSourceHandles = new Set(unfulfilledIndexes.map((index) => nodeId + "-output-" + index))
        const ignoreEdges = edges.filter((edge) => edge.source === nodeId && unfulfilledSourceHandles.has(edge.sourceHandle))

        for (const ignoreEdge of ignoreEdges) {
            ignoreNodeIds.push(ignoreEdge.target)
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant