@@ -1435,16 +1435,18 @@ export function useWorkflowExecution() {
14351435 const handleRunFromBlock = useCallback (
14361436 async ( blockId : string , workflowId : string ) => {
14371437 const snapshot = getLastExecutionSnapshot ( workflowId )
1438- if ( ! snapshot ) {
1438+ const workflowEdges = useWorkflowStore . getState ( ) . edges
1439+ const incomingEdges = workflowEdges . filter ( ( edge ) => edge . target === blockId )
1440+ const isTriggerBlock = incomingEdges . length === 0
1441+
1442+ if ( ! snapshot && ! isTriggerBlock ) {
14391443 logger . error ( 'No execution snapshot available for run-from-block' , { workflowId, blockId } )
14401444 return
14411445 }
14421446
1443- const workflowEdges = useWorkflowStore . getState ( ) . edges
1444- const incomingEdges = workflowEdges . filter ( ( edge ) => edge . target === blockId )
14451447 const dependenciesSatisfied =
1446- incomingEdges . length === 0 ||
1447- incomingEdges . every ( ( edge ) => snapshot . executedBlocks . includes ( edge . source ) )
1448+ isTriggerBlock ||
1449+ ( snapshot && incomingEdges . every ( ( edge ) => snapshot . executedBlocks . includes ( edge . source ) ) )
14481450
14491451 if ( ! dependenciesSatisfied ) {
14501452 logger . error ( 'Upstream dependencies not satisfied for run-from-block' , {
@@ -1454,10 +1456,20 @@ export function useWorkflowExecution() {
14541456 return
14551457 }
14561458
1459+ // For trigger blocks with no snapshot, create an empty one
1460+ const effectiveSnapshot : SerializableExecutionState = snapshot || {
1461+ blockStates : { } ,
1462+ executedBlocks : [ ] ,
1463+ blockLogs : [ ] ,
1464+ decisions : { router : { } , condition : { } } ,
1465+ completedLoops : [ ] ,
1466+ activeExecutionPath : [ ] ,
1467+ }
1468+
14571469 logger . info ( 'Starting run-from-block execution' , {
14581470 workflowId,
14591471 startBlockId : blockId ,
1460- snapshotExecutedBlocks : snapshot . executedBlocks . length ,
1472+ isTriggerBlock ,
14611473 } )
14621474
14631475 setIsExecuting ( true )
@@ -1471,7 +1483,7 @@ export function useWorkflowExecution() {
14711483 await executionStream . executeFromBlock ( {
14721484 workflowId,
14731485 startBlockId : blockId ,
1474- sourceSnapshot : snapshot ,
1486+ sourceSnapshot : effectiveSnapshot ,
14751487 callbacks : {
14761488 onExecutionStarted : ( data ) => {
14771489 logger . info ( 'Run-from-block execution started:' , data )
@@ -1579,21 +1591,23 @@ export function useWorkflowExecution() {
15791591
15801592 onExecutionCompleted : ( data ) => {
15811593 if ( data . success ) {
1582- const mergedBlockStates : Record < string , BlockState > = { ...snapshot . blockStates }
1594+ const mergedBlockStates : Record < string , BlockState > = {
1595+ ...effectiveSnapshot . blockStates ,
1596+ }
15831597 for ( const [ bId , state ] of accumulatedBlockStates ) {
15841598 mergedBlockStates [ bId ] = state
15851599 }
15861600
15871601 const mergedExecutedBlocks = new Set ( [
1588- ...snapshot . executedBlocks ,
1602+ ...effectiveSnapshot . executedBlocks ,
15891603 ...executedBlockIds ,
15901604 ] )
15911605
15921606 const updatedSnapshot : SerializableExecutionState = {
1593- ...snapshot ,
1607+ ...effectiveSnapshot ,
15941608 blockStates : mergedBlockStates ,
15951609 executedBlocks : Array . from ( mergedExecutedBlocks ) ,
1596- blockLogs : [ ...snapshot . blockLogs , ...accumulatedBlockLogs ] ,
1610+ blockLogs : [ ...effectiveSnapshot . blockLogs , ...accumulatedBlockLogs ] ,
15971611 activeExecutionPath : Array . from ( mergedExecutedBlocks ) ,
15981612 }
15991613 setLastExecutionSnapshot ( workflowId , updatedSnapshot )
0 commit comments