fix(workflow-in-workflow): variables not accessible in child workflow (#783)

* fix(workflow-in-workflow): child workflow must be able to access vars

* simplify
This commit is contained in:
Vikhyath Mondreti
2025-07-24 16:17:38 -07:00
committed by GitHub
parent 5ddfe1b709
commit a84c55772d
2 changed files with 19 additions and 18 deletions

View File

@@ -264,24 +264,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any): P
{} as Record<string, Record<string, any>>
)
// 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<string, any>) || {}
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}`)
}

View File

@@ -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<string, any>) || {}
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)