Skip to content

Commit 2345756

Browse files
committed
fix(terminal): cycle guard in collectWorkflowDescendants, workflow node running/canceled state
1 parent 8b8b88c commit 2345756

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ const WorkflowNodeRow = memo(function WorkflowNodeRow({
382382
() => Boolean(entry.error) || hasErrorInTree(children),
383383
[entry.error, children]
384384
)
385-
const hasRunningDescendant = useMemo(() => hasRunningInTree(children), [children])
385+
const hasRunningDescendant = useMemo(
386+
() => Boolean(entry.isRunning) || hasRunningInTree(children),
387+
[entry.isRunning, children]
388+
)
386389
const hasCanceledDescendant = useMemo(
387-
() => hasCanceledInTree(children) && !hasRunningDescendant,
388-
[children, hasRunningDescendant]
390+
() => (Boolean(entry.isCanceled) || hasCanceledInTree(children)) && !hasRunningDescendant,
391+
[entry.isCanceled, children, hasRunningDescendant]
389392
)
390393

391394
return (

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,16 @@ interface IterationGroup {
199199
*/
200200
function collectWorkflowDescendants(
201201
workflowBlockId: string,
202-
workflowChildGroups: Map<string, ConsoleEntry[]>
202+
workflowChildGroups: Map<string, ConsoleEntry[]>,
203+
visited: Set<string> = new Set()
203204
): ConsoleEntry[] {
205+
if (visited.has(workflowBlockId)) return []
206+
visited.add(workflowBlockId)
204207
const direct = workflowChildGroups.get(workflowBlockId) ?? []
205208
const result = [...direct]
206209
for (const entry of direct) {
207210
if (isWorkflowBlockType(entry.blockType)) {
208-
result.push(...collectWorkflowDescendants(entry.blockId, workflowChildGroups))
211+
result.push(...collectWorkflowDescendants(entry.blockId, workflowChildGroups, visited))
209212
}
210213
}
211214
return result

0 commit comments

Comments
 (0)