Skip to content

Commit c25ea5c

Browse files
authored
fix(triggers): disabled trigger shouldn't be added to dag (#2012)
* Fix disabled blocks * Comments * Fix api/chat trigger not found message
1 parent dccd9e9 commit c25ea5c

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,10 @@ export function useWorkflowExecution() {
682682
const workflowEdges = (executionWorkflowState?.edges ??
683683
latestWorkflowState.edges) as typeof currentWorkflow.edges
684684

685-
// Filter out blocks without type (these are layout-only blocks)
685+
// Filter out blocks without type (these are layout-only blocks) and disabled blocks
686686
const validBlocks = Object.entries(workflowBlocks).reduce(
687687
(acc, [blockId, block]) => {
688-
if (block?.type) {
688+
if (block?.type && block.enabled !== false) {
689689
acc[blockId] = block
690690
}
691691
return acc
@@ -725,13 +725,18 @@ export function useWorkflowExecution() {
725725
}
726726
})
727727

728-
// Do not filter out trigger blocks; executor may need to start from them
728+
// Filter out blocks without type and disabled blocks
729729
const filteredStates = Object.entries(mergedStates).reduce(
730730
(acc, [id, block]) => {
731731
if (!block || !block.type) {
732732
logger.warn(`Skipping block with undefined type: ${id}`, block)
733733
return acc
734734
}
735+
// Skip disabled blocks to prevent them from being passed to executor
736+
if (block.enabled === false) {
737+
logger.warn(`Skipping disabled block: ${id}`)
738+
return acc
739+
}
735740
acc[id] = block
736741
return acc
737742
},

apps/sim/executor/dag/construction/paths.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ export class PathConstructor {
2828
const block = workflow.blocks.find((b) => b.id === triggerBlockId)
2929

3030
if (block) {
31+
if (!block.enabled) {
32+
logger.error('Provided triggerBlockId is disabled, finding alternative', {
33+
triggerBlockId,
34+
blockEnabled: block.enabled,
35+
})
36+
// Try to find an alternative enabled trigger instead of failing
37+
const alternativeTrigger = this.findExplicitTrigger(workflow)
38+
if (alternativeTrigger) {
39+
logger.info('Using alternative enabled trigger', {
40+
disabledTriggerId: triggerBlockId,
41+
alternativeTriggerId: alternativeTrigger,
42+
})
43+
return alternativeTrigger
44+
}
45+
throw new Error(
46+
`Trigger block ${triggerBlockId} is disabled and no alternative enabled trigger found`
47+
)
48+
}
3149
return triggerBlockId
3250
}
3351

@@ -95,8 +113,13 @@ export class PathConstructor {
95113

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

99118
for (const connection of workflow.connections) {
119+
if (!enabledBlocks.has(connection.source) || !enabledBlocks.has(connection.target)) {
120+
continue
121+
}
122+
100123
const neighbors = adjacency.get(connection.source) ?? []
101124
neighbors.push(connection.target)
102125
adjacency.set(connection.source, neighbors)

apps/sim/lib/workflows/executor/execution-core.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,7 @@ export async function executeWorkflowCore(
257257
const startBlock = TriggerUtils.findStartBlock(mergedStates, executionKind, false)
258258

259259
if (!startBlock) {
260-
const errorMsg =
261-
executionKind === 'api'
262-
? 'No API trigger block found. Add an API Trigger block to this workflow.'
263-
: executionKind === 'chat'
264-
? 'No chat trigger block found. Add a Chat Trigger block to this workflow.'
265-
: 'No trigger block found for this workflow.'
260+
const errorMsg = 'No start block found. Add a start block to this workflow.'
266261
logger.error(`[${requestId}] ${errorMsg}`)
267262
throw new Error(errorMsg)
268263
}

apps/sim/lib/workflows/triggers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ export function resolveStartCandidates<T extends MinimalBlock>(
177177
const candidates: StartBlockCandidate<T>[] = []
178178

179179
for (const [blockId, block] of entries) {
180+
// Skip disabled blocks - they cannot be used as triggers
181+
if ('enabled' in block && block.enabled === false) {
182+
continue
183+
}
184+
180185
const path = classifyStartBlock(block)
181186
if (!path) continue
182187

0 commit comments

Comments
 (0)