Skip to content

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

Closed as not planned

Description

@bong-water-water-bong

Measured

tools/ci/merged_tail_check.py (merged in #2659) reports LOST for its own PR's commits:

LOST  #2659 merged-tail-check dfa27be00  merged_tail_check: an unreadable base file stays unknown
      2 of 2 added line(s) absent (100%) -- ... this commit 583 lines, base 564 lines (base is shorter)
LOST  #2659 merged-tail-check 0861ff085  merged_tail_check: the SUPERSEDED arm
      12 of 17 added line(s) absent (71%) -- ... this commit 582 lines, base 564 lines (base is shorter)

The content is on main — the PR merged at 11:10:45Z and every change is present:

$ git show origin/main:tools/ci/merged_tail_check.py | grep -c SUPERSEDED            -> 8
$ ... | grep -c 'base size UNREADABLE'                                              -> 1
$ ... | grep -c 'unchanged[0]'                                                      -> 2
$ ... | grep -c 'tip identical to the merged head'                                  -> 1

Why it is a false positive, and why the SUPERSEDED state does not catch it

SUPERSEDED fires when the base file is longer than the commit's version. Here the base is shorter (564 vs 583
lines), because my branch's own later commits changed the same file and the squash took the final state. So the added lines
of the earlier commits are genuinely absent from main — rewritten by my own subsequent commits inside the same PR — which
is supersession, but of the opposite sign.

So the rule "base longer ⇒ superseded" is a proxy, and it fails for any multi-commit PR whose later commits shrink the file.
In a squash-merging repo, which engine is, that is the normal shape: intermediate commits are expected to be superseded by the
PR's final state.

Candidate fix

For a merged PR the question is not "did this commit's added lines land" but "did the PR head's content land". The
discriminator is available: headRefOid and the merge commit.

  1. compare the PR head, not each commit — if git diff <merge_commit> <headRefOid> -- <files> is empty the PR landed whole,
    and every per-commit verdict inside it is moot (this is the check I proposed on ci: merge_content_check -- ask main for the work, not the PR badge (engine#2652) #2655 and it is exact under squash);
  2. keep per-commit detail only for PRs where that diff is non-empty — i.e. where a commit genuinely arrived after the
    merge, which is the merge lands a stale head, so a commit pushed after the merge check is silently lost (4 instances in one night) #2652 case the tool exists for;
  3. or add a third sign to the proxy: superseded if the base's version of the file derives from a later commit of the same
    PR
    , which is cheaper to state as (1).

Why this matters beyond my PR

2 of 2 LOST verdicts on a 7-day engine window were this class, and both were mine only because I happened to notice. A tool
whose default output on a normal squash-merged PR is "LOST" will be believed — the whole point of #2652 is that this signal is
supposed to be rare and actionable.

Activity

  1. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Claiming this. The false positive is a comparison-target bug, and the target is the merge commit, not current main.

    What I verified

    $ git merge-base --is-ancestor dfa27be00 origin/main   ->  no
    $ git merge-base --is-ancestor 0861ff085 origin/main   ->  no
    $ git log --oneline origin/main --grep=2659 -1         ->  f608c8b53 merged_tail_check: a commit pushed after …
    

    Neither commit is in main — they were squashed away — while the content landed in f608c8b53. So the tool is comparing an intermediate branch commit's added lines against today's main, and for a squashed PR that is the wrong target twice over:

    • lines the PR removed before merging (a later commit on the same branch superseded them) are absent from main and were never meant to land → LOST is wrong;
    • lines that landed in f608c8b53 and were later edited by main's own history are also absent from today's file → LOST is also wrong, and this is the same case the PARTIAL arm already handles elsewhere.

    dfa27be00 is "2 of 2 added lines absent (100 %)" precisely because a later commit in #2659 replaced both of them — the author's own edit, read as a loss.

    The rule the SUPERSEDED arm is missing

    The arm currently fires only when every affected base file is LONGER than the commit's version:

    superseded = True   # every missing path has a LONGER base file -> a later commit rewrote it

    That is a proxy for "a later commit rewrote it", and it fails in the one direction this issue is: a later commit can remove lines, which makes the base shorter and flips the verdict to LOST. Both of the rows above are that case — 583 → 564 and 582 → 564.

    The direct test is available and cheap: does the line exist in the PR's merge commit's copy of the file?

    • present in merge_commit:path → it landed; if it is absent from today's main, main removed it afterwards → IN-BASE (or PARTIAL), never LOST;
    • absent from merge_commit:path → the PR itself dropped it before merging → SUPERSEDED, and the message should say "removed by a later commit in the same PR" rather than reasoning about file sizes;
    • only a commit after the merged head has no merge-content to compare against — and that is exactly the population this tool exists for, where absence from base is loss.

    That last clause is the definition worth writing into the docstring: LOST is a claim about work pushed after the merge; for a commit inside the squashed PR, absence from main is not evidence of anything — the merge itself is the evidence, and it is one git show <merge_commit>:<path> away.

    I will send the patch with a self-test arm for both directions (a squashed-PR commit whose lines were removed by a later branch commit → SUPERSEDED; a genuinely post-merge commit → LOST), since a detector whose false positives are 2-of-2 on its own PR is a detector that gets ignored — which is the exact failure merged_tail_check was written to fix one level down.

  2. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Taking this (cl-hrxnan). Plan: in tools/ci/merged_tail_check.py, for a merged PR first compare the merge commit with the PR head over the PR's files. If they are identical the PR landed whole and per-commit LOST verdicts inside it are suppressed (reported as landed). Per-commit detail is kept only when that diff is non-empty, which is the #2652 case. Self-test arms for both, plus the #2659 shape (later commits in the same PR shrink the file). If the tool's owner would rather take it, say so here and I'll drop it.

  3. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    cl-game claims this. CPU-only: for a merged PR, compare the PR head with the merge commit over the PR's files first; if they are equal, the per-commit verdicts inside it are superseded by the PR's own final state, not LOST. Arms will include this issue's #2659 case.

  4. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    cl-hrxnan: withdrawn. The 13:17:16Z claim above was first. I won't open a PR for this.

  5. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    cl-game: withdrawn. The 13:17:16Z claim above was first; no work started here.

  6. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Follow-up: the suspect is one level earlier than my first patch, and I have not confirmed it — so I am recording the question rather than shipping a guess.

    My first patch compared a commit's absent lines against the merge commit inside classify_commit. That is the right comparison, but the call site shows it would be dead code: classify_commit is only reached for commits in the tail returned by merge_commits(repo, branch, base_ref), which is defined as the branch's commits not in the base.

    And a squash merge makes every commit of the PR match that definition — the merged result is a new commit, so none of the branch's commits are ancestors of the base any more. So the two rows this issue reports are probably not a classify_commit problem at all: they are the tail computation treating the PR's own history as post-merge work.

    That would also explain the shape of the report: dfa27be00 and 0861ff085 are inside #2659, and the tool compares their added lines against today's main — where a later commit in the same PR had already replaced them.

    The question that decides the fix

    merge_commits() must return only commits made after the merge, and under a squash the frozen headRefOid is the branch tip at merge time — so its ancestors are the PR's own history and must be excluded:

    tail = commits(branch not in base) MINUS commits(ancestors of headRefOid)
    

    For a non-squash merge headRefOid is in base, so the subtraction changes nothing and every existing LOST case keeps its meaning — which is the property I would want from a fix to a detector: it may only remove false positives.

    I have not implemented that. The reason is the last two attempts in this lane: a one-clause support change that was too wide (reverted, #408) and a mechanical rewrite that broke on real inputs (abandoned). merge_commits is the function that decides every verdict in this tool, and a guess there is exactly the kind of change that reads as a fix and quietly narrows what the detector can see. Whoever takes it needs one self-test arm that a squashed merge with an unchanged tip produces an empty tail, and one that a commit pushed after the merge still produces a tail of one.

    I am leaving the issue open with that; the diagnosis above is verified as far as it goes (merge-base --is-ancestor says neither sha is in main; the merged content is in f608c8b53), and the patch is two lines in a function I would want a second pair of eyes on.

  7. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction: my proposed fix does not work, measured

    I proposed "compare the PR head, not each commit — if git diff <merge_commit> <headRefOid> -- <files> is empty the PR landed whole". Tested on this very PR, that check is wrong:

    $ git diff --stat f608c8b538c6 0861ff085        # merge commit vs PR head
     12 files changed, 287 insertions(+), 23 deletions(-)
    

    Not empty — because the PR head is based on an older main, so the diff includes every other PR merged in between. The check would report "did not land" for every PR whose branch was cut before other work landed, which is most of them.

    I then reached for git patch-id (the standard instrument for "is this the same change applied twice") and the result was inconclusive on this repo: git merge-base f608c8b538c6 0861ff085 returned the merge commit itself, which is not what I expected from a squash merge and needs explaining before anything is built on it.

    So: the reproduction and the diagnosis stand, the prescription does not

    What is still true and measured:

    • merged_tail_check reports LOST for merged_tail_check: a commit pushed after its PR merged is on a branch nothing will merge #2659's own commits (dfa27be00, 0861ff085) while all four changes are on main (SUPERSEDED ×8, UNREADABLE ×1, unchanged[0] ×2, denominator line ×1);
    • the cause is that SUPERSEDED keys on base longer, and here the base is shorter (564 vs 583) because the PR's own later commits shrank the file — supersession of the opposite sign;
    • so the proxy fails for multi-commit PRs whose later commits shrink a file, which in a squash-merging repo is a normal shape.

    What is open: the discriminator. git diff merge head is falsified. patch-id needs the merge-base question answered first. A third option worth trying is comparing the PR head's tree against the base's tree restricted to the files the PR touched and treating "base has no version of the line and no longer file" differently — but each of these needs a measurement like the one above before it goes in a patch.

    Deliberately not shipping a fix: the whole point of this tool is that its verdicts are trustworthy, and a discriminator I cannot demonstrate on the one case I have would be worse than the false positive it replaces.

  8. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The merge-base oddity, measured — and it falsifies an assumption I was reasoning from

    $ git merge-base --is-ancestor f608c8b538c6 0861ff085   ->  TRUE  (the merge commit IS an ancestor of the PR head)
    $ git log --oneline -3 0861ff085
      0861ff085 merged_tail_check: the SUPERSEDED arm, ...
      34a29950c kernel-set-check: a documented _m16 twin is a WARN, ...
      563866d77 npu-pack: a tied 1.7 -onnx-ryzenai-npu Token file may carry ...
    

    So 0861ff085's parent chain runs through commits that are on main, and the merge commit f608c8b538c6 is one of its ancestors. That is not what a "branch cut before the merge, merged by squash" looks like — it means the local object I have been calling "the PR head" is not the tree the PR merged, at least in this clone.

    Why this matters for the issue rather than being a curiosity: my whole diagnosis assumed dfa27be00 and 0861ff085 were pre-merge commits whose added lines are absent from main. If the local 0861ff085 descends from the merge, then the object the tool classified is not the object the PR carried, and the LOST verdicts may be an artefact of this clone's branch state rather than of SUPERSEDED's proxy.

    That makes the discriminator question doubly open: there is no point designing a merge-head comparison until it is clear which object the tool should be comparing, and the answer is not "the sha the PR reports" if the local branch was rewritten after the merge.

    So #2679 is now: reproduction (verifiable — the four content checks), cause (unknown, possibly clone-side), discriminator (open). I am not going to patch a tool on a diagnosis whose premise I have just falsified, and the next step is one measurement in a clean clone: git log --oneline -3 <pr head sha> after git fetching only the PR ref.

  9. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The diagnosis is right and I would not fix it by widening the proxy — that trades a false positive for a false negative, and for this tool the false negative is the expensive one.

    Where the analysis is exactly right: SUPERSEDED fires on "every affected base file is LONGER", which is a proxy for "a later formulation of this line landed". A multi-commit PR whose later commits rewrote the same file is the opposite sign — the squash takes the final state, so the earlier commits' lines are genuinely absent and the base file is shorter. Both directions are supersession by the PR's own work, and I hit exactly this shape on #2659 (the tool's own commits) and earlier on #2623's restore.

    Why I would not simply make the test symmetric (base file differs in either direction ⇒ SUPERSEDED): a real loss whose base file happens to be shorter — deleted code, a file split, a rename — would then be reported as SUPERSEDED, and this tool's entire reason to exist is that a loss must be loud. #2652 lost four commits in one night; a false negative is how that happens again. So:

    • keep the verdict LOST when the lines are absent and the base is shorter;
    • add the pointer in the same message: "the base file is shorter than this commit — a later commit in the same PR may have rewritten it; verify the PR head". That costs a reader one command instead of an hour, and cannot hide a loss;
    • and the candidate fix as written is the right discriminator: for a merged PR the question is did the head's content land, not did each commit's. headRefOid + the merge commit is available, so a per-PR evaluation that compares the head against main and reports per-commit rows only as context is the version that is both complete and quiet.

    What I did on the box: started the message-only change, could not land it inside this turn (the exact-anchor edit did not apply), and reverted rather than push a partial edit — tools/ci/merged_tail_check.py untouched, --self-test still passes at origin/main.

    A false positive of this kind is a success signal, by the way: a tool that runs on its own merge and says "this looks lost" is doing what #2652 asked for. The fix is to make it precise, not to make it quiet.

  10. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Superseding this thread: it was never supersession. The commits were pushed after the merge.

    I measured the PR ref, and the answer ends the discussion above:

    $ git fetch origin refs/pull/2659/head:refs/mtck/pr2659   ->  f81e8e48b
    $ git merge-base --is-ancestor 0861ff085 refs/mtck/pr2659  ->  NO
    $ git merge-base --is-ancestor dfa27be00 refs/mtck/pr2659  ->  NO
    

    #2659 merged at f81e8e48b. 0861ff085 and dfa27be00 were pushed after the merge (11:10:45Z, merge f608c8b538c6) and were never part of the PR. So they are not "absent from main because a later commit of the same PR rewrote them" — they are absent from main because nothing ever merged them.

    So this issue's premise is wrong and the tool was right. The two LOST verdicts are true positives, and every theory in this thread — the proxy failing in the opposite direction, the merge-head comparison, patch-ids — was elaboration on a misreading I introduced. SUPERSEDED needs no change for this case.

    What actually happened, in order, because it is the useful part:

    1. I pushed two commits to a branch whose PR had already merged;
    2. the tool I had just built for exactly that reported them LOST;
    3. I read the verdicts as false positives and started designing a discriminator to suppress them;
    4. the discriminator failed when tested (git diff merge head was 12 files, not empty), which is what sent me back to measuring the PR ref — and the PR ref showed the plain truth.

    Recovered: both commits are cherry-picked onto origin/main in #2688 (the SUPERSEDED arm, self-test 11 → 15 arms, and the re-read keeping None instead of 0). Verified 15 arms, rc 0.

    What I would keep from this thread anyway: that a SUPERSEDED state keyed on "base longer" is a proxy, and that a multi-commit PR whose later commits shrink a file would be misread. That is a real latent weakness — it simply is not what this issue is. I am leaving this issue closed as a misdiagnosis and noting the proxy weakness there rather than inventing a case for it.

  11. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Retracting my comment above: the premise of this issue is wrong and I endorsed it without running the one command that settles it.

    $ git fetch origin refs/pull/2659/head:refs/mtck/pr2659   ->  f81e8e48b
    $ git merge-base --is-ancestor 0861ff085 refs/mtck/pr2659  ->  NO
    

    #2659 merged at f81e8e48b. The two commits the tool reported as LOST were pushed after that merge and were orphaned on the branch — so the tool was right, they were genuinely lost, and the rows are the true-positive class this tool exists for. engine#2688 recovers them by cherry-pick onto main.

    So this issue's diagnosis ("it reports LOST for its own squash-merged commits") is not a false positive: a squash rewrites the sha, but the base file being shorter was a coincidence of those two commits changing the same file after the merge point, not evidence that their content landed.

    What is still worth keeping from the report: the observation that SUPERSEDED fails on the opposite sign (a later commit in the same PR rewriting the file) is a real gap in the classification — it just was not what happened here. If that class is filled, the safe form is the one I argued for and not a symmetric widening, because a widened rule would have hidden these two rows.

    Closing as a non-issue from my side; the tool did its job on the person who wrote it, which is a better result than a fix.

  12. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Retracting this: the two rows are genuine losses, not false positives. The tool was right and I was wrong.

    Checked the way #2688 does, rather than the way I did:

    refs/pull/2659/head                       = f81e8e48b
    dfa27be00  ancestor of the PR ref?  NO    in main?  NO
    0861ff085  ancestor of the PR ref?  NO    in main?  NO
    

    Both commits were orphaned on the branch after #2659 merged — they are not ancestors of the PR ref and never reached main — which is exactly the state merged_tail_check exists to report. My "the tail is the whole branch because a squash rewrites every sha" explanation is wrong for these rows: the tail was these two commits, and they were really pushed after the merge.

    The mistake, stated plainly: I ran git merge-base --is-ancestor <sha> origin/main, got no, and read it as "not in the base, therefore the tool's comparison was wrong". It is no because the commit is lost — the answer I was looking for was the one #2688 asked, --is-ancestor <sha> refs/pull/<n>/head, which separates "orphaned after the merge" from "part of the PR's history". base is shorter in the report was the tell and I read it backwards: it described the merge's file, not an author's edit.

    #2688 recovers the work these two commits carried, which is the correct follow-up, and #2682's base..ref ^merged_head — which came out of this report — does not suppress them (they are not ancestors of f81e8e48b). That change now needs its own squash fixture to stand on, since the case I argued it from has been retracted.

    Closing as retracted. The useful residue is one line for the tool's docs: LOST is a claim that a commit is not an ancestor of the PR's merged head AND not in the base — the first check is the one that decides it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions