From 3b1657b6faa7187adbd1aeee0d8333e12039b4d0 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Wed, 24 Sep 2025 15:28:50 +0200 Subject: [PATCH] Store history when iterator reset the step info (#14684) - before reseting the step, enrich info with previous result - reset only when a step is executed more than once. This will avoid to store the initial `NOT_STARTED` status of the step --- .../iterator/iterator.workflow-action.ts | 18 +++++++++++++++++- .../types/WorkflowRunStateStepInfos.ts | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts index 4bf154bf9e..dd247936f1 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts @@ -105,7 +105,7 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { hasProcessedAllItems, }; - if (!hasProcessedAllItems) { + if (!hasProcessedAllItems && currentItemIndex > 0) { await this.resetStepsInLoop({ iteratorStepId, initialLoopStepIds, @@ -140,6 +140,14 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { steps, }); + const workflowRunToUpdate = + await this.workflowRunWorkspaceService.getWorkflowRunOrFail({ + workflowRunId, + workspaceId, + }); + + const stepInfos = workflowRunToUpdate.state.stepInfos; + await this.workflowRunWorkspaceService.updateWorkflowRunStepInfos({ stepInfos: stepIdsToReset.reduce( (acc, stepId) => { @@ -147,6 +155,14 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { status: StepStatus.NOT_STARTED, result: undefined, error: undefined, + history: [ + ...(stepInfos[stepId]?.history ?? []), + { + result: stepInfos[stepId]?.result, + error: stepInfos[stepId]?.error, + status: stepInfos[stepId]?.status, + }, + ], }; return acc; diff --git a/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts b/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts index fcb1d6ea98..c1e9642b95 100644 --- a/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts +++ b/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts @@ -11,6 +11,11 @@ export type WorkflowRunStepInfo = { result?: object; error?: string; status: StepStatus; + history?: { + status: StepStatus; + result?: object; + error?: string; + }[]; }; export type WorkflowRunStepInfos = Record;