@@ -442,36 +442,9 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
442442 deploymentStatuses : { } ,
443443 }
444444 } else {
445- // If no state in DB, create a default Start block
446- const starterId = crypto . randomUUID ( )
445+ // If no state in DB, use empty state (Start block was created during workflow creation)
447446 workflowState = {
448- blocks : {
449- [ starterId ] : {
450- id : starterId ,
451- type : 'start_trigger' ,
452- name : 'Start' ,
453- position : { x : 200 , y : 300 } ,
454- enabled : true ,
455- horizontalHandles : true ,
456- isWide : false ,
457- advancedMode : false ,
458- triggerMode : false ,
459- height : 0 ,
460- subBlocks : {
461- inputFormat : {
462- id : 'inputFormat' ,
463- type : 'input-format' ,
464- value : [ ] ,
465- } ,
466- } ,
467- outputs : {
468- input : { type : 'string' , description : 'Primary user input or message' } ,
469- conversationId : { type : 'string' , description : 'Conversation thread identifier' } ,
470- files : { type : 'files' , description : 'User uploaded files' } ,
471- } ,
472- data : { } ,
473- } ,
474- } ,
447+ blocks : { } ,
475448 edges : [ ] ,
476449 loops : { } ,
477450 parallels : { } ,
@@ -481,7 +454,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
481454 lastSaved : Date . now ( ) ,
482455 }
483456
484- logger . info ( `Created default Start block for empty workflow ${ id } ` )
457+ logger . info ( `Workflow ${ id } has no state yet - will load from DB or show empty canvas ` )
485458 }
486459
487460 if ( workflowData ?. isDeployed || workflowData ?. deployedAt ) {
@@ -591,16 +564,76 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
591564
592565 // Initialize subblock values to ensure they're available for sync
593566 if ( ! options . marketplaceId ) {
594- // For non-marketplace workflows, initialize empty subblock values
595- const subblockValues : Record < string , Record < string , any > > = { }
567+ // For non-marketplace workflows, create a default Start block
568+ const starterId = crypto . randomUUID ( )
569+ const defaultStartBlock = {
570+ id : starterId ,
571+ type : 'start_trigger' ,
572+ name : 'Start' ,
573+ position : { x : 200 , y : 300 } ,
574+ enabled : true ,
575+ horizontalHandles : true ,
576+ isWide : false ,
577+ advancedMode : false ,
578+ triggerMode : false ,
579+ height : 0 ,
580+ subBlocks : {
581+ inputFormat : {
582+ id : 'inputFormat' ,
583+ type : 'input-format' ,
584+ value : [ ] ,
585+ } ,
586+ } ,
587+ outputs : {
588+ input : { type : 'string' , description : 'Primary user input or message' } ,
589+ conversationId : { type : 'string' , description : 'Conversation thread identifier' } ,
590+ files : { type : 'files' , description : 'User uploaded files' } ,
591+ } ,
592+ data : { } ,
593+ }
596594
597- // Update the subblock store with the initial values
595+ // Initialize subblock values
598596 useSubBlockStore . setState ( ( state ) => ( {
599597 workflowValues : {
600598 ...state . workflowValues ,
601- [ serverWorkflowId ] : subblockValues ,
599+ [ serverWorkflowId ] : {
600+ [ starterId ] : {
601+ inputFormat : [ ] ,
602+ } ,
603+ } ,
602604 } ,
603605 } ) )
606+
607+ // Persist the default Start block to database immediately
608+
609+ ; ( async ( ) => {
610+ try {
611+ logger . info ( `Persisting default Start block for new workflow ${ serverWorkflowId } ` )
612+ const response = await fetch ( `/api/workflows/${ serverWorkflowId } /state` , {
613+ method : 'PUT' ,
614+ headers : {
615+ 'Content-Type' : 'application/json' ,
616+ } ,
617+ body : JSON . stringify ( {
618+ blocks : {
619+ [ starterId ] : defaultStartBlock ,
620+ } ,
621+ edges : [ ] ,
622+ loops : { } ,
623+ parallels : { } ,
624+ lastSaved : Date . now ( ) ,
625+ } ) ,
626+ } )
627+
628+ if ( ! response . ok ) {
629+ logger . error ( 'Failed to persist default Start block:' , await response . text ( ) )
630+ } else {
631+ logger . info ( 'Successfully persisted default Start block' )
632+ }
633+ } catch ( error ) {
634+ logger . error ( 'Error persisting default Start block:' , error )
635+ }
636+ } ) ( )
604637 }
605638
606639 // Don't set as active workflow here - let the navigation/URL change handle that
0 commit comments