Skip to content

Fix duplicate iteration execution tree ids#6545

Open
vicksiyi wants to merge 2 commits into
FlowiseAI:mainfrom
vicksiyi:codex/fix-iteration-tree-ids
Open

Fix duplicate iteration execution tree ids#6545
vicksiyi wants to merge 2 commits into
FlowiseAI:mainfrom
vicksiyi:codex/fix-iteration-tree-ids

Conversation

@vicksiyi

Copy link
Copy Markdown

Summary

  • group iteration execution children by the concrete parent node instance instead of only parentNodeId
  • generate virtual iteration tree ids from the parent uniqueNodeId to avoid duplicate RichTreeView ids when the same iteration node executes more than once
  • apply the same fix to execution details and chat message execution cards

Tests

  • pnpm --dir packages/ui build

Notes

@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 refactors the iteration node grouping and tree-building logic in both ExecutionDetails.jsx and AgentExecutedDataCard.jsx to use unique parent node IDs (parentUniqueNodeId) instead of simple parent IDs. This allows for direct parent node lookups via a map rather than performing linear scans in the second pass. The feedback suggests further optimizing the first pass by replacing the backward linear scan for finding the parent's unique ID with an $O(1)$ map lookup of the most recently seen indices, which prevents potential UI performance issues on large execution trees.

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 +397 to +413
const iterationGroups = new Map() // parent uniqueNodeId -> Map of iterationIndex -> nodes

// Group iteration child nodes by their parent and iteration index
nodes.forEach((node, index) => {
if (node.data?.parentNodeId && node.data?.iterationIndex !== undefined) {
const parentId = node.data.parentNodeId
const iterationIndex = node.data.iterationIndex
let parentUniqueNodeId = null

if (!iterationGroups.has(parentId)) {
iterationGroups.set(parentId, new Map())
for (let i = index; i >= 0; i--) {
if (nodes[i].nodeId === parentId) {
parentUniqueNodeId = `${nodes[i].nodeId}_${i}`
break
}
}

if (!parentUniqueNodeId) return

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

Instead of performing a backward linear scan ($O(N)$) for every iteration child node to find its parent node's unique ID, we can maintain a map of the most recently seen index for each nodeId as we iterate. This optimizes the lookup to $O(1)$ time complexity, preventing potential UI performance degradation when rendering large execution trees.

        const iterationGroups = new Map() // parent uniqueNodeId -> Map of iterationIndex -> nodes
        const lastSeenIndices = new Map()

        // Group iteration child nodes by their parent and iteration index
        nodes.forEach((node, index) => {
            lastSeenIndices.set(node.nodeId, index)
            if (node.data?.parentNodeId && node.data?.iterationIndex !== undefined) {
                const parentId = node.data.parentNodeId
                const iterationIndex = node.data.iterationIndex
                const parentIndex = lastSeenIndices.get(parentId)
                const parentUniqueNodeId = parentIndex !== undefined ? parentId + '_' + parentIndex : null

                if (!parentUniqueNodeId) return

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in 9728aa1 to keep a last-seen parent index map during traversal, which removes the per-child backward scan while preserving the unique node id format.

Comment on lines +372 to +388
const iterationGroups = new Map() // parent uniqueNodeId -> Map of iterationIndex -> nodes

// Group iteration child nodes by their parent and iteration index
nodes.forEach((node, index) => {
if (node.data?.parentNodeId && node.data?.iterationIndex !== undefined) {
const parentId = node.data.parentNodeId
const iterationIndex = node.data.iterationIndex
let parentUniqueNodeId = null

if (!iterationGroups.has(parentId)) {
iterationGroups.set(parentId, new Map())
for (let i = index; i >= 0; i--) {
if (nodes[i].nodeId === parentId) {
parentUniqueNodeId = `${nodes[i].nodeId}_${i}`
break
}
}

if (!parentUniqueNodeId) return

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

Instead of performing a backward linear scan ($O(N)$) for every iteration child node to find its parent node's unique ID, we can maintain a map of the most recently seen index for each nodeId as we iterate. This optimizes the lookup to $O(1)$ time complexity, preventing potential UI performance degradation when rendering large execution trees.

        const iterationGroups = new Map() // parent uniqueNodeId -> Map of iterationIndex -> nodes
        const lastSeenIndices = new Map()

        // Group iteration child nodes by their parent and iteration index
        nodes.forEach((node, index) => {
            lastSeenIndices.set(node.nodeId, index)
            if (node.data?.parentNodeId && node.data?.iterationIndex !== undefined) {
                const parentId = node.data.parentNodeId
                const iterationIndex = node.data.iterationIndex
                const parentIndex = lastSeenIndices.get(parentId)
                const parentUniqueNodeId = parentIndex !== undefined ? parentId + '_' + parentIndex : null

                if (!parentUniqueNodeId) return

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in 9728aa1 to keep a last-seen parent index map during traversal, which removes the per-child backward scan while preserving the unique node id format.

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.

MUI X: The Tree View component requires all items to have a unique id property.

1 participant