Skip to content

[IMP] merge bot: queue merges per target branch - #377

Open
mileo wants to merge 2 commits into
OCA:masterfrom
kmee:master-merge-bot-queue
Open

mileo wants to merge 2 commits into
OCA:masterfrom
kmee:master-merge-bot-queue

Conversation

@mileo

@mileo mileo commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

When several /ocabot merge commands are issued on the same target branch, each one prepares a merge bot branch from the same tip and runs the CI in parallel. Only the first can land. Every other one is prepared again on the new tip and runs the whole CI again ("It looks like something changed on 18.0 in the meantime"). When two finish close together, the second push is rejected and that merge fails for good.

This PR merges one PR at a time per target branch:

 /ocabot merge
+  if another merge is in progress on the target branch
+    comment, add the "bot merge queued" label, stop
   prepare the merge bot branch
+  add the "bot is merging" label (before pushing, so it holds the queue)
   push it, wait for the checks

 checks finished
   green: merge
-    push rejected: fail ("could not be finalized")
+    push rejected (fetch first, cannot lock ref): prepare again, as when the target moved
   red or error: report
+  start the oldest queued PR of the target branch

A merge holds the queue while its merge bot branch exists, its PR is open with the bot is merging label, and the branch is more recent than MERGE_BOT_QUEUE_TIMEOUT hours (12 by default). The branches left behind by failed merges (OCA/l10n-brazil has 10 right now) therefore do not block it. The queue order comes from a hidden marker in the bot's own "queued" comment, so nobody can queue a merge on behalf of someone else, and permissions are checked again when the merge starts. A task every 15 minutes restarts the queues in case a webhook is lost. Two commands issued within seconds, before either branch exists, can still start together; they fall back to the current retry.

Evidence

New tests:

merge bot branch ready, then another commit lands on the target branch before the final push
  before: the merge fails
  after:  the merge is prepared again
closed PR, PR without the merging label, merge bot branch older than the timeout
  do not hold the queue
queue marker in a comment from someone other than the bot
  is ignored

The whole suite passes. The behaviour against GitHub itself was not exercised, it needs a running bot.

Merge Danger

Door: two-way

Revert, or add merge_bot_queue to BOT_TASKS_DISABLED. PRs left with the bot merge queued label then need the merge command issued again. The queue is enabled by default here; happy to make it opt-in if you prefer.

Blast Radius: merge-bot

All repositories using the bot. A bug in the queue would make a queued PR wait (until the 15 minute task, the 12 hour timeout or a new merge command), but the target branch is not at risk: what is pushed is still exactly what was tested. The bot is merging label is now added before the merge bot branch is pushed instead of after.

Merge one PR at a time per target branch. A merge command issued while
another merge is in progress on the same target branch is queued (label
"bot merge queued") and starts when that merge finishes, whether it
succeeds or fails, instead of preparing a branch whose tests will have
to run again once the first merge lands.

A merge holds the queue while its merge bot branch exists, its PR is
open with the "bot is merging" label, and the branch is more recent than
MERGE_BOT_QUEUE_TIMEOUT hours (default 12), so branches left behind by
failed merges do not block the queue. A periodic task restarts queues
that nothing restarted. The queue can be disabled with the
merge_bot_queue switch.

When the final push is rejected because the target branch moved in the
meantime (fetch first, cannot lock ref), retry the merge instead of
failing.
@mileo
mileo marked this pull request as ready for review November 27, 2026 21:51
@mileo

mileo commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@rvalyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant