{"record":{"id":"776baef8bf7580fc","repo":"flowable/flowable-engine","slug":"no-process-instance-found-for-id-processinstanc","errorCode":null,"errorMessage":"No process instance found for id '${processInstanceId}'","messagePattern":"No process instance found for id '(.+?)'","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteProcessInstanceCmd.java","lineNumber":49,"sourceCode":"\n    private static final long serialVersionUID = 1L;\n    protected String processInstanceId;\n    protected String deleteReason;\n\n    public DeleteProcessInstanceCmd(String processInstanceId, String deleteReason) {\n        this.processInstanceId = processInstanceId;\n        this.deleteReason = deleteReason;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (processInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        ExecutionEntity processInstanceEntity = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);\n        if (processInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No process instance found for id '\" + processInstanceId + \"'\", ProcessInstance.class);\n        }\n        if (processInstanceEntity.isDeleted()) {\n            return null;\n        }\n\n        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstanceEntity.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.deleteProcessInstance(processInstanceId, deleteReason);\n        } else {\n            CommandContextUtil.getExecutionEntityManager(commandContext).deleteProcessInstance(processInstanceEntity.getProcessInstanceId(), deleteReason, false, true);\n        }\n\n        return null;\n    }\n\n}\n","sourceCodeStart":31,"sourceCodeEnd":66,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteProcessInstanceCmd.java#L31-L66","documentation":"Thrown as FlowableObjectNotFoundException when no execution exists for the given processInstanceId. The process instance was either never created, already completed/deleted, or the id is wrong. The exception carries ProcessInstance.class so callers can detect the missing entity type.","triggerScenarios":"Calling runtimeService.deleteProcessInstance(id, reason) with an id that findById cannot resolve — nonexistent id, already-terminated instance, id from another engine/database, or a typo.","commonSituations":"Deleting an instance after a competing request already deleted it; cleaning up stale ids stored in external tables; pointing a test environment client at a production id; using a task id or job id by mistake.","solutions":["Query the instance first with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() and skip if null.","Check ACT_RU_EXECUTION (or history tables) to confirm the id ever existed.","Verify you are connected to the same database/engine that owns the instance.","Confirm the id is a process instance id, not an execution/task/plan-item id.","Treat already-completed instances as expected: check HistoricProcessInstanceQuery before deleting."],"exampleFix":"// before\nruntimeService.deleteProcessInstance(instanceId, \"cancelled\");\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery()\n    .processInstanceId(instanceId).singleResult();\nif (pi != null) {\n    runtimeService.deleteProcessInstance(instanceId, \"cancelled\");\n}","handlingStrategy":"validation","validationCode":"ProcessInstance pi = rs.createProcessInstanceQuery().processInstanceId(id).singleResult();\nif (pi == null) { /* skip or report */ } else rs.deleteProcessInstance(id, reason);","typeGuard":null,"tryCatchPattern":"try { rs.deleteProcessInstance(id, reason); } catch (FlowableObjectNotFoundException e) { log.info(\"Instance {} already gone\", id); }","preventionTips":["Check HistoricProcessInstanceQuery for already-completed instances","Handle idempotent deletes for concurrent cleanup jobs","Verify engine/database alignment when ids cross environments"],"tags":["workflow","not-found","process-instance","resource-missing"],"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"}