{"record":{"id":"558ce4bff2de6022","repo":"Activiti/Activiti","slug":"no-process-instance-found-for-id-processinstanc-558ce4","errorCode":null,"errorMessage":"No process instance found for id '${processInstanceId}'","messagePattern":"No process instance found for id '(.+?)'","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntityManagerImpl.java","lineNumber":467,"sourceCode":"        );\n\n        for (String processInstanceId : processInstanceIds) {\n            deleteProcessInstance(processInstanceId, deleteReason, cascade);\n        }\n\n        if (cascade) {\n            getHistoricProcessInstanceEntityManager().deleteHistoricProcessInstanceByProcessDefinitionId(\n                processDefinitionId\n            );\n        }\n    }\n\n    @Override\n    public void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade) {\n        ExecutionEntity execution = findById(processInstanceId);\n\n        if (execution == null) {\n            throw new ActivitiObjectNotFoundException(\n                \"No process instance found for id '\" + processInstanceId + \"'\",\n                ProcessInstance.class\n            );\n        }\n\n        deleteProcessInstanceCascade(execution, deleteReason, cascade);\n    }\n\n    protected void deleteProcessInstanceCascade(ExecutionEntity execution, String deleteReason, boolean deleteHistory) {\n        // fill default reason if none provided\n        if (deleteReason == null) {\n            deleteReason = DeleteReason.PROCESS_INSTANCE_DELETED;\n        }\n\n        for (ExecutionEntity subExecutionEntity : execution.getExecutions()) {\n            if (subExecutionEntity.isMultiInstanceRoot()) {\n                for (ExecutionEntity miExecutionEntity : subExecutionEntity.getExecutions()) {\n                    if (miExecutionEntity.getSubProcessInstance() != null) {","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntityManagerImpl.java#L449-L485","documentation":"Activiti throws ActivitiObjectNotFoundException when deleteProcessInstance is given a processInstanceId that does not resolve to a process-instance execution. The entity manager findById returns null and the engine throws before attempting the cascade delete. It signals the instance never existed, already completed, or was already deleted.","triggerScenarios":"Calling runtimeService.deleteProcessInstance(id, reason) with an id from a finished instance, an already-deleted instance, or a mistyped/non-existent id (also internally from deleteProcessInstancesByProcessDefinition cascades).","commonSituations":"Cleanup jobs racing with instance completion; deleting instances that ended between listing and deleting; stale ids cached in application state; environment/database mismatch.","solutions":["Check existence first with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() and skip when null.","Handle ActivitiObjectNotFoundException in the cleanup loop and treat it as success (idempotent deletion).","Only attempt deletion of instances in a running state (query with .active() if applicable).","Confirm the id is a process instance id (root execution), not a child execution id from another table/query."],"exampleFix":"// before\nruntimeService.deleteProcessInstance(instanceId, \"cleanup\"); // throws when already gone\n// after\nif (runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult() != null) {\n    runtimeService.deleteProcessInstance(instanceId, \"cleanup\");\n}","handlingStrategy":"validation","validationCode":"boolean running = runtimeService.createProcessInstanceQuery()\n    .processInstanceId(processInstanceId)\n    .count() > 0;\nif (!running) log.info(\"Instance {} already ended/deleted, skipping delete\", processInstanceId);","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.deleteProcessInstance(processInstanceId, reason);\n} catch (org.activiti.engine.ActivitiObjectNotFoundException e) {\n    log.info(\"Process instance {} already gone\", processInstanceId);\n}","preventionTips":["Re-check instance existence immediately before delete in batch jobs","Make cleanup loops idempotent by swallowing not-found exceptions","Confirm ids come from ProcessInstanceQuery, not child executions"],"tags":["process-instance","not-found","delete"],"backgroundTag":"resource-not-found","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}