Workflow command not getting executed when batched with last WorkflowTaskCompleted?

Hi Team,

We had a use-case where we wanted to use a workflow to launch multiple child workflows and terminate the parent workflow. There we were facing a weird behaviour and we don’t if its a bug or a conscious call in the temporal’s design. Can you please help in understanding this behaviour better ?

Issue Description
We know temporal’s SDK does batch the commands generated from the workflow until it can’t make any further progress, beyond which the commands are sent to the temporal server for execution. However, if the commands are batched with the last WorkflowTaskCompleted beyond which WorkflowExecutionCompleted event is generated, we are not seeing any command execution.

How to Reproduce
To show case this I have modified the child-workflow example in the go-samples.

func SampleParentWorkflow(ctx workflow.Context) (string, error) {
	logger := workflow.GetLogger(ctx)

	var result string
	// var future workflow.ChildWorkflowFuture

	for i := 0; i < 10; i++ {
		cwo := workflow.ChildWorkflowOptions{
			WorkflowID:            "child-workflow-" + strconv.Itoa(i),
			ParentClosePolicy:     enums.PARENT_CLOSE_POLICY_ABANDON,

		_ = workflow.ExecuteChildWorkflow(workflow.WithChildOptions(ctx, cwo), SampleChildWorkflow, "World")

	logger.Info("Parent execution completed.", "Result", result)
	return result, nil

What We Expected
The parent workflow execution should finish and result in orphan child workflow executions.

What We Saw Instead
The parent workflow execution terminates and child workflows aren’t spawned by the temporal servers.

What Lead To Expected Behaviour
However, if we place a blocking call at the end of workflow e.g. workflow.Sleep(ctx, 2*time.Millisecond) or wait on one of the child workflow future, the child workflow executions are proceeding.

In fact, we saw parent workflow task execution failed in the middle with an error UnhandledCommand.

Got it. I was not aware of this existing post. I would like to volunteer to solve this issue if possible. Let me know if I can be of any help.

This requires a pretty intrusive change in the history service. So it is not a simple contribution to make.