{"record":{"id":"3adf60bc665ad960","repo":"flowable/flowable-engine","slug":"could-not-find-plan-item-instance-for","errorCode":null,"errorMessage":"Could not find plan item instance for ","messagePattern":"Could not find plan item instance for ","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"critical","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskCmd.java","lineNumber":98,"sourceCode":"            throw new FlowableIllegalArgumentException(\"Null task id\");\n        }\n        \n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        TaskEntity taskEntity = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n        if (taskEntity == null) {\n            throw new FlowableObjectNotFoundException(\"Could not find task entity for id \" + taskId, TaskEntity.class);\n        }\n        \n        if (StringUtils.isNotEmpty(taskEntity.getProcessInstanceId())) {\n            throw new FlowableException(taskEntity + \" is created by the process engine and should be completed via the process engine API\");\n        }\n        \n        String planItemInstanceId = taskEntity.getSubScopeId();\n        PlanItemInstanceEntity planItemInstanceEntity = null;\n        if (planItemInstanceId != null) {\n            planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId);\n            if (planItemInstanceEntity == null) {\n                throw new FlowableException(\"Could not find plan item instance for \" + taskEntity);\n            }\n        }\n        \n        if (variables != null) {\n            taskEntity.setVariables(variables);\n        }\n        if (variablesLocal != null) {\n            taskEntity.setVariablesLocal(variablesLocal);\n        }\n        if (transientVariables != null) {\n            taskEntity.setTransientVariables(transientVariables);\n        }\n        if (transientVariablesLocal != null) {\n            taskEntity.setTransientVariablesLocal(transientVariablesLocal);\n        }\n\n        logUserTaskCompleted(taskEntity, cmmnEngineConfiguration);\n        ","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskCmd.java#L80-L116","documentation":"Thrown by CompleteTaskCmd when the task's subScopeId points to a plan item instance that no longer exists in the CMMN database. The task is linked to a CMMN plan item (e.g. a case user task) but the plan item row is missing, so the engine cannot complete the plan item as part of completing the task. This indicates internal data inconsistency, typically a concurrently deleted/finished case.","triggerScenarios":"Completing a CMMN task whose subScopeId no longer resolves via planItemInstanceEntityManager.findById: the case/plan item was terminated or deleted concurrently, or the database rows were partially removed/manipulated externally.","commonSituations":"Race between a user completing a task and another user terminating the case; custom SQL/manual cleanup of CMMN tables; restoring a database backup for only some tables; failed cascade deletes.","solutions":["Verify the case instance and plan item instance still exist and are active before completing the task.","Avoid manual deletes on ACT_CMMN_* tables; use the engine's CaseInstanceService/terminate APIs to end cases.","Check for concurrent termination of the case and handle FlowableException gracefully (task no longer completable).","If data is inconsistent, re-seed from a consistent backup or use Flowable's database consistency checks."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(task.getScopeId()).count() == 0) {\n    throw new IllegalStateException(\"Case already terminated; task not completable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    cmmnTaskService.completeTask(taskId);\n} catch (FlowableException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Could not find plan item instance\")) {\n        log.warn(\"Plan item for task {} vanished (case terminated concurrently?)\", taskId);\n        // surface stale-task state to the user instead of retrying\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never delete or edit ACT_CMMN_* runtime tables manually.","Terminate cases through engine APIs so dependent rows are removed consistently.","Refresh task lists after case termination to purge stale tasks in the UI."],"tags":["cmmn","data-consistency","plan-item-instance","flowable"],"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-18T11:17:12.947Z"}