@@ -17,7 +17,7 @@ import {
1717 getSubBlockValue ,
1818} from '@/lib/schedules/utils'
1919import { decryptSecret , generateRequestId } from '@/lib/utils'
20- import { loadDeployedWorkflowState } from '@/lib/workflows/db-helpers'
20+ import { blockExistsInDeployment , loadDeployedWorkflowState } from '@/lib/workflows/db-helpers'
2121import { updateWorkflowRunCounts } from '@/lib/workflows/utils'
2222import { Executor } from '@/executor'
2323import { Serializer } from '@/serializer'
@@ -206,6 +206,20 @@ export async function GET() {
206206 const parallels = deployedData . parallels
207207 logger . info ( `[${ requestId } ] Loaded deployed workflow ${ schedule . workflowId } ` )
208208
209+ // Validate that the schedule's trigger block exists in the deployed state
210+ if ( schedule . blockId ) {
211+ const blockExists = await blockExistsInDeployment (
212+ schedule . workflowId ,
213+ schedule . blockId
214+ )
215+ if ( ! blockExists ) {
216+ logger . warn (
217+ `[${ requestId } ] Schedule trigger block ${ schedule . blockId } not found in deployed workflow ${ schedule . workflowId } . Skipping execution.`
218+ )
219+ return { skip : true , blocks : { } as Record < string , BlockState > }
220+ }
221+ }
222+
209223 const mergedStates = mergeSubblockState ( blocks )
210224
211225 // Retrieve environment variables with workspace precedence
@@ -355,7 +369,6 @@ export async function GET() {
355369 )
356370
357371 const input = {
358- workflowId : schedule . workflowId ,
359372 _context : {
360373 workflowId : schedule . workflowId ,
361374 } ,
@@ -460,6 +473,12 @@ export async function GET() {
460473 }
461474 } ) ( )
462475
476+ // Check if execution was skipped (e.g., trigger block not found)
477+ if ( 'skip' in executionSuccess && executionSuccess . skip ) {
478+ runningExecutions . delete ( schedule . workflowId )
479+ continue
480+ }
481+
463482 if ( executionSuccess . success ) {
464483 logger . info ( `[${ requestId } ] Workflow ${ schedule . workflowId } executed successfully` )
465484
0 commit comments