Behavior for Nested workflow started without ChildWorkflowOptions

Say I have two workflows
Workflow1

final WorkflowOptions options =
        WorkflowOptions.newBuilder()
            .setTaskQueue("default")
            .setWorkflowId("workflow1")
            .build();
Workflow1 workflow1 =  workflowClient.newWorkflowStub(Workflow1.class, options);
WorkflowClient.start(() -> workflow1.execute())

Workflow1 execute method calls workflow2

public Workflow1Impl implements Workflow1 {

  SomeActivity someActivity = .....
  
  public void execute() {
       someActivity.startWorkflow2();
  }
}

SomeActivityImpl

public class SomeActivityImpl implements someActivity {

  public void startWorkflow2() {
    final WorkflowOptions options =
                    WorkflowOptions.newBuilder()
                        .setTaskQueue("default")
                        .setWorkflowId("workflow2")
                        .build();
            Workflow1 workflow2 =  workflowClient.newWorkflowStub(Workflow2.class, options);
            WorkflowClient.start(() -> workflow2.execute())
  }
}

In most of the docs which I have read we are doing this by creating child workflows and using ChildWorkflowOptions.

How workflow2 will behave in above case

  1. workflow2 will be async?
  2. workflow 2 will act as child workflow by default? This means if parent workflow1 terminates then workflow2 will terminate immediately irrespective of if it has finished or not
  3. workflow2 will execute as synchronous and workflow2 will finish first before workflow 1 finishes (I don’t think this will be the case)
  4. Does above code guarantee if workflow2 will start for sure
  5. Is this recommended way to start nested workflow
  1. You are invoking this workflow async from activity using WorkflowClient.start, so yes this api unblocks as soon as workflow2 is created. Would make sure you handle exceptions here in case a workflow execution with this set workflow id is already running, or set workflow id reuse policy to “terminate” if thats your use case.

  2. No, this created workflow is independent (not a child), same as when you create it from client.

  3. Either will not affect the execution of the other. Completion of workflow2 is not recorded in workflow1 event history

  4. If WorkflowClient.start in your activity code does not fail, yes

  5. That is up to you, if you need to have the parent-child relationship and parent close policy defined then use child workflow.

Thanks @tihomir