From 9825e4673210bdda4b55cb6dfb16fdcadfcf5adc Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 3 Mar 2025 19:47:12 -0800 Subject: [PATCH] feat(loops): additional logic to ensure we enforce min and max loops, removed unused type --- executor/loops.ts | 22 ++++++++++++++++++---- executor/types.ts | 9 --------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/executor/loops.ts b/executor/loops.ts index 2b28266f44..aba3623978 100644 --- a/executor/loops.ts +++ b/executor/loops.ts @@ -35,12 +35,15 @@ export class LoopManager { continue } - // Check if we need to force iteration due to minimum iterations requirement + // Get min iterations for the loop const minIterations = loop.minIterations || this.defaultMinIterations - const forceIteration = currentIteration < minIterations // Check if loop should iterate again - const shouldIterate = forceIteration || this.shouldIterateLoop(loopId, context) + const normalIteration = this.shouldIterateLoop(loopId, context) + const forceIteration = + currentIteration < minIterations && this.allBlocksExecuted(loop.nodes, context) + + const shouldIterate = normalIteration || forceIteration if (shouldIterate) { // Increment iteration counter @@ -115,7 +118,7 @@ export class LoopManager { const loop = this.loops[loopId] if (!loop) return false - const allBlocksExecuted = loop.nodes.every((nodeId) => context.executedBlocks.has(nodeId)) + const allBlocksExecuted = this.allBlocksExecuted(loop.nodes, context) if (!allBlocksExecuted) return false const currentIteration = context.loopIterations.get(loopId) || 0 @@ -145,6 +148,17 @@ export class LoopManager { return false } + /** + * Checks if all blocks in a list have been executed. + * + * @param nodeIds - IDs of nodes to check + * @param context - Current execution context + * @returns Whether all blocks have been executed + */ + private allBlocksExecuted(nodeIds: string[], context: ExecutionContext): boolean { + return nodeIds.every((nodeId) => context.executedBlocks.has(nodeId)) + } + /** * Checks if a connection forms a feedback path in a loop. * A feedback path points to an earlier block in the loop. diff --git a/executor/types.ts b/executor/types.ts index 4a31462adc..3cfcc9f936 100644 --- a/executor/types.ts +++ b/executor/types.ts @@ -108,15 +108,6 @@ export interface ExecutionResult { } } -/** - * Configuration options for workflow execution. - */ -export interface ExecutionOptions { - maxLoopIterations?: number // Maximum iterations for any loop (default: 5) - continueOnError?: boolean // Whether to continue execution after errors - timeoutMs?: number // Maximum execution time in milliseconds before timeout -} - /** * Interface for a block executor component. */