code: public static void createCopyOfSubProcessExecutionForCompensation(ExecutionEntity subProcessExecution) {
      EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
      List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.findEventSubscriptionsByExecutionAndType(subProcessExecution.getId(), "compensate");
      
      List<CompensateEventSubscriptionEntity> compensateEventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>();
      for (EventSubscriptionEntity event : eventSubscriptions) {
        if (event instanceof CompensateEventSubscriptionEntity) {
          compensateEventSubscriptions.add((CompensateEventSubscriptionEntity) event);
        }
      }
  
      if (CollectionUtil.isNotEmpty(compensateEventSubscriptions)) {
        
        ExecutionEntity processInstanceExecutionEntity = subProcessExecution.getProcessInstance();
        
        ExecutionEntity eventScopeExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(processInstanceExecutionEntity); 
        eventScopeExecution.setActive(false);
        eventScopeExecution.setEventScope(true);
        eventScopeExecution.setCurrentFlowElement(subProcessExecution.getCurrentFlowElement());
  
        // copy local variables to eventScopeExecution by value. This way,
        // the eventScopeExecution references a 'snapshot' of the local variables
        new SubProcessVariableSnapshotter().setVariablesSnapshots(subProcessExecution, eventScopeExecution);
  
        // set event subscriptions to the event scope execution:
        for (CompensateEventSubscriptionEntity eventSubscriptionEntity : compensateEventSubscriptions) {
          eventSubscriptionEntityManager.delete(eventSubscriptionEntity);
  
          CompensateEventSubscriptionEntity newSubscription = eventSubscriptionEntityManager.insertCompensationEvent(
              eventScopeExecution, eventSubscriptionEntity.getActivityId());
          newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
          newSubscription.setCreated(eventSubscriptionEntity.getCreated());
        }
  
        CompensateEventSubscriptionEntity eventSubscription = eventSubscriptionEntityManager.insertCompensationEvent(
            processInstanceExecutionEntity, eventScopeExecution.getCurrentFlowElement().getId());
        eventSubscription.setConfiguration(eventScopeExecution.getId());
      }
    }
docs: Creates a new event scope execution and moves existing event subscriptions to this new execution