{"record":{"id":"33b010628fa01983","repo":"flowable/flowable-engine","slug":"following-execution-of-sub-process-instance-is-not","errorCode":null,"errorMessage":"Following execution of sub process instance is not moved \" + subProcessExecution.getId()","messagePattern":"Following execution of sub process instance is not moved \" \\+ subProcessExecution\\.getId\\(\\)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java","lineNumber":721,"sourceCode":"\n        //Confirm that all the subProcessExecutions are in the executions pool\n        List<ExecutionEntity> subProcessExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(processInstanceId);\n        \n        Set<String> executionIdsToMove = new HashSet<>();\n        for (ExecutionEntity executionPoolItem : executionsPool) {\n            executionIdsToMove.add(executionPoolItem.getId());\n        }\n\n        for (ExecutionEntity subProcessExecution : subProcessExecutions) {\n            FlowElement currentFlowElement = subProcessExecution.getCurrentFlowElement();\n            if (currentFlowElement != null && currentFlowElement instanceof BoundaryEvent) {\n                String parentExecutionId = subProcessExecution.getParentId();\n                if (!StringUtils.isNotEmpty(parentExecutionId) || !executionIdsToMove.contains(parentExecutionId)) {\n                    throw new FlowableException(\"Unbound boundary event execution prevents the sub process instance to be moved \" + subProcessExecution.getId());\n                }\n            \n            } else if (!executionIdsToMove.contains(subProcessExecution.getId())) {\n                throw new FlowableException(\"Following execution of sub process instance is not moved \" + subProcessExecution.getId());\n            }\n        }\n\n        // delete the sub process instance\n        executionEntityManager.deleteProcessInstance(processInstanceId, deleteReason, true);\n    }\n\n    protected ExecutionEntity deleteParentExecutions(String parentExecutionId, Collection<FlowElementMoveEntry> moveToFlowElements, CommandContext commandContext) {\n        return deleteParentExecutions(parentExecutionId, moveToFlowElements, null, commandContext);\n    }\n\n    protected ExecutionEntity deleteParentExecutions(String parentExecutionId, Collection<FlowElementMoveEntry> moveToFlowElements, Collection<String> executionIdsNotToDelete, CommandContext commandContext) {\n        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);\n\n        ExecutionEntity parentExecution = executionEntityManager.findById(parentExecutionId);\n        if (parentExecution != null && parentExecution.getCurrentFlowElement() instanceof SubProcess parentSubProcess) {\n            if (!isSubProcessAncestorOfAnyNewFlowElements(parentSubProcess.getId(), moveToFlowElements)) {\n                ExecutionEntity toDeleteParentExecution = resolveParentExecutionToDelete(parentExecution, moveToFlowElements);","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java#L703-L739","documentation":"Thrown during process instance migration when a subprocess of the migrating instance has an execution that is not included in the set of execution IDs being moved. Since the old sub process instance is about to be deleted, every active execution inside it must be part of the migration mapping; otherwise that execution's state would be silently lost, so the engine aborts.","triggerScenarios":"ProcessMigrationService migration where an active execution inside a subprocess (embedded or call-activity) corresponds to an activity not covered by addActivityMapping entries — e.g. a parallel branch or active wait state inside the subprocess that was not mapped.","commonSituations":"Migrating instances with parallel gateway branches inside subprocesses while only mapping the 'main' path; forgetting child executions of multi-instance subprocess activities; mapping only top-level activities.","solutions":["Add an activity mapping for the unmapped execution's activity inside the subprocess","Cancel the extra executions before migrating (terminate token/parallel branch) so all executions are covered","Inspect execution tree (ExecutionQuery / act_ru_execution) to find all active executions and map each one","Use autoMapActivities/autoMapEqualActivities to map identical activities across the two definitions instead of mapping manually"],"exampleFix":"// before\nmigrationBuilder.addActivityMapping(\"start\", \"start\").migrateTo(newDefId);\n// after\nmigrationBuilder.addActivityMapping(\"start\", \"start\")\n    .addActivityMapping(\"parallelTaskB\", \"parallelTaskB\") // cover subprocess branch\n    .autoMapEqualActivities()\n    .migrateTo(newDefId);","handlingStrategy":"validation","validationCode":"List<String> activeIds = runtimeService.createExecutionQuery().processInstanceId(pid).list()\n    .stream().map(Execution::getId).collect(toList());\nList<String> unmapped = activeIds.stream().filter(id -> !executionIdsToMove.contains(id)).collect(toList());\nif (!unmapped.isEmpty()) throw new IllegalStateException(\"Unmapped executions: \" + unmapped);","typeGuard":null,"tryCatchPattern":"try {\n    migrationBuilder.migrateTo(newDefId);\n} catch (FlowableException ex) {\n    if (ex.getMessage().startsWith(\"Following execution of sub process instance\")) {\n        String execId = ex.getMessage().substring(ex.getMessage().lastIndexOf(' ') + 1);\n        // find its activity and add a mapping, then retry\n    } else throw ex;\n}","preventionTips":["Enumerate all active executions inside subprocesses before migration","Map parallel branches and multi-instance child executions explicitly","Cancel stale parallel tokens before migrating","Add integration tests migrating instances mid-subprocess"],"tags":["process-migration","subprocess","flowable","execution-tree"],"backgroundTag":"invalid-state-transition","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}