Skip to content

Commit 25347a9

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(terminal): attribute repeated block output by invocation
1 parent 8104c33 commit 25347a9

28 files changed

Lines changed: 940 additions & 256 deletions

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,8 @@ async function handleExecutePost(
18661866
blockType: string,
18671867
executionOrder: number,
18681868
iterationContext?: IterationContext,
1869-
childWorkflowContext?: ChildWorkflowContext
1869+
childWorkflowContext?: ChildWorkflowContext,
1870+
blockExecutionId?: string
18701871
) => {
18711872
reqLogger.info('onBlockStart called', { blockId, blockName, blockType })
18721873
await sendEvent({
@@ -1892,6 +1893,7 @@ async function handleExecutePost(
18921893
childWorkflowBlockId: childWorkflowContext.parentBlockId,
18931894
childWorkflowName: childWorkflowContext.workflowName,
18941895
}),
1896+
...(blockExecutionId && { blockExecutionId }),
18951897
},
18961898
})
18971899
}
@@ -1902,7 +1904,8 @@ async function handleExecutePost(
19021904
blockType: string,
19031905
callbackData: BlockCompletionCallbackData,
19041906
iterationContext?: IterationContext,
1905-
childWorkflowContext?: ChildWorkflowContext
1907+
childWorkflowContext?: ChildWorkflowContext,
1908+
blockExecutionId?: string
19061909
) => {
19071910
const compactCallbackData = {
19081911
...callbackData,
@@ -1982,6 +1985,9 @@ async function handleExecutePost(
19821985
}),
19831986
...childWorkflowData,
19841987
...instanceData,
1988+
...((blockExecutionId || callbackData.blockExecutionId) && {
1989+
blockExecutionId: blockExecutionId ?? callbackData.blockExecutionId,
1990+
}),
19851991
},
19861992
})
19871993
} else {
@@ -2021,13 +2027,17 @@ async function handleExecutePost(
20212027
}),
20222028
...childWorkflowData,
20232029
...instanceData,
2030+
...((blockExecutionId || callbackData.blockExecutionId) && {
2031+
blockExecutionId: blockExecutionId ?? callbackData.blockExecutionId,
2032+
}),
20242033
},
20252034
})
20262035
}
20272036
}
20282037

20292038
const onStream = async (streamingExec: StreamingExecution) => {
20302039
const blockId = (streamingExec.execution as any).blockId
2040+
const { blockExecutionId } = streamingExec
20312041

20322042
// Live answer text rides the sink when available (pending deltas
20332043
// stream as the model generates; chunk_reset clears intermediate
@@ -2038,6 +2048,7 @@ async function handleExecutePost(
20382048
// Sync window: attach sink before first await so pump delivers thinking/tools.
20392049
const unsubscribe = forwardAgentStreamToExecutionEvents(streamingExec, {
20402050
blockId,
2051+
blockExecutionId,
20412052
executionId,
20422053
workflowId,
20432054
sendEvent,
@@ -2079,7 +2090,7 @@ async function handleExecutePost(
20792090
timestamp: new Date().toISOString(),
20802091
executionId,
20812092
workflowId,
2082-
data: { blockId, chunk, display },
2093+
data: { blockId, ...(blockExecutionId && { blockExecutionId }), chunk, display },
20832094
})
20842095
}
20852096

@@ -2089,7 +2100,7 @@ async function handleExecutePost(
20892100
timestamp: new Date().toISOString(),
20902101
executionId,
20912102
workflowId,
2092-
data: { blockId },
2103+
data: { blockId, ...(blockExecutionId && { blockExecutionId }) },
20932104
})
20942105
}
20952106
} catch (error) {
@@ -2150,7 +2161,8 @@ async function handleExecutePost(
21502161
childWorkflowInstanceId: string,
21512162
iterationContext?: IterationContext,
21522163
executionOrder?: number,
2153-
childWorkflowContext?: ChildWorkflowContext
2164+
childWorkflowContext?: ChildWorkflowContext,
2165+
blockExecutionId?: string
21542166
) => {
21552167
await sendEvent({
21562168
type: 'block:childWorkflowStarted',
@@ -2174,6 +2186,7 @@ async function handleExecutePost(
21742186
childWorkflowName: childWorkflowContext.workflowName,
21752187
}),
21762188
...(executionOrder !== undefined && { executionOrder }),
2189+
...(blockExecutionId && { blockExecutionId }),
21772190
},
21782191
})
21792192
}

0 commit comments

Comments
 (0)