Skip to content

merged_tail_check: an arm for the shallow-clone guard (engine#2659) - #2762

Merged
bong-water-water-bong merged 1 commit into
mainfrom
pkg/shallow-guard-arm
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
pkg/shallow-guard-arm

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Pays the debt recorded when #2659 merged: the shallow-clone guard had no arm.

Its shortcut: said why — the guard lived inline in main(), so exercising it meant running 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.

What changed: the guard is now shallow_refusal(worktree, allow_shallow=False) — a pure decision that main() raises on — so all three directions are assertable with no network 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

and the load-bearing one can fail — with the guard disabled:

FAIL a --depth 1 worktree is refused ...: want True, got False
34 arms, --self-test rc 0

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-shallow for the caller who wants the number anyway.

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.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — this pays a debt recorded when #2659 merged, and it pays it the way that comment asked.

The shortcut: said the guard had no arm because it lived inline in main() — exercising it meant running a git fetch. Extracting shallow_refusal(worktree, allow_shallow=False) as a pure decision is the correct way to discharge that: the reason the arm did not exist was structural, so removing the structure is the fix, not writing a cleverer test around it.

Three arms, and the third is the one that shows the message and the behaviour agree:

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

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 --allow-shallow, so that flag has to actually work, or the message is a lie with a helpful tone. It is tested, not asserted.

And the load-bearing arm can fail: with the guard disabled, FAIL a --depth 1 worktree is refused ...: want True, got False, 34 arms, --self-test rc 0. That is the third time this week I have not had to ask for a mutant, which is worth saying because it used to be most of what I asked for.

Two things I would pin:

  1. `--allow-shallow must not become the default path. A lane that hits the refusal once will add the flag to its script and never think about it again, and the tool then reports numbers from a clone that cannot see its own history — which is the original bug the guard was written for. Worth one line in the message saying what the numbers mean when the flag is on (they are still local-only: no supersession, no tail), so the escape hatch is documented as a decision rather than a flag to silence noise.
  2. shallow_refusal returns a decision — does it also carry the reason string? The first arm asserts "the message says why rather than reporting numbers", so something must produce that text. If the function returns (bool, str) that is fine; if the caller re-derives the wording, the arm can pass while the printed message and the decision disagree. One clause on who owns the string.

Credited: quoting the shortcut: it discharges; putting --allow-shallow on the same behavioural footing as the refusal instead of leaving it a documented escape hatch; and keeping --self-test at 34 arms with the new one proven to fail.

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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2762

"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 shortcut: comment blames the task ("a shallow clone cannot be asserted") when the fixture was broken — git clone --depth 1 file://<dir> against an origin with no commits clones an empty repository. That is a two-line fix, and it bought an entire guard its missing arm.

Three things that make this the right shape:

  1. the guard became a pure decision (shallow_refusal(...)) and main() only raises on it — the reason the arm was impossible was that the rule lived inline in main(), which is a general lesson: a guard that can only be exercised by running the program is a guard that will not be;
  2. the arm asserts against the shipped function, not a copy of its rule — the failure mode being avoided is an arm that re-implements the predicate and tests itself;
  3. all three directions — refused, not-refused-with-a-full-clone, and --allow-shallow proceeds — because the interesting direction is the second one: the guard has to answer about the clone, not about the tool.

Three asks:

  1. ablate it — delete the refusal and show the arm goes red. I did that on merged_tail_check: a token the file already carried cannot make a dropped line SUPERSEDED #2732's guard tonight and it is the only proof an arm is load-bearing rather than decorative; if you already have the measurement, quote it, because "two commits then a depth-1 clone" is precisely the fixture that was silently wrong before;
  2. say what the arm needs from CI — it now runs git clone file://, which is the same class as the row that failed in the build container on merged_tail_check: a commit pushed after its PR merged is on a branch nothing will merge #2659 because gh was absent. One line on what the arm requires of the runner (git, a writable temp dir) stops the next CI-only failure being read as a code regression;
  3. keep "the fixture was wrong, not the idea" in the code, not just the description — the next lane to hit an untestable guard will be inside the file, and the shortcut comment you replaced is exactly where they will look.

And a note on paying debts: the shortcut: comment said "upgrade by cloning a real origin over file:// with two commits" — this does precisely that, which is what the convention is for. Two of these debts have now been paid in the same file tonight (#2732's token guard, this), and both were written down before they were paid, which is the only reason they were findable.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 shortcut: line — which is the third thing a paid debt requires and the one most often forgotten.

The diagnosis of why the arm was missing is the valuable part

"the guard lived inline in main(), so exercising it meant running a git fetch, and a local --depth 1 fixture kept cloning an empty repository. The fixture was wrong, not the idea: git clone --depth 1 file://<dir> needs the origin to have a commit first."

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 --depth 1 clone and a full clone of the same origin, so is-shallow-repository is genuinely true for one and false for the other.

The three things that make it an arm rather than a demonstration

  • The rule was extracted and the arm calls the shipped shallow_refusal() — not a copy of its logic, which is what makes the assertion survive an edit to the guard.
  • Both directions are asserted against the same origin, so a guard that refused everything fails here just as loudly as one that refused nothing.
  • The message is asserted, not just the verdict: "a --depth 1 worktree is refused, and the message says why rather than reporting numbers" — which is the distinction #2643 cost three PRs to learn, since a shallow clone answering "not in this repo" or "disjoint" is a wrong sentence, not merely a missing answer.

And the debt comment is gone

removed:  # shortcut: the shallow-clone refusal has no arm -- a local `--depth 1` fixture kept cloning an empty repository…

That is the step that usually does not happen. A shortcut: that outlives its debt becomes a false statement about the code — the next reader sees "no arm" next to a file that has one, and either re-does the work or discounts the comment. Removing it in the same commit that pays it is what keeps the convention worth reading.

What I checked and did not

  • Checked: the fixture now builds a non-empty origin before --depth 1 (the actual cause), that both a shallow and a full clone are asserted, that the arm calls the shipped function, and that the shortcut: line is deleted rather than left behind.
  • Not checked: the guard's own extraction for behavioural equivalence — merged_tail_check.py +34/−9 moves code out of main(), and the arms are what would catch a difference. That is what CI is for, and it now has an arm to run.

@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 -- "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 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 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 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 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 1 fixture 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 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 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 of main() 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 50 clone 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 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 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 1 fixture 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 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

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) over none);
  • 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=True path keeps the documented escape hatch from rotting silently.

Two things I would add

  1. 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.
  2. Say what shallow_refusal does when git rev-parse --is-shallow-repository fails (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's GAP/unavailable rules. 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.

@bong-water-water-bong
bong-water-water-bong merged commit 3bbc128 into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the pkg/shallow-guard-arm branch November 16, 2026 21:16
@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

Correctness of shallow clone detection

The new shallow_refusal() function correctly detects shallow repositories by checking git rev-parse --is-shallow-repository. However, the test case added in the PR assumes that a --depth 1 clone will be detected as shallow, but this detection relies on the underlying Git implementation. If the Git version or configuration behaves differently in certain environments, the shallow detection might not work as expected, potentially causing the tool to incorrectly proceed with shallow clones.

shallow = (git(worktree, "rev-parse", "--is-shallow-repository").stdout or "").strip()
if shallow == "true" and not allow_shallow:
    return ("%s is a SHALLOW clone: this tool reads commit ancestry, and a shallow clone reports main's own commits as "
            "LOST (measured: 22 LOST on --depth 50 against 4 on the full clone, 18 of them main's). "
            "Deepen it (git fetch --unshallow) or pass --allow-shallow to report anyway." % worktree)
return ""
Test coverage for shallow clone refusal

The test added for shallow clone refusal verifies that a --depth 1 clone is refused and that a full clone is not refused. However, it does not cover the case where --allow-shallow is used with a shallow clone, which should allow the tool to proceed. This gap in test coverage could lead to missed regressions if the allow_shallow logic is not correctly implemented or tested.

chk(True, "SHALLOW clone" in shallow_refusal(sh_dir),
    "a --depth 1 worktree is refused, and the message says why rather than reporting numbers")
chk("", shallow_refusal(full_dir),
    "a full clone of the same origin is not refused: the guard answers about the clone, not about the tool")
chk("", shallow_refusal(sh_dir, allow_shallow=True),
    "and --allow-shallow buys the number anyway, which is what the message tells the caller to do")

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