diff --git a/apps/sim/app/api/workflows/[id]/execute/route.ts b/apps/sim/app/api/workflows/[id]/execute/route.ts index 55a8c79dc4..618608d04c 100644 --- a/apps/sim/app/api/workflows/[id]/execute/route.ts +++ b/apps/sim/app/api/workflows/[id]/execute/route.ts @@ -264,24 +264,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any): P {} as Record> ) - // Get workflow variables - let workflowVariables = {} - if (workflow.variables) { - try { - // Parse workflow variables if they're stored as a string - if (typeof workflow.variables === 'string') { - workflowVariables = JSON.parse(workflow.variables) - } else { - // Otherwise use as is (already parsed JSON) - workflowVariables = workflow.variables - } - logger.debug( - `[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}` - ) - } catch (error) { - logger.error(`[${requestId}] Failed to parse workflow variables: ${workflowId}`, error) - // Continue execution even if variables can't be parsed - } + // Get workflow variables - they are stored as JSON objects in the database + const workflowVariables = (workflow.variables as Record) || {} + + if (Object.keys(workflowVariables).length > 0) { + logger.debug( + `[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}` + ) } else { logger.debug(`[${requestId}] No workflow variables found for: ${workflowId}`) } diff --git a/apps/sim/executor/handlers/workflow/workflow-handler.ts b/apps/sim/executor/handlers/workflow/workflow-handler.ts index bf9d83407c..a5b0ba61dd 100644 --- a/apps/sim/executor/handlers/workflow/workflow-handler.ts +++ b/apps/sim/executor/handlers/workflow/workflow-handler.ts @@ -89,6 +89,7 @@ export class WorkflowBlockHandler implements BlockHandler { workflow: childWorkflow.serializedState, workflowInput: childWorkflowInput, envVarValues: context.environmentVariables, + workflowVariables: childWorkflow.variables || {}, }) const startTime = performance.now() @@ -176,9 +177,20 @@ export class WorkflowBlockHandler implements BlockHandler { workflowState.parallels || {} ) + const workflowVariables = (workflowData.variables as Record) || {} + + if (Object.keys(workflowVariables).length > 0) { + logger.info( + `Loaded ${Object.keys(workflowVariables).length} variables for child workflow: ${workflowId}` + ) + } else { + logger.debug(`No workflow variables found for child workflow: ${workflowId}`) + } + return { name: workflowData.name, serializedState: serializedWorkflow, + variables: workflowVariables, } } catch (error) { logger.error(`Error loading child workflow ${workflowId}:`, error)