flowable/flowable-engine · error · FlowableException
Process instance is still running, cannot delete
Error message
Process instance is still running, cannot delete
What it means
DeleteHistoricProcessInstanceCmd only deletes historic records; if the historic instance has no endTime the process is still running and the engine throws FlowableException. Deleting a running instance from history is not allowed; cancel it via the runtime API instead.
Source
Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java:56
this.processInstanceId = processInstanceId;
}
@Override
public Object execute(CommandContext commandContext) {
if (processInstanceId == null) {
throw new FlowableIllegalArgumentException("processInstanceId is null");
}
// Check if process instance is still running
HistoricProcessInstanceEntity instance = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findById(processInstanceId);
if (instance == null) {
throw new FlowableObjectNotFoundException("No historic process instance found with id: " + processInstanceId, HistoricProcessInstance.class);
}
if (instance.isDeleted()) {
return null;
}
if (instance.getEndTime() == null) {
throw new FlowableException("Process instance is still running, cannot delete " + instance);
}
if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, instance.getProcessDefinitionId())) {
Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
compatibilityHandler.deleteHistoricProcessInstance(processInstanceId);
return null;
}
CommandContextUtil.getHistoryManager(commandContext).recordProcessInstanceDeleted(processInstanceId, instance.getProcessDefinitionId(), instance.getTenantId());
return null;
}
}
View on GitHub (pinned to d6d39ce1c6)
Solutions
- Use runtimeService.deleteProcessInstance(id, reason) to terminate a running instance first, then delete its history
- Check HistoricProcessInstance.getEndTime() != null before calling delete
- Filter queries with .finished() when bulk-deleting historic instances
Example fix
// before
historyService.deleteHistoricProcessInstance(id); // instance still running
// after
if (runtimeService.createProcessInstanceQuery().processInstanceId(id).count() > 0) {
runtimeService.deleteProcessInstance(id, "cleanup");
}
historyService.deleteHistoricProcessInstance(id); Defensive patterns
Strategy: validation
Validate before calling
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(id).singleResult();
if (hpi != null && hpi.getEndTime() == null) {
runtimeService.deleteProcessInstance(id, "cancel before history delete");
} Type guard
boolean isFinished = id -> {
HistoricProcessInstance h = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(id).singleResult();
return h != null && h.getEndTime() != null;
}; Try / catch
try {
historyService.deleteHistoricProcessInstance(id);
} catch (FlowableException e) {
if (e.getMessage().contains("still running")) {
runtimeService.deleteProcessInstance(id, "terminated by cleanup");
historyService.deleteHistoricProcessInstance(id);
}
} Prevention
- Check endTime before any historic delete
- Use runtimeService APIs for running instances, historyService only for finished ones
- In bulk cleanup use .finished() query criteria
When it happens
Trigger: historyService.deleteHistoricProcessInstance(id) where the process instance has started but not finished (endTime is null), typically an id pointing at an active instance.
Common situations: Calling history deletion while the process is still executing, cleanup scripts that iterate ids without checking endTime, or confusion between deleteProcessInstance (runtime) and deleteHistoricProcessInstance (history).
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- processInstanceId is null
- No historic process instance found with id:
- task does not have an endTime, cannot delete
- process instance ${processInstanceId} is suspended, cannot s
- Process instance is still running, cannot delete historic pr
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/39347cbf7631d8dd.
Report an issue: GitHub.