docs: public void leave(DelegateExecution childExecution) {
      DelegateExecution multiInstanceRootExecution = getMultiInstanceRootExecution(childExecution);
      int nrOfInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_INSTANCES);
      int loopCounter = getLoopVariable(childExecution, getCollectionElementIndexVariable()) + 1;
      int nrOfCompletedInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
      int nrOfActiveInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_ACTIVE_INSTANCES);
  
      setLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
      setLoopVariable(childExecution, getCollectionElementIndexVariable(), loopCounter);
      logLoopDetails(childExecution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
      
      Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) childExecution, null);
      callActivityEndListeners(childExecution);
      
      //executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution);
  
      if (loopCounter >= nrOfInstances || completionConditionSatisfied(multiInstanceRootExecution)) {
        removeLocalLoopVariable(childExecution, getCollectionElementIndexVariable());
        multiInstanceRootExecution.setMultiInstanceRoot(false);
        multiInstanceRootExecution.setScope(false);
        multiInstanceRootExecution.setCurrentFlowElement(childExecution.getCurrentFlowElement());
        Context.getCommandContext().getExecutionEntityManager().deleteChildExecutions((ExecutionEntity) multiInstanceRootExecution, "MI_END", false);
        super.leave(multiInstanceRootExecution);
        
      } else {
        try {
          
          if (childExecution.getCurrentFlowElement() instanceof SubProcess) {
            ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
            ExecutionEntity executionToContinue = executionEntityManager.createChildExecution((ExecutionEntity) multiInstanceRootExecution);
            executionToContinue.setCurrentFlowElement(childExecution.getCurrentFlowElement());
            executionToContinue.setScope(true);
            setLoopVariable(executionToContinue, getCollectionElementIndexVariable(), loopCounter);
            executeOriginalBehavior(executionToContinue, loopCounter);
          } else {
            executeOriginalBehavior(childExecution, loopCounter);
          }
          
        } catch (BpmnError error) {
          // re-throw business fault so that it can be caught by an Error
          // Intermediate Event or Error Event Sub-Process in the process
          throw error;
        } catch (Exception e) {
          throw new ActivitiException("Could not execute inner activity behavior of multi instance behavior", e);
        }
      }
    }