Workflow newChildWorkflowStub creation fails - Called from non workflow or workflow callback thread

This is a Burst Task with parent - child workflows, where Parent workflow calls activity and activity creates child workflows. Creating parent workflow and calling activity part works fine. From Activity when tried to create number of child workflows gets an error as below:

for (task in 1..numTasks) {
    Workflow.newChildWorkflowStub(XxxWorkflowInterface::class.java, childWorkflowOptions)
}

“thread”:“Activity Executor taskQueue=“PAGE_TASK_QUEUE”, namespace=“default”: 8”,“class”:“io.temporal.internal.sync.POJOActivityTaskHandler”,“exception”:"java.lang.Error: Called from non workflow or workflow callback thread\n\tat io.temporal.internal.sync.DeterministicRunnerImpl.currentThreadInternal(DeterministicRunnerImpl.java:135)\n\tat io.temporal.internal.sync.WorkflowInternal.getWorkflowInterceptor(WorkflowInternal.java:293)\n\tat io.temporal.internal.sync.WorkflowInternal.newChildWorkflowStub(WorkflowInternal.java:220)\n\tat io.temporal.workflow.Workflow.newChildWorkflowStub(Workflow.java:459)

Child workflow by definition can be created from a parent workflow code only. Activity code is not considered a part of a workflow. So any code to Workflow.[method] from a non-workflow thread is expected to fail by design.

You either start child workflows from the workflow code or use the WorkflowClient to start non-child workflows from an activity.

1 Like