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

  1. Verify the id exists by querying historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult() before deleting.
  2. Check you are connected to the same database/schema the instance was created in.
  3. Confirm a history cleanup job did not already purge the record (treat 404 as idempotent success in retry logic).
  4. 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

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


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)