@@ -572,6 +572,7 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
572572 }
573573 insertStatusResult , err := c .systemDB .InsertWorkflowStatus (uncancellableCtx , insertInput )
574574 if err != nil {
575+ c .logger .Error ("failed to insert workflow status" , "error" , err , "workflow_id" , workflowID )
575576 return nil , err
576577 }
577578
@@ -597,6 +598,7 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
597598 }
598599 err = c .systemDB .RecordChildWorkflow (uncancellableCtx , childInput )
599600 if err != nil {
601+ c .logger .Error ("failed to record child workflow" , "error" , err , "parent_workflow_id" , parentWorkflowState .workflowID , "child_workflow_id" , workflowID )
600602 return nil , newWorkflowExecutionError (parentWorkflowState .workflowID , fmt .Sprintf ("recording child workflow: %v" , err ))
601603 }
602604 }
@@ -631,6 +633,11 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
631633 stopFunc = context .AfterFunc (workflowCtx , dbosCancelFunction )
632634 }
633635
636+ // Commit the transaction. This must happen before we start the goroutine to ensure the workflow is found by steps in the database
637+ if err := tx .Commit (uncancellableCtx ); err != nil {
638+ return nil , newWorkflowExecutionError (workflowID , fmt .Sprintf ("failed to commit transaction: %v" , err ))
639+ }
640+
634641 // Run the function in a goroutine
635642 c .workflowsWg .Add (1 )
636643 go func () {
@@ -668,11 +675,6 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
668675 close (outcomeChan )
669676 }()
670677
671- // Commit the transaction
672- if err := tx .Commit (uncancellableCtx ); err != nil {
673- return nil , newWorkflowExecutionError (workflowID , fmt .Sprintf ("failed to commit transaction: %v" , err ))
674- }
675-
676678 return & workflowHandle [any ]{workflowID : workflowID , outcomeChan : outcomeChan , dbosContext : uncancellableCtx }, nil
677679}
678680
0 commit comments