Skip to content

shepherd: keep approval when a merge of main leaves the PR's own change identical (Part of #7455) - #7464

Closed
squid-protocol wants to merge 1 commit into
mainfrom
7455-keep-approval-merge-only
Closed

squid-protocol wants to merge 1 commit into
mainfrom
7455-keep-approval-merge-only

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #7455 (item 3). No workflow file changes here.

Why. A plain merge of main into an approved PR could still drop shepherd:merge, flip the PR to draft, cancel its runs and re-run everything. clean_main_merge (#4979) gave up if main and the PR touched the same file, or if main moved 300 files or more.

What. It now compares the PR's own change and ignores how much main moved. The approval carries over only when all of these hold:

  1. The new head has two parents: the approved head and a commit already on main.
  2. Against that main commit, the new head's diff (everything it adds to main, so an extra change in a merge shows up) names the same files as the approved diff.
  3. Each file has the same status, blob and patch. If main touched that file too, the new blob must be byte for byte the clean three-way merge (git merge-file on bytes read through the API, on fixed temp names; no PR code runs).
  4. Each file has the same mode (GraphQL). Compare does not show a mode change on a file the PR already changes.

Anything else drops the approval: a failed read, a file over 1 MB that needs reading, more than 20 such files, a PR of 300 files or more, a rename or add or delete in a file that moved, a patch already on main. The approval marker for the new head is still written by the bot, so each head stays bound to a marker.

Why not git patch-id --stable. It ignores whitespace and hunk position, and either can be a real change. It would also need a repo with history, and the pass only reads the API. The rule here is stricter.

Replay, with the real code against the live API. I ran clean_main_merge on the 19 merge-shaped heads among the 72 drops on the 300 newest PRs (2026-10-30..11-01). The other 53 were 52 real commits and 1 unreadable head, and neither can pass rule 1.

Drops Count Result
real commits 52 still dropped
approved head further back than a parent 7 still dropped; the patch differed in each
unreadable 1 still dropped
merge that changed the patch, nearly all conflict resolutions 9 still dropped
whole patch already on main (#7271) 1 still dropped
identical patch 2 kept (#7332, #7140)

The honest number: this saves 2 of 72 drops. It does not help the two PRs that prompted it. Both #7441 drops were conflict resolutions that changed its patch, and #7439's was a real commit, so all three are correct drops under the safety rule.

Verified. tests/tools/test_shepherd_gh.py, test_shepherd_markers_not_hand_written.py and test_workflow_draft_gate.py: 239 passed. The new tests cover: identical patch keeps (no draft flip, no cancels), one extra line, unreadable compare and file, evil merge three ways (own file, a file only main changed, inside a shared file), conflict resolution, whitespace-only, same hunk moved, mode change, unreadable mode, truncated compare. Mutation check: removing the file-set test, the blob test, the mode test or the parent test each fails tests (2, 5, 1 and 3 failures). ruff_audit --ci and mypy_audit --ci: no new findings.

Not verified. A real merge through a real pass: the workflows run main's code, so this applies only after merge. clean_main_merge itself did run against the live API, including the GraphQL mode read on #7332 and #7140. Whether a pass misreads a real carried head end to end is what the first merged PR will show.

🤖 Generated with Claude Code

…ge identical (Part of #7455)

clean_main_merge gave up when main and the PR shared a file or main moved
300 files. It now compares the PR's own change: against the main parent,
the new head names the same files as the approved diff, each with the same
mode, status, blob and patch, or (main touched it too) the exact clean
three-way merge. Anything else, or any failed read, still drops approval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol

Copy link
Copy Markdown
Owner Author

On hold for an owner decision. This widens when approval carries over, by allowing files main also touched through a three-way merge check, and it saves 2 of the 72 recent approval drops. Main's existing clean_main_merge refuses those overlaps. The new file-mode check may be worth taking on its own.

@squid-protocol

Copy link
Copy Markdown
Owner Author

Waiting on an owner decision (asked privately, 2026-11-01). Nothing is needed from contributors; work resumes once it is answered.

@squid-protocol

Copy link
Copy Markdown
Owner Author

Closed on the owner's decision. Main's clean_main_merge already keeps approval on a clean merge and refuses files both the PR and main touched. This PR would allow those overlaps, on a safety gate, to save 2 of the 72 recent approval drops. Measurement is in #7455.

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