Skip to content

Serialize Mergify queue requests in a task worktree - #1346

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

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

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The shared GitHub comments fake reproduces the race with an accepted write and a lost reply. Focused Mergify tests passed.

Base

Base: b69efec

Validation

(no loopzero check run recorded)


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

Review

  • primary, claude, 3aef682, approve

Architecture-Review: unchanged; Mergify still uses head-and-queue markers and the existing worktree lock is released before queue polling.
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 3aef68208cd733ca7be5c7a4eaf2a3ae43f8a131, 35.8s: 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/mergify.py
github._api(f"repos/{repo}/issues/{number}/comments", {"body": body})
try:
github._api(f"repos/{repo}/issues/{number}/comments", {"body": body})
except (github.GhError, github.ProcTimeout, OSError):

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: A lost-reply re-read still allows a duplicate request if the comment shows up late

After _api raises ProcTimeout, request() reads the comments again right away. If GitHub accepted the POST but the comment isn't in the list yet (for example, the gh process was killed while GitHub was still committing the write), markers() returns False. The first invocation then raises and releases the lock, and the next invocation posts a second @mergifyio queue comment. The acceptance criteria allow this, since a missing marker counts as a failed POST, and Mergify mostly ignores a duplicate queue command. So this doesn't block the change. It is still the one race that remains. The smallest fix is a short bounded retry of the re-read, done only on ProcTimeout, before re-raising. It is also fine to leave this as is and document it.

Comment thread src/loopzero/cli.py
if not confirmed and confirmed_marker:
sha = github.merged_sha(config.repo, pr.number, expected_head=pr.head_sha)
if sha:
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: Admission lock waits with no bound and ignores the --wait budget

_lock_task_state calls a blocking flock(LOCK_EX). A second merge --wait N stays blocked for as long as the first invocation takes in its admission network calls: markers, membership, merged_sha, mark_confirmed and request, each with its own gh timeout. The second invocation only checks admit_by after it gets the lock. These calls have timeouts, so the wait is bounded in practice and the admission check still runs. However, the time spent waiting for the lock can use up most of the --wait budget without any message to the user. This is a non-blocking note. If it matters, you could print a line when the lock is contended, or use LOCK_NB in a poll loop bounded by admit_by.

eowca and others added 2 commits November 26, 2026 03:31
…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>
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1428. Main’s queue-departure changes required a conflict resolution, and Loop Zero declined a delta review. The replacement preserves that behavior under the worktree lock.

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