{"record":{"id":"eb2971cba7e611fa","repo":"flowable/flowable-engine","slug":"no-task-entity-found-for-plan-item-instance-plani","errorCode":null,"errorMessage":"No task entity found for plan item instance <planItemInstanceId>","messagePattern":"No task entity found for plan item instance <planItemInstanceId>","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/AbstractCmmnDynamicStateManager.java","lineNumber":456,"sourceCode":"                // all existing plan items are available, we can continue without any changes\n                continue;\n            }\n            \n            if (existingPlanItemInstance == null) {\n                throw new FlowableException(\"No active or enabled plan item instances found for plan item definition \" + planItemDefinitionMapping.getPlanItemDefinitionId());\n            }\n            \n            PlanItemInstanceEntity existingPlanItemInstanceEntity = (PlanItemInstanceEntity) existingPlanItemInstance;\n\n            if (!evaluateCondition(existingPlanItemInstanceEntity, planItemDefinitionMapping)) {\n                continue;\n            }\n\n            if (existingPlanItemInstanceEntity.getPlanItem().getPlanItemDefinition() instanceof HumanTask) {\n                TaskService taskService = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService();\n                List<TaskEntity> taskEntities = taskService.findTasksBySubScopeIdScopeType(existingPlanItemInstanceEntity.getId(), ScopeTypes.CMMN);\n                if (taskEntities == null || taskEntities.isEmpty()) {\n                    throw new FlowableException(\"No task entity found for plan item instance \" + existingPlanItemInstanceEntity.getId());\n                }\n\n                // Should be only one\n                for (TaskEntity taskEntity : taskEntities) {\n                    if (!taskEntity.isDeleted()) {\n                        TaskHelper.deleteTask(taskEntity, \"Change plan item state\", false, false, cmmnEngineConfiguration);\n                    }\n                }\n            }\n\n            CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);\n            agenda.planChangePlanItemInstanceToAvailableOperation(existingPlanItemInstanceEntity);\n        }\n    }\n    \n    protected void executeAddWaitingForRepetitionPlanItemInstances(CaseInstanceChangeState caseInstanceChangeState, \n            CaseInstanceEntity caseInstance, CommandContext commandContext) {\n","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/AbstractCmmnDynamicStateManager.java#L438-L474","documentation":"When moving a plan item instance of a HumanTask to AVAILABLE, Flowable deletes the underlying task entity; if no task entity is found for the plan item instance (sub-scope lookup by scope type CMMN returns nothing), this FlowableException is thrown because the engine's internal data is inconsistent.","triggerScenarios":"changePlanItemState moving an ACTIVE HumanTask plan item instance where the corresponding task row is missing from the task tables (deleted externally, incomplete data, or task never created due to prior engine errors).","commonSituations":"Database manipulated manually or by external jobs deleting tasks; upgrading between Flowable versions with leftover inconsistent data; a previous failed transaction left the plan item ACTIVE without its task.","solutions":["Inspect the ACT_RU_TASK table for a row with the plan item instance id as SUB_SCOPE_ID_ and restore/repair consistency","Delete or disable the orphaned plan item instance instead of moving it, then recreate the task flow","Check for external processes/integrations that delete tasks outside the engine API","Restore from a consistent backup or re-deploy/restart the case instance if data corruption is confirmed"],"exampleFix":"// before\ncmmnRuntimeService.changePlanItemState(caseInstanceId, changeState); // throws: task row missing\n// after\nlong tasks = taskService.createTaskQuery().subScopeId(planItemInstanceId).count();\nif (tasks == 0) {\n    // repair: disable the orphaned plan item instead of moving it\ncmmnRuntimeService.changePlanItemState(caseInstanceId, changeState);","handlingStrategy":"validation","validationCode":"Task task = taskService.createTaskQuery()\n    .subScopeId(planItemInstanceId).caseInstanceId(caseInstanceId).singleResult();\nif (task == null) throw new IllegalStateException(\"Missing task for plan item instance \" + planItemInstanceId);","typeGuard":null,"tryCatchPattern":"try {\n    cmmnRuntimeService.changePlanItemState(caseInstanceId, changeState);\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"No task entity found\")) {\n        // repair data or disable plan item instead of moving\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never delete tasks via direct SQL; use TaskService APIs","Monitor for orphaned ACT_RU_TASK rows after upgrades","Handle failed transactions so plan item and task data stay consistent"],"tags":["cmmn","dynamic-state","task","data-integrity"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}