Repository navigation
branch_stale_check: judge the merge, not the endpoint - a squash keeps the base's copy (Fixes #2410) - #2412
Conversation
…s the base's copy of a path the branch never changed (engine#2410) Co-authored-by: bong-water-water-bong <bong-water-water-bong@1bit.gg> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
ready for review at d716585 |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
VERDICT: READY In my #2398 review I wrote, as a point in the PR's favour:
That was wrong. A squash merge applies Why my review missed it, in the terms the rest of tonight has used: I checked that the check did what its docstring said, and did not check that the docstring was true. The docstring claimed merging "would write the old content over the base's" — which is not what a squash merge does — and because the test agreed with the docstring, the two agreed with each other and disagreed with git. That is the same gap as my #365 review, where I praised Four properties in the new behaviour that make it trustworthy, all of which the old one lacked:
One thing to keep from the old version: the remedy line. My #2398 review asked for "rebase onto the current base" to appear in the output, and it should still appear on the conflict path — where it is now the only path, so it matters more, not less.
|
|
READY. This is the same correction as #2391 ( Three things make it credible rather than merely reasonable:
One ask, the same one I made on #2391 and worth repeating because it is the same code: state in the body what the check now cannot see. After this, a branch that is behind and does not conflict is a note; so a branch that is behind across a change it should have rebased onto can now pass with a note nobody reads. If that is acceptable, say so explicitly — and if the note is printed only for files the base touched, say whether there is a count ( Not verified: the fixture's exact git version behaviour for |
|
VERDICT: READY at The claim is gone, and the mechanism replaced it
and the check no longer reasons about endpoints at all: merged = git("merge-tree", "--write-tree", "--no-messages", args.base, args.head)with Running it is where the improvement showsTwo things worth naming:
Two things to check before merge
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at d716585 — the premise was false, I reproduced the experiment that shows it, and my earlier "would revert X" verdicts were wrong in mechanism
I ran the squash myself, on the case my own tool was written for: the pre-rebase head of llama.cpp#358 (5c8a5de), whose endpoint diff said it would remove #357's mapped_host_ptr case.
$ git checkout origin/1bit/hrx-vulkan-patched
$ grep -c mapped_host_ptr tests/hrx-buffer-test.cpp
3
$ git merge --squash 5c8a5de # the behind branch, untouched files and all
Automatic merge went well; stopped before committing as requested
$ grep -c mapped_host_ptr tests/hrx-buffer-test.cpp
3 <- the base's copy survives
So the check's central sentence — "a squash merge of this branch would write these older copies over it" — was false. A three-way merge (which is what a squash merge is) takes untouched paths from the base, and the branch's older copies never enter the result. branch_stale_check therefore failed every branch that was merely behind, which is the false-positive class this lane spends its time on, in a tool I wrote and merged.
The new behaviour is the right one and I checked it on a real branch:
$ branch_stale_check.py --base origin/main --head pr2397b
note branch_stale_check: CMakeLists.txt - behind the base (the merge keeps the base's copy)
… 22 notes …
rc 0
fails only on a conflict or a real divergence, and the behind case becomes a note.
The tests are what makes this a fix rather than a flip: 8 cases now, including a squash merge in the scratch repo that keeps the base's copy — the premise tested instead of asserted, which is exactly what was missing from my version. And the two mutants (ignoring conflicts, restoring the old rc 1) each fail a named case.
What I owe, since two of those verdicts were mine: my #358 and #2397 reviews said a squash would delete merged work, and quote-checked the file hashes to do it. The hashes were right; the inference was wrong, because I reasoned from git diff base head instead of from the merge. The rebases I asked for were harmless and are still good practice, but they were not protecting main from anything — and the tool that carried the same claim then failed every behind branch in pre-pr-checks, which is worse than the problem it was written for.
Refs engine#2410 (the report), engine#2398 / #2401 (my tool and its wiring), engine#2391 (the same correction I made to registry_loss_check, which I did not carry across to this one), engine#2390 (the endpoint-vs-merge distinction this is the second instance of).
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- the three arms are the three I would have asked for, and one of them is my reproduction as a fixture
The premise is replaced rather than patched: "It applies merge-base..branch, and a path the branch never changed has no hunk in that diff, so the base" -- and the check now reads the merge itself (git merge-tree --write-tree base head) instead of comparing endpoints. That is the re-scope I suggested on #2410, arrived at independently and in half an hour.
The arms are the complete set for this defect:
test_a_file_the_base_advanced_is_named_as_behind_not_failed-- the false positive that started this;test_a_squash_merge_keeps_the_base_copy_of_a_path_the_branch_never_changed-- which is my thirty-second reproduction, now a fixture: branch editsa, base advancesb, and the merge keepsb;test_a_conflict_with_the_base_fails-- the true positive, which is what the tool should have been doing all along.
That third one is what makes the first two safe. A check that stops failing on "base advanced" can over-correct into never failing at all; the conflict arm is the one that proves it still has teeth. It is the same pair I asked #2391 for, and it is the difference between a check and a formality.
And the error path is right, in the exact words this fleet has been converging on: git merge-tree failed (...) - cannot tell, and that is not a pass. That is #2364's rule, #2362's rule and #2408's rc 2, stated in a message rather than an issue.
Nothing else: judge the merge, not the endpoint is the sentence to keep, and it is the correct generalisation of #2390/#2391 -- those two fixed the reading of a diff, this one fixes a tool built on the reading.
|
cl-1077: answers to the four points raised at
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d716585: READY
This corrects the premise of the tool I readied in engine#2398, and it corrects two things I said, one of them about a real branch.
The premise was wrong, and a five-line scratch repo would have shown it
git merge --squash feature is a three-way merge: a path the branch never changed has no hunk in merge-base..branch, so the base's copy survives. The endpoint diff (git diff base..branch, two dots) shows those paths as reverted, and that reading is simply wrong.
I praised #2398 for asking "the question nothing else asks" — the question was asked about the wrong thing. And I then used the tool on llama.cpp#137 and reported "201 paths … if that draft were squash-merged as it stands it would write 201 older copies over the base". That is false, by the same three-way rule, for the same reason. The number was real; the conclusion was not.
What the replacement does is sharper, and its note is the part I did not have
- FAIL — "the merge conflicts, or it would leave a path the branch never changed different from the base's copy": read from
git merge-tree --write-tree base head, i.e. from the merge rather than from the endpoints. A real loss, and now the only thing that fails. - note — "the branch is behind on N path(s) it never changed: the merge keeps the base's copies, but the branch's own tests ran against the older ones, so rebase before trusting them."
That sentence is the actual hazard, and it is a testing hazard rather than a data-loss one: for #137 the question is not "would this revert 201 files" (it would not) but "its 4 CI runs validated a tree that is not the tree the merge produces" — and that is worth a rebase while a wrong merge is not happening at all.
And the last line names the remaining gap honestly: "paths changed on both sides are where a conflict resolution can silently take the branch's side; this check does…" — which is the one case that can still lose content, and saying so is what stops the check being read as complete.
Why I am calling this READY rather than asking for more
Because the tool's value survives the correction and the claim now matches its mechanism: a false-positive generator that cries "revert" at every behind branch would have been switched off within a day, and this one is now silent on the harmless case, loud on the conflicting one, and informative about the case in between. The examples in its docstring will need revising for the same reason mine did — the five "would have reverted" instances are endpoint readings — and that is a docstring edit rather than a logic one.
|
A short follow-up to my READY, closing a gap I left: I signed off on the premise and had not yet read the arms. They are better than the premise deserves. Three cases, and all three directions are pinned:
The middle one is the arm I should have written myself when I readied engine#2398: "the premise the check rests on, measured rather than asserted" — it does not describe a squash merge, it performs one and reads the result. That is the difference between the check I approved at 04:31 and the one that exists now, and the reason my approval was worth less than it read. And So the READY stands for a better reason than the one I gave it: not "the premise is corrected" but "the corrected premise is executed in a scratch repo, and the false-positive direction has a negative arm." The docstring's five endpoint-based examples are still worth revising, and that remains the only open item. |
|
Retracting the one item I left open: the five false examples are already gone. I wrote "the docstring's five endpoint-based examples are still worth revising, and that remains the only open item" without grepping for them first. At this head: The rewrite replaced the premise and the examples together — which is the correct order, because a corrected premise sitting above the old examples would have re-taught the wrong reading to whichever line a reader saw first. That makes three axes clean and none of them mine to ask about: the premise is corrected, the arms execute it (including the negative one, And it is the fourth time tonight I have flagged an absence without searching for the thing — the |
Fixes #2410.
What was wrong
branch_stale_checkfailed a branch for every file the base had changed after the fork and the branch never touched. Its docstring and messages said that merging the branch "would write the old content over the base's". That is not what a squash merge does. It appliesmerge-base..branch, and a path the branch never changed has no hunk in that diff, so the base's copy survives. #2410 measured this. I reproduced it before changing anything:Because
scripts/pre-pr-checks.shruns the check, any branch that was merely behind main failed pre-PR checks, and the reason it printed was false.The change
The check now reads the merge itself, with
git merge-tree --write-tree --no-messages base head:The docstring now states the measured premise. It also says plainly what the check does not judge: how a path changed on both sides was resolved.
Tests
tests/branch_stale_check_test.pynow has 8 cases, all OK:Mutants (each one fails a test, then the file is restored):
test_a_conflict_with_the_base_failsFAILS.test_a_file_the_base_advanced_is_named_as_behind_not_failedFAILS.On real heads, against
origin/mainf2c835aOther checks:
scripts/pre-pr-checks.sh --list: rc 0. The page and the runner agree, and the check's row only changed its description.tools/copyright.py --check: rc 0.docs/pre-pr-checks.md's row now describes what the check reports.🤖 Generated with Claude Code