{"record":{"id":"09ff519340e9ee09","repo":"flowable/flowable-engine","slug":"ad-hoc-sub-process-has-running-child-executions-th","errorCode":null,"errorMessage":"Ad-hoc sub process has running child executions that need to be completed first. ","messagePattern":"Ad-hoc sub process has running child executions that need to be completed first\\. ","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CompleteAdhocSubProcessCmd.java","lineNumber":55,"sourceCode":"    public CompleteAdhocSubProcessCmd(String executionId) {\n        this.executionId = executionId;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);\n        ExecutionEntity execution = executionEntityManager.findById(executionId);\n        if (execution == null) {\n            throw new FlowableObjectNotFoundException(\"No execution found for id '\" + executionId + \"'\", ExecutionEntity.class);\n        }\n\n        if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {\n            throw new FlowableException(\"The current flow element of the requested \" + execution + \" is not an ad-hoc sub process\");\n        }\n\n        List<? extends ExecutionEntity> childExecutions = execution.getExecutions();\n        if (childExecutions.size() > 0) {\n            throw new FlowableException(\"Ad-hoc sub process has running child executions that need to be completed first. \" + execution);\n        }\n\n        ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());\n        outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());\n\n        executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);\n\n        CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":37,"sourceCodeEnd":69,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CompleteAdhocSubProcessCmd.java#L37-L69","documentation":"Before completing an ad-hoc sub-process, all its child executions must be finished. Flowable throws FlowableException when the ad-hoc sub-process still has running child executions (e.g. active ad-hoc tasks).","triggerScenarios":"runtimeService.completeAdhocSubProcess(executionId, ...) while ad-hoc sub-process children (active tasks) are still running.","commonSituations":"Trying to complete the ad-hoc sub-process without terminating/cancelling remaining ad-hoc tasks; concurrent user tasks still open inside the sub-process.","solutions":["Complete or delete the running child executions/tasks inside the ad-hoc sub-process first.","Use runtimeService.deleteProcessInstance or cancel the child executions if the remaining work should be discarded.","Query child executions (runtimeService.createExecutionQuery().parentId(executionId)) and handle each before completing."],"exampleFix":"// before\nruntimeService.completeAdhocSubProcess(executionId, outcome); // children still running\n// after\nList<Execution> children = runtimeService.createExecutionQuery().parentId(executionId).list();\nif (children.isEmpty()) {\n    runtimeService.completeAdhocSubProcess(executionId, outcome);\n}","handlingStrategy":"validation","validationCode":"List<Execution> children = runtimeService.createExecutionQuery().parentId(executionId).list();\nif (!children.isEmpty()) {\n    throw new IllegalStateException(\"Complete or cancel child executions first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.completeAdhocSubProcess(executionId, outcome);\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"running child executions\")) {\n        // cancel or complete children, then retry\n    }\n}","preventionTips":["Before completing, enumerate and resolve all child executions/ad-hoc tasks.","Decide upfront whether remaining ad-hoc tasks should be completed or cancelled."],"tags":["flowable","ad-hoc-subprocess","state","child-executions"],"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-18T11:17:12.947Z"}