{"record":{"id":"88ae31592062d574","repo":"Activiti/Activiti","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":404,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java","lineNumber":48,"sourceCode":"\n    private static final long serialVersionUID = 1L;\n    protected String processInstanceId;\n\n    public DeleteHistoricProcessInstanceCmd(String processInstanceId) {\n        this.processInstanceId = processInstanceId;\n    }\n\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            .findById(processInstanceId);\n\n        if (instance == null) {\n            throw new ActivitiObjectNotFoundException(\n                \"No historic process instance found with id: \" + processInstanceId,\n                HistoricProcessInstance.class\n            );\n        }\n        if (instance.getEndTime() == null) {\n            throw new ActivitiException(\n                \"Process instance is still running, cannot delete historic process instance: \" + processInstanceId\n            );\n        }\n\n        executeInternal(commandContext, instance);\n        return null;\n    }\n\n    protected void executeInternal(CommandContext commandContext, HistoricProcessInstance instance) {\n        commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);\n    }\n}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java#L30-L66","documentation":"After validating the id is non-null, DeleteHistoricProcessInstanceCmd looks up the historic process instance via the HistoricProcessInstanceEntityManager. If no record with that id exists in the ACT_HI_PROCINST table, it throws ActivitiObjectNotFoundException carrying the id and HistoricProcessInstance.class as the entity type.","triggerScenarios":"Calling HistoryService.deleteHistoricProcessInstance(id) with an id that does not exist, was already deleted, or was never historic (the process instance is still running so only a runtime instance exists).","commonSituations":"Double-delete after a retry, deleting an instance of a different engine/database than the one queried, id confusion between the runtime process instance id and historic data purged by a history-cleanup job, or deleting an id from another tenant/DB.","solutions":["Verify the id exists by querying historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult() before deleting.","Check you are connected to the same database/schema the instance was created in.","Confirm a history cleanup job did not already purge the record (treat 404 as idempotent success in retry logic).","Catch ActivitiObjectNotFoundException and handle it as a no-op or user-facing not-found error."],"exampleFix":"// before\nhistoryService.deleteHistoricProcessInstance(id);\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(processInstanceId).singleResult();\nif (hpi == null) {\n    return; // already deleted or never existed — handle as no-op\n}","typeGuard":"boolean historicProcessExists(String id) {\n    return id != null && historyService.createHistoricProcessInstanceQuery()\n        .processInstanceId(id).count() > 0;\n}","tryCatchPattern":"try {\n    historyService.deleteHistoricProcessInstance(pid);\n} catch (ActivitiObjectNotFoundException e) {\n    LOG.info(\"Historic process instance {} already gone; treating as idempotent delete\", pid);\n}","preventionTips":["Make history deletion idempotent in retry/cleanup jobs.","Query before delete when the id originates from external input.","Confirm you target the same database/engine the instance was created in.","Account for history-cleanup jobs that may purge records before your delete runs."],"tags":["activiti","not-found","history","entity"],"backgroundTag":"record-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"}