Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,10 @@ export function useWorkflowExecution() {
const workflowEdges = (executionWorkflowState?.edges ??
latestWorkflowState.edges) as typeof currentWorkflow.edges

// Filter out blocks without type (these are layout-only blocks)
// Filter out blocks without type (these are layout-only blocks) and disabled blocks
const validBlocks = Object.entries(workflowBlocks).reduce(
(acc, [blockId, block]) => {
if (block?.type) {
if (block?.type && block.enabled !== false) {
acc[blockId] = block
}
return acc
Expand Down Expand Up @@ -725,13 +725,18 @@ export function useWorkflowExecution() {
}
})

// Do not filter out trigger blocks; executor may need to start from them
// Filter out blocks without type and disabled blocks
const filteredStates = Object.entries(mergedStates).reduce(
(acc, [id, block]) => {
if (!block || !block.type) {
logger.warn(`Skipping block with undefined type: ${id}`, block)
return acc
}
// Skip disabled blocks to prevent them from being passed to executor
if (block.enabled === false) {
logger.warn(`Skipping disabled block: ${id}`)
return acc
}
acc[id] = block
return acc
},
Expand Down
23 changes: 23 additions & 0 deletions apps/sim/executor/dag/construction/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ export class PathConstructor {
const block = workflow.blocks.find((b) => b.id === triggerBlockId)

if (block) {
if (!block.enabled) {
logger.error('Provided triggerBlockId is disabled, finding alternative', {
triggerBlockId,
blockEnabled: block.enabled,
})
// Try to find an alternative enabled trigger instead of failing
const alternativeTrigger = this.findExplicitTrigger(workflow)
if (alternativeTrigger) {
logger.info('Using alternative enabled trigger', {
disabledTriggerId: triggerBlockId,
alternativeTriggerId: alternativeTrigger,
})
return alternativeTrigger
}
throw new Error(
`Trigger block ${triggerBlockId} is disabled and no alternative enabled trigger found`
)
}
return triggerBlockId
}

Expand Down Expand Up @@ -95,8 +113,13 @@ export class PathConstructor {

private buildAdjacencyMap(workflow: SerializedWorkflow): Map<string, string[]> {
const adjacency = new Map<string, string[]>()
const enabledBlocks = new Set(workflow.blocks.filter((b) => b.enabled).map((b) => b.id))

for (const connection of workflow.connections) {
if (!enabledBlocks.has(connection.source) || !enabledBlocks.has(connection.target)) {
continue
}

const neighbors = adjacency.get(connection.source) ?? []
neighbors.push(connection.target)
adjacency.set(connection.source, neighbors)
Expand Down
7 changes: 1 addition & 6 deletions apps/sim/lib/workflows/executor/execution-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,7 @@ export async function executeWorkflowCore(
const startBlock = TriggerUtils.findStartBlock(mergedStates, executionKind, false)

if (!startBlock) {
const errorMsg =
executionKind === 'api'
? 'No API trigger block found. Add an API Trigger block to this workflow.'
: executionKind === 'chat'
? 'No chat trigger block found. Add a Chat Trigger block to this workflow.'
: 'No trigger block found for this workflow.'
const errorMsg = 'No start block found. Add a start block to this workflow.'
logger.error(`[${requestId}] ${errorMsg}`)
throw new Error(errorMsg)
}
Expand Down
5 changes: 5 additions & 0 deletions apps/sim/lib/workflows/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ export function resolveStartCandidates<T extends MinimalBlock>(
const candidates: StartBlockCandidate<T>[] = []

for (const [blockId, block] of entries) {
// Skip disabled blocks - they cannot be used as triggers
if ('enabled' in block && block.enabled === false) {
continue
}

const path = classifyStartBlock(block)
if (!path) continue

Expand Down