Skip to content

The open alternative to Salesforce, designed for AI.

Stop a failed iterator from re-entering its loop (#28524)

Charles Bochetbead13c28e89
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-fail-safely-iterator-step.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-fail-safely-iterator-step.util.spec.ts
index 4604eab07f0..6a9adcab269 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-fail-safely-iterator-step.util.spec.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-fail-safely-iterator-step.util.spec.ts
@@ -2,6 +2,7 @@ import { StepStatus } from 'twenty-shared/workflow';
import {
createMockCodeStep,
+ createMockIfElseStep,
createMockIteratorStep,
} from 'src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util';
import { shouldFailSafelyIteratorStep } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util';
@@ -147,4 +148,46 @@ describe('shouldFailSafelyIteratorStep', () => {
expect(result).toBe(false);
});
});
+ describe('iterator already failed safely', () => {
+ it.each([true, false])(
+ 'should return false when its loop comes back to it (flag: %s)',
+ (shouldContinueOnIterationFailure) => {
+ const findStep = createMockCodeStep('find', ['iterator1'], {
+ continueOnFailure: true,
+ });
+ const iterator = createMockIteratorStep(
+ 'iterator1',
+ [],
+ ['ifElseA'],
+ shouldContinueOnIterationFailure,
+ );
+ const ifElseA = createMockIfElseStep('ifElseA', [
+ { id: 'branchA1', nextStepIds: ['updateA'] },
+ { id: 'branchA2', nextStepIds: ['ifElseB'] },
+ ]);
+ const updateA = createMockCodeStep('updateA', ['iterator1']);
+ const ifElseB = createMockIfElseStep('ifElseB', [
+ { id: 'branchB1', nextStepIds: ['updateB'] },
+ { id: 'branchB2', nextStepIds: ['iterator1'] },
+ ]);
+ const updateB = createMockCodeStep('updateB', ['iterator1']);
+ const steps = [findStep, iterator, ifElseA, updateA, ifElseB, updateB];
+
+ const result = shouldFailSafelyIteratorStep({
+ step: iterator,
+ steps,
+ stepInfos: {
+ find: { status: StepStatus.FAILED_SAFELY, error: 'Invalid filter' },
+ iterator1: { status: StepStatus.FAILED_SAFELY },
+ ifElseA: { status: StepStatus.FAILED_SAFELY },
+ updateA: { status: StepStatus.FAILED_SAFELY },
+ ifElseB: { status: StepStatus.FAILED_SAFELY },
+ updateB: { status: StepStatus.FAILED_SAFELY },
+ },
+ });
+
+ expect(result).toBe(false);
+ },
+ );
+ });
});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util.ts
index ab8cef231d4..9062d13b5ef 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util.ts
@@ -56,6 +56,11 @@ export const shouldFailSafelyIteratorStep = ({
return areAllExternalParentsTerminal && hasFailedSafelyExternalParent;
}
+ // Failing it again would hand the failure back to its loop, which returns to it forever
+ if (stepInfos[step.id]?.status === StepStatus.FAILED_SAFELY) {
+ return false;
+ }
+
const allParentStatuses = allParentSteps.map((parentStep) =>
getEffectiveParentStatus({ parentStep, childStepId: step.id, stepInfos }),
);