Skip to content

Serialize Mergify queue requests in a task worktree - #1428

Closed
eowca wants to merge 3 commits into
mainfrom
lean178/1327-mergify-request-replacement
Closed

eowca wants to merge 3 commits into
mainfrom
lean178/1327-mergify-request-replacement

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #1806 after resolving the conflict with main’s queue budget check. Both review rounds were already used here.

Serialize Mergify queue requests in a task worktree

Context and goal

  • Goal: Overlapping merge commands share one Mergify request for the same PR, head and queue.
  • Problem: Both invocations can observe no request marker before either writes its queue comment.
  • Context: Loop Zero already locks task-state updates and records the head and queue in the request comment.

Closes #1327

Acceptance

  • Two overlapping invocations share the accepted request even if the POST reply is lost.
  • A failed POST without a marker allows the next invocation to submit.
  • The existing worktree lock covers admission and is released before queue polling.

Notes

Base

Base: b8abab8

Validation

(no loopzero check run recorded)


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

…rktree lock

Architecture-Review: unchanged; admission still uses the existing marker and lock and queue waiting starts after the lock is released.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero primary review by claude on e4eb71bede3db393ae00603fc0ade05d3eabf1f5, 35.2s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py
if not confirmed and confirmed_marker:
closed: list[github.GhError] = []
if sha := _mergify_departure(config, pr, queue, closed, confirmed=True):
with _lock_task_state(wt):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Worktree lock is held across several GitHub round-trips that other task-state writers share

_lock_task_state is the same flock that _save_report (cli.py:374) and the other task-state writers (cli.py:544, 675, 860) use. Admission now holds it while it pages issue comments (markers), reads membership, calls merged_sha, may post mark_confirmed, may build a departure report, and on a lost reply runs a second markers page read. Each of these can take up to the gh timeout, so a concurrent loopzero check can block for several timeouts before it publishes its receipt. This is correct, since it is released before _wait_for_mergify as the acceptance requires, but it is broader than needed. If contention matters, a smaller fix is to move the lock-free reads (merged_sha and the confirmed/departure handling) outside the lock. The lock would then cover only re-reading markers/membership and the request POST. Alternatively, add a comment explaining why the wider scope is intentional.

Comment thread src/loopzero/mergify.py
def request(repo: str, number: int, head: str, queue: str) -> None:
body = f"@mergifyio queue\n\n{_marker(REQUEST, head, queue)}" # Mergify deprecates naming the queue
github._api(f"repos/{repo}/issues/{number}/comments", {"body": body})
try:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Lost-reply recovery in request is only correct when the caller holds the admission lock

The fallback treats any existing REQUEST marker for this head and queue as proof that this POST was accepted. That holds only because the caller re-read the markers under _lock_task_state and found none. request is a public module function with no such precondition in its signature, so a future unlocked caller could take a marker from an earlier run as its own success. A one-line docstring would document the precondition: the caller must have seen no marker under the worktree lock.

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero delta review by claude on 98cf014b38ed88cb6f4045229b7c65b088ccc544, 7.7s: approve (0 critical, 0 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

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.

Avoid duplicate Mergify queue comments from overlapping merge retries

1 participant