Generating another process Instance

hi all,
In flowable i have task as
ParentProcess
start->user1->user2->callActivity
SubProcess(call Activity)
start->user1-user2->end

Now lets say i complete the user1 and user2 task and move to the callActivity This is possible
but its also making another process Instance Id as
user1 task completed
user2 task not completed

Why is that happening?

My backend code is

public class FlowableService {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private SubProcessBusinessKeyGenerator subProcessBusinessKeyGenerator;

public void startprocess(String orderId){
    Map<String,Object> variables=new HashMap<>();
    variables.put("businessKey",orderId);
    ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionKey("startprocess").singleResult();
    ProcessInstance instance=runtimeService.startProcessInstanceById(processDefinition.getId(),orderId,variables);
  
    System.out.println("The process Instance Id "+Instance.getProcessInstanceId());
}
public List<WorkflowTask> getTask(String orderId, Map<String,Object> variables){

    List<WorkflowTask> task=taskService.createTaskQuery().processInstanceId(getProcessInstanceId()).list();
    taskService.setVariables(task.get(0).getId(),variables);
    return task;
}
public void completeTask(String taskId){
    taskService.complete(taskId);
}

}

As you can see it has created the process Instance when i have already completed all the task and moved to the callActivity

Please do tell me what are the reasom why it creates another processInstamces

Hey, can you also show your bpmn files?

Multiple remarks:

ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionKey("startprocess").singleResult();

Will crash as soon as you create a new deployment for the same process key.

runtimeService.createProcessInstanceBuilder().processDefinitionKey(“yourKey”).businessKey(orderId).variables(variables).start();

might be better for your use case.

The other question:
Why are you setting the variables of a task within your getTask method? You are only updating the first task, but the task query returns a list of tasks.

Greetings

Christopher