From add8d2aeddc3f4cb0e53d21acb5b9b99e47d6790 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Fri, 13 Nov 2026 20:26:29 -0400 Subject: [PATCH] registry_loss_check: ask the merge, not the endpoints (the false positive I shipped) A two-ended diff answers 'what does the branch's tree look like', not 'what would merging it do'. On a branch that is merely behind the base those differ, and the tool I merged an hour ago reported the difference as a loss: on engine#2021 ac36bd0 it said class 'Skylar2ForCausalLM' was gone, while git diff base...branch touches no registry file and git merge-tree --write-tree keeps the class. Same on engine#2369 bc4126c for the two files there. Now: if the endpoint diff shows a class missing, ask git merge-tree --write-tree what the merge produces. Present in the merged tree -> 'behind the base', rc 0. Absent from the merged tree -> a real loss, rc 1. A conflicting merge -> rc 2 with 'a conflicted branch is neither a loss nor a pass', because that needs a human and not a verdict. Six cases in tests/registry_loss_check_test.py, one of them the staleness shape; mutating the merge arm to 'behind_classes = []' turns exactly that case red. --- tests/registry_loss_check_test.py | 16 ++++++++++++ tools/ci/registry_loss_check.py | 41 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/tests/registry_loss_check_test.py b/tests/registry_loss_check_test.py index 56082fc1b..083d710fa 100644 --- a/tests/registry_loss_check_test.py +++ b/tests/registry_loss_check_test.py @@ -106,6 +106,22 @@ def test_a_census_value_that_moved_is_not_a_failure(self): result = self.run_check(self.base, "HEAD") self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + def test_a_class_missing_only_because_the_branch_is_behind_is_not_a_loss(self): + # engine#2390: the endpoint diff says the class is gone; the merge keeps it, so nothing was lost. + self.write("notes.txt", "branch work\n") + commit(self.repo, "the branch does something unrelated") + behind = git(self.repo, "rev-parse", "HEAD").stdout.strip() + git(self.repo, "checkout", "-q", self.base) + self.write("registry/significant.json", + json.dumps({"classes": {"Skylar2ForCausalLM": {"model_type": "skylar2"}, + "OmoikaneForCausalLM": {}, + "LaterForCausalLM": {}}}, indent=1)) + commit(self.repo, "the base adds a class after the branch was cut") + result = self.run_check("HEAD", behind) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("behind the base", result.stdout) + self.assertNotIn("FAIL", result.stdout) + def test_a_ref_that_cannot_be_read_refuses_instead_of_passing(self): result = self.run_check(self.base, "no-such-ref") self.assertEqual(result.returncode, 2, result.stdout + result.stderr) diff --git a/tools/ci/registry_loss_check.py b/tools/ci/registry_loss_check.py index 0b26995b1..51a7284da 100644 --- a/tools/ci/registry_loss_check.py +++ b/tools/ci/registry_loss_check.py @@ -65,6 +65,35 @@ def ref_exists(rev): return git("rev-parse", "--verify", "--quiet", f"{rev}^{{commit}}").returncode == 0 +def merged_classes(base, head, problems): + """The class set a merge of `head` into `base` would produce, or None when git cannot tell. + + A two-ended comparison answers "what does the branch's tree look like", not "what would merging it do". + On a branch that is merely behind the base those differ: the endpoint diff lists every file the base has + advanced as removed, and nothing is removed by the merge. `git merge-tree --write-tree` is git's own + answer, so ask it instead of reasoning about the diff (engine#2390). + """ + result = git("merge-tree", "--write-tree", head, base) + if result.returncode != 0: + detail = (result.stderr or result.stdout).strip().splitlines() + first = detail[0][:160] if detail else "" + if result.returncode == 1: + problems.append(f"merging {head} into {base} conflicts ({first}); resolve it and re-run - " + f"a conflicted branch is neither a loss nor a pass") + else: + problems.append(f"git merge-tree {head} {base} failed: {first}") + return None + tree = result.stdout.split("\n", 1)[0].strip() + if not tree: + problems.append("git merge-tree printed no tree") + return None + shown = git("show", f"{tree}:{SIGNIFICANT}") + if shown.returncode != 0: + problems.append(f"the merged tree {tree} has no {SIGNIFICANT}") + return None + return classes_of(shown.stdout, problems, "merged") + + def classes_of(text, problems, label): if text is None: return None @@ -151,6 +180,15 @@ def main(): lost_classes = sorted(base_classes - head_classes) added_classes = sorted(head_classes - base_classes) + behind_classes = [] + if lost_classes: + merged = merged_classes(args.base, args.head, problems) + if merged is None: + print("registry_loss_check: " + "; ".join(problems[-1:]), file=sys.stderr) + return 2 + # The merge is the authority: a class the merge keeps was never lost, only behind the base's moves. + behind_classes = [name for name in lost_classes if name in merged] + lost_classes = [name for name in lost_classes if name not in merged] base_census = counters_of(read_ref(args.base, CENSUS), problems, "base") head_census = counters_of(read_ref(args.head, CENSUS), problems, "head") @@ -184,6 +222,9 @@ def main(): print(f"FAIL registry_loss_check: census counter {item}") for item in lost_mentions: print(f"FAIL registry_loss_check: {item}") + if behind_classes and not args.quiet: + print(f"registry_loss_check: {len(behind_classes)} class(es) are absent at the head only because it is " + f"behind the base - the merge keeps them, so they are not a loss: {', '.join(behind_classes)}") if added_classes and not args.quiet: print(f"registry_loss_check: {len(added_classes)} class(es) added: {', '.join(added_classes)}") if moved_counters and not args.quiet: