Fix loop/parallel yaml

This commit is contained in:
Siddharth Ganesan
2025-07-09 10:23:44 -07:00
parent 218041dba3
commit 3c1914c566
2 changed files with 22 additions and 17 deletions
+10 -5
View File
@@ -41,8 +41,13 @@ function extractBlockInputs(
if (blockState.data) { if (blockState.data) {
Object.entries(blockState.data).forEach(([key, value]) => { Object.entries(blockState.data).forEach(([key, value]) => {
// Include relevant configuration properties // Include relevant configuration properties
if (key === 'count' || key === 'loopType' || key === 'collection' || if (
key === 'parallelType' || key === 'distribution') { key === 'count' ||
key === 'loopType' ||
key === 'collection' ||
key === 'parallelType' ||
key === 'distribution'
) {
if (value !== undefined && value !== null && value !== '') { if (value !== undefined && value !== null && value !== '') {
inputs[key] = value inputs[key] = value
} }
@@ -54,14 +59,14 @@ function extractBlockInputs(
} }
}) })
} }
// Include any additional values from subBlockValues that might not be in data // Include any additional values from subBlockValues that might not be in data
Object.entries(blockSubBlockValues).forEach(([key, value]) => { Object.entries(blockSubBlockValues).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '' && !inputs.hasOwnProperty(key)) { if (value !== undefined && value !== null && value !== '' && !Object.hasOwn(inputs, key)) {
inputs[key] = value inputs[key] = value
} }
}) })
return inputs return inputs
} }
+12 -12
View File
@@ -266,17 +266,17 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
const sorted: ImportedBlock[] = [] const sorted: ImportedBlock[] = []
const processed = new Set<string>() const processed = new Set<string>()
const visiting = new Set<string>() // Track blocks currently being processed to detect cycles const visiting = new Set<string>() // Track blocks currently being processed to detect cycles
// Create a map for quick lookup // Create a map for quick lookup
const blockMap = new Map<string, ImportedBlock>() const blockMap = new Map<string, ImportedBlock>()
blocks.forEach(block => blockMap.set(block.id, block)) blocks.forEach((block) => blockMap.set(block.id, block))
// Process blocks recursively, ensuring parents are added first // Process blocks recursively, ensuring parents are added first
function processBlock(block: ImportedBlock) { function processBlock(block: ImportedBlock) {
if (processed.has(block.id)) { if (processed.has(block.id)) {
return // Already processed return // Already processed
} }
if (visiting.has(block.id)) { if (visiting.has(block.id)) {
// Circular dependency detected - break the cycle by processing this block without its parent // Circular dependency detected - break the cycle by processing this block without its parent
logger.warn(`Circular parent-child dependency detected for block ${block.id}, breaking cycle`) logger.warn(`Circular parent-child dependency detected for block ${block.id}, breaking cycle`)
@@ -284,9 +284,9 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
processed.add(block.id) processed.add(block.id)
return return
} }
visiting.add(block.id) visiting.add(block.id)
// If this block has a parent, ensure the parent is processed first // If this block has a parent, ensure the parent is processed first
if (block.parentId) { if (block.parentId) {
const parentBlock = blockMap.get(block.parentId) const parentBlock = blockMap.get(block.parentId)
@@ -294,16 +294,16 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
processBlock(parentBlock) processBlock(parentBlock)
} }
} }
// Now process this block // Now process this block
visiting.delete(block.id) visiting.delete(block.id)
sorted.push(block) sorted.push(block)
processed.add(block.id) processed.add(block.id)
} }
// Process all blocks // Process all blocks
blocks.forEach(block => processBlock(block)) blocks.forEach((block) => processBlock(block))
return sorted return sorted
} }
@@ -623,8 +623,8 @@ export async function importWorkflowFromYaml(
} else { } else {
logger.warn(`Parent block not found for mapping: ${blockData.data.parentId}`) logger.warn(`Parent block not found for mapping: ${blockData.data.parentId}`)
// Remove invalid parent reference // Remove invalid parent reference
delete blockData.data.parentId blockData.data.parentId = undefined
delete blockData.data.extent blockData.data.extent = undefined
} }
} }
} }