"Cannot read workflow model" error after AEM migration

Issue

After migrating to a newer version of AEM, the error below is flooding the logs:

18.08.2017 13:03:36.620 ERROR [10.1.40.68 [1503075812864] GET /mnt/overlay/granite/ui/content/shell/header/actions/pulse.data.json HTTP/1.1] com.adobe.granite.workflow.core.model.WorkflowModelCacheImpl cannot load model. id: /etc/workflow/models/dam/update_asset/jcr:content/model vid: 1.0
com.adobe.granite.workflow.WorkflowException: Cannot read workflow model from node: /etc/workflow/models/dam/update_asset/jcr:content/model
at com.adobe.granite.workflow.core.jcr.WorkflowModelManager.getWorkflowModelFromRepo(WorkflowModelManager.java:179)
at com.adobe.granite.workflow.core.model.WorkflowModelCacheImpl.getModel(WorkflowModelCacheImpl.java:162)
at com.adobe.granite.workflow.core.jcr.WorkflowModelManager.getWorkflowModel(WorkflowModelManager.java:91)
at com.adobe.granite.workflow.core.WorkflowSessionImpl.getCachedModel(WorkflowSessionImpl.java:448)
at com.adobe.granite.workflow.core.util.NodeReader.createWorkflow(NodeReader.java:249)
at com.adobe.granite.workflow.core.util.NodeReader.createWorkItem(NodeReader.java:336)
at com.adobe.granite.workflow.core.jcr.WorkItemAdapterFactory.getAdapter(WorkItemAdapterFactory.java:128)
at org.apache.sling.adapter.internal.AdapterManagerImpl.getAdapter(AdapterManagerImpl.java:147)
at com.adobe.granite.workflow.core.jcr.WorkItemManager.getInboxItems(WorkItemManager.java:289)
at com.adobe.granite.workflow.core.WorkflowSessionImpl.getActiveInboxItems(WorkflowSessionImpl.java:711)
at com.adobe.granite.workflow.core.WorkflowSessionImpl.getActiveInboxItems(WorkflowSessionImpl.java:618)
at org.apache.jsp.libs.cq.gui.components.shell.badge.data_json_jsp._jspService(data_json_jsp.java:610)
...
Caused by: javax.jcr.InvalidItemStateException: Item is stale /jcr:system/jcr:versionStorage/01/00/1f/01001f76-9ea5-45ed-934f-dca169e9c9b6
at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.getTree(NodeDelegate.java:885)
at org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate.getVersion(VersionHistoryDelegate.java:81)
at org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl$5.perform(VersionHistoryImpl.java:137)
at org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl$5.perform(VersionHistoryImpl.java:133)
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:208)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)
at org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl.getVersion(VersionHistoryImpl.java:133)
at com.adobe.granite.workflow.core.jcr.WorkflowModelManager.getWorkflowModelFromRepo(WorkflowModelManager.java:160)
... 134 common frames omitted

Environment

AEM 6.x

Cause

Workflow versions weren't migrated from the older AEM version so the workflow instances reference versions don't exist.

Resolution

  1. Go to the package manager (http://host:port/crx/packmgr/index.jsp).
  2. Create two separate backup packages, /etc/workflow/models (including the rep: policy node) and /etc/workflow/instances.
  3. Go to CRXDE (http://host:port/crx/de/index.jsp) and log in as admin.
  4. Browse /etc/workflow/models.
  5. Right click the /etc/workflow/models node and select Delete.
  6. Click Save All.
  7. Go to the package manager (http://host:port/crx/packmgr/index.jsp).
  8. Reinstall the package containing /etc/workflow/models.
  9. Install the attached package workflow-version-fix-tool-1.1.zip.
  10. Go to /apps/workflow-tools/workflowversionfix/run.html
  11. Run the script - this script resets all workflow instances to reference the newly reinstalled workflow model versions.

Download