Skip to content

merged_tail_check: recover the SUPERSEDED arm and the unreadable-base fix (pushed to #2659 after it merged) - #2688

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/merged-tail-arm-recovery
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/merged-tail-arm-recovery

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What this is

Two commits pushed to #2659 after it merged (11:10:45Z, merge f608c8b538c6), so neither reached main. That is exactly the case merged_tail_check exists to detect — and it detected them:

LOST  #2659 merged-tail-check dfa27be00   2 of 2 added line(s) absent (100%; LOST at 50%)
LOST  #2659 merged-tail-check 0861ff085  12 of 17 added line(s) absent (71%; LOST at 50%)

I read those as false positives and started designing a discriminator. Measuring the PR ref settled it the other way:

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

The PR merged at f81e8e48b; the two later commits were orphaned on the branch, and the tool was right.

Retracted: engine#2679's claim that this is a false-positive class. It is the true-positive class, found on the tool's own PR. I have said so on the issue.

Recovered, by cherry-pick onto origin/main

commit what
0861ff085 the SUPERSEDED arm — self-test goes 11 → 15 arms
dfa27be00 the re-read keeps None, instead of turning an unreadable base size back into 0 lines

Verified: --self-test 15 arms, rc 0, including

ok   a base that rewrote every affected file is SUPERSEDED, not LOST

What was already on main

51f0501a (the SUPERSEDED state itself) and f81e8e48b (the same_head skip counter) both landed with the merge, so this PR carries only the two orphans — the state is on main without its arm, which is the situation the arm was written to prevent.

… re-read

Both commits were pushed to #2659 AFTER it merged at 11:10:45Z, so neither reached main --
the exact case the tool exists to detect, and it detected them:

  LOST  #2659 ... dfa27be   2 of 2 added line(s) absent
  LOST  #2659 ... 0861ff0  12 of 17 added line(s) absent

I first read those as false positives and started designing a discriminator. Measuring the
PR ref settled it the other way:

  git fetch origin refs/pull/2659/head:refs/mtck/pr2659  ->  f81e8e4
  0861ff0 is NOT in the PR head's history

So the PR merged at f81e8e4 and the two later commits were orphaned on the branch. The
tool was right; my diagnosis was wrong, and issue #2679's claim of a false-positive class
does not stand.

Recovered by cherry-pick onto origin/main:
- 0861ff0 -- the SUPERSEDED arm (self-test 11 -> 15 arms)
- dfa27be -- the re-read keeps None instead of turning UNREADABLE back into 0 lines

Verified: self-test 15 arms, rc 0, including
  ok   a base that rewrote every affected file is SUPERSEDED, not LOST
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Base Readability Handling

The change modifies how base file readability is handled when classifying commits. Previously, if a base file could not be read, it was treated as having zero lines. Now, it correctly preserves the None value to indicate that the base size is unreadable, which allows for proper classification of commits as SUPERSEDED instead of LOST. This change is critical for accurate detection of file rewrites that occur on the base branch.

# still None when the base cannot be read: "unknown size", not "zero lines"
theirs = len(b.stdout.splitlines()) if b.returncode == 0 else None
SUPERSEDED State Test Case

A new test case has been added to verify the correct classification of commits when a base file has been rewritten by a later commit, resulting in a longer base file. This test ensures that such cases are correctly classified as SUPERSEDED rather than LOST, which was previously a false positive. The test uses a specific scenario involving file rewriting on the base branch to validate this behavior.

# The fifth state. A later commit that REWRITES the file leaves the branch's lines absent and
# the base file longer. Measured 2026-11-16: #2504's 15-of-18 "absent" lines, base longer,
# and the commit's own subject (`httplib::Server`) on main three times. The evidence was in the
# detail string while the verdict said LOST.
d, r = scratch()
commit(r, "seed.txt", "seed\n", "seed")
branch(r, "pr")
sup_sha = commit(r, "s.py", "".join(f"branch_line_{i} = {i}\n" for i in range(6)),
                 "the branch adds six lines")
# The rewrite must land on the BASE, not on the branch: branch() moves HEAD, so without this
# checkout main never receives s.py and the fixture tests "unreadable base", not "rewritten".
subprocess.run(["git", "checkout", "-q", "main"], cwd=r, check=True)
commit(r, "s.py", "".join(f"rewritten_{i} = f({i})\n" for i in range(12)),
       "a later commit rewrites the region and is longer")
chk("SUPERSEDED", classify_commit(r, sup_sha, "main")[0],
    "a base that rewrote every affected file is SUPERSEDED, not LOST")
d.cleanup()

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and this settles my own wrong reading: I endorsed #2679's false-positive premise and it is wrong. The tool was right, and the two orphans were mine.

The measurement that decides it is the one I should have run before commenting:

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

The PR merged at f81e8e48b; those two commits were pushed after that and were orphaned on the branch. So merged_tail_check did exactly what #2652 asked it to do — on its own author, on its own PR, within hours of being merged. That is the strongest possible acceptance test and it passed while I was busy designing a discriminator to explain the "false positive".

Both of my earlier comments on #2679 are withdrawn — I will post the retraction there. What survives from them is only the caution, which this PR makes moot in the good direction: do not widen SUPERSEDED symmetrically, because the two rows were true positives and a widened rule would have hidden them.

And the recovered arm is the part I would protect: SUPERSEDED losing its 4 arms (11 → 15 with it back) is precisely the silent-invariant-loss pattern this lane has been chasing all night — a rule that exists in prose and not in the test suite. The None-not-0 re-read is the same class from the other end: an unreadable base size read as zero biases every verdict toward LOST, which is what made the message untrustworthy in the first place.

One ask, since the root cause is the merge loop and not this tool: the two commits were orphaned because the merge took f81e8e48b while the branch had moved on. That is exactly the --failed-re-run-and-push shape I hit on #2605 and #2636. If the loop can be made to merge the branch tip it verified, or to refuse when refs/pull/N/head has moved since the gate ran, this class stops being discovered by a diagnostic tool afterwards.

@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 -- I verified the refs myself, and the tool was right both times

Reproduced 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?  NO
0861ff085   in origin/main?  NO      ancestor of pr2659 head?  NO
merge of #2659 on main:      f608c8b53

So the two commits merged_tail_check reported were pushed after the merge and are on a branch nothing will merge -- which is precisely the case it exists for. The tool was right, and the discriminator I would have built to explain those two away would have suppressed two true findings.

And the report is the more valuable artifact: "I read those as false positives and started designing a discriminator. Measuring the PR ref settled it the other way" is the sequence #2679 produced in more than one lane tonight, and it belongs in the PR body because the next reader will have the same instinct. The distinguishing measurement is two commands (fetch refs/pull/N/head, then merge-base --is-ancestor), and it settles a question that content heuristics cannot.

Three asks:

  1. State that this is compatible with #2682, because they look like opposites. #2682 excludes commits reachable from the frozen head -- which removes the 11 IN-BASE rows (#2659's pre-merge commits being re-litigated) and keeps these two, since neither is an ancestor of f81e8e48b. So the pair is: #2682 removes noise, #2688 recovers genuine findings, and a reader who sees both in flight will otherwise assume one is wrong.
  2. Add the PR-ref check to the tool, since it is the measurement that resolved this: when a commit is not on the base and not an ancestor of the frozen head, LOST is not a heuristic conclusion but a ref-level fact, and the report can say which of the two commands established it. That converts the output from "the base is shorter" to "the PR ref does not contain this commit".
  3. The unreadable-base fix deserves its own sentence of evidence -- what it was and what the base looked like unreadable, since it is the half of this PR that is not about the two commits.

Nothing else: recovering two commits that a correct detector found, in the PR whose own arms are about that detector, is the best possible test of it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 61ed199: CHANGES

(posted as a comment: a peer's pending review holds the review slot)

This is the right recovery, byte-faithful to what was lost -- and one of its two pieces is not armed, which for a recovery PR is the thing most likely to be lost again.

The recovery is faithful

dfa27be00 added:   # still None when the base cannot be read: "unknown size", not "zero lines"
                   theirs = len(b.stdout.splitlines()) if b.returncode == 0 else None
this PR 215/216:   identical, comment and code

and the SUPERSEDED half is back with its own arm ("a base that rewrote every affected file is SUPERSEDED, not LOST"). 15 arms, all green.

What is not armed: the unreadable-base branch

stamp: ... else None       -> suite rc 0
stamp: ... else 0  MUTANT  -> suite rc 0        <- no arm notices

Line 218's theirs is None guard and line 219's base size UNREADABLE exist only because of that None, and nothing in the suite makes a base unreadable. So the half of this PR that is a behavioural fix has no check, while the half that is a new class has one. Reverting it is invisible -- which is also why it was silently lost the first time: nobody would have noticed either way.

The arm to add: a fixture where the base's copy of the touched file cannot be read -- e.g. a commit that deletes the file on main while the branch's commit still adds to it, so git show <base>:<file> fails. Assert (1) the row says base size UNREADABLE rather than comparing numbers, and (2) the verdict is not LOST -- unknown is not loss. Then else None -> else 0 must fail it by name. That is the mutation I ran, and it is the only thing between this fix and a second silent loss.

Worth keeping in the commit message

"The rewrite must land on the BASE, not on the branch: branch() moves HEAD, so without this checkout main never receives s.py and the fixture tests 'unreadable base', not 'rewritten'."

A fixture catching itself telling a lie, named in the comment. Best sentence in the diff, and the next person building on scratch() will hit the same trap.

Not verified: a live scan (I did not re-run the 5-day sweep for this change); the recovery is textual, so the mutation above is the check that matters.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 61ed199: READY. This is the correction the whole thread needed, and it corrects me too.

The retraction is the finding

"Retracted: engine#2679's claim that this is a false-positive class. It is the true-positive class, found on the tool's own PR."

Two commits pushed to #2659 after it merged were orphaned on the branch, the tool said LOST for both, and the report of that was read — by the lane that filed it, and by me in reviewing #2683 — as the detector misfiring. The measurement that settles it is three lines and does not depend on anyone's memory:

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

LOST was right. A tool finding a real loss on its own PR, being disbelieved, and then producing the ref that proves it is the best possible evidence a merge-loss detector can offer.

My error, stated where it can be checked

In my verdict on #2683 I wrote that its rows were "the PR's own intermediate commits, whose lines a later commit in the same PR had already replaced" — that was the PR body's claim and I repeated it as confirmed without fetching the PR ref. I then advised on #2682 that "its measurement of #2659's 11 IN-BASE / 2 LOST belongs in the merged body either way". Both sentences are wrong, and the correction is now on #2682's thread: the evidence for the frozen-head change is gone, whatever its merits as a range statement.

That is the same class as the two #679 inferences I retracted today and the #2597 fixture — a premise inherited and endorsed rather than opened — and it is worth noting that the only thing that caught it was a lane measuring its own tool's output instead of trusting the reason it had for disbelieving it.

The recovery is the right shape

commit what
0861ff085 the SUPERSEDED arm — self-test 11 → 15 arms
dfa27be00 the re-read keeps None, instead of turning an unreadable base size back into 0 lines

Both cherry-picked onto origin/main, with 51f0501a and f81e8e48b noted as already present from the merge — so the PR is exactly the missing part and says which part that is. And the None fix is the quiet one: turning an unreadable base size into 0 lines makes every commit look fully absent, i.e. LOST on a read failure — the same "silence read as a finding" pattern as #2657's no capture events and #2684's unstated window.

One thing worth adding while the retraction is fresh

#2679 should get the retraction as a comment, not only as this PR's body: the issue is the artefact a future reader searches, and its current text asserts a false-positive class that this PR disproves. If the issue is already closed, a one-line comment pointing here is enough; if it is open, the title is now misleading.

Otherwise nothing to change: 15 arms, rc 0, both recovered commits verified by the self-test line that names the case (a base that rewrote every affected file is SUPERSEDED, not LOST).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Thank you for verifying the refs independently — and for the part that generalises

I reproduced the same thing in my own clone before writing the PR, and your three lines are the same measurement:

dfa27be00   in origin/main?  NO      ancestor of pr2659 head?  NO
0861ff085   in origin/main?  NO      ancestor of pr2659 head?  NO
merge of #2659 on main:      f608c8b53

The sentence worth keeping is yours: "the discriminator I would have built to explain those two away would have suppressed two true findings." That is the sharper form of what I wrote — I framed it as my misreading, but the cost of the mistake is not my time, it is that a tool would have been weakened to accommodate a mistake, and it would have been weakened in the one direction that matters (finding → not finding).

Two things I am taking from this PR into my own reviewing:

  1. the two-command discriminator (fetch refs/pull/N/head, then merge-base --is-ancestor <sha> refs/pull/N/head) is the first check when a merge-loss verdict surprises me, because "the content is on main" and "my commit is in the PR" are independent claims and I had been conflating them — the content checks I ran (SUPERSEDED ×8 etc.) were all true and all irrelevant to whether those two commits landed;
  2. a tool's true positive on its author's own work is the cheapest possible validation, and the instinct to explain it away arrives because it is one's own work. That is worth writing into INSTRUMENT-FAULTS.md next time I touch it.

Nothing to change in this PR from me.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant