@@ -198,17 +198,25 @@ interface IterationGroup {
198198 * enabling correct tree construction for deeply-nested child workflows.
199199 */
200200function collectWorkflowDescendants (
201- workflowBlockId : string ,
201+ instanceKey : string ,
202202 workflowChildGroups : Map < string , ConsoleEntry [ ] > ,
203203 visited : Set < string > = new Set ( )
204204) : ConsoleEntry [ ] {
205- if ( visited . has ( workflowBlockId ) ) return [ ]
206- visited . add ( workflowBlockId )
207- const direct = workflowChildGroups . get ( workflowBlockId ) ?? [ ]
205+ if ( visited . has ( instanceKey ) ) return [ ]
206+ visited . add ( instanceKey )
207+ const direct = workflowChildGroups . get ( instanceKey ) ?? [ ]
208208 const result = [ ...direct ]
209209 for ( const entry of direct ) {
210210 if ( isWorkflowBlockType ( entry . blockType ) ) {
211- result . push ( ...collectWorkflowDescendants ( entry . blockId , workflowChildGroups , visited ) )
211+ // Use childWorkflowInstanceId when available (unique per-invocation) to correctly
212+ // separate children across loop iterations of the same workflow block.
213+ result . push (
214+ ...collectWorkflowDescendants (
215+ entry . childWorkflowInstanceId ?? entry . blockId ,
216+ workflowChildGroups ,
217+ visited
218+ )
219+ )
212220 }
213221 }
214222 return result
@@ -387,11 +395,12 @@ function buildEntryTree(entries: ConsoleEntry[]): EntryNode[] {
387395 // Block nodes within this iteration — workflow blocks get their full subtree
388396 const blockNodes : EntryNode [ ] = iterBlocks . map ( ( block ) => {
389397 if ( isWorkflowBlockType ( block . blockType ) ) {
390- const allDescendants = collectWorkflowDescendants ( block . blockId , workflowChildGroups )
398+ const instanceKey = block . childWorkflowInstanceId ?? block . blockId
399+ const allDescendants = collectWorkflowDescendants ( instanceKey , workflowChildGroups )
391400 const rawChildren = allDescendants . map ( ( c ) => ( {
392401 ...c ,
393402 childWorkflowBlockId :
394- c . childWorkflowBlockId === block . blockId ? undefined : c . childWorkflowBlockId ,
403+ c . childWorkflowBlockId === instanceKey ? undefined : c . childWorkflowBlockId ,
395404 } ) )
396405 return {
397406 entry : block ,
@@ -426,11 +435,12 @@ function buildEntryTree(entries: ConsoleEntry[]): EntryNode[] {
426435
427436 for ( const block of regularBlocks ) {
428437 if ( isWorkflowBlockType ( block . blockType ) ) {
429- const allDescendants = collectWorkflowDescendants ( block . blockId , workflowChildGroups )
438+ const instanceKey = block . childWorkflowInstanceId ?? block . blockId
439+ const allDescendants = collectWorkflowDescendants ( instanceKey , workflowChildGroups )
430440 const rawChildren = allDescendants . map ( ( c ) => ( {
431441 ...c ,
432442 childWorkflowBlockId :
433- c . childWorkflowBlockId === block . blockId ? undefined : c . childWorkflowBlockId ,
443+ c . childWorkflowBlockId === instanceKey ? undefined : c . childWorkflowBlockId ,
434444 } ) )
435445 const children = buildEntryTree ( rawChildren )
436446 workflowNodes . push ( { entry : block , children, nodeType : 'workflow' as const } )
0 commit comments