{"record":{"id":"1082b2789e34bd14","repo":"flowable/flowable-engine","slug":"no-historic-process-instance-found-with-id","errorCode":null,"errorMessage":"No historic process instance found with id: ","messagePattern":"No historic process instance found with id: ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java","lineNumber":50,"sourceCode":"public class DeleteHistoricProcessInstanceCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String processInstanceId;\n\n    public DeleteHistoricProcessInstanceCmd(String processInstanceId) {\n        this.processInstanceId = processInstanceId;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (processInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"processInstanceId is null\");\n        }\n        // Check if process instance is still running\n        HistoricProcessInstanceEntity instance = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findById(processInstanceId);\n\n        if (instance == null) {\n            throw new FlowableObjectNotFoundException(\"No historic process instance found with id: \" + processInstanceId, HistoricProcessInstance.class);\n        }\n        if (instance.isDeleted()) {\n            return null;\n        }\n        if (instance.getEndTime() == null) {\n            throw new FlowableException(\"Process instance is still running, cannot delete \" + instance);\n        }\n\n        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, instance.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.deleteHistoricProcessInstance(processInstanceId);\n            return null;\n        }\n\n        CommandContextUtil.getHistoryManager(commandContext).recordProcessInstanceDeleted(processInstanceId, instance.getProcessDefinitionId(), instance.getTenantId());\n\n        return null;\n    }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java#L32-L68","documentation":"DeleteHistoricProcessInstanceCmd looks up the historic process instance by id in the ACT_HI_PROCINST table; if no row exists it throws FlowableObjectNotFoundException. The engine refuses to delete a historic record that does not exist rather than silently succeeding.","triggerScenarios":"historyService.deleteHistoricProcessInstance(id) where the id does not match any historic process instance, e.g. the id belongs to a still-running instance (not yet in history), a task-only id, or a different database/schema.","commonSituations":"Deleting against a wrong datasource, using the runtime instance id after the instance never reached history, cleaned history tables (history level none/audit cleanup), or typos in the id (instanceId vs executionId).","solutions":["Confirm the id refers to a completed process instance recorded in history","Query first with historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult() before deleting","Check you are connected to the database/schema that holds the history data"],"exampleFix":"// before\nhistoryService.deleteHistoricProcessInstance(id); // may throw if not found\n// after\nHistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()\n    .processInstanceId(id).singleResult();\nif (hpi != null) {\n    historyService.deleteHistoricProcessInstance(id);\n}","handlingStrategy":"validation","validationCode":"HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()\n    .processInstanceId(id).singleResult();\nif (hpi == null) {\n    logger.warn(\"No historic process instance for id \" + id + \", skipping delete\");\n    return;\n}","typeGuard":"boolean historicInstanceExists = id -> historyService.createHistoricProcessInstanceQuery()\n    .processInstanceId(id).count() > 0;","tryCatchPattern":"try {\n    historyService.deleteHistoricProcessInstance(id);\n} catch (FlowableObjectNotFoundException e) {\n    logger.info(\"Historic process instance already gone: \" + id);\n}","preventionTips":["Query for existence before delete in cleanup jobs","Use .finished() filters in bulk-delete queries","Verify datasource/history configuration matches the environment"],"tags":["flowable","not-found","history","process-instance"],"backgroundTag":"resource-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"}