Skip to content

Recover native merge after a lost GitHub reply - #1436

Merged
mergify[bot] merged 3 commits into
mainfrom
lean178/1325-native-merge-replacement
Nov 26, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
lean178/1325-native-merge-replacement

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Recover native merge after a lost GitHub reply

Context and goal

  • Goal: Verify and follow the original merge request when GitHub accepted it before losing the reply.
  • Problem: A lost native merge reply can report failure after landing, or cause a retry to send another queue request.
  • Context: GitHub provides a landed SHA and queue admission tied to the PR head.

Closes #1325

Acceptance

  • An accepted squash merge with a lost reply verifies the landed SHA and cleans up in the same invocation.
  • An accepted queue request with a lost reply follows the normal queue path, and a retry observes admission before writing.
  • A moved head or missing evidence preserves the worktree and reports failure.

Notes

  • Replaces Recover native merge after a lost GitHub reply #1345. Mergify reported a conflict with main and Loop Zero declined a delta review of the resolved merge.

  • The CLI fake loses the reply after accepting the merge. Focused CLI and GitHub merge tests passed after the fix.

Base

Base: b9a018c

Validation

Recorded for b669a890261c

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

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

Review

Architecture-Review: unchanged; merge recovery keeps the reviewed head checks and the conflict resolution only changes a test reference.
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 d82dd4afa3df822d0ccaae9215d3ccfa59fcafb1, 44.2s: approve (0 critical, 0 important, 3 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/github.py
raise MergeFailed(exc.command, exc.tail) from exc
except (GhError, ProcTimeout, OSError) as exc:
write_error = exc
sha = merged_sha(repo, number, expected_head=head_sha)

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: The write error is lost when the follow-up read raises

write_error is only added to the message when all three reads finish without an error. If gh pr merge fails and merged_sha then raises, the caller sees only the read error and never the real reason the merge was rejected. This happens when the head has moved ("PR head changed before merge verification" hides gh's "head commit mismatch"), on invalid evidence, or on ClosedUnmerged. The same applies when merge_pending raises queue_error (line 1415). The run still fails closed and keeps the worktree, so this is not a correctness bug, but the diagnosis is harder. Smallest fix: wrap the reads after the write so that a GhError raised while write_error is set is re-raised as MergeFailed, with the write error added to its tail and chained with from.

Comment thread src/loopzero/github.py
argv = (
"pr", "merge", str(number), "--repo", repo, *method, "--match-head-commit", head_sha,
)
if strategy == "queue" and merge_pending(repo, number, head_sha):

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: The admission check before writing only runs for strategy == "queue"

merge_pending also returns True for an accepted auto-merge request. The squash, merge and rebase strategies reach that state on a queue-protected base, and test_merge_queued_returns_none covers that case. A retry after a lost reply under those strategies still sends a second gh pr merge. That second write is probably harmless, because gh rejects it or treats it as a no-op and the queue check afterwards returns None. Still, it falls short of the stated goal that a retry observes admission before writing. Consider either running the check for every strategy, or documenting that only queue is protected this way.

Comment thread tests/test_github.py

def _queue_json(queued: bool) -> dict:
return {"data": {"repository": {"pullRequest": {"isInMergeQueue": queued}}}}
return {"data": {"repository": {"pullRequest": {"isInMergeQueue": queued, "headRefOid": HEAD}}}}

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: No test for a missing or changed headRefOid in the queue check

The new head check in merge_pending (github.py:1376) is part of the acceptance criteria ('moved head or missing evidence ... reports failure'). Every updated fixture supplies a matching headRefOid, so no test fails if the check is removed. Add a test_github case where headRefOid is missing or different, for both the check before writing and the check after writing. It should assert that MergeFailed is raised and that no pr merge write is sent when the check before writing fails.

…erge-replacement

# Conflicts:
#	src/loopzero/cli.py
#	tests/test_cli.py
#	tests/test_github.py

@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 a82cb89ce9a299ade7f146d072f6a1237ea7bc6c, 18.4s: approve (0 critical, 0 important, 1 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 tests/test_github.py
snapshots.append(merge_json(state="MERGED", sha="d" * 40))
arm_merge(gh, accepted, *snapshots)
if strategy == "queue":
gh.respond("api graphql", _queue_json(False), accepted)

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: The queue branch silently replaces the GraphQL responses that arm_merge sets

arm_merge already calls gh.respond("api graphql", accepted). FakeGh.respond replaces the responses for a key rather than adding to them, so for strategy == "queue" the extra gh.respond("api graphql", _queue_json(False), accepted) throws away what arm_merge set. The test is correct, but a reader has to know that replace behaviour to see why. Smallest fix: call arm_merge(gh, _queue_json(False) if strategy == "queue" else accepted, *snapshots) and use gh.append("api graphql", accepted) for the queue case, or add a short comment saying the call overrides the earlier one.

@eowca
eowca marked this pull request as ready for review November 26, 2026 14:31
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

❌ Left the queue · Loop-zero Eligibility failed

1 min in the queue, 1 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 14:32 · rule main · triggered by @eowca with the @mergifyio queue command
  • ❌ Checks failed · draft #1939
  • 🚫 Left the queue 14:34 · b669a89

Not proven to be this pull request's failure. It failed on top of the pull requests ahead of it, and was not tested alone.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Loop-zero Eligibility

Failing checks:

  • ❌ Loop-zero Eligibility

To get back in the queue

  • If the failure comes from the pull requests it was tested with, or is a flake, comment @mergifyio queue to queue it again as it is.
  • If it is this pull request's, push a fix: the pull request is queued again once its queue conditions match.

Merge conditions not met when it left the queue

  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-neutral = checks
    • check-skipped = checks
    • check-success = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility
    • check-success = Loop-zero Eligibility
1 merge condition met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required

Times in UTC · dashboard · how the merge queue works

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify mergify Bot added dequeued and removed queued labels Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 60c3263 at 14:42 UTC

6 min in the queue, 5 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 14:36 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1945
  • ✅ Merged 14:42 · 60c3263 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify mergify Bot removed the dequeued label Nov 26, 2026
@mergify
mergify Bot merged commit 60c3263 into main Nov 26, 2026
21 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1325-native-merge-replacement branch November 26, 2026 14:44
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.

Verify a native GitHub merge when its response is lost

2 participants