Activiti/Activiti · error · ActivitiObjectNotFoundException
No historic process instance found with id
Error message
No historic process instance found with id: ${processInstanceId} What it means
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.
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.
Example fix
// before
historyService.deleteHistoricProcessInstance(id);
// after
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(id).singleResult();
if (hpi != null) {
historyService.deleteHistoricProcessInstance(id);
} Defensive patterns
Strategy: validation
Validate before calling
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
if (hpi == null) {
return; // already deleted or never existed — handle as no-op
} Type guard
boolean historicProcessExists(String id) {
return id != null && historyService.createHistoricProcessInstanceQuery()
.processInstanceId(id).count() > 0;
} Try / catch
try {
historyService.deleteHistoricProcessInstance(pid);
} catch (ActivitiObjectNotFoundException e) {
LOG.info("Historic process instance {} already gone; treating as idempotent delete", pid);
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- No historic task exists with the given id
- activity tenant id is null
- Cannot assign a groupId to a task assignment that already…
- Cannot assign a userId to a task assignment that already…
- Cannot find process definition with id
AI-assisted analysis of Activiti/Activiti@56435b1a97 (2026-09-09).
Data as JSON: /api/errors/88ae31592062d574.
Report an issue: GitHub.
Appendix: source
Thrown at activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java:48
private static final long serialVersionUID = 1L;
protected String processInstanceId;
public DeleteHistoricProcessInstanceCmd(String processInstanceId) {
this.processInstanceId = processInstanceId;
}
public Object execute(CommandContext commandContext) {
if (processInstanceId == null) {
throw new ActivitiIllegalArgumentException("processInstanceId is null");
}
// Check if process instance is still running
HistoricProcessInstance instance = commandContext
.getHistoricProcessInstanceEntityManager()
.findById(processInstanceId);
if (instance == null) {
throw new ActivitiObjectNotFoundException(
"No historic process instance found with id: " + processInstanceId,
HistoricProcessInstance.class
);
}
if (instance.getEndTime() == null) {
throw new ActivitiException(
"Process instance is still running, cannot delete historic process instance: " + processInstanceId
);
}
executeInternal(commandContext, instance);
return null;
}
protected void executeInternal(CommandContext commandContext, HistoricProcessInstance instance) {
commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);
}
}View on GitHub (pinned to 56435b1a97)