Fix duplicate iteration execution tree ids#6545
Conversation
There was a problem hiding this comment.
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
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.
| 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 |
There was a problem hiding this comment.
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
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) returnThere was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
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) returnThere was a problem hiding this comment.
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.
Summary
parentNodeIduniqueNodeIdto avoid duplicate RichTreeView ids when the same iteration node executes more than onceTests
pnpm --dir packages/ui buildNotes
idproperty. #5248