From 6d49f3712a228523ccdea7729bffcea73c02ce0a Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Wed, 3 Jun 2026 09:52:30 -0700 Subject: [PATCH] refactor(core): reuse materializeWorkflowSteps in selectTaskWorkflow Consolidate the duplicated step-materialization loop; validate by compiling before any mutation so a non-linear graph still aborts with nothing written. --- packages/core/src/store.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/core/src/store.ts b/packages/core/src/store.ts index 0e80d56158..e364ac9c3e 100644 --- a/packages/core/src/store.ts +++ b/packages/core/src/store.ts @@ -11164,20 +11164,11 @@ ${stepsSection}`; async selectTaskWorkflow(taskId: string, workflowId: string): Promise { const def = await this.getWorkflowDefinition(workflowId); if (!def) throw new Error(`Workflow '${workflowId}' not found`); - // Compile first so a non-linear graph aborts before we mutate anything. - const inputs = compileWorkflowToSteps(def.ir); - + // Validate by compiling first so a non-linear graph aborts before any + // mutation (including removal of the prior selection's steps). + compileWorkflowToSteps(def.ir); this.removeMaterializedSelection(taskId); - - const ids: string[] = []; - for (const input of inputs) { - const step = await this.createWorkflowStep({ - ...input, - templateId: `${WORKFLOW_COMPILED_STEP_TEMPLATE_PREFIX}${workflowId}`, - enabled: true, - }); - ids.push(step.id); - } + const ids = await this.materializeWorkflowSteps(workflowId, def.ir); await this.updateTask(taskId, { enabledWorkflowSteps: ids }); this.writeTaskWorkflowSelection(taskId, workflowId, ids);