fix: condition node incorrectly executes nodes on unfulfilled branches with multiple edges#6539
fix: condition node incorrectly executes nodes on unfulfilled branches with multiple edges#6539joo9906 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
Improvement Opportunity
Currently, edges.filter is called inside a loop over unfulfilledIndexes. This results in
We can optimize this to 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)
}
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:
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