{"record":{"id":"295ef36134d1997d","repo":"flowable/flowable-engine","slug":"multiple-active-or-enabled-plan-item-instances-fou","errorCode":null,"errorMessage":"multiple active or enabled plan item instances found for plan item definition <planItemDefinitionId>","messagePattern":"multiple active or enabled plan item instances found for plan item definition <planItemDefinitionId>","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":427,"sourceCode":"                if (planItemDefinitionMapping.getWithLocalVariables() != null && !planItemDefinitionMapping.getWithLocalVariables().isEmpty()) {\n                    availablePlanItemInstance.setVariablesLocal(planItemDefinitionMapping.getWithLocalVariables());\n                }\n                \n                CmmnHistoryManager cmmnHistoryManager = cmmnEngineConfiguration.getCmmnHistoryManager();\n                cmmnHistoryManager.recordPlanItemInstanceCreated(availablePlanItemInstance);\n                \n                CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);\n                agenda.planChangePlanItemInstanceToAvailableOperation(availablePlanItemInstance);\n                \n                continue;\n            }\n            \n            PlanItemInstance existingPlanItemInstance = null;\n            boolean allExistingPlanItemsAreAvailable = true;\n            for (PlanItemInstance planItemInstance : planItemInstances) {\n                if (PlanItemInstanceState.ACTIVE.equals(planItemInstance.getState()) || PlanItemInstanceState.ENABLED.equals(planItemInstance.getState())) {\n                    if (existingPlanItemInstance != null) {\n                        throw new FlowableException(\"multiple active or enabled plan item instances found for plan item definition \" + planItemDefinitionMapping.getPlanItemDefinitionId());\n                    } else {\n                        existingPlanItemInstance = planItemInstance;\n                    }\n                }\n                if (!PlanItemInstanceState.AVAILABLE.equals(planItemInstance.getState())) {\n                    allExistingPlanItemsAreAvailable = false;\n                }\n            }\n\n            if (allExistingPlanItemsAreAvailable) {\n                // 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            ","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/AbstractCmmnDynamicStateManager.java#L409-L445","documentation":"During a plan item state change to AVAILABLE, Flowable expects at most one active or enabled plan item instance per plan item definition mapping. When two or more instances of the same plan item definition are simultaneously active or enabled, the operation is ambiguous, so this FlowableException is thrown.","triggerScenarios":"Calling changePlanItemState / changePlanItemInstancesToAvailableState when multiple plan item instances for the same planItemDefinitionId are in ACTIVE or ENABLED state, e.g. multi-instance-like repeated tasks or several enabled tasks of the same definition.","commonSituations":"Cases where a human task plan item was completed and re-created multiple times leaving several enabled instances; attempting a bulk state move on a plan item that occurs multiple times in the model; user event listeners enabled repeatedly.","solutions":["Complete or disable the duplicate active/enabled instances first so only one remains, then retry the state change","Use movePlanItemInstance(s) targeting specific plan item instance ids rather than definition-level mapping","Query PlanItemInstanceQuery for the planItemDefinitionId to inspect the duplicates and resolve them","Restructure the case model (e.g. stage/milestone boundaries) to avoid multiple concurrent instances"],"exampleFix":"// before\nchangeState.addPlanItemDefinitionMapping(\n    new SimplePlanItemDefinitionMapping.Builder().planItemDefinitionId(\"taskDef\").build()); // ambiguous\n// after\nList<PlanItemInstance> pis = cmmnRuntimeService.createPlanItemInstanceQuery()\n    .planItemDefinitionId(\"taskDef\").caseInstanceId(caseId).list();\n// move only the specific instance\nchangeState.addPlanItemInstanceMapping(\n    new SimplePlanItemInstanceMapping.Builder().planItemId(pis.get(0).getId()).build());","handlingStrategy":"validation","validationCode":"long active = cmmnRuntimeService.createPlanItemInstanceQuery()\n    .caseInstanceId(caseInstanceId).planItemDefinitionId(defId)\n    .list().stream()\n    .filter(p -> PlanItemInstanceState.ACTIVE.equals(p.getState()) || PlanItemInstanceState.ENABLED.equals(p.getState()))\n    .count();\nif (active > 1) throw new IllegalStateException(\"Ambiguous move: \" + active + \" active/enabled instances\");","typeGuard":null,"tryCatchPattern":"try {\n    cmmnRuntimeService.changePlanItemState(caseInstanceId, changeState);\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"multiple active or enabled plan item instances\")) {\n        // fall back to instance-id based move\n    } else {\n        throw e;\n    }\n}","preventionTips":["Query plan item instances before definition-level state changes","Prefer movePlanItemInstance(s)To... with explicit instance ids when duplicates may exist","Model multi-occurrence cases so at most one instance is enabled at a time"],"tags":["cmmn","dynamic-state","ambiguity","plan-item"],"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-14T11:17:12.474Z"}