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

View File

@@ -41,8 +41,13 @@ function extractBlockInputs(
if (blockState.data) {
Object.entries(blockState.data).forEach(([key, value]) => {
// Include relevant configuration properties
if (key === 'count' || key === 'loopType' || key === 'collection' ||
key === 'parallelType' || key === 'distribution') {
if (
key === 'count' ||
key === 'loopType' ||
key === 'collection' ||
key === 'parallelType' ||
key === 'distribution'
) {
if (value !== undefined && value !== null && value !== '') {
inputs[key] = value
}
@@ -54,14 +59,14 @@ function extractBlockInputs(
}
})
}
// Include any additional values from subBlockValues that might not be in data
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
}
})
return inputs
}

View File

@@ -266,17 +266,17 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
const sorted: ImportedBlock[] = []
const processed = new Set<string>()
const visiting = new Set<string>() // Track blocks currently being processed to detect cycles
// Create a map for quick lookup
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
function processBlock(block: ImportedBlock) {
if (processed.has(block.id)) {
return // Already processed
}
if (visiting.has(block.id)) {
// 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`)
@@ -284,9 +284,9 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
processed.add(block.id)
return
}
visiting.add(block.id)
// If this block has a parent, ensure the parent is processed first
if (block.parentId) {
const parentBlock = blockMap.get(block.parentId)
@@ -294,16 +294,16 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[]
processBlock(parentBlock)
}
}
// Now process this block
visiting.delete(block.id)
sorted.push(block)
processed.add(block.id)
}
// Process all blocks
blocks.forEach(block => processBlock(block))
blocks.forEach((block) => processBlock(block))
return sorted
}
@@ -623,8 +623,8 @@ export async function importWorkflowFromYaml(
} else {
logger.warn(`Parent block not found for mapping: ${blockData.data.parentId}`)
// Remove invalid parent reference
delete blockData.data.parentId
delete blockData.data.extent
blockData.data.parentId = undefined
blockData.data.extent = undefined
}
}
}