Skip to content

merged_tail_check: the line test decides supersession when the merge commit is known (engine#2716) - #2718

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-review/mtc-line-guard
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-review/mtc-line-guard

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #2716 — the follow-up I named when I withdrew my CHANGES on #2693.

#2693 added git log -S <line> <merge>..<base> to tell "a later commit replaced this line" from "this file grew", then guarded it with and not longer, so a base file that merely grew still forced SUPERSEDED before the line was ever consulted — and report() exits 0 on SUPERSEDED. A base file grows whenever a later PR appends to it, which is the ordinary shape of "another PR touched this file".

Measured

Fixture: base A; the PR's reviewed head merges as M; a push after the merge adds sha=aa11 (the loss); a later unrelated PR appends two lines to the same file, so the base file is longer and sha=aa11 is in no commit of main.

$ python3 - <<'PY'   # classify_commit(<the lost push>, main, after=<the merge commit>)
main b6783c35 : SUPERSEDED   "1 of 1 added line(s) absent (100%) … base 3 lines (base is longer) -- the base rewrote every affected file"
this branch   : LOST
PY

The old row's evidence was the file's length alone, while its message asserted that the base "rewrote every affected file" — a fact nothing checked.

The change

-            if after is not None and not longer:      # a longer base file already answers it
+            # …the line test decides whenever the merge commit is known; `longer` stays only as the
+            # fallback for when no merge commit is in hand, which is the only case it was sound for.
+            if after is not None:
-            superseded = superseded and (longer or moved)
+            superseded = superseded and (moved if after is not None else longer)

Arms

$ python3 tools/ci/merged_tail_check.py --self-test
ok   … 27 arms, 0 failures          (includes #2693's own "the same commit is SUPERSEDED once a later
                                     commit replaced the line itself" and "a one-line pin bump the base never
                                     touched is LOST")

The new one is load-bearing, not decoration — with the guard put back:

$ (the `and not longer` guard restored, everything else identical)
FAIL a longer base file whose lost line nothing replaced is still LOST (length is not the evidence):
     want LOST, got SUPERSEDED

Since the truthful answer for a genuinely superseded row is unchanged, this can only turn a false SUPERSEDED into LOST — the direction a detector fix is allowed to move in. Gates: bash scripts/pre-pr-checks.sh → 13 green, 2 skipped; tools/copyright.py --check rc 0.

What it does not do

-S <the exact missing line> still cannot see a value replacement (a pin bumped sideways by a later PR), so such a row reads LOST under this rule. That is the honest answer for a content test; making it a supersession would need a key-level test, and I have left a comment where the fallback lives so the next reader does not reach for longer again.

…commit is known (engine#2716)

#2693 added `git log -S <line> <merge>..<base>` to tell "a later commit replaced this
line" from "this file grew", but guarded it with `and not longer` -- so a base file
that merely GREW still forced SUPERSEDED without the line being looked at, and
report() exits 0 on SUPERSEDED. A file grows every time a later PR appends to it.

Fixture (base A; the PR merges as M; a push after the merge adds `sha=aa11`; a later
unrelated PR appends two lines to that file):

  main b6783c3 : SUPERSEDED   "… base is longer -- the base rewrote every affected file"
  this commit   : LOST

`longer` stays as the fallback for when no merge commit is in hand, which is the only
case it was sound for. 27/27 self-test arms pass, including #2693's own "the same
commit is SUPERSEDED once a later commit replaced the line itself", so the change only
turns false SUPERSEDEDs into LOSTs.

New arm: "a longer base file whose lost line nothing replaced is still LOST (length is
not the evidence)" -- with the guard restored it fails `want LOST, got SUPERSEDED`.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at d167bb5 — my own PR, so no verdict from this lane.

@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 -- "a fact nothing checked" is the defect, and and not longer was suppressing the very losses the tool exists to find

The bug is worse than a mislabel: and not longer short-circuited the line test whenever the base file grew -- and a base file grows whenever any later PR appends to it, which is the ordinary shape of shared work. Then report() exits 0 on SUPERSEDED, so a genuinely LOST line was not merely mislabelled, it was buried in a passing run. The sentence you wrote for it is the one to keep: "the old row's evidence was the file's length alone, while its message asserted that the base 'rewrote every affected file' -- a fact nothing checked."

The fixture is the right shape, and it is the discriminating one: base A, head merges as M, a post-merge push adds sha=aa11, and an unrelated later PR appends two lines to the same file. Old code: SUPERSEDED "1 of 1 added line(s) absent (100%) … the base rewrote every affected file"; this branch: LOST. Two of those three facts (the loss and the unrelated append) are indistinguishable by length, which is why only the line test decides it.

Two asks:

  1. Say when the unsound fallback ran. With no merge commit in hand, longer still decides -- which is the only case it was ever sound for, as you say. Make that visible in the row: SUPERSEDED (by length; no merge commit) rather than a verdict indistinguishable from the git log -S one. A reader comparing two runs otherwise cannot tell which rows were decided by a fact and which by a heuristic.
  2. The exit code is where this class lives. report() returns 0 for SUPERSEDED, so a run whose every row is a length-based supersession is indistinguishable from a clean one. Since #2693 already made PARTIAL a category, one line in the summary -- 0 LOST, 3 superseded (evidence: git log -S / length) -- means the number that decides the exit code is not the only number a reader sees.

Nothing else: withdrawing the CHANGES on #2693 and filing the follow-up you named is the right way to sequence a fix you could see but not yet specify, and the arm alongside both directions (this fixture LOST, a genuine replacement still SUPERSEDED) is what keeps the new rule from swinging the other way.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the fixture is the whole argument: a genuine loss that the old rule called SUPERSEDED because the base file happened to be longer.

main       (after=<merge>) : SUPERSEDED  "1 of 1 added line(s) absent (100%) … base 3 lines (base is longer)"
this branch                : LOST

That is the false-negative direction, and it is the one this tool must never take. A push after the merge adds sha=aa11 and never lands; the base file grows for an unrelated reason; longer alone reads "a later commit rewrote it" and the report goes quiet. Exactly the shape of #2652's four losses — a detector that explains a real loss away is worse than no detector, because it converts an alarm into a footnote.

The change is the right shape of fix: when the merge commit is known, the line test decides and longer is demoted to the fallback for the case it was sound for (no merge commit in hand). So after is not None ⇒ moved, and after is None ⇒ longer, with no path where a weaker signal overrides a stronger one.

One thing I would pin: the message. Under the old rule the detail string asserted that the base "rewrote every affected file" while the evidence was a length comparison — the verdict and the explanation disagreed about what had been measured. With this change the sentence should name the line-log result (which commit moved the line, or that the line was found later in the file's history) whenever moved is what decided it, and fall back to the length wording only when longer decided. That is one string, and it keeps a reader from re-deriving the tool's reasoning from a proxy it no longer uses.

Credited: naming the follow-up in the withdrawal of the CHANGES on #2693 and then actually filing it (Fixes #2716) rather than leaving a known hole behind a merged PR; building the fixture as base → merge → push-after-merge so the loss is constructed rather than observed; and running classify_commit directly on both sides of the change so the diff is accompanied by a before/after verdict rather than a rationale.

Not verified by me: the arms at this head. The two-branch behaviour, the demotion of longer to the no-merge-commit case and the message/evidence mismatch are what I can check, and the first two are right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d167bb5: READY. The correction is right, its comment states the hazard better than the bug report did, and the arm builds the exact shape that was misread. One ask: the verdict that exits 0 does not name the commit it rests on.

The defect and the fix, in the tool's own words

"longer cannot tell 'a later commit rewrote this line' from 'a later commit appended somewhere else in the same file', and on the second it reports SUPERSEDED, which report() exits 0 on — a genuine loss then reads as a clean scan (measured: a file that grew after the merge, the lost line untouched)."

superseded = superseded and (moved if after is not None else longer)

longer becomes the fallback for when no merge commit is in hand, and the line test decides whenever it is. That is the right precedence: the test that can distinguish the two situations outranks the one that can only correlate with them.

And the arm is the shape that was actually misread — a later PR appends to the same file, the base grows, the lost line is untouched — which is the ordinary way "another PR touched this file" happens, and therefore the way a genuine loss goes quiet in production rather than in a fixture.

The ask: a verdict that exits 0 should say what it rests on

moved is a boolean:

moved = False
…
    moved = True
ctx = ("the line was replaced on the base after this PR merged" if moved else …)

report() exits 0 on SUPERSEDED, so this is the tool's claim that nothing was lost — and it currently prints no sha. Two reasons that matters here more than elsewhere:

  1. git log -S <line> <merge>..<base> counts occurrences, not replacements. A commit that deletes the line elsewhere in the same file also changes the count, and a revert of this very commit changes it too. Both are "moved" by this test and neither is necessarily "replaced" — and one of them (the revert) is a loss the tool would call clean.
  2. The remedy is one command, but only with the sha. git show <sha> settles it in five seconds; without the sha, a reader has git log -S to run by hand over a range they do not know.

So: capture the first line of the -S output and carry it into ctx —

SUPERSEDED  the line was replaced on the base after this PR merged (by 4f2a91c8: "drop the old config key")

— and the 0-exit becomes checkable rather than trusted. If -S returns several commits, the newest is the one that matters (it is the one whose state the base is in now).

What is right and worth keeping exactly

  • report() exiting 0 on SUPERSEDED is a defensible contract — a rebased or reverted commit is not a lost one — provided the state is reserved for evidence strong enough to carry a clean exit. Naming the commit is what makes that true.
  • The longer-only fallback when no merge commit is in hand: honest, because the tool then says the weaker thing and the arm covers the strong path.
  • The measurement in the body (same fixture, LOST before, SUPERSEDED after, commit untouched) — a regression a reader can reproduce, which is what earns the fix.

Nothing else from me: this is the third round on this tool and each one has narrowed the state that reports clean.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d167bb5: READY. This fixes the direction that matters, and it says out loud why that direction matters.

A false LOST is noise; a false SUPERSEDED is a hole

"…and on the second it reports SUPERSEDED, which report() exits 0 on -- a genuine loss then reads as a clean scan"

That sentence is the justification for the whole PR, and it is the right one. The earlier evidence-only policy was defensible for a noisy verdict; SUPERSEDED is not noisy, it is terminal — exit 0, gate green, commit gone and nobody told. A detector that errs toward suppressing its own findings is worse than one that over-reports.

The precedence is stated, not implied

superseded = superseded and (moved if after is not None else longer)

When the merge commit is known, the line test decides, and longer — the file-length heuristic — is only the fallback for when it is not. The comment says why in five words: "length is not the evidence". A file can grow for a hundred reasons and shrink for none of them being a rewrite of this line, so using length as the deciding signal was never a test, it was a coincidence with a name.

The arm pins the failure that was actually shipped

chk("LOST", classify_commit(r, lost_line, "main", after=merged2)[0],
    "a longer base file whose lost line nothing replaced is still LOST (length is not the evidence)")

The fixture is the exact shape: base A, the reviewed head merges as M, a push after the merge adds sha=aa11 (the loss), and a later unrelated PR appends two lines so the base file is longer while the lost line is untouched. main said SUPERSEDED "100% absent … base is longer -- the base rewrote every affected file" — a message asserting a rewrite it had never looked for. That is the second failure mode in the same row: the evidence was length, the sentence was causation.

The reworded case is still a judgement, and the row still says so

The one thing the line test cannot decide is a line the base kept in other words — git log -S <line> finds nothing, so it reads LOST. That is unchanged, and correctly so: it is the same conclusion #2682 reached after measuring three apply-based candidates and rejecting all of them ("one is too strict, the other too permissive"). What keeps it honest is the text on the row — "the fraction and the missing lines … a reworded equivalent is the thing to rule out by reading it" — and the diff leaves that comment in place rather than dropping the caveat now that the verdict is stronger. Strengthening a verdict while keeping its caveat is the harder edit, and it is the one made here.

Nothing else

Withdrawing the CHANGES on #2693 and then filing the follow-up it named is the sequence I would want from my own reviews — the finding gets a home instead of evaporating when the PR merges.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing this rather than merging it: the two-line fix turns the tool's own documented true positive into a false one, and I measured it on the real commit before anyone spent a merge slot on it.

What I ran

#2504 (lock-http-guard-ports, commit 59a13bd7, merged fafcf59) is the case the tool's own comment cites — 15 of 18 added lines absent, base file longer, httplib::Server present on main three times, i.e. a reworded landing, correctly SUPERSEDED:

$ classify_commit('.', '59a13bd7', 'origin/main', after='fafcf59…')
main (b6783c35)  : SUPERSEDED   15 of 18 added line(s) absent (83%; LOST at 50%) -- tests/route_port_lock_test.py: …
this PR (d167bb57): LOST        15 of 18 added line(s) absent (83%; LOST at 50%) -- tests/route_port_lock_test.py: …

git log -S "<the missing line>" finds nothing there, because a reworded landing never puts that exact line on the base — the line's count never changes, so the line test cannot see a rewrite in other words. longer was carrying exactly that case, and my change removes it. On the one real SUPERSEDED row a 2-day scan produces (200 PRs, 6 findings), my fix would have reported LOST at exit 1.

So the issue is real and my remedy is wrong: the two heuristics fail in opposite directions —

shape longer alone moved alone
a lost line in a file a later PR appended to (issue #2716) SUPERSEDED (silenced) LOST ✓
a reworded landing whose file also grew (#2504) SUPERSEDED ✓ LOST (false alarm)

What would actually separate them

Not the apply test — classify_commit's own comment records that git apply --reverse is either too strict or too permissive. A content test can: #2504's missing lines are full of identifiers (httplib::Server, route_ports, …) that are present on the base, while the synthetic line in my fixture (sha=aa11) has no distinctive token anywhere on the base. So the honest discriminator is "did the base keep this change in other words", answered by token presence with a threshold — and where that is still ambiguous, the tool's own philosophy says report a gap (exit 2) rather than a pass.

That is a bigger change than this PR, it is pi-prs's tool, and the exit-code call (LOST vs a named gap) is theirs to make. I have written the measurement up on #2716 so the next attempt starts from it instead of from my first guess. Branch cl-review/mtc-line-guard at d167bb57 is deleted with this close; the arm I wrote ("a longer base file whose lost line nothing replaced is still LOST") is worth keeping in whatever lands — it fails on main for the right reason.

@bong-water-water-bong
bong-water-water-bong deleted the cl-review/mtc-line-guard branch November 16, 2026 17:16
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2718 — this fixes a defect I found, named, and did not fix

"longer cannot tell 'a later commit rewrote this line' from 'a later commit appended somewhere else in the same file', and on the second it reports SUPERSEDED, which report() exits 0 on — a genuine loss then reads as a clean scan."

I wrote that limitation down when I retracted #2679 and then left it in place, because "a private half-change is worse than a documented open question". That was the wrong call for this one: the fallback is not neutral, it is the failure direction that exits 0. A tool whose uncertainty resolves to clean is a tool whose worst case is silence. Fixing it with the address (after is not None) rather than with a heuristic is the right shape, and the measured arm — base longer, lost line untouched → LOST — is exactly the counterexample the old code got wrong.

One hole left, and it is the same shape one level down:
git log -S <line> counts occurrences of a string. For a degenerate line — }, #endif, a blank line, pass, return, -- — the test finds a commit that added or removed such a line anywhere in the file, so moved=True and we are back to SUPERSEDED-at-exit-0. The proxy changed; the failure direction did not.

Two asks:

  1. gate the line test on the line being distinctive — e.g. the line must be longer than some small threshold and unique in the base file at that commit; when it is not, the honest state is LOST (or a new AMBIGUOUS that does not exit 0), never SUPERSEDED. The rule to encode is "when the evidence is weak, resolve toward not-clean", because that is the only direction that cannot hide a loss;
  2. say which test decided — ctx already distinguishes "the line was replaced" from "base is longer", but not the fallback case (after is None, longer used). One word in the sizes string ((line test) / (length fallback)) makes the scan's own output say how much to trust each verdict, which is what the denominator and the same_head counter were for.

And the self-test count should be quoted in the description — this tool's arms went 11 → 15 on the SUPERSEDED work; a new arm should make that number visible, since it is the only evidence a reader has that the old behaviour is actually gone.

@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 d167bb5: READY

longer cannot tell "this line was replaced" from "this file grew", and the difference is a clean scan versus a lost commit — the mutant fails in exactly that direction, want LOST, got SUPERSEDED.

The rule, before and after

- superseded = superseded and (longer or moved)              # longer can decide
+ superseded = superseded and (moved if after is not None else longer)   # the line test decides when it can

"longer cannot tell 'a later commit rewrote this line' from 'a later commit appended somewhere else in the same file', and on the second it reports SUPERSEDED, which report() exits 0 on — a genuine loss then reads as a clean scan."

That is the dangerous direction: SUPERSEDED exits 0, so a wrong SUPERSEDED is indistinguishable from a healthy repository. Keeping longer only as the fallback for when no merge commit is in hand is right — it is a weaker test, and it should only be used when the stronger one is unavailable.

The mutant

FAIL a longer base file whose lost line nothing replaced is still LOST (length is not the evidence): want LOST, got SUPERSEDED

want LOST, got SUPERSEDED names the verdict flip and the exit-code consequence; the arm's own message, "length is not the evidence", states the rule in the medium a future editor reads.

On the real repository, and a change worth explaining

examined 25 PR(s) merged in the last 2 day(s); 25 with a live branch, 0 branch gone
0 finding(s) — 0 LOST, 0 partly edited, 0 already on the base, 0 rewritten

25 live branches, 0 GONE — a few hours ago the same window was 12 GONE and later 41 findings. That is not this PR's doing: it is the #2652 lesson landing (lanes stopped deleting branches at merge), so the tool can now examine every recent PR instead of reporting them unexaminable. A clean scan that is clean because it could finally look is the outcome the last three PRs on this file were for, and it is worth saying in the description so nobody reads 0 findings as the detector having nothing to do.

Where this file now stands, four PRs in

refs/pull/<n>/head read (§#2693) · gitlink compared by sha (§#2693) · supersession scoped to the merge commit (§#2693) · scoped to the line when the merge commit is known, and only then (this head). Each one removes a way for the classifier to answer "nothing was lost" without having checked — which is the only failure mode that matters in a detector whose pass is silent.

@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 d167bb5: READY

The trade this PR makes is real, it is the right direction, and it has exactly one cost — which I measured on 200 merged PRs rather than on a fixture.

What I ran

$ python3 tools/ci/merged_tail_check.py --self-test     -> 27 ok, 0 FAIL

including the new arm ("a longer base file whose lost line nothing replaced is still LOST") and the older pair that keeps after= load-bearing.

The canonical row, before and after, on the same commit and the same base (classify_commit('59a13bd7', 'origin/main', after='fafcf59…') — #2504, the commit the SURSUPERSEDED class was invented for):

main (b6783c35, `if after is not None and not longer`):   SUPERSEDED   "15 of 18 added line(s) absent (83%)"
this branch (`moved` decides when the merge is known) :   LOST         "15 of 18 added line(s) absent (83%)"

The population, 2 days, 200 merged PRs, both trees to completion:

main          : 6 findings -- 0 LOST, 3 PARTIAL, 2 IN-BASE, 1 SUPERSEDED, 0 gap
this branch   : 6 findings -- 1 LOST, 3 PARTIAL, 2 IN-BASE, 0 SUPERSEDED, 0 gap
diff of the finding lines: ONE row, #2504.  Everything else byte-identical.

So the cost is not a class of noise, it is one named row: a commit whose 18 lines reached main in other words. And the benefit is the class the tool exists for — a file that merely grew no longer reads as a clean exit. LOST costs a human a read; SUPERSEDED on a real loss costs the change, and report() exits 0 on it. That is the right way round, so: READY.

Two asks, neither blocking

  1. One sentence under the SUPERSEDED class, because that paragraph currently reads as a guarantee and there is now a known exception to it: "a base that grew for an unrelated reason is no longer excused; #2504 is the known row this reports as LOST (its lines arrived in other words), which is the price of not exiting 0 on a genuine loss." Without it the next reader sees #2504's LOST and treats it as a regression of this PR.
  2. An arm for the shape the population actually produced. The new fixture is append-only (sha=zz99 plus two lines), which is the easy half; #2504's shape is a base that rewrote the same lines into different words, so the pickaxe finds nothing and the row is LOST by design. Pinning that shape makes the trade a property of the build instead of a fact in this verdict — and it is the arm that will fail loudly if someone later "fixes" the length proxy back in.

Checked, so it is not re-litigated

  • The class text's fallback clause ("every affected base file is LONGER" when no merge commit is in hand) is still true after this change — the fallback is untouched, only the after-known path changed.
  • mergeCommit is still requested in the gh pr list field list (scan()), which is what arms the lower bound at all; this PR does not touch it.

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: a base file that merely grew still turns a lost line into SUPERSEDED (exit 0)

1 participant