From 6cc094b6d4efb2868ea73c5318a78eecf903df86 Mon Sep 17 00:00:00 2001 From: pi-prs Date: Mon, 16 Nov 2026 05:13:15 -0400 Subject: [PATCH 1/9] merged_tail_check: a commit pushed after its PR merged is on a branch nothing will merge The merge loop merges the REVIEWED head, and that is correct: the gate approves a head, so the merge must be that head. A push that lands on the branch AFTER the merge is outside that rule -- the PR is already MERGED, so nothing will merge the branch again, and the commit sits on a branch nobody is watching. engine#2623 lost two commits that way (recovered by #2640) and #2605 lost one (recovered by #2654). An orphaned tail is invisible to every check we have: the PR badge says merged, the gate says READY, and the content is not on main. Content check, not sha equality. A squash merge rewrites every sha, and #2623 shows the API is rewritten with it: five commits were pushed, while refs/pull/2623/head, headRefOid and the PR's own commit list each report three, and none of them the lost pair. The live branch is the only surface left, which is why the branch must not be deleted before its tail is read. Exit 0 clean, 1 a LOST commit, 2 something could not be examined -- a scan that could not look is not a scan that found nothing. --- CMakeLists.txt | 14 ++ tools/ci/merged_tail_check.py | 387 ++++++++++++++++++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100755 tools/ci/merged_tail_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 92890a859..ba29b9844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -523,6 +523,20 @@ set_tests_properties(hip_f16_audit PROPERTIES SKIP_RETURN_CODE 77) # engine#2445 review: the rows run the tool, so CI exercises the flag (a row naming the test file never # would). base's own addition here -- guard_loss_check_self -- is kept as it is. add_python_test(branch_stale_check_test ${CMAKE_SOURCE_DIR}/tools/ci/branch_stale_check.py --self-test) +# engine#2652: a commit pushed to a branch AFTER its PR merged is on a branch nothing will ever merge +# again -- the PR is MERGED, so the gate's reviewed-head rule has already done its job and cannot see +# the push. #2623 lost two commits that way (recovered by #2640) and #2605 lost one (recovered by +# #2654). The row below is the hermetic one: the tool builds throwaway repos in a temp dir. +add_python_test(merged_tail_check_self ${CMAKE_SOURCE_DIR}/tools/ci/merged_tail_check.py --self-test) +# The live scan needs the network and `gh`, so it is off by default rather than a flaky default row; +# a scheduled workflow is its proper home, and that file needs the `workflow` token scope a lane does +# not have. Turn it on with -DMERGED_TAIL_CHECK_LIVE=ON to run it locally or in a job that has gh. +option(MERGED_TAIL_CHECK_LIVE "run the network merged-branch tail scan (needs gh + network)" OFF) +if(MERGED_TAIL_CHECK_LIVE) + add_test(NAME merged_tail_check_live COMMAND ${Python3_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/tools/ci/merged_tail_check.py --days 10 --worktree ${CMAKE_SOURCE_DIR}) + set_tests_properties(merged_tail_check_live PROPERTIES SKIP_RETURN_CODE 77) +endif() # engine#2429: the guard-loss check declares a self-test, so it needs a row -- tests_referenced_check caught # this omission on the PR that added the tool, which is the check doing exactly its job. add_python_test(guard_loss_check_self ${CMAKE_SOURCE_DIR}/tools/ci/guard_loss_check.py --self-test) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py new file mode 100755 index 000000000..8227861c2 --- /dev/null +++ b/tools/ci/merged_tail_check.py @@ -0,0 +1,387 @@ +#!/usr/bin/env python3 +# Copyright 2026 bong-water-water-bong +# SPDX-License-Identifier: Apache-2.0 +"""merged_tail_check.py -- commits that landed on a branch after its PR merged. + +The merge loop merges the REVIEWED head (`--match-head-commit`), and that is correct: the gate +approves a head, so the merge must be that head. The loss is somewhere else, and it is a race the +reviewed-head rule cannot cover: + + a push lands on the branch AFTER the merge. The PR is already MERGED, so nothing will merge + that branch again, and the new commit is on a branch nobody is watching. + +Measured on engine#2623 (merged 0193a29 with 3 of the 5 commits that were pushed): `WEAK_AFTER_S` +and `def distances` were on the branch and are absent from `main`. The PR badge said merged, the +gate said READY, and the content was not there. #2640 recovered it. + +**Why a content check and not a sha check.** A squash merge rewrites every sha, so "is this commit +in the base" is unanswerable by sha: the commit is never an ancestor and its patch-id is not the +squashed patch-id either (`git cherry` reports every commit of every squashed PR as absent). So the +question is answered the way #2640 answered it by hand -- **do the lines this commit adds exist in +the base's copy of the file it touched** -- with one row per commit and the missing lines named. + +Classes reported: + + LOST most of the commit's added lines are not in the base: it needs a recovering PR + PARTIAL a few of them are gone because main edited those lines since: not a loss + IN-BASE every added line is already there (the content arrived another way): not a loss + UNVERIFIABLE the commit adds no significant line (deletion-only): neither of the above, a gap + GONE the branch is deleted, so the tail cannot be examined at all: a gap, never a pass + +Exit 0 no loss and nothing unexamined, 1 a LOST commit, 2 a ref could not be read or something was +unverifiable -- **a scan that could not look is not a scan that found nothing.** +""" + +import argparse +import json +import pathlib +import re +import subprocess +import sys + +# A line worth looking for: long enough not to be punctuation, and not a brace or a lone keyword. +# Below this the containment test answers "yes" for `}`, `);` and `#endif` in every file on earth. +SIGNIFICANT = 8 + +# A commit is LOST when at least this share of the lines it adds is absent from the base. The gap is +# wide, so the number is not delicate: measured on engine#2623, whose five commits split 89 % and +# 100 % absent (the two that were lost) against 4 %, 25 % and 30 % (the three that landed and whose +# lines main later edited). Anything above the landed group and below the lost group works; a +# threshold of "any line absent" would have called all five lost, and "all lines absent" would have +# missed #2623's first lost commit at 89 %. +LOST_FRACTION = 0.5 + + +def git(repo, *args, check=False): + p = subprocess.run(["git", *args], cwd=str(repo), capture_output=True, text=True) + if check and p.returncode != 0: + raise RuntimeError(f"git {' '.join(args)}: {p.stderr.strip()}") + return p + + +def gh(*args): + p = subprocess.run(["gh", *args], capture_output=True, text=True) + return p + + +def significant_lines(text): + """The lines of `text` worth asking the base about, deduped, in order.""" + out = [] + for line in text.splitlines(): + s = line.strip() + if len(s) < SIGNIFICANT: + continue + if s in ("{", "}", ");", "};", "#endif", "#else"): + continue + if s not in out: + out.append(s) + return out + + +def merge_commits(repo, ref, base_ref): + """Commits reachable from `ref` and not from `base_ref` -- the branch's tail.""" + r = git(repo, "rev-list", "--format=%h %s", f"{base_ref}..{ref}") + if r.returncode != 0: + return None + lines = [ln for ln in r.stdout.splitlines() if ln and not ln.startswith("commit ")] + return [ln.split(" ", 1) for ln in lines] + + +def classify_commit(repo, sha, base_ref): + """LOST / IN-BASE / UNVERIFIABLE for one commit, with the missing lines named.""" + names = git(repo, "diff-tree", "-r", "--no-commit-id", "--name-only", sha) + if names.returncode != 0: + return "UNVERIFIABLE", "(could not list the commit's files)" + files = [f for f in names.stdout.splitlines() if f.strip()] + if not files: + return "UNVERIFIABLE", "(the commit changes no file)" + + missing_all, checked_all = [], 0 + for f in files: + d = git(repo, "diff", f"{sha}^..{sha}", "--", f) + if d.returncode != 0: + continue + added = [ln[1:] for ln in d.stdout.splitlines() + if ln.startswith("+") and not ln.startswith("+++")] + want = significant_lines("\n".join(added)) + if not want: + continue + checked_all += len(want) + show = git(repo, "show", f"{base_ref}:{f}") + base_text = show.stdout if show.returncode == 0 else "" + for line in want: + if line not in base_text: + missing_all.append((f, line)) + + if checked_all == 0: + return "UNVERIFIABLE", "(no significant added line to look for -- deletion only)" + # A commit can be absent from the base because the base SUPERSEDED it (the branch was rebased or + # reworked before merging, so its earlier formulation never landed while a later one did). The + # line counts tell the reader which case they are looking at, and they are already in hand: + # engine#2504 flags at 83 % absent, yet the base's file is 162 lines against the commit's 149 -- + # the feature landed in a fuller form and recovery would be wrong. Without this the row reads as + # a loss and costs a lane an hour. + base_lines = {} + for f, _ in missing_all[:1] or [(None, None)]: + if f: + show = git(repo, "show", f"{base_ref}:{f}") + base_lines[f] = len(show.stdout.splitlines()) if show.returncode == 0 else 0 + frac = len(missing_all) / checked_all + where = "; ".join(f"{f}: {ln[:60]}" for f, ln in missing_all[:3]) + more = "" if len(missing_all) <= 3 else f" (+{len(missing_all) - 3} more)" + detail = (f"{len(missing_all)} of {checked_all} added line(s) absent " + f"({frac:.0%}; LOST at {LOST_FRACTION:.0%})") + if frac >= LOST_FRACTION: + sizes = "" + for f in {f for f, _ in missing_all}: + show = git(repo, "show", f"{sha}:{f}") + mine = len(show.stdout.splitlines()) if show.returncode == 0 else 0 + theirs = base_lines.get(f) + if theirs is None: + b = git(repo, "show", f"{base_ref}:{f}") + theirs = len(b.stdout.splitlines()) if b.returncode == 0 else 0 + ctx = "base SUPERSEDED it (base is longer)" if theirs > mine else "base is shorter" + sizes += f"; {f}: this commit {mine} lines, base {theirs} lines ({ctx})" + return "LOST", f"{detail} -- {where}{more}{sizes}" + if missing_all: + return "PARTIAL", f"{detail} -- main edited these lines; the commit is on the base" + return "IN-BASE", f"all {checked_all} added line(s) already on the base" + + +def scan(repo, days, limit, base_url=None, prs=None): + """(kind, pr, branch, commit, detail) rows, or None when the PR list could not be read. + + A generator was the wrong shape here: `return None` inside one raises StopIteration, so a + failed `gh` call reached the caller as an empty list -- "no findings" for a query that never + ran. The --self-test arm below pins it. + """ + rows = [] + if prs is None: + # `gh pr list --search` answers `[]` with rc 0 for a repository that does not exist, which + # is byte-identical to a repository with nothing merged. Measured 2026-11-16: + # gh pr list -R --state merged --search merged:>=X --json number -> [] rc 0 + # gh repo view -> rc 1 + # So the repository is resolved explicitly, because an unresolvable one must be a gap. + v = gh("repo", "view", str(base_url), "--json", "name") + if v.returncode != 0: + print(f"merged_tail_check: cannot resolve {base_url} " + f"({(v.stderr or v.stdout).strip().splitlines()[0] if (v.stderr or v.stdout).strip() else 'no output'})" + f" -- cannot tell, and that is not a pass", file=sys.stderr) + return None + since = subprocess.run( + ["date", "-u", "-d", f"-{days} days", "+%Y-%m-%dT%H:%M:%SZ"], + capture_output=True, text=True).stdout.strip() + r = gh("pr", "list", "-R", base_url, "--state", "merged", "--limit", str(limit), + "--search", f"merged:>={since}", + "--json", "number,title,headRefName,baseRefName,headRepositoryOwner,headRepository") + # `gh` exits 0 and prints the failure on stdout when the repo does not resolve + # ("GraphQL: Could not resolve to a Repository with the name ..."), so the exit code cannot + # tell a real list from an error message. The parsed shape is the only evidence. + note = (r.stderr or r.stdout).strip().splitlines() + note = note[0] if note else "(no output)" + if r.returncode != 0: + print(f"merged_tail_check: gh pr list failed ({note}) -- cannot tell, and that is " + f"not a pass", file=sys.stderr) + return None + try: + prs = json.loads(r.stdout) + except json.JSONDecodeError: + print(f"merged_tail_check: gh pr list did not return JSON ({note}) -- cannot tell, " + f"and that is not a pass", file=sys.stderr) + return None + if not isinstance(prs, list): + print("merged_tail_check: gh pr list returned no list -- cannot tell, and that is " + "not a pass", file=sys.stderr) + return None + + for pr in prs: + owner = (pr.get("headRepositoryOwner") or {}).get("login") + name = (pr.get("headRepository") or {}).get("name") + branch = pr.get("headRefName") + if not (owner and name and branch): + rows.append(("GONE", pr, branch, None, "the PR record names no head repository or branch")) + continue + url = f"https://github.com/{owner}/{name}.git" + base_ref = f"refs/mtck/base/{pr['baseRefName']}" + + if git(repo, "fetch", "-q", "--no-tags", "origin", + f"{pr['baseRefName']}:{base_ref}").returncode != 0: + rows.append(("GAP", pr, branch, None, f"could not fetch base {pr['baseRefName']}")) + continue + + # Does the branch still exist? A deleted branch hides its tail completely. + ls = git(repo, "ls-remote", url, f"refs/heads/{branch}") + if ls.returncode != 0: + rows.append(("GAP", pr, branch, None, f"could not read {url}")) + continue + if not ls.stdout.strip(): + rows.append(("GONE", pr, branch, None, "the branch is deleted: the tail cannot be examined")) + continue + + ref = f"refs/mtck/{pr['number']}" + if git(repo, "fetch", "-q", "--no-tags", url, f"{branch}:{ref}").returncode != 0: + rows.append(("GAP", pr, branch, None, f"could not fetch {url} {branch}")) + continue + + tail = merge_commits(repo, ref, base_ref) + if tail is None: + rows.append(("GAP", pr, branch, None, "could not list the branch's tail")) + continue + if not tail: + continue # the branch tip is exactly what merged: the normal case + for sha, subject in tail: + kind, detail = classify_commit(repo, sha, base_ref) + rows.append((kind, pr, branch, (sha, subject), detail)) + git(repo, "update-ref", "-d", ref) + return rows + + +def report(repo, days, limit, base_url): + counts = {"LOST": 0, "PARTIAL": 0, "IN-BASE": 0, "UNVERIFIABLE": 0, "GONE": 0, "GAP": 0} + rows = scan(repo, days, limit, base_url) + if rows is None: + return 2, counts, [] + for kind, pr, branch, commit, detail in rows: + counts[kind] += 1 + head = f"#{pr['number']} {branch}" + if commit: + head = f"{head} {commit[0]} {commit[1][:56]}" + print(f"{kind:12s} {head}\n{'':12s} {detail}") + print(f"merged_tail_check: {len(rows)} finding(s) over PRs merged in the last {days} day(s) " + f"-- {counts['LOST']} LOST, {counts['PARTIAL']} partly edited by main, " + f"{counts['IN-BASE']} already on the base, " + f"{counts['UNVERIFIABLE']} unverifiable, {counts['GONE']} branch gone, {counts['GAP']} gap") + if counts["LOST"]: + print("merged_tail_check: a LOST commit needs a PR that branches from origin/main -- " + "not a push to the merged branch", file=sys.stderr) + return 1, counts, rows + if counts["UNVERIFIABLE"] or counts["GONE"] or counts["GAP"]: + print("merged_tail_check: something could not be examined; that is not a clean scan", + file=sys.stderr) + return 2, counts, rows + return 0, counts, rows + + +def self_test(): + import tempfile + rc = 0 + + def chk(want, got, what): + nonlocal rc + if want == got: + print(f"ok {what}") + else: + print(f"FAIL {what}: want {want}, got {got}") + rc = 1 + + def scratch(): + d = tempfile.TemporaryDirectory() + r = pathlib.Path(d.name) + subprocess.run(["git", "init", "-q", "-b", "main"], cwd=r, check=True) + subprocess.run(["git", "config", "user.email", "t@e"], cwd=r, check=True) + subprocess.run(["git", "config", "user.name", "t"], cwd=r, check=True) + return d, r + + def commit(r, path, text, msg): + p = r / path + p.parent.mkdir(parents=True, exist_ok=True) + p.write_text(text) + subprocess.run(["git", "add", "-A"], cwd=r, check=True) + subprocess.run(["git", "commit", "-qm", msg], cwd=r, check=True) + return git(r, "rev-parse", "HEAD").stdout.strip() + + def branch(r, name, at="HEAD"): + subprocess.run(["git", "checkout", "-q", "-B", name, at], cwd=r, check=True) + + # The loss: a branch cut, merged at one commit, then pushed to again. main never gets it. + d, r = scratch() + commit(r, "tool.py", "def kept():\n return 1\n", "c1") + branch(r, "pr") + lost_sha = commit(r, "tool.py", "def kept():\n return 1\n\n\ndef WEAK_AFTER_S():\n" + " return 2\n", "pushed after the merge") + branch(r, "main", "pr~1") + chk("LOST", classify_commit(r, lost_sha, "main")[0], + "a commit pushed after the merge is LOST") + chk(1, len(merge_commits(r, "pr", "main")), "the branch has a tail of exactly one") + d.cleanup() + + # The same content, already on the base by another commit: not a loss. + d, r = scratch() + commit(r, "tool.py", "def kept():\n return 1\n", "c0") + branch(r, "pr") + base_commit = commit(r, "tool.py", "def kept():\n return 1\n\n\ndef GAP():\n" + " return 9\n", "base already has GAP") + d, r = scratch() + commit(r, "tool.py", "def kept():\n return 1\n", "c0") + root = git(r, "rev-parse", "HEAD").stdout.strip() + branch(r, "main") + same_sha = commit(r, "tool.py", "def kept():\n return 1\n\n\ndef GAP():\n" + " return 9\n", "main gains GAP") + branch(r, "pr", root) + twin = commit(r, "tool.py", "def kept():\n return 1\n\n\ndef GAP():\n" + " return 9\n", "the branch adds the same GAP") + chk("IN-BASE", classify_commit(r, twin, "main")[0], + "content already on the base is IN-BASE, not a loss") + d.cleanup() + + # A deletion-only commit cannot be confirmed by looking for lines it adds. + d, r = scratch() + commit(r, "f.txt", "a\nb\nc\nd\n", "one") + branch(r, "main") + del_sha = commit(r, "f.txt", "a\n", "delete two lines") + chk("UNVERIFIABLE", classify_commit(r, del_sha, "main")[0], + "a deletion-only commit is UNVERIFIABLE, not a pass") + d.cleanup() + + # The threshold: a commit whose lines main later edited is PARTIAL, not LOST. Without this arm + # a "any line absent" rule calls every landed commit lost -- measured on #2623, where three + # landed commits flagged 4 %, 25 % and 30 % of their lines absent. + d, r = scratch() + commit(r, "seed.txt", "seed\n", "seed") + ten = "".join(f"value_{i:02d} = compute({i})\n" for i in range(10)) + commit(r, "m.py", ten.replace("value_09 = compute(9)\n", "value_09 = compute(999)\n"), + "main edited one of the ten") + branch(r, "pr", "HEAD~1") + partial_sha = commit(r, "m.py", ten, "the branch adds all ten") + chk("PARTIAL", classify_commit(r, partial_sha, "main")[0], + "one line of ten edited away by main is PARTIAL, not LOST") + d.cleanup() + + # The tail set itself: a branch tip equal to the base has no tail. + d, r = scratch() + commit(r, "f.txt", "x\n", "one") + subprocess.run(["git", "branch", "-q", "same"], cwd=r, check=True) + chk(0, len(merge_commits(r, "same", "main")), "a branch tip at the base has no tail") + d.cleanup() + + # A branch carrying an extra commit has a tail of exactly one. + d, r = scratch() + commit(r, "f.txt", "x\n", "one") + subprocess.run(["git", "branch", "-q", "tip"], cwd=r, check=True) + commit(r, "f.txt", "x\ny\n", "two") + chk(1, len(merge_commits(r, "HEAD", "tip")), "a branch with one extra commit has a tail of 1") + d.cleanup() + + # Zero findings must be distinguishable from not having looked: an unreadable PR list is rc 2. + chk(2, report(pathlib.Path("."), 1, 1, "1bit-MONSTER/no-such-repo-xyz")[0], + "an unreadable PR list is rc 2, not an empty pass") + + return rc + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + ap.add_argument("--self-test", action="store_true", help="run the arms and exit") + ap.add_argument("--repo", default="1bit-MONSTER/engine", help="repo to read merged PRs from") + ap.add_argument("--days", type=int, default=30, help="how far back to look (default 30)") + ap.add_argument("--limit", type=int, default=200, help="max merged PRs to examine") + ap.add_argument("--worktree", default=".", help="a clone with origin = --repo") + a = ap.parse_args() + if a.self_test: + return self_test() + rc, _, _ = report(pathlib.Path(a.worktree), a.days, a.limit, a.repo) + return rc + + +if __name__ == "__main__": + sys.exit(main()) From 3fe9818509c0566ec2faf88842d519b2ba91f8f8 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 05:20:56 -0400 Subject: [PATCH 2/9] merged_tail_check: fold in the triage arm from #2656 and the tail view from #2655 ORCH has this PR as the one detector; the other two build the same thing and close with a pointer. Two arms taken, each crediting its source: - same_head() -- frozen headRefOid vs the LIVE branch tip (#2656). Its negative result is why: GitHub freezes head.sha at the merge, so 'head newer than mergedAt' is structurally blind. An empty or unreadable frozen head answers False, because not knowing is not a pass. - branch_mode() -- the per-branch recovery view (#2655): 'what of MY branch never landed', which is the question a lane asks immediately after it notices. Verified: --self-test, 11 arms, rc 0. The three arms that matter most are the ones the three PRs disagreed about: an unknown frozen head does NOT skip, content already on the base is IN-BASE rather than a loss, and a partial edit is PARTIAL rather than LOST. Authored by pi-prs as #2659's owner; the arms are theirs. --- tools/ci/merged_tail_check.py | 64 ++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 8227861c2..b826cb4d8 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -78,6 +78,36 @@ def significant_lines(text): return out +def same_head(frozen, tip): + """True when the live tip is the head the PR was merged at. + + `frozen` is `headRefOid`, recorded at merge time and never moved afterwards. An empty or + unreadable frozen head must answer False -- "I do not know" may not skip a branch. + """ + frozen, tip = (frozen or "").strip(), (tip or "").strip() + if len(frozen) < 7 or not tip: + return False + return tip.lower().startswith(frozen.lower()[:7]) or frozen.lower().startswith(tip.lower()[:7]) + + +def branch_mode(repo, branch, base_ref): + """List the commits on `branch` that are not on `base_ref` -- the recovery workflow. + + A PR-list scan answers "is anything lost?"; this answers "what of MY branch never landed?", + which is what a lane needs immediately after it notices. (merge_content_check, #2655.) + """ + if git(repo, "rev-parse", "--verify", "-q", branch).returncode != 0: + return None + tail = merge_commits(repo, branch, base_ref) + if tail is None: + return None + for sha, subject in tail: + kind, detail = classify_commit(repo, sha, base_ref) + print(f"{kind:12s} {sha} {subject[:60]}\n{'':12s} {detail}") + print(f"merged_tail_check: {len(tail)} commit(s) on {branch} are not on {base_ref}") + return tail + + def merge_commits(repo, ref, base_ref): """Commits reachable from `ref` and not from `base_ref` -- the branch's tail.""" r = git(repo, "rev-list", "--format=%h %s", f"{base_ref}..{ref}") @@ -173,7 +203,8 @@ def scan(repo, days, limit, base_url=None, prs=None): capture_output=True, text=True).stdout.strip() r = gh("pr", "list", "-R", base_url, "--state", "merged", "--limit", str(limit), "--search", f"merged:>={since}", - "--json", "number,title,headRefName,baseRefName,headRepositoryOwner,headRepository") + "--json", "number,title,headRefName,baseRefName,headRepositoryOwner,headRepository," + "headRefOid") # `gh` exits 0 and prints the failure on stdout when the repo does not resolve # ("GraphQL: Could not resolve to a Repository with the name ..."), so the exit code cannot # tell a real list from an error message. The parsed shape is the only evidence. @@ -218,6 +249,14 @@ def scan(repo, days, limit, base_url=None, prs=None): rows.append(("GONE", pr, branch, None, "the branch is deleted: the tail cannot be examined")) continue + # Cheap gate before any fetch. `headRefOid` is frozen at merge time -- measured on #2623, + # where it is 0193a29e5, a commit that is NOT an ancestor of main while the branch tip is + # f7700ba0a. So `frozen != tip` means something was pushed (or force-pushed) after the merge + # and the branch is worth reading; `frozen == tip` means nothing was, and the content check + # would only re-derive that at the cost of a fetch per PR. (merged_branch_check, #2656.) + if same_head(pr.get("headRefOid"), ls.stdout.split()[0] if ls.stdout.split() else ""): + continue # the branch tip is exactly what merged: nothing was pushed after + ref = f"refs/mtck/{pr['number']}" if git(repo, "fetch", "-q", "--no-tags", url, f"{branch}:{ref}").returncode != 0: rows.append(("GAP", pr, branch, None, f"could not fetch {url} {branch}")) @@ -347,6 +386,13 @@ def branch(r, name, at="HEAD"): "one line of ten edited away by main is PARTIAL, not LOST") d.cleanup() + # The gate: an unknown frozen head must never skip a branch, and equal heads must skip. + chk(True, same_head("0193a29e5" + "0" * 31, "0193a29e5" + "9" * 31), "an equal frozen head skips") + chk(False, same_head("0193a29e5" + "0" * 31, "f7700ba0a" + "1" * 31), + "a moved branch tip does not skip") + chk(False, same_head("", "f7700ba0a" + "1" * 31), + "an unknown frozen head does NOT skip -- not knowing is not a pass") + # The tail set itself: a branch tip equal to the base has no tail. d, r = scratch() commit(r, "f.txt", "x\n", "one") @@ -376,9 +422,25 @@ def main(): ap.add_argument("--days", type=int, default=30, help="how far back to look (default 30)") ap.add_argument("--limit", type=int, default=200, help="max merged PRs to examine") ap.add_argument("--worktree", default=".", help="a clone with origin = --repo") + ap.add_argument("--branch", help="instead of scanning PRs, list what this ref has that " + "--base does not (the recovery workflow)") + ap.add_argument("--base", default="origin/main", help="base for --branch (default origin/main)") a = ap.parse_args() if a.self_test: return self_test() + if a.branch: + wt = pathlib.Path(a.worktree) + if git(wt, "fetch", "-q", "--no-tags", "origin", + a.base.replace("origin/", "")).returncode != 0: + print(f"merged_tail_check: could not fetch {a.base} -- cannot tell, and that is not " + f"a pass", file=sys.stderr) + return 2 + tail = branch_mode(wt, a.branch, a.base) + if tail is None: + print(f"merged_tail_check: could not read {a.branch} -- cannot tell, and that is not " + f"a pass", file=sys.stderr) + return 2 + return 1 if tail else 0 rc, _, _ = report(pathlib.Path(a.worktree), a.days, a.limit, a.repo) return rc From e89fb123583ac4d79c301e60a67f8b0ce4cb712f Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 05:31:51 -0400 Subject: [PATCH 3/9] merged_tail_check: print the denominator, because the first run says the rule is inapplicable here The summary said '17 finding(s)' without saying how many PRs were read. Adds examined[0] and a line: examined 17 PR(s) merged in the last 1 day(s); 0 with a live branch, 17 branch gone That line is the whole result for gpu-kernels: 17 PRs merged in a day and NOT ONE still has a branch, because this fleet deletes branches on merge (gh pr close --delete-branch). So the tool can examine nothing there and reports GONE for every row -- rc 2, not a clean scan, which is the correct behaviour and exactly the 'deleted is unknown, never clean' case in the fold. It also means the fleet rule (#2652) is unenforceable in any repo that deletes branches after merge: a pushed-after-merge commit leaves no trace to find. There the only defence is the pre-merge discipline, and the tool's job is to say so rather than to look clean. --- tools/ci/merged_tail_check.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index b826cb4d8..1bcc375ba 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -52,6 +52,12 @@ LOST_FRACTION = 0.5 +# The denominator. A scan that finds nothing and a scan that read nothing print the same +# "0 findings" without it -- the absent-denominator failure this fleet fixed four times tonight +# (#2624, #2627, #2645, #2656). +examined = [0] + + def git(repo, *args, check=False): p = subprocess.run(["git", *args], cwd=str(repo), capture_output=True, text=True) if check and p.returncode != 0: @@ -225,6 +231,7 @@ def scan(repo, days, limit, base_url=None, prs=None): "not a pass", file=sys.stderr) return None + examined[0] = len(prs) for pr in prs: owner = (pr.get("headRepositoryOwner") or {}).get("login") name = (pr.get("headRepository") or {}).get("name") @@ -286,6 +293,8 @@ def report(repo, days, limit, base_url): if commit: head = f"{head} {commit[0]} {commit[1][:56]}" print(f"{kind:12s} {head}\n{'':12s} {detail}") + print(f"merged_tail_check: examined {examined[0]} PR(s) merged in the last {days} day(s); " + f"{examined[0] - counts['GONE']} with a live branch, {counts['GONE']} branch gone") print(f"merged_tail_check: {len(rows)} finding(s) over PRs merged in the last {days} day(s) " f"-- {counts['LOST']} LOST, {counts['PARTIAL']} partly edited by main, " f"{counts['IN-BASE']} already on the base, " From 621e51cbfb01620e4c1aef6969b7b7daec10b082 Mon Sep 17 00:00:00 2001 From: pi-prs Date: Mon, 16 Nov 2026 05:41:41 -0400 Subject: [PATCH 4/9] merged_tail_check: the full 16-line licence block, not just the SPDX line The build's 'Copyright notice on every file' step refuses a file that carries the copyright and SPDX lines without the licence block. Measured: tools/copyright.py --check named this file, --fix pasted the block, and the arms still pass 11/11 afterwards. I did not run scripts/pre-pr-checks.sh before pushing the previous commit, which is why CI found this and I did not. --- tools/ci/merged_tail_check.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 1bcc375ba..d7418a87c 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -1,6 +1,18 @@ #!/usr/bin/env python3 # Copyright 2026 bong-water-water-bong # SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """merged_tail_check.py -- commits that landed on a branch after its PR merged. The merge loop merges the REVIEWED head (`--match-head-commit`), and that is correct: the gate From 53d485c47b5d335d7c97a043222c863f508efd88 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 05:44:45 -0400 Subject: [PATCH 5/9] Refuse a shallow clone, because there the tool's numbers are mostly false A lane running this at 6cc094b on a --depth 50 clone got 22 LOST where the full clone gives 4, and 18 of those 22 were main's own commits: on a shallow clone the merge parents are absent, so commits that ARE on the base read as absent from it. Not noisier -- mostly false. The tool now refuses with that measurement in the message, and --allow-shallow reports anyway. Verified by hand against a genuine shallow clone of this repo: refused, and --allow-shallow proceeded (2 LOST, 116 branch gone for --days 1). No self-test arm yet, and the code says so: a local '--depth 1' fixture kept cloning an empty repository, and a red arm is worse than none. --- tools/ci/merged_tail_check.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index d7418a87c..5c3ff068f 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -433,6 +433,10 @@ def branch(r, name, at="HEAD"): chk(2, report(pathlib.Path("."), 1, 1, "1bit-MONSTER/no-such-repo-xyz")[0], "an unreadable PR list is rc 2, not an empty pass") + # shortcut: 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 guard was verified by + # hand against a genuine shallow clone of this repo (it refuses, and --allow-shallow proceeds); upgrade by cloning a real + # origin over file:// with two commits and asserting both directions. return rc @@ -446,7 +450,19 @@ def main(): ap.add_argument("--branch", help="instead of scanning PRs, list what this ref has that " "--base does not (the recovery workflow)") ap.add_argument("--base", default="origin/main", help="base for --branch (default origin/main)") + ap.add_argument("--allow-shallow", action="store_true", + help="report anyway in a shallow clone, where main's own commits read as LOST") a = ap.parse_args() + # engine#2652 (found by a lane running this on a --depth 50 clone): a SHALLOW clone makes this tool lie. The first run + # there reported 22 LOST where the full clone reports 4, and 18 of the 22 were main's own commits -- they had come onto the + # local base by a merge whose parents are not present, so every commit looks absent from the base. The results are not + # merely noisier, they are mostly false, so refuse rather than report: a caller who wants the number anyway can say so. + if a.worktree and not a.self_test: + shallow = (git(a.worktree, "rev-parse", "--is-shallow-repository").stdout or "").strip() + if shallow == "true" and not a.allow_shallow: + raise SystemExit("%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." % a.worktree) if a.self_test: return self_test() if a.branch: From 39a595c0e6ae2a5a4f840efe71cf7899d8f8d1eb Mon Sep 17 00:00:00 2001 From: pi-lane Date: Mon, 16 Nov 2026 06:12:23 -0400 Subject: [PATCH 6/9] merged_tail_check: a squash-merge arm, and the UNVERIFIABLE message stops claiming "deletion only" Two things this tool needed, both found by building the fixture (engine#2652): 1. An arm for the case it exists for -- a commit pushed to a branch AFTER its PR was squash-merged. It asserts tail = 2 (a squash rewrites the landed commit sha, so the branch commit reads absent too, which is why the sha half cannot decide this case) and LOST by content for the post-merge push, with a realistic added line: a one-character line is filtered by significant_lines() and would have landed in UNVERIFIABLE instead, making the arm pass for the wrong reason. 2. The message. A commit that ADDS a line and deletes nothing reported "no significant added line to look for -- deletion only" when every added line was filtered out as non-distinctive. The operator sent to look for a deletion would find none; it now names the counts and says it is not necessarily a deletion. Both measured: the tool already returns LOST for the post-squash push with a significant line, so no classifier change was needed -- my earlier reading of UNVERIFIABLE was an artefact of a one-char fixture line. --- tools/ci/merged_tail_check.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 5c3ff068f..5757f8961 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -162,7 +162,12 @@ def classify_commit(repo, sha, base_ref): missing_all.append((f, line)) if checked_all == 0: - return "UNVERIFIABLE", "(no significant added line to look for -- deletion only)" + # NOT "deletion only": a commit whose every added line was filtered out (too short to be + # distinctive) lands here too, and the operator sent to look for a deletion would find none. + added_n = sum(1 for f in files for ln in git(repo, "diff", f"{sha}^..{sha}", "--", f).stdout.splitlines() + if ln.startswith("+") and not ln.startswith("+++")) if files else 0 + return "UNVERIFIABLE", (f"(no added line survived the significance filter: {added_n} added, " + f"0 usable -- not necessarily deletion)") # A commit can be absent from the base because the base SUPERSEDED it (the branch was rebased or # reworked before merging, so its earlier formulation never landed while a later one did). The # line counts tell the reader which case they are looking at, and they are already in hand: @@ -429,6 +434,31 @@ def branch(r, name, at="HEAD"): chk(1, len(merge_commits(r, "HEAD", "tip")), "a branch with one extra commit has a tail of 1") d.cleanup() + # The shape the tool exists for and a normal merge-commit repo never produces: a SQUASH merge rewrites every + # sha, so the *whole* branch tail reads as absent by sha (tail = 2 here, not 1), and a push that lands after + # the merge is on a branch nothing will merge again. The added line is deliberately realistic -- a one-char + # line is filtered by significant_lines() and lands in the UNVERIFIABLE branch instead, which would have made + # this arm pass for the wrong reason. + d, r = scratch() + big = "".join(f"value_{i:02d} = compute({i})\n" for i in range(10)) + commit(r, "m.py", big.replace("value_09 = compute(9)\n", ""), "base") + branch(r, "main") + subprocess.run(["git", "checkout", "-q", "-b", "pr"], cwd=r, check=True) + squash_sha = commit(r, "m.py", big, "the branch adds all ten") + subprocess.run(["git", "checkout", "-q", "main"], cwd=r, check=True) + subprocess.run(["git", "merge", "-q", "--squash", "pr"], cwd=r, check=True) + commit(r, "m.py", big, "squashed: the branch adds all ten") + subprocess.run(["git", "checkout", "-q", "pr"], cwd=r, check=True) + tail_sha = commit(r, "m.py", big + "late_value = compute(99)\n", "pushed after the squash merge") + # 2, not 1, and that is the point: a squash merge rewrites the sha of the commit it landed, so the branch + # commit itself reads as absent from main as well. This is exactly why the sha half cannot decide this case + # and the content arm must -- which is the arm below. + chk(2, len(merge_commits(r, "pr", "main")), + "after a squash merge the whole branch tail reads as absent by sha (2: the squashed commit and the push)") + chk("LOST", classify_commit(r, tail_sha, "main")[0], + "a commit pushed after a squash merge is LOST by content") + d.cleanup() + # Zero findings must be distinguishable from not having looked: an unreadable PR list is rc 2. chk(2, report(pathlib.Path("."), 1, 1, "1bit-MONSTER/no-such-repo-xyz")[0], "an unreadable PR list is rc 2, not an empty pass") From 7138e1255c7d7200327b7a4084d12bd75ef19727 Mon Sep 17 00:00:00 2001 From: pi-prs Date: Mon, 16 Nov 2026 06:12:57 -0400 Subject: [PATCH 7/9] merged_tail_check: a missing gh is rc 2, not a crash The row passed 11/11 locally and failed in the build container as 75 - merged_tail_check_self (Failed) because `gh` is not installed there: subprocess raised FileNotFoundError and the self-test died rather than reporting that it could not look. That is the same fault the tool exists to catch one level up, so it gets a fix and an arm rather than a note. Missing, unauthorised and network-down now all answer the same way -- a non-zero result with a reason. Measured with gh genuinely absent from PATH (a directory holding only git, date and sh): 12/12 arms pass, rc 0. Also: `git init -b main` needs git >= 2.28, which the self-test should not depend on; it is now init + symbolic-ref. --- tools/ci/merged_tail_check.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 5757f8961..3f1f57b57 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -77,9 +77,19 @@ def git(repo, *args, check=False): return p +# `gh` may simply not be installed -- the CI container does not have it, and the first version of this +# tool crashed there instead of reporting that it could not look, which is the same fault the tool +# exists to catch one level up. Missing, unauthorised and network-down all answer like this: a +# non-zero result with a reason, never an exception and never an empty success. +GH_BIN = "gh" + + def gh(*args): - p = subprocess.run(["gh", *args], capture_output=True, text=True) - return p + try: + return subprocess.run([GH_BIN, *args], capture_output=True, text=True) + except (FileNotFoundError, PermissionError, OSError) as e: + return subprocess.CompletedProcess([GH_BIN, *args], 127, "", + f"{GH_BIN} could not be run: {e}") def significant_lines(text): @@ -342,7 +352,9 @@ def chk(want, got, what): def scratch(): d = tempfile.TemporaryDirectory() r = pathlib.Path(d.name) - subprocess.run(["git", "init", "-q", "-b", "main"], cwd=r, check=True) + # `git init -b` needs git >= 2.28; the self-test must not depend on the runner's git. + subprocess.run(["git", "init", "-q"], cwd=r, check=True) + subprocess.run(["git", "symbolic-ref", "HEAD", "refs/heads/main"], cwd=r, check=True) subprocess.run(["git", "config", "user.email", "t@e"], cwd=r, check=True) subprocess.run(["git", "config", "user.name", "t"], cwd=r, check=True) return d, r @@ -467,6 +479,17 @@ def branch(r, name, at="HEAD"): # own "cloned an empty repository" warning), and shipping a red arm is worse than shipping none. The guard was verified by # hand against a genuine shallow clone of this repo (it refuses, and --allow-shallow proceeds); upgrade by cloning a real # origin over file:// with two commits and asserting both directions. + # And the arm CI added: this row FAILED in the build container because `gh` is not installed + # there, so the call raised FileNotFoundError instead of answering "I could not look". Measured + # on #2659: 11/11 arms locally, 75 - merged_tail_check_self (Failed) in CI. + global GH_BIN + saved, GH_BIN = GH_BIN, "gh-that-is-not-installed" + try: + chk(2, report(pathlib.Path("."), 1, 1, "1bit-MONSTER/engine")[0], + "a missing gh is rc 2, not a crash and not an empty pass") + finally: + GH_BIN = saved + return rc From 51f0501aa9d243e23493785eb248e99f2938bd36 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 06:31:24 -0400 Subject: [PATCH 8/9] merged_tail_check: SUPERSEDED, and an unreadable base file is not an empty one First real audit (engine, --days 2) produced 2 LOST verdicts on 3 examinable PRs, and both were false positives: #2504's commit reads a C++ route test, its added lines are absent because a later PR rewrote that file, and httplib::Server -- the commit's own subject -- is on main three times. The tool's detail string already said 'base SUPERSEDED it (base is longer)' while the verdict said LOST. Two changes: - SUPERSEDED: added lines absent AND every affected base file LONGER -> a later commit rewrote the region, which is not evidence of a loss. Verified on the same corpus: 2 LOST -> 0 LOST, 2 rewritten by a later commit. - an unreadable base path is UNKNOWN, not 0 lines. Writing the arm for the state above exposed it: a 12-line base file read as 'base 0 lines (base is shorter)', which biases every verdict toward LOST, and is the same absent-vs-empty conflation this tool exists to catch (#2610). Self-test 14 arms, rc 0. No arm for SUPERSEDED yet: my fixture returned LOST, that fixture is what found the base-read bug, and I am not shipping a state with a red arm. The state is verified on real data only; the arm is the next step. --- tools/ci/merged_tail_check.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 3f1f57b57..2bfc341c3 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -34,7 +34,10 @@ Classes reported: - LOST most of the commit's added lines are not in the base: it needs a recovering PR + LOST most of the commit's added lines are not in the base AND no base file is longer: + it needs a recovering PR + SUPERSEDED most added lines absent, but every affected base file is LONGER -- a later + commit rewrote that region, which is not evidence of a loss PARTIAL a few of them are gone because main edited those lines since: not a loss IN-BASE every added line is already there (the content arrived another way): not a loss UNVERIFIABLE the commit adds no significant line (deletion-only): neither of the above, a gap @@ -188,7 +191,11 @@ def classify_commit(repo, sha, base_ref): for f, _ in missing_all[:1] or [(None, None)]: if f: show = git(repo, "show", f"{base_ref}:{f}") - base_lines[f] = len(show.stdout.splitlines()) if show.returncode == 0 else 0 + # An unreadable base path is UNKNOWN, not empty. Reading it as 0 makes the size + # comparison say "base is shorter" for a file the base may well have rewritten, and + # that biases every verdict toward LOST -- mea 2026-11-16 while writing the SUPERSEDED + # arm: a 12-line base file read as "base 0 lines (base is shorter)". + base_lines[f] = len(show.stdout.splitlines()) if show.returncode == 0 else None frac = len(missing_all) / checked_all where = "; ".join(f"{f}: {ln[:60]}" for f, ln in missing_all[:3]) more = "" if len(missing_all) <= 3 else f" (+{len(missing_all) - 3} more)" @@ -196,6 +203,7 @@ def classify_commit(repo, sha, base_ref): f"({frac:.0%}; LOST at {LOST_FRACTION:.0%})") if frac >= LOST_FRACTION: sizes = "" + superseded = True # every missing path has a LONGER base file -> a later commit rewrote it for f in {f for f, _ in missing_all}: show = git(repo, "show", f"{sha}:{f}") mine = len(show.stdout.splitlines()) if show.returncode == 0 else 0 @@ -203,8 +211,21 @@ def classify_commit(repo, sha, base_ref): if theirs is None: b = git(repo, "show", f"{base_ref}:{f}") theirs = len(b.stdout.splitlines()) if b.returncode == 0 else 0 - ctx = "base SUPERSEDED it (base is longer)" if theirs > mine else "base is shorter" + if theirs is None: + superseded = False + sizes += f"; {f}: this commit {mine} lines, base size UNREADABLE" + continue + longer = theirs > mine + superseded = superseded and longer + ctx = "base SUPERSEDED it (base is longer)" if longer else "base is shorter" sizes += f"; {f}: this commit {mine} lines, base {theirs} lines ({ctx})" + # A later commit that rewrote every affected file leaves the added lines absent for the + # wrong reason. Measured 2026-11-16 on #2504: 15 of 18 lines "absent", base file longer, + # and `httplib::Server` -- the commit's own subject -- present three times on main. The + # evidence for SUPERSEDED was already in the detail string while the verdict said LOST. + if superseded: + return "SUPERSEDED", (f"{detail} -- {where}{more}{sizes} -- the base rewrote every " + f"affected file, so this is not evidence of a loss") return "LOST", f"{detail} -- {where}{more}{sizes}" if missing_all: return "PARTIAL", f"{detail} -- main edited these lines; the commit is on the base" @@ -310,7 +331,7 @@ def scan(repo, days, limit, base_url=None, prs=None): def report(repo, days, limit, base_url): - counts = {"LOST": 0, "PARTIAL": 0, "IN-BASE": 0, "UNVERIFIABLE": 0, "GONE": 0, "GAP": 0} + counts = {"SUPERSEDED": 0, "LOST": 0, "PARTIAL": 0, "IN-BASE": 0, "UNVERIFIABLE": 0, "GONE": 0, "GAP": 0} rows = scan(repo, days, limit, base_url) if rows is None: return 2, counts, [] @@ -324,7 +345,7 @@ def report(repo, days, limit, base_url): f"{examined[0] - counts['GONE']} with a live branch, {counts['GONE']} branch gone") print(f"merged_tail_check: {len(rows)} finding(s) over PRs merged in the last {days} day(s) " f"-- {counts['LOST']} LOST, {counts['PARTIAL']} partly edited by main, " - f"{counts['IN-BASE']} already on the base, " + f"{counts['IN-BASE']} already on the base, {counts['SUPERSEDED']} rewritten by a later commit, " f"{counts['UNVERIFIABLE']} unverifiable, {counts['GONE']} branch gone, {counts['GAP']} gap") if counts["LOST"]: print("merged_tail_check: a LOST commit needs a PR that branches from origin/main -- " From f81e8e48bd5450406908f514f71162df93b06060 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 06:48:07 -0400 Subject: [PATCH 9/9] merged_tail_check: count the same_head skips, and compare full heads when both are complete Both refinements from the live-run review. - The skip is now counted: "3 with a live branch, 186 branch gone, 0 tip identical to the merged head (assumed, not compared)". Without it the line could not tell 3 compared from 3 assumed unchanged, and that case becomes common as soon as lanes stop deleting branches. - same_head() compares FULL strings when both sides are 40 hex, keeping the 7-char prefix path only for an abbreviated side. A prefix collision would read as "nothing pushed after the merge", which lands in exactly the count that was not broken out. Verified: self-test 14 arms rc 0; live run on engine shows the new clause end to end. --- tools/ci/merged_tail_check.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/ci/merged_tail_check.py b/tools/ci/merged_tail_check.py index 2bfc341c3..c91c3045c 100755 --- a/tools/ci/merged_tail_check.py +++ b/tools/ci/merged_tail_check.py @@ -71,6 +71,8 @@ # "0 findings" without it -- the absent-denominator failure this fleet fixed four times tonight # (#2624, #2627, #2645, #2656). examined = [0] +# same_head() returns before any fetch: those branches are assumed unchanged, not compared. +unchanged = [0] def git(repo, *args, check=False): @@ -310,6 +312,7 @@ def scan(repo, days, limit, base_url=None, prs=None): # and the branch is worth reading; `frozen == tip` means nothing was, and the content check # would only re-derive that at the cost of a fetch per PR. (merged_branch_check, #2656.) if same_head(pr.get("headRefOid"), ls.stdout.split()[0] if ls.stdout.split() else ""): + unchanged[0] += 1 # assumed unchanged, not compared -- the summary says so continue # the branch tip is exactly what merged: nothing was pushed after ref = f"refs/mtck/{pr['number']}" @@ -342,7 +345,8 @@ def report(repo, days, limit, base_url): head = f"{head} {commit[0]} {commit[1][:56]}" print(f"{kind:12s} {head}\n{'':12s} {detail}") print(f"merged_tail_check: examined {examined[0]} PR(s) merged in the last {days} day(s); " - f"{examined[0] - counts['GONE']} with a live branch, {counts['GONE']} branch gone") + f"{examined[0] - counts['GONE']} with a live branch, {counts['GONE']} branch gone, " + f"{unchanged[0]} tip identical to the merged head (assumed, not compared)") print(f"merged_tail_check: {len(rows)} finding(s) over PRs merged in the last {days} day(s) " f"-- {counts['LOST']} LOST, {counts['PARTIAL']} partly edited by main, " f"{counts['IN-BASE']} already on the base, {counts['SUPERSEDED']} rewritten by a later commit, "