Merging a pull request via merge queue intermittently fails with EntityOutOfDateException due to a rescope race condition

XMLWordPrintable

    • Severity 3 - Minor

      Issue Summary

      Intermittently, when a pull request is processed by the merge queue, it fails with an EntityOutOfDateException and gets ejected from the queue instead of merging. This is a race condition between the merge queue attempting to rescope the pull request and an asynchronous repository hook thread rescoping the same PR concurrently in response to the same push event. Whichever path loses the optimistic locking race throws the exception, causing the merge queue to treat the PR as failed.

      Steps to Reproduce

      Note: this issue may be difficult to reproduce consistently due to the narrow race window between the merge queue and the async rescoping thread.

      1. Set up a repository with merge queue enabled using the strict per-pull-request strategy
      2. Have multiple pull requests queued
      3. Merge a pull request that is ahead in the queue, triggering a push to the target branch
      4. Observe that a subsequent pull request in the queue fails to merge and is ejected

      Expected Results

      The pull request is successfully merged via the merge queue.

      Actual Results

      The pull request is ejected from the merge queue and the merge fails. The below exception is thrown in the atlassian-bitbucket.log file:

      2026-04-14 00:57:25,674 ERROR [merge-queue-executor:thread-2]  c.a.b.i.m.p.s.StrictPerPullRequestStrategy [2]: Failed to merge pull request 3
      com.atlassian.bitbucket.EntityOutOfDateException: You are attempting to modify an entity based on out-of-date information.
      	at com.atlassian.stash.internal.aop.ExceptionRewriteAdvice.getSpecificOutOfDateException(ExceptionRewriteAdvice.java:92)
      	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
      	at jdk.proxy3/jdk.proxy3.$Proxy414.rescope(Unknown Source)
      	at com.atlassian.bitbucket.internal.mergequeue.process.strategy.StrictPerPullRequestStrategy.rescopePullRequest(StrictPerPullRequestStrategy.java:265)
      	at com.atlassian.bitbucket.internal.mergequeue.process.strategy.StrictPerPullRequestStrategy.mergeEntry(StrictPerPullRequestStrategy.java:197)
      	at com.atlassian.bitbucket.internal.mergequeue.process.strategy.StrictPerPullRequestStrategy.lambda$mergeReadyEntries$2(StrictPerPullRequestStrategy.java:237)
      

      Workaround

      Re-add the pull request to the merge queue. The issue is intermittent due to the race condition and the PR should merge successfully on a subsequent attempt.

              Assignee:
              Unassigned
              Reporter:
              Josh Aguilar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: