{"record":{"id":"335dc3553d01de39","repo":"flowable/flowable-engine","slug":"no-process-instance-found-for-id-processinstance","errorCode":null,"errorMessage":"No process instance found for id '<processInstanceId>'","messagePattern":"No process instance found for id '<processInstanceId>'","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntityManager.java","lineNumber":67,"sourceCode":"        }\n\n        if (cascade) {\n            Context\n                    .getCommandContext()\n                    .getHistoricProcessInstanceEntityManager()\n                    .deleteHistoricProcessInstanceByProcessDefinitionId(processDefinitionId);\n        }\n    }\n\n    public void deleteProcessInstance(String processInstanceId, String deleteReason) {\n        deleteProcessInstance(processInstanceId, deleteReason, false);\n    }\n\n    public void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade) {\n        ExecutionEntity execution = findExecutionById(processInstanceId);\n\n        if (execution == null) {\n            throw new ActivitiObjectNotFoundException(\"No process instance found for id '\" + processInstanceId + \"'\", ProcessInstance.class);\n        }\n\n        deleteProcessInstanceCascade(execution, deleteReason, cascade);\n    }\n\n    private void deleteProcessInstanceCascade(ExecutionEntity execution, String deleteReason, boolean deleteHistory) {\n        CommandContext commandContext = Context.getCommandContext();\n\n        ProcessInstanceQueryImpl processInstanceQuery = new ProcessInstanceQueryImpl(commandContext);\n        List<ProcessInstance> subProcesses = processInstanceQuery.superProcessInstanceId(execution.getProcessInstanceId()).list();\n        for (ProcessInstance subProcess : subProcesses) {\n            deleteProcessInstanceCascade((ExecutionEntity) subProcess, deleteReason, deleteHistory);\n        }\n\n        commandContext\n                .getTaskEntityManager()\n                .deleteTasksByProcessInstanceId(execution.getId(), deleteReason, deleteHistory);\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntityManager.java#L49-L85","documentation":"deleteProcessInstance looks up the execution row for the given process instance id before cascading the delete. If no execution entity exists with that id, the engine throws ActivitiObjectNotFoundException. It signals the target process instance does not exist (or was already deleted / never started in this engine's database).","triggerScenarios":"Calling RuntimeService.deleteProcessInstance(processInstanceId, reason) with an id that has no execution row; the instance already completed or was deleted; the id belongs to a different database/tenant; a historic-only id is passed.","commonSituations":"Race conditions where a job or another thread completes the instance between lookup and delete; pointing at a test database while the instance lives in production; using a process instance id from an export/backup of another environment; deleting in a retry loop without checking existence.","solutions":["Verify the processInstanceId via runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before deleting.","Check you are connected to the correct database/schema and tenant the instance lives in.","If the instance may have already ended, look it up in history (historicProcessInstanceQuery) and skip deletion or delete history instead.","Handle ActivitiObjectNotFoundException as a benign already-deleted case in idempotent cleanup code."],"exampleFix":"// before\nruntimeService.deleteProcessInstance(instanceId, \"cancelled\");\n\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult();\nif (pi != null) {\n    runtimeService.deleteProcessInstance(instanceId, \"cancelled\");\n}","handlingStrategy":"validation","validationCode":"ProcessInstance pi = runtimeService.createProcessInstanceQuery()\n    .processInstanceId(instanceId).singleResult();\nif (pi == null) { /* skip or delete history instead */ }","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.deleteProcessInstance(instanceId, reason);\n} catch (ActivitiObjectNotFoundException e) {\n    log.info(\"Instance {} already gone; treating as deleted\", instanceId);\n}","preventionTips":["Check existence with a processInstanceQuery before deleting","Make cleanup jobs idempotent by ignoring not-found exceptions","Confirm database/tenant before operating on ids from other environments"],"tags":["process-instance","not-found","runtime"],"backgroundTag":"record-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"}