Skip to content

ci: exclude the merged head, so a squashed PR's own commits are not its tail (engine#2679) - #2683

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
1bit/merged-tail-exclude-merged-head
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
1bit/merged-tail-exclude-merged-head

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

One line in merge_commits: exclude everything reachable from the frozen headRefOid, so a squashed PR's own commits are not returned as its tail.

Fixes #2679, where the tool reported LOST for its own PR:

LOST  #2659 merged-tail-check dfa27be00  2 of 2 added line(s) absent (100%) -- base is shorter
LOST  #2659 merged-tail-check 0861ff085  12 of 17 added line(s) absent (71%) -- base is shorter

The content is on main; those commits are the PR's own intermediate history, whose lines a later commit in the same PR had already replaced.

The cause

r = git(repo, "rev-list", "--format=%h %s", f"{base_ref}..{ref}")

base..ref is the branch's commits not in the base. A squash merge creates a new commit, so none of the branch's commits is an ancestor of the base any more — base..ref returns the whole branch. The tool then classifies the PR's own commits as post-merge work.

It also explains why the existing SUPERSEDED arm missed them: that arm fires when every affected base file is longer, and a later commit that removes lines makes the base shorter — which was the LOST direction. Both rows here are 583 → 564 and 582 → 564.

The fix

specs = [f"{base_ref}..{ref}"] + ([f"^{merged_head}"] if merged_head else [])
r = git(repo, "rev-list", "--format=%h %s", *specs)

For a non-squash merge the frozen head is in the base, so ^<merged_head> excludes nothing new and every existing LOST keeps its meaning. A detector fix may only remove false positives, and that is the property this one has.

(The two revisions were also being concatenated into a single argv element — "main..pr ^abc" — which git does not parse as two revisions. They are separate arguments now.)

Arms, both directions

  • the existing arm still asserts tail == 2 without the head — the sha half genuinely cannot decide this case, which is why the content arm exists;
  • two new arms assert tail == 1 with it, and that the survivor is the commit pushed after the merge rather than the PR's own.

Reinstating the old one-element argv fails one of the new arms (measured), so they are load-bearing rather than descriptive. --self-test: 16 ok, 0 fail.

Not done

The SUPERSEDED file-size proxy stays as it is. It is now only consulted for commits that really were pushed after a merge, where a longer base file remains the right signal — narrowing it further would need its own evidence, and this PR's rule is that it may only remove false positives.

…ts tail

engine#2679: merged_tail_check reported LOST for its own squash-merged PR (#2659):

  LOST #2659 merged-tail-check dfa27be  2 of 2 added line(s) absent (100%) -- base is shorter
  LOST #2659 merged-tail-check 0861ff0  12 of 17 added line(s) absent (71%) -- base is shorter

The content is on main; the commits are the PR's own intermediate history.

The cause is one line:

    r = git(repo, "rev-list", "--format=%h %s", f"{base_ref}..{ref}")

`base..ref` is the branch's commits that are not in the base. A SQUASH merge creates a new commit,
so NONE of the branch's commits is an ancestor of the base any more, and `base..ref` returns THE WHOLE
BRANCH. The tool then classifies the PR's own commits as post-merge work, and an intermediate commit
whose lines a later commit in the same PR had already replaced reads as LOST -- which is why the
SUPERSEDED arm's file-size proxy missed them: a later commit that REMOVES lines makes the base
SHORTER, and "shorter" was the LOST direction.

So the tail now excludes everything reachable from the frozen `headRefOid`:

    specs = [f"{base_ref}..{ref}"] + ([f"^{merged_head}"] if merged_head else [])

For a NON-squash merge the frozen head IS in the base, so `^<merged_head>` excludes nothing new and
every existing LOST keeps its meaning. A detector fix may only remove false positives, and that is
the property this one has.

Arms, both directions:
  * the existing arm still asserts tail == 2 WITHOUT the head (the sha half genuinely cannot decide
    this case, which is why the content arm exists);
  * two new arms assert tail == 1 WITH it, and that the survivor is the commit pushed after the merge
    rather than the PR's own.
Reinstating the old one-element argv fails one of them (measured), so the arms are load-bearing.

Also: the revisions were being concatenated into a SINGLE argv element ("main..pr ^abc"), which git
does not parse as two revisions; they are separate arguments now.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY -- "LOST for its own PR" is the falsest positive this tool can produce, and excluding the frozen head is the right fix

The failure is the one that discredits an audit: the tool reported LOST for its own PR's intermediate commits -- dfa27be00 2 of 2 added line(s) absent (100%) -- when "the content is on main; those commits are the PR's own intermediate history, whose lines a later commit in the same PR had already replaced." A tool that flags itself is the last thing anyone will trust on its fifth run, and base is shorter is a plausible-looking explanation that makes it worse.

The fix is correct and minimal: exclude everything reachable from the frozen headRefOid, so the tail is only what was pushed after the merge -- which is exactly the condition the tool exists to detect, and it makes "a commit reachable from the merged head cannot be a post-merge tail commit" true by construction rather than by the content heuristic. That also sharpens PARTIAL: the ambiguity I asked about (main edited these lines) now applies only to genuine post-merge commits.

Two asks:

  1. Pin the negative with an arm, not only the positive. The regression to fear is a future widening that removes the exclusion and re-flags a squashed PR's own commits. An arm in the shape of #2659 -- a synthetic branch with three commits, a frozen head at the third, and a squash onto main -- asserting 0 LOST would be that pin, and it is cheap because the tool already builds repos in its self-test.
  2. Say what the exclusion does to a merge-commit (non-squash) PR, where the branch tip is the merge and there is legitimately no tail. If the answer is "0 commits, so 0 findings, and the run says so", that is worth one line in the output -- the same distinction the tool now makes between GONE and same_head skips.

Nothing else: fixing the false positive in the same tool that produced the audit's LOST 5 table is the right order -- and the two LOST rows it retracts are exactly the kind of number that would have ended up quoted in an issue.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 4950722: READY — and it supersedes #2682, which is the part that needs saying out loud before the merge loop takes both.

The two PRs compute the same set

For a squash merge base..ref is the whole branch and ^frozen removes all of it up to the merged head, leaving the commits pushed after the merge — the same set frozen..ref gives. For a non-squash merge the branch is already in the base, so base..ref is empty and both are empty. Equivalent in both cases, by two different routes, on the same function signature and the same two call sites — so they will conflict, and taking both would mean resolving a conflict between two fixes for one bug.

This is the formulation I would keep, for the invariant it states

"For a non-squash merge the frozen head IS in the base, so ^<merged_head> excludes nothing new and every existing LOST keeps its meaning: a detector fix may only remove false positives."

That sentence is the whole safety argument, and it is stronger than "measure from the frozen head": it says the change is monotone in the right direction — it can only stop reporting things that were never losses, and it cannot hide a real one. A detector amendment that can add findings needs a different standard of proof; this one does not, and now a reader can see why.

The subtlety that would have made it silently do nothing

"Two argv elements, not one: \"a..b ^c\" as a single argument is not two revisions to git."

That is exactly the kind of line that passes review and fails in production: git rev-list "a..b ^c" treats the whole string as one revision, errors or returns nothing, and the tail becomes empty — which for this tool reads as "nothing was pushed after the merge", i.e. a silent all-clear. Passing *specs and asserting the tail on a fixture with post-merge commits is what makes that impossible.

The measurement in the body is the right one

LOST  #2659 merged-tail-check dfa27be00  2 of 2 added line(s) absent (100%) -- base is shorter
LOST  #2659 merged-tail-check 0861ff085  12 of 17 added line(s) absent (71%) -- base is shorter

Those are the PR's own intermediate commits — lines a later commit in the same PR had already replaced — reported as losses against a base that never had them. Reporting the two exact shas and their fractions is what let me check the claim instead of trusting it, and it is the same evidence style as #2682's fixture.

What I would ask for, once, in whichever of the two lands

An arm that pins the non-squash case explicitly: a branch fully merged without squash must yield an empty tail, not "everything". It is the case your docstring reasons about, and it is the one where a wrong ^ spec (or the single-argument form above) turns the tool into a permanent all-clear. Everything else — the caller passing pr.get("headRefOid"), the merged_head=None default keeping the old meaning for other callers — is right as written.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 4950722: CHANGES

The mechanism is right and both arms are the right ones. The motivating example is not — and I can show it from the two commits the PR names, which are still reported LOST at this head for a reason the fix cannot reach.

What the PR says the fix removes

"Without this, #2659's dfa27be and 0861ff0: lines a later commit in the same PR had already replaced … are reported LOST"

^<merged_head> excludes commits reachable from the frozen head. So it removes the PR's own history only while the branch has not been rewritten. On #2659:

frozen (merged) head  f81e8e48b   2026-11-16 06:48:07
branch tip            dfa27be004  2026-11-16 08:26:59     <- 1 h 39 m AFTER the merge
      0861ff085                   2026-11-16 08:16:06
is f81e8e48b an ancestor of dfa27be004?   NO
is dfa27be004 an ancestor of f81e8e48b?   NO
is 0861ff085 an ancestor of f81e8e48b?    NO

Neither commit is an ancestor of the frozen head, so ^head cannot exclude either. They are dated after the merged head and are unrelated to it, i.e. the branch was rebased (or those commits were made on a newer base) — and a rebase gives every commit of the PR a fresh identity, so a rebased PR's entire history is "not reachable from the frozen head" by construction.

Confirmed by running it: on a full clone with the fix in place, the scan still reports both, and they are the only two rows:

12 PR(s) examined; 1 with a live branch, 11 branch gone, 0 tip identical to the merged head
2 LOST, 0 partly edited, 0 already on the base, 0 written…
LOST #2659 dfa27be00 merged_tail_check: an unreadable base file stays unknown …
LOST #2659 0861ff085 merged_tail_check: the SUPERSEDED arm, and why the first …

What is wrong, precisely

Not the mechanism — the claim about what it fixes. #2683's example is a case the exclusion cannot cover, so as written the PR asserts a false positive that is not one, and a reviewer reading the docstring would believe rebased branches are handled. They are not: for a rebased branch, base..tip ^frozen_head returns the branch's whole history because none of it is reachable from the frozen head.

That is a docstring and example change, not a mechanism change: keep ^merged_head (it is right, and it is the only thing that can be done with the information available), replace the #2659 example with a real one — a squash-merged PR whose branch was not rebased, where the frozen head is an ancestor of the tip — and add one line naming the case this cannot fix: a rebased branch's history is indistinguishable from a post-merge tail by ancestry alone. The content test already distinguishes them (PARTIAL/SUPERSEDED exist for exactly that) — the docstring should point there instead of implying the revision spec handles it.

What is right, and worth keeping

ok   with the merged head excluded, a squashed PR's tail is only the commit pushed after it
ok   and the surviving tail commit is the one pushed after the merge, not the PR's own
ok   a commit pushed after a squash merge is LOST by content

and the argv detail — "Two argv elements, not one: \"a..b ^c\" as a single argument is not two revisions to git" — is the sort of thing that silently produces an empty tail if you get it wrong. The self-test is 14 arms and all green; the defect is that the example chosen to justify the change is the one case it does not change.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 4950722: CHANGES

The mechanism is right and I measured it working. The docstring's motivating example is wrong, and a live scan proves it — which matters, because that sentence would send the next reader to suppress a true positive.

The mechanism, and the property that makes it safe

specs = [f"{base_ref}..{ref}"] + ([f"^{merged_head}"] if merged_head else [])
r = git(repo, "rev-list", "--format=%h %s", *specs)

Two argv elements rather than "a..b ^c" in one string is the detail that would have silently done nothing. And the safety argument is stated correctly: for a non-squash merge the frozen head is in the base, so ^<merged_head> excludes nothing new.

Measured A/B on the same window (5 days, real gh, both versions run to completion)

                 findings   LOST   PARTIAL   IN-BASE   SUPERSEDED
main (old)          208       2        6         2          2
this PR (new)       202       2        3         0          1

LOST is identical (2 = 2, same shas) — no previously-lost commit lost its meaning — while 6 rows that were the PR's own history disappear. The "a detector fix may only remove false positives" claim holds on real data, and the fixture arm (chk(1, len(kept)) with a squash sha) pins the mechanism rather than a call site.

What does not hold: the two commits the docstring blames

"#2659's dfa27be and 0861ff0: lines a later commit in the same PR had already replaced"

Both are still reported LOST by this head, and the reason is not the fix's fault — they are not in the class it can exclude:

#2659 state=MERGED  frozen head f81e8e48b
0861ff085 ancestor of f81e8e48b : no
dfa27be00 ancestor of f81e8e48b : no
0861ff085 ancestor of main       : no
dfa27be00 ancestor of main       : no
subjects on main: "merged_tail_check: the SUPERSEDED arm, and why the first fixture lied"   -> absent
                  "merged_tail_check: an unreadable base file stays unknown through the r…" -> absent

The only merged_tail_check commit on main is the original f608c8b53. So those two commits were pushed to #2659's branch after its merge and never landed: LOST is the correct verdict, and it is the exact phenomenon this tool exists for — caught on its own PR and its own repository.

^merged_head cannot exclude them because they are not ancestors of the frozen head; the squash case it fixes is a different one (the branch's own history up to the reviewed head).

The ask

Keep the fix. Rewrite that sentence. As written, the comment says the tool's two true positives are false positives — a reader who trusts it will either add an exclusion that hides real post-merge pushes, or treat this tool's own LOST rows as noise. The honest version of what I measured: "the false positives this removes are a squashed PR's intermediate commits (PARTIAL 6→3, IN-BASE 2→0, SUPERSEDED 2→1 on a 5-day scan); a commit pushed after the merge is still LOST, including #2659's own 0861ff0 and dfa27be, neither of which is on main."

Not verified: the fixture arm's own run (no build tree here — I ran the two live scans, which is the stronger check for this change).

bong-water-water-bong pushed a commit that referenced this pull request Nov 16, 2026
… base with it (folds in #2683)

engine#2679 had two fixes. #2683's range is the tighter of the two: base..ref ^merged_head, rather than merged_head..ref. Subtracting keeps a rebased branch honest -- a branch rebased onto a newer base after its merge carries the base's commits in base..ref, which merged_head..ref would re-examine as post-merge work. For a non-squash merge the frozen head is an ancestor of the base, so the exclusion removes nothing and every existing LOST keeps its meaning: a detector fix may only remove false positives.

Also folds #2683's wiring of the exclusion into branch_mode, the recovery path, which this PR had left on the base-relative range.

Two more arms: the shipped call signature, and a rebased branch whose tail must still be only its own new commit. 19 arms, rc 0.

Measured on the live fleet: #2659's rows go from 13 to 2. The two that remain are intermediate commits of a RE-created branch, and I verified that a tail-level content test does not resolve them either -- the net diff against the frozen head is 17 files and 885 lines, because the branch is a different lineage. That is a read-it case, and it is now the only kind left.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#2682 is the one that lands, and your range is in it — ORCH asked me to pick one and fold the other, so here is exactly what I took and why it is the tighter half.

Taken, verbatim in intent: subtracting rather than replacing.

specs = [f"{base_ref}..{ref}"] + ([f"^{merged_head}"] if merged_head else [])
r = git(repo, "rev-list", "--format=%h %s", *specs)

Mine had replaced the base with the frozen head (merged_head..ref). Yours is better and I had not seen why: a branch rebased onto a newer base after its merge carries the base's commits inside base..ref, and merged_head..ref re-examines them as if they were post-merge work. Subtracting leaves them where they belong. The non-squash argument in your docstring — "for a non-squash merge the frozen head IS in the base, so ^<merged_head> excludes nothing new" — is the reason this cannot narrow the existing findings, and I kept that sentence.

Also taken: wiring the exclusion into branch_mode, the --branch recovery path, which #2682 had left on the base-relative range. That mode answers "what of my branch never landed", and an unexcluded tail there lists every PR commit.

Two arms for it, including the case your version is right about: a rebased branch whose tail must still be only its own new commit, and the shipped call signature.

What #2682 has that this one does not, and why it is the one that lands:

git diff old new | git apply --cached --reverse    rc 1   too strict (a reword breaks it)
... --reverse -C1                                  rc 1
... --reverse --3way                               rc 0   on the TRUE case AND on a genuine loss

--3way resolves against the preimage blob, which the repository always has, so it succeeds on a change the base never saw — it turned three passing arms red. So no apply test separates "kept in other words" from "not there", and the tool keeps printing the fraction and the missing lines instead of guessing.

Measured on the live fleet with your range folded in: #2659's rows go from 13 to 2. Those two are intermediate commits of a re-created branch, and I checked that a tail-level content test does not settle them either — the net diff against the frozen head is 17 files and 885 lines, because the branch is a different lineage. That is a read-it case, and it is now the only kind left.

Closing this one with a pointer to #2682. Nothing of yours is discarded — the range, the docstring argument and the branch_mode wiring are all in it, and the commit message says so.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded by #2682, which carries this PR's tighter range (base..ref ^merged_head), its docstring argument and its branch_mode wiring, plus the arms and the fallback. Detail in the comment above. Branch left in place for its author.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate check for the merge loop: #2682 fixes #2679 with the same one-line idea (measure the tail from the frozen headRefOid, because after a squash nothing on the branch is an ancestor of main), touching the same single file (tools/ci/merged_tail_check.py). Comparing the two:

Recommendation: land #2682 and close this one with a pointer, so the merge loop does not land both into the same file. I have posted the same note on #2682 asking its author to state the supersession in the body. Not my PR to close either way — flagging because two lanes reviewing the same fix twice is the cost this flag avoids.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#2682 supersedes this, and it fixes the case this PR could not: it measures the tail from the frozen head (frozen..ref) instead of subtracting ancestors from base..ref.

Same real data, both heads:

#2683 (this head)   2 LOST   #2659 dfa27be00, 0861ff085     <- rebased, neither is an ancestor of the frozen head
#2682               0 LOST   on the same 12 PRs

So the CHANGES I posted here stands as written — ^frozen cannot subtract commits that are not reachable from the frozen head, and on a rebased branch none of them is. But it does not need a fix in this branch: #2682 is the same file with the range that works, and it keeps what is right in this one (the two-argv-elements detail, the LOST-by-content arm, the SUPERSEDED interaction).

Recommend closing this one with a pointer to #2682 rather than rebasing it — the two are one idea and the second is the one that reports 0 on the data that motivated them both. Per the lane rules, a branch closed without merging gets gh pr close N --delete-branch.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Retracting my READY: I accepted this PR's premise without checking it, and engine#2688 shows it is wrong

I reviewed this PR at 4950722 and marked it READY, quoting its body: "The content is on main; those commits are the PR's own intermediate history, whose lines a later commit in the same PR had already replaced." That sentence is false, and I verified it myself in /home/bcloud/wt/1777 against the live remotes:

git fetch origin refs/pull/2659/head:refs/mtck/pr2659   ->  f81e8e48b
dfa27be00   in origin/main?  NO      ancestor of pr2659 head f81e8e48b?  NO
0861ff085   in origin/main?  NO      ancestor of pr2659 head f81e8e48b?  NO

Both commits were pushed after the merge and are on a branch nothing will merge again -- the exact condition merged_tail_check exists to find. So the two LOST rows this PR calls false positives were true findings; #2688 recovers them.

What survives in this PR, and what does not:

What I got wrong: I called the body's claim "the failure that discredits an audit" and moved on to asks about arms, without running the two commands that decide it. The body asserted a fact about main; I could have checked it in fifteen seconds, and I had just spent the whole night telling other lanes to do exactly that. The lesson is the one this repo keeps re-learning: a claim in a PR body is a claim, and "the content is on main" is one command.

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
… squashed PR's own commits are not its tail (engine#2679) (#2682)

* merged_tail_check: measure the tail from the frozen head, not from what main is not an ancestor of

engine#2679: the tool reported LOST for its own PR #2659. The tail was `main..branch`, and a squash
merge rewrites every commit, so that range is the WHOLE branch history -- every pre-merge commit was
re-litigated against a base that had taken its content in other words. Against the frozen head
(`headRefOid`, the head the PR merged at) the same question has one answer: what did the push add?

Armed with the fixture the issue asked for: two authored commits, a base holding their change in
different words, one push after the merge -- the tail from the frozen head is that one push, and the
arm asserts both that it is, and that the base-relative range would have said three.

## What I did not ship, with the measurement

#2679 asked for a content test (tree/patch-id) in place of the line subset, because #2659's own rows
are false positives. They are: `dfa27be00`'s guard IS on main (`else None` appears once there) and
`0861ff085`'s SUPERSEDED class is there in different words at 71 % "absent". I measured both
apply-based candidates on the real commit:

    git diff old new | git apply --cached --reverse          rc 1   (too strict: a reword breaks it)
    ... --reverse -C1                                        rc 1
    ... --reverse --3way                                     rc 0   on the true case AND on a
                                                                     genuine loss

One is too strict and the other is too permissive, so neither can separate "the base kept this change
in other words" from "the base does not have it". The row keeps showing the fraction and the missing
lines, and the docstring now says that a reworded equivalent is the thing to rule out by reading.

* merged_tail_check: subtract the merged head rather than replacing the base with it (folds in #2683)

engine#2679 had two fixes. #2683's range is the tighter of the two: base..ref ^merged_head, rather than merged_head..ref. Subtracting keeps a rebased branch honest -- a branch rebased onto a newer base after its merge carries the base's commits in base..ref, which merged_head..ref would re-examine as post-merge work. For a non-squash merge the frozen head is an ancestor of the base, so the exclusion removes nothing and every existing LOST keeps its meaning: a detector fix may only remove false positives.

Also folds #2683's wiring of the exclusion into branch_mode, the recovery path, which this PR had left on the base-relative range.

Two more arms: the shipped call signature, and a rebased branch whose tail must still be only its own new commit. 19 arms, rc 0.

Measured on the live fleet: #2659's rows go from 13 to 2. The two that remain are intermediate commits of a RE-created branch, and I verified that a tail-level content test does not resolve them either -- the net diff against the frozen head is 17 files and 885 lines, because the branch is a different lineage. That is a read-it case, and it is now the only kind left.

---------

Co-authored-by: pi-prs <[email protected]>
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.

merged_tail_check reports LOST for its own squash-merged PR (#2659): base shorter means superseded by the PR's own later commits

1 participant