flowable/flowable-engine · error · FlowableException

ActivityInstance not found for

Error message

ActivityInstance not found for 

What it means

Thrown when inserting a historic form property and no unfinished activity instance can be resolved for the execution. Flowable requires an activityInstanceId to attach the historic form property record to, so if the ActivityInstanceManager cannot find one for the given ExecutionEntity, it aborts. This indicates the execution has no currently open/unrecorded activity, usually because historic activity instance tracking is out of sync or the execution is not inside a real activity.

Source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/HistoricDetailEntityManagerImpl.java:59

    @Override
    public HistoricFormPropertyEntity insertHistoricFormPropertyEntity(ExecutionEntity execution,
        String propertyId, String propertyValue, String taskId, Date createTime) {

        HistoricFormPropertyEntity historicFormPropertyEntity = dataManager.createHistoricFormProperty();
        historicFormPropertyEntity.setProcessInstanceId(execution.getProcessInstanceId());
        historicFormPropertyEntity.setExecutionId(execution.getId());
        historicFormPropertyEntity.setTaskId(taskId);
        historicFormPropertyEntity.setPropertyId(propertyId);
        historicFormPropertyEntity.setPropertyValue(propertyValue);
        historicFormPropertyEntity.setTime(createTime);

        ActivityInstanceEntity activityInstance = getActivityInstanceEntityManager().findUnfinishedActivityInstance(execution);
        String activityInstanceId;
        if (activityInstance != null) {
            activityInstanceId = activityInstance.getId();
        } else {
            throw new FlowableException("ActivityInstance not found for " + execution);
        }
        historicFormPropertyEntity.setActivityInstanceId(activityInstanceId);

        insert(historicFormPropertyEntity);
        return historicFormPropertyEntity;
    }

    @Override
    public HistoricDetailVariableInstanceUpdateEntity copyAndInsertHistoricDetailVariableInstanceUpdateEntity(VariableInstanceEntity variableInstance,
        Date createTime) {
        HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = dataManager.createHistoricDetailVariableInstanceUpdate();
        historicVariableUpdate.setProcessInstanceId(variableInstance.getProcessInstanceId());
        historicVariableUpdate.setExecutionId(variableInstance.getExecutionId());
        historicVariableUpdate.setTaskId(variableInstance.getTaskId());
        historicVariableUpdate.setTime(createTime);
        historicVariableUpdate.setRevision(variableInstance.getRevision());
        historicVariableUpdate.setName(variableInstance.getName());
        historicVariableUpdate.setVariableType(variableInstance.getType());

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Ensure the process engine history level is ACTIVITY or higher (flowable.history-level / historyLevel config) so activity instances are created before form properties are recorded.
  2. Verify the execution passed is an active execution currently positioned at an activity; do not call historic form-property insertion manually for arbitrary executions.
  3. Check ACT_HI_ACTINST for the process instance; if rows are missing, restore from backup or restart the instance rather than continuing.
  4. If you only need form data history, store it as process/task variables with history enabled instead of calling the historic detail API directly.

Example fix

// before
historyService.createHistoricDetailQuery()... // relies on form property history
// config after
// flowable.cfg.xml
<property name="historyLevel" value="ACTIVITY" /> <!-- or FULL -->
Defensive patterns

Strategy: validation

Validate before calling

boolean active = runtimeService.createExecutionQuery().processInstanceId(pid).activityId(activityId).count() > 0;
if (!active) throw new IllegalStateException("No active execution/activity to record form property for");

Try / catch

try { ... } catch (FlowableException e) { if (e.getMessage().startsWith("ActivityInstance not found")) { /* skip history recording or raise history level */ } else throw e; }

Prevention

When it happens

Trigger: Calling HistoricDataService / form-property recording (historyLevel FORM) via insertHistoricFormPropertyEntity when execution has no matching unfinished ActivityInstanceEntity — e.g. recording form properties for an execution not positioned at an activity, custom code invoking historic detail insertion manually, or history/activity-instance data deleted or not created due to history level misconfiguration.

Common situations: Running with a history level below ACTIVITY so activity instances are never recorded while form property history is attempted; custom jobs or migration scripts copying executions without their activity instances; database cleanup jobs deleting ACT_HI_ACTINST rows for running instances; using an execution obtained outside the normal activity scope.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/43bc7816371bad9e. Report an issue: GitHub.