{"record":{"id":"3989ed7995fcec4a","repo":"flowable/flowable-engine","slug":"no-historic-process-instance-found-with-id-proc","errorCode":null,"errorMessage":"No historic process instance found with id: ${processInstanceId}","messagePattern":"No historic process instance found with id: (.+?)","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java","lineNumber":48,"sourceCode":"    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 ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n        // Check if process instance is still running\n        HistoricProcessInstance instance = commandContext\n                .getHistoricProcessInstanceEntityManager()\n                .findHistoricProcessInstance(processInstanceId);\n\n        if (instance == null) {\n            throw new ActivitiObjectNotFoundException(\"No historic process instance found with id: \" + processInstanceId, HistoricProcessInstance.class);\n        }\n        if (instance.getEndTime() == null) {\n            throw new ActivitiException(\"Process instance is still running, cannot delete historic process instance: \" + processInstanceId);\n        }\n\n        commandContext\n                .getHistoricProcessInstanceEntityManager()\n                .deleteHistoricProcessInstanceById(processInstanceId);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":30,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java#L30-L62","documentation":"DeleteHistoricProcessInstanceCmd looks up a completed process instance in the ACT_HI_PROCINST history table by id. If no historic row exists with that id, it throws ActivitiObjectNotFoundException carrying HistoricProcessInstance.class as the reference type. History deletion only operates on already-archived instances.","triggerScenarios":"Calling runtimeService/historyService deleteHistoricProcessInstance(id) (this command) with an id that has no row in the historic process instance table: a bogus id, an id whose history was already deleted, or a process whose history level was configured to 'none' or 'activity' so no historic instance was ever written.","commonSituations":"Double-deletion in cleanup jobs that don't check for prior removal; processes executed under historyLevel=none; purging history in a different database/environment than the one that recorded it; typos or stale ids cached from another deployment.","solutions":["Query historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult() before deleting and skip missing ids.","Verify the process instance actually completed (endTime set) and ran under a history level that records the instance (audit/activity).","Wrap the delete in try/catch for ActivitiObjectNotFoundException and treat it as already-deleted in cleanup code.","Confirm you are connected to the same database/schema where the process ran."],"exampleFix":"// before\nhistoryService.deleteHistoricProcessInstance(processInstanceId);\n// after\nHistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()\n        .processInstanceId(processInstanceId).singleResult();\nif (hpi != null) {\n    historyService.deleteHistoricProcessInstance(processInstanceId);\n}","handlingStrategy":"validation","validationCode":"if (historyService.createHistoricProcessInstanceQuery()\n        .processInstanceId(processInstanceId).count() == 0) {\n    return; // nothing to delete\n}","typeGuard":null,"tryCatchPattern":"try {\n    historyService.deleteHistoricProcessInstance(processInstanceId);\n} catch (ActivitiObjectNotFoundException e) {\n    // already deleted or never recorded; treat as success\n}","preventionTips":["Filter cleanup queries with finished() so only deletable history rows are selected","Ensure historyLevel records instances (>= activity) for processes you plan to purge","Make history cleanup jobs idempotent by tolerating missing ids"],"tags":["history","process-instance","not-found","cleanup"],"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"}