{"record":{"id":"e0f3a8ca63a356dd","repo":"flowable/flowable-engine","slug":"could-not-find-a-scope-execution-for-compensation","errorCode":null,"errorMessage":"Could not find a scope execution for compensation boundary event ${boundaryEvent.getId()} for ${executionEntity}","messagePattern":"Could not find a scope execution for compensation boundary event (.+?) for (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"critical","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/behavior/BoundaryCompensateEventActivityBehavior.java","lineNumber":96,"sourceCode":"            throw new FlowableException(\"Compensation activity could not be found (or it is missing 'isForCompensation=\\\"true\\\"') for \" + executionEntity);\n        }\n\n        // find SubProcess or Process instance execution\n        ExecutionEntity scopeExecution = null;\n        ExecutionEntity parentExecution = executionEntity.getParent();\n        while (scopeExecution == null && parentExecution != null) {\n            if (parentExecution.getCurrentFlowElement() instanceof SubProcess) {\n                scopeExecution = parentExecution;\n\n            } else if (parentExecution.isProcessInstanceType()) {\n                scopeExecution = parentExecution;\n            } else {\n                parentExecution = parentExecution.getParent();\n            }\n        }\n\n        if (scopeExecution == null) {\n            throw new FlowableException(\"Could not find a scope execution for compensation boundary event \" + boundaryEvent.getId() + \" for \" + executionEntity);\n        }\n\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();\n        EventSubscriptionEntity eventSubscription = (EventSubscriptionEntity) processEngineConfiguration.getEventSubscriptionServiceConfiguration()\n                .getEventSubscriptionService().createEventSubscriptionBuilder()\n                        .eventType(CompensateEventSubscriptionEntity.EVENT_TYPE)\n                        .executionId(scopeExecution.getId())\n                        .processInstanceId(scopeExecution.getProcessInstanceId())\n                        .activityId(sourceActivity.getId())\n                        .tenantId(scopeExecution.getTenantId())\n                        .create();\n        \n        CountingEntityUtil.handleInsertEventSubscriptionEntityCount(eventSubscription);\n    }\n\n    @Override\n    public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {\n        ExecutionEntity executionEntity = (ExecutionEntity) execution;","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/behavior/BoundaryCompensateEventActivityBehavior.java#L78-L114","documentation":"Flowable throws this when execute() cannot find the scope execution (the enclosing subprocess or process instance execution) under which to register the CompensateEventSubscription. The algorithm walks up the parent-execution chain looking for a scope execution; if the chain is exhausted (parentExecution == null) without finding one, the execution tree is inconsistent with the model. This indicates a corrupted runtime execution hierarchy rather than a modeling error.","triggerScenarios":"A boundary compensate event fires on an execution whose parent chain lacks a scope execution — e.g. after custom execution-tree manipulation, concurrent modification of executions, or engine internals (cascade delete, partial rollback) leaving orphaned child executions.","commonSituations":"Concurrent operations on the same process instance (cancel/terminate racing with event firing); custom JavaDelegate/listener code that creates, deletes, or reparents executions; database state edited manually; engine bugs during multi-instance subprocess compensation.","solutions":["Inspect the execution tree in ACT_RU_EXECUTION for the reported executionEntity; look for a missing or dangling parentExecutionId and fix by terminating/restarting the process instance.","Cancel and restart the affected process instance to rebuild a consistent execution tree.","Remove custom code that mutates executions (ExecutionEntityManager.createChildExecution/deleteExecution misuse).","Check for concurrency issues: serialize operations on the process instance or add optimistic-locking-aware retries.","If reproducible on a supported flowable version, file an issue with the process model and stack trace."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.trigger(executionId);\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"Could not find a scope execution\")) {\n        // runtime execution tree corrupted: inspect ACT_RU_EXECUTION,\n        // terminate and restart the process instance\n    }\n}","preventionTips":["Never manually create, delete, or reparent ExecutionEntity objects from custom code.","Avoid concurrent operations (terminate + signal) on the same process instance; serialize via optimistic locking retries.","Back up and verify ACT_RU_EXECUTION integrity after database restores or manual maintenance."],"tags":["flowable","compensation","execution-tree","runtime-state","concurrency"],"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"}