From c5971debc415112dd555bb5f558c2b18a2a2635c Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Thu, 12 Nov 2026 19:51:11 -0400 Subject: [PATCH] registration_loss_check: an unreadable revision is "cannot tell", not "every row is missing" Found by pointing my own tool at a ref that does not exist: $ registration_loss_check.py --check --base origin/main --head origin/does-not-exist registration_loss: 437 of 437 registration(s) at origin/main are missing (0 deleted by this branch, 437 it simply never had) ... rc 1 `files_at_rev()` asked `git show :` for each candidate, every call failed, and the empty result was treated as a tree with no registrations. The verdict was loud, confident and wrong -- and in the direction that makes a lane rebase or "restore" rows that were never lost. The base had a guard of sorts ("nothing parsed at the base - cannot tell"), but that only fires when the base itself is empty, so a typo in `--head` slipped past it entirely. Both revisions are now checked with `git rev-parse --verify ^{commit}` before anything is compared: cannot read origin/does-not-exist - cannot tell, and that is not a pass rc 2 Two arms pin it (unreadable head, unreadable base), and the real-ref behaviour is unchanged: `--base origin/main --head origin/main` still reports all 437 present, and `main-whisper-tool` in its stale state still gets the stale-and-conflicting verdict this tool was written for. Same trap as `dmesg` returning 0 lines under `kernel.dmesg_restrict=1` earlier tonight: a tool that cannot read its input must say so, and "empty" must never be indistinguishable from "unreadable". --- tools/ci/registration_loss_check.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/ci/registration_loss_check.py b/tools/ci/registration_loss_check.py index 2ccc47e40..5aef57704 100755 --- a/tools/ci/registration_loss_check.py +++ b/tools/ci/registration_loss_check.py @@ -76,6 +76,15 @@ def registrations(text: str) -> set[tuple[str, str]]: return out +def readable(root: pathlib.Path, rev: str) -> bool: + """Is `rev` a commit this repository can read? Checked before anything is compared, because an unreadable revision used + to produce an empty tree and a confident "437 of 437 registrations are missing" -- a wrong answer in the loud direction, + which is worse than the cannot-tell it should have been.""" + p = subprocess.run(["git", "-C", str(root), "rev-parse", "--verify", "--quiet", f"{rev}^{{commit}}"], + capture_output=True, text=True, check=False) + return p.returncode == 0 + + def files_at_rev(root: pathlib.Path, rev: str) -> list[str]: """The CMake files AS THEY EXIST AT THAT REVISION, not as they exist in the working tree. @@ -123,6 +132,12 @@ def merges_cleanly(root: pathlib.Path, base: str, head: str) -> tuple[bool, list def check(root: pathlib.Path, base: str, head: str | None = None) -> int: + if not readable(root, base): + print(f"registration_loss: cannot read {base} - cannot tell, and that is not a pass") + return 2 + if head and not readable(root, head): + print(f"registration_loss: cannot read {head} - cannot tell, and that is not a pass") + return 2 before = at_rev(root, base) after = at_rev(root, head) if head else at_tree(root) if not before: @@ -243,6 +258,11 @@ def repo(trees: list[dict[str, str | None]]) -> tuple[pathlib.Path, list[str]]: check_that(check(d6, shas6[0], shas6[1]) == 1, "a branch that lacks rows AND conflicts is the dangerous combination") + # 5c. an unreadable revision is 'cannot tell' -- it used to report every base row as missing, which is the loud direction + d7, shas7 = repo([{"CMakeLists.txt": "add_test(NAME a COMMAND x)\n"}]) + check_that(check(d7, shas7[0], "no-such-rev") == 2, "an unreadable --head is exit 2, not 'everything is missing'") + check_that(check(d7, "no-such-rev", shas7[0]) == 2, "an unreadable --base is exit 2 too") + # 6. nothing parsed at the base is 'cannot tell', not a pass d3, shas3 = repo([{"CMakeLists.txt": "# nothing\n"}]) check_that(check(d3, shas3[0], shas3[0]) == 2, "a base with no registrations is exit 2, not a pass")