Skip to content

fix(terminal): thread executionOrder through child workflow SSE events for loop support#3346

Merged
waleedlatif1 merged 4 commits intostagingfrom
waleedlatif1/fix-child-wf-logs
Feb 26, 2026
Merged

fix(terminal): thread executionOrder through child workflow SSE events for loop support#3346
waleedlatif1 merged 4 commits intostagingfrom
waleedlatif1/fix-child-wf-logs

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Thread executionOrder through the block:childWorkflowStarted SSE event chain so updateConsole can precisely target the correct console entry per loop iteration
  • Without this, all loop iterations share the same blockId, so childWorkflowInstanceId from later iterations overwrites earlier ones, breaking the expandable child workflow tree

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 26, 2026 1:41am

Request Review

@waleedlatif1 waleedlatif1 force-pushed the waleedlatif1/fix-child-wf-logs branch from a95624d to a0822dc Compare February 26, 2026 01:32
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

This PR threads executionOrder through the child workflow SSE event chain to fix a bug where loop iterations overwrite each other's childWorkflowInstanceId in the terminal console.

Key Changes:

  • Added executionOrder parameter to onChildWorkflowInstanceReady callback signature across ExecutionCallbacks, ContextExtensions, and ExecutionContext
  • BlockExecutor now passes executionOrder from blockLog into nodeMetadata
  • WorkflowBlockHandler threads executionOrder to the callback when notifying about child workflow instances
  • SSE events and frontend handlers propagate executionOrder to console store updates
  • Enhanced matchesEntryForUpdate with childWorkflowBlockId check for more precise entry matching in loops
  • Changed iteration children rendering from BlockRow to EntryNodeRow to enable recursive workflow tree expansion

Impact:
The changes ensure that when workflow blocks execute inside loops, each iteration maintains its own distinct console entry and child workflow tree, preventing later iterations from overwriting earlier ones. All changes use optional parameters and backward-compatible patterns.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation properly threads a single field through the execution stack using consistent patterns. All changes use optional parameters and conditional spreads for backward compatibility. The terminal rendering change correctly enables recursive node rendering. No breaking changes or logic errors detected.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx Changed iteration children rendering from BlockRow to EntryNodeRow for proper recursive workflow tree expansion support
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts Added executionOrder field to block:childWorkflowStarted event handler and passes it to updateConsole
apps/sim/executor/execution/block-executor.ts Threads executionOrder from blockLog into nodeMetadata for child workflow handlers
apps/sim/executor/handlers/workflow/workflow-handler.ts Added executionOrder to nodeMetadata type and passes it to onChildWorkflowInstanceReady callback
apps/sim/stores/terminal/console/store.ts Added childWorkflowBlockId check to matchesEntryForUpdate for more precise entry matching in loop iterations

Sequence Diagram

sequenceDiagram
    participant BE as BlockExecutor
    participant WH as WorkflowHandler
    participant SSE as SSE Events
    participant Hook as useWorkflowExecution
    participant Store as ConsoleStore

    BE->>BE: createBlockLog(executionOrder)
    BE->>BE: Build nodeMetadata with executionOrder
    BE->>WH: executeWithNode(nodeMetadata)
    WH->>WH: Extract executionOrder from nodeMetadata
    WH->>SSE: onChildWorkflowInstanceReady(blockId, instanceId, iterationContext, executionOrder)
    SSE->>SSE: Spread executionOrder into event data
    SSE->>Hook: block:childWorkflowStarted event
    Hook->>Hook: Extract executionOrder from event data
    Hook->>Store: updateConsole(blockId, {executionOrder, ...})
    Store->>Store: matchesEntryForUpdate checks executionOrder + childWorkflowBlockId
    Store->>Store: Update correct entry for loop iteration
Loading

Last reviewed commit: 42127d2

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

9 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

…kflow block expansion

IterationNodeRow was rendering all children as flat BlockRow components,
ignoring nodeType. Workflow blocks inside loop iterations were never
rendered as WorkflowNodeRow, so they had no expand chevron or child tree.
Sub-executors reset executionOrderCounter, so child blocks across loop
iterations share the same blockId + executionOrder. Without checking
childWorkflowBlockId, updateConsole for iteration N overwrites entries
from iterations 0..N-1, causing all child blocks to be grouped under
the last iteration's workflow instance.
@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1 waleedlatif1 merged commit d98545d into staging Feb 26, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/fix-child-wf-logs branch February 26, 2026 03:02
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