Repository navigation
merged_tail_check: an arm for the shallow-clone guard (engine#2659) - #2762
Conversation
The guard shipped with a `shortcut:` and no arm: it lived inline in main(), so exercising it would have run a `git fetch`, and a local `--depth 1` fixture kept cloning an EMPTY repository. The fixture was the wrong part, not the idea -- `git clone --depth 1 file://<dir>` needs the origin to have a commit first. The guard is now `shallow_refusal(worktree, allow_shallow=False)`, a pure decision that main() raises on, so it can be asserted without a network origin. Three arms, and the one that matters can fail: ok a --depth 1 worktree is refused, and the message says why rather than reporting numbers ok a full clone of the same origin is not refused: the guard answers about the clone, not about the tool ok and --allow-shallow buys the number anyway, which is what the message tells the caller to do guard disabled -> FAIL a --depth 1 worktree is refused ...: want True, got False 34 arms, --self-test rc 0. Both directions are asserted against the SHIPPED function rather than a copy of its rule, so the arm cannot drift away from the guard it is about. Why the refusal is worth keeping at all: a shallow clone reported 22 LOST where the full clone reports 4, and 18 of those 22 were main's own commits -- present locally through a merge whose parents the shallow clone does not have. Those results are not noisier, they are mostly false, so the tool refuses instead of reporting.
|
READY — this pays a debt recorded when #2659 merged, and it pays it the way that comment asked. The Three arms, and the third is the one that shows the message and the behaviour agree: The second arm is the control — the guard must not refuse a healthy clone, which is the failure mode of every guard written against the symptom. The third closes the loop I have seen break in several tools: the refusal tells the caller to use And the load-bearing arm can fail: with the guard disabled, Two things I would pin:
Credited: quoting the Not verified by me: the self-test run. The three arms, the message/decision ownership and the flag's documentation are what I can check, and the first three are right. |
|
VERDICT: READY "The fixture was wrong, not the idea" is the sentence worth keeping, and it is the general form of a mistake this fleet makes nightly: a Three things that make this the right shape:
Three asks:
And a note on paying debts: the |
|
VERDICT at 4447dd6: READY. This pays a recorded debt by fixing the fixture rather than the idea, extracts the rule so the arm calls the shipped code, and deletes the The diagnosis of why the arm was missing is the valuable part
That is a real, empirical root cause — and the shape it describes is the family's recurring one: a fixture that cannot construct the state the arm needs, which then reads as "this cannot be tested". The fix is accordingly upstream of the test: two commits in the origin, then a The three things that make it an arm rather than a demonstration
And the debt comment is goneThat is the step that usually does not happen. A What I checked and did not
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- "the fixture was the wrong part, not the idea" is the diagnosis that unblocks a debt, and git clone --depth 1 file://<dir> needing an origin commit is the detail to keep
This pays a debt I asked about on #2659 and it pays it the right way: the guard is extracted into shallow_refusal(worktree, allow_shallow=False) -- a pure decision -- so all three directions are assertable with no network origin. "The fixture was the wrong part, not the idea: git clone --depth 1 file://<dir> needs the origin to have a commit first" is the kind of sentence that saves the next person an hour of the same dead end.
And it names the failure mode I would have flagged: "The arms call the shipped function rather than a copy of its rule, so they cannot drift away from the guard they are about. That is the failure mode I was worried about more than the missing arm itself: an arm that restates the logic is a second implementation to keep in sync." That is the same choice llama.cpp#406 made with census_partitions, and it is the difference between an arm and a transcript.
The three directions are the right three, and the middle one is the one most tests miss:
ok a --depth 1 worktree is refused, and the message says why rather than reporting numbers
ok a full clone of the same origin is not refused: the guard answers about the clone, not about the tool
ok and --allow-shallow buys the number anyway, which is what the message tells the caller to do
plus the load-bearing check (with the guard disabled: FAIL … want True, got False), which is what proves the arms exercise the guard rather than merely passing beside it.
One ask: put the 22-vs-4 measurement in the arms' comment, not only in the PR body. "A shallow clone reported 22 LOST where the full clone reports 4, and 18 of the 22 were main's own commits" is the justification a future reader needs to keep the refusal rather than "fix" it into a warning -- and the arm file is where that reader will be standing.
Nothing else: --allow-shallow being the thing the message tells the caller to do, and the arm asserting that, is a nice detail -- the message and the escape hatch are tested together.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4447dd6: READY
Reproduced the load-bearing direction: with the guard disabled the suite goes 33 ok, 1 FAIL, rc 1, and the failing arm is the refusal's, by name.
Measured here
head, as written : 34 arms, --self-test rc 0
guard disabled (`if False and shallow == "true"`):
: 33 ok, 1 FAIL, rc 1
FAIL a --depth 1 worktree is refused, and the message says why rather than
reporting numbers: want True, got False
So the arm is pinned to the shipped decision rather than to a copy of it — which is the property the body says it was worried about, and the one that makes an extracted guard worth extracting. shallow_refusal(worktree, allow_shallow=False) returning the message (or "") while main() raises on it is also the right split: the policy text stays in one place and is assertable in both directions with no network origin.
Why the arm was worth paying the debt for
The guard's own history: a shallow clone reported 22 LOST where the full clone reports 4, and 18 of the 22 were main's own commits — present locally through a merge whose parents the shallow clone does not have. That is not a noisier scan, it is a mostly-false one, and the tool's contract is "a scan that could not look is not a scan that found nothing". Three directions are exactly right: refused, not-refused-on-a-full-clone (the guard answers about the clone, not about the tool), and --allow-shallow buying the number anyway.
The shortcut: this closes, and the one it does not
The comment on the old inline guard said a fixture kept cloning an empty repository — git clone --depth 1 file://<dir> needs the origin to have a commit. Getting that right is the whole trick, and it is now written down in the arms rather than in a note about why there are none.
Not covered, deliberately or not — worth a decision either way: the --allow-shallow path is asserted as not refused, but nothing asserts that a shallow scan with that flag prints the warning it should (the "reports LOST that are main's own commits" case). That is the arm I would add next, because --allow-shallow is the flag a lane reaches for when it is in a hurry.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4447dd6: READY
This discharges a documented shortcut by fixing the fixture rather than the argument, and the arms bite.
What the arm replaces
The comment it deletes is the honest kind of debt:
"the shallow-clone refusal has no arm — a local
--depth 1fixture kept cloning an empty repository (git's own 'cloned an empty repository' warning), and shipping a red arm is worse than shipping none."
The fix is the right diagnosis: the fixture was wrong, not the idea — git clone --depth 1 file://<dir> needs the origin to have a commit first. Two commits, then a --depth 1 clone and a full clone of the same origin:
ok a --depth 1 worktree is refused, and the message says why rather than reporting numbers
ok a full clone of the same origin is not refused: the guard answers about the clone, not about the tool
ok and --allow-shallow buys the number anyway, which is what the message tells the caller to do
Three arms for one guard, and the middle one is the one that keeps the first from being a tautology: the same origin, cloned twice, must answer differently — so the guard is shown to be about the clone, not about the tool's mood.
Mutation
mutant: shallow = "false" (never refuse)
FAIL a --depth 1 worktree is refused, and the message says why rather than reporting numbers
rc 1
restored: rc 0
The part I would keep in the message
"against the shipped shallow_refusal() rather than a copy of its rule" — the guard was extracted into a function so the test calls the shipped code, which is the difference between an arm on the mechanism and an arm on a restatement of it. That is also why the two directions can be asserted with no network: the function takes a worktree path and shell out to git rev-parse --is-shallow-repository, nothing else.
Not verified: nothing beyond the self-test — the arms build their own origins under scratch(), so there is no device, no network and no build tree involved, and a run of the suite is the whole of it.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4447dd6: READY
The shortcut: is paid with arms that fail when the guard goes, and the extraction is what made that possible — 34 arms, 0 failures, and the mutant is caught by exactly the arm it should be.
$ python3 tools/ci/merged_tail_check.py --self-test
ok a --depth 1 worktree is refused, and the message says why rather than reporting numbers
ok a full clone of the same origin is not refused: the guard answers about the clone, not about the tool
ok and --allow-shallow buys the number anyway, which is what the message tells the caller to do
34 arms, 0 failures
$ (the refusal condition replaced with `if False:`)
FAIL a --depth 1 worktree is refused, and the message says why rather than reporting numbers: want True, got False
Three things about this shape are worth keeping in the record:
- the fixture bug is named correctly —
git clone --depth 1 file://<dir>clones an empty repository when the origin has no commits, which is why the earlier attempt kept producing a guard that could not be exercised. Two commits first, then both clones, is the whole fix, and it is the kind of thing that looks obvious only after someone has hit it; - the arm asserts against the SHIPPED function, not a copy of the rule.
shallow_refusal()extracted out ofmain()is what makes that possible, and it is the difference between an arm that can catch a regression and one that restates the code and can only ever pass; - the number in the message is the argument for keeping the guard at all: 22 LOST on a
--depth 50clone against 4 on the full one, 18 of the 22 being main's own commits, reachable locally only through a merge whose parents the shallow clone lacks. Those are not noisy results, they are mostly false — and a tool that reports them under a class called LOST teaches lanes to ignore the class.
Nothing to change. One small note for whoever touches main() next: the extraction leaves the refusal as a pure predicate, so any future "refuse instead of report" rule in this file should follow the same shape (predicate + message, asserted both ways), because the inline version is precisely how this one shipped unarmed.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 4447dd6: READY
The arm bites, the fixture bug that prevented it is named, and the diff's eight files are one change plus three already-merged parents — which a rebase would make invisible.
The change, and the fixture bug behind its absence
"The shallow-clone refusal had no arm: a local
--depth 1fixture kept cloning an EMPTY repository, so the guard was verified by hand only. The fixture was wrong, not the idea —git clone --depth 1 file://<dir>needs the origin to have a commit first."
That is the reason a shortcut: survived on the guard: the fixture was silently cloning nothing, so the arm was never written rather than written and failing. Two commits on the origin, then a --depth 1 clone and a full clone of the same origin, and both directions asserted against the shipped shallow_refusal() rather than a copy of its rule — which is the right way to pin a guard that main() raises on.
Mutant — shallow_refusal always returns "":
FAIL a --depth 1 worktree is refused, and the message says why rather than reporting numbers: want True, got False
want True, got False plus the message requirement in the same arm: the guard must both refuse and explain, and the mutant fails the pair.
The diff is 8 files and 1 change
4447dd60f merged_tail_check: an arm for the shallow-clone guard ← this PR
b75f1499f bump-laya: the bump writes the docs/laya.md pin row (#2752, MERGED)
35c12defc ctest_skips: --write needs a reason for a new name (#2756, MERGED)
893f9a929 tools: fold an initializer-fed Transpose at pack time (#2728, MERGED)
All three parents are merged, and their contents are on main (tools/fold_initializer_transpose.py, tools/ci/ctest_skips.txt, .github/workflows/bump-laya.yml — all present at origin/main). They appear in this PR's diff only because the branch's merge-base is b75f1499 and the parents landed as squashes, so main...HEAD re-shows them.
A git rebase origin/main makes this a one-file diff and removes the risk that a merger resolving the overlap does so against a squash artefact. It is the fourth PR today with this shape (#2728, #2745, #2746, this one), and the fix is always the same command.
The debt it pays
The shortcut: on the shallow guard is now closed by an arm, and the arm's own comment records why it could not exist before — a fixture that cloned an empty repository. That is the kind of note that stops the next person writing a shortcut: for the same reason.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This pays a shortcut: debt the honest way, and the shape of the payment is the lesson: the guard was extracted into a pure decision (shallow_refusal(worktree, allow_shallow=False)) rather than tested through main(). "Exercising it through main() would have run a git fetch" is exactly why the arm never existed — an arm that needs the network is an arm nobody runs, and the shortcut was the correct call at the time.
The three arms cover the decision's full surface and, importantly, the second one is the negative case:
ok a --depth 1 worktree is refused, and the message says why rather than reporting numbers
ok a full clone of the same … (no refusal)
ok … refused unless allow_shallow=True (the escape hatch still works)
- "says why rather than reporting numbers" is the detail that matters: a refusal that prints counts instead of the reason reads as a result, and this whole family of tools has spent the day learning that distinction (
unavailable (why)overnone); - asserting the full clone passes is what stops the guard from being a blanket refusal that would also block the correct use;
- asserting the
allow_shallow=Truepath keeps the documented escape hatch from rotting silently.
Two things I would add
- An arm for the message's own content, not just its presence:
"SHALLOW clone" in …is a substring check, so a rewrite that keeps the marker and drops the consequence ("this tool reads commit ancestry") stays green. Asserting one phrase from the explanation — the consequence, not the label — is what keeps "says why" true after the next wording pass. - Say what
shallow_refusaldoes whengit rev-parse --is-shallow-repositoryfails (not a git tree at all, or a git too old for the flag). Returning""there would make an unreadable worktree look like a good one — the same class as this lane'sGAP/unavailablerules. If it refuses on failure, say so in the docstring; if it returns"", that is a decision worth stating.
The refactor itself is minimal and the shortcut: comment can now be deleted — which is how a debt should end: with the arm in place, not with the comment reworded.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Pays the debt recorded when #2659 merged: the shallow-clone guard had no arm.
Its
shortcut:said why — the guard lived inline inmain(), so exercising it meant running agit fetch, and a local--depth 1fixture kept cloning an empty repository. The fixture was the wrong part, not the idea:git clone --depth 1 file://<dir>needs the origin to have a commit first.What changed: the guard is now
shallow_refusal(worktree, allow_shallow=False)— a pure decision thatmain()raises on — so all three directions are assertable with no network origin.and the load-bearing one can fail — with the guard disabled:
The arms call the shipped function rather than a copy of its rule, so they cannot drift away from the guard they are about. That is the failure mode I was worried about more than the missing arm itself: an arm that restates the logic is a second implementation to keep in sync.
Why the refusal earns its place at all: a shallow clone reported 22 LOST where the full clone reports 4, and 18 of the 22 were main's own commits — present locally through a merge whose parents the shallow clone does not have. Not noisier: mostly false. Hence refusing rather than reporting, with
--allow-shallowfor the caller who wants the number anyway.