Sling job fails with OakState0002 and branch reset errors in AEM

A custom Sling job that moves assets between folders fails intermittently with JCR commit errors such as OakState0002 and branch reset failures. The job processes assets under concurrent load using long-lived sessions and large commit operations, leading to repeated commit failures. To resolve the issue, refactor session handling and implement retry logic.

Description description

Environment

Adobe Experience Manager as a Cloud Service (AEMaaCS)

Issue/Symptoms

  • The custom Sling Job com.adidasedamprogram.core.job.MoveAssetsFromUploadToIngestionAreaJob fails intermittently to execute on the author instance while moving assets between folders.
  • A temporary backlog forms with increased queue depth in move_assets_upload_to_ingestion/queue/1..4 during peak ingestion periods.
  • The job activity spikes during specific time windows while processing large volumes of assets, leading to inconsistent execution.
  • Error logs display commit failures, including:

java.lang.IllegalStateException: Branch with failed reset
Caused by: CommitFailedException: OakOak0100: Branch reset failed

OakState0002: Conflicting concurrent change

  • These errors remain isolated and do not indicate a platform-wide outage, but cause temporary delays in asset processing.

Root cause

The root cause is the use of long-lived JCR sessions and large commits under concurrent load without refresh-and-retry handling for Oak commit conflicts. This results in transient commit failures such as OakState0002 and branch reset errors.

Resolution resolution

To resolve the issue, follow the steps below:

  1. Refactor the custom Sling Job implementation to avoid long-lived JCR sessions by using short-lived sessions for each asset or a small batch of assets, ensuring that session scope remains minimal and reduces contention.
  2. Reduce the size of each commit by committing changes per asset or in small batches instead of performing large bulk operations, which helps prevent commit failures under concurrent load.
  3. Implement bounded retry logic for commit operations by detecting failures such as OakState0002 or branch reset errors, refreshing the session using session.refresh(true), and retrying the commit a limited number of times.
  4. Ensure that the retry logic enforces strict limits to prevent infinite loops or excessive retries, maintaining system stability and avoiding unnecessary resource usage.
  5. Monitor the job’s queue depth and error logs after applying these changes to confirm that the frequency of commit conflicts reduces and job processing stabilizes.
  6. No platform or infrastructure changes are required, as the underlying AEM environment and container health are not implicated.

Assets don’t move from upload to target folder in AEMaaCS

recommendation-more-help
experience-cloud-kcs-help-kbarticles