From dc54e645fdba2f654c21bd509b36bf7af17e06c6 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 14 Nov 2026 17:25:31 -0400 Subject: [PATCH 1/3] pre-pr-checks: run guard_loss_check, and fix the crash it exposed on the rewrite path The check landed in #2429 with a false-positive rate measured over 15 open PR heads and no runner, deliberately: a hit needs a human to decide re-shape vs loss. Wiring it for real is what found the first defect in it. **The bug.** check()'s print loop unpacks `moved` entries as 3-tuples, and the "guard rewritten in place, identifiers still present" path appended 2-tuples. So any diff that rewrites a guard - the common, benign shape - raised ValueError, and Python's traceback exits **1**, which is the LOST exit code. A crash wearing a verdict, in the tool whose subject is exactly that. Fixed, with a self-test arm (rewritten in place -> note, rc 0) that turns red when the 2-tuple is put back. Nothing else in the tool changes: the rarity rule, the head-tree search, the three-way exits and the 15 arms are as merged. **The row.** `tools/ci/guard_loss_check.py --check --base $base`, beside the other --base checks and before hip_f16_audit (which is the one row that depends on a fetched tree). Added to docs/pre-pr-checks.md at the same position, because the runner refuses to run when the page and the array disagree about which checks run or their order. Measured on this branch: `all 10 check(s) green, 1 skipped`, and the row prints its own verdict ("0 removed guard-shaped line(s), 0 lost, 0 rewritten"). A non-zero rc from it becomes a failed row like any other - which is what makes the LOST exit code mean something now. The row is a real check, not a note tier: a LOST means a refusal was deleted and nothing replaced it, which is the class six restore PRs in one night were written for. The human decision ("is this a re-shape or a loss?") happens after the row goes red, the same as registration_loss and branch_stale. --- docs/pre-pr-checks.md | 1 + scripts/pre-pr-checks.sh | 4 ++++ tools/ci/guard_loss_check.py | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/pre-pr-checks.md b/docs/pre-pr-checks.md index 56dc2af55..20f339d05 100644 --- a/docs/pre-pr-checks.md +++ b/docs/pre-pr-checks.md @@ -38,6 +38,7 @@ below says why. The table's order is the runner's order: cheapest and most commo | `python3 tools/ci/registration_loss_check.py --check --base origin/main` | your branch would drop rows `main` has | | `python3 tools/ci/registry_loss_check.py --base origin/main` | a reviewed class, a `coverage` counter or a test's mention of a class that the base has is gone at the merge, not only at the endpoint (engine#2385, #2391) | | `python3 tools/ci/branch_stale_check.py --base origin/main` | the merge with the base conflicts, or would not keep a base change the branch never touched; a branch that is only behind gets a note (the merge keeps the base's copy, but the branch's tests ran on the older one) (engine#2398, #2410) | +| `python3 tools/ci/guard_loss_check.py --check --base origin/main` | a guard-shaped line was deleted and its identifiers appear nowhere at head (a refusal or an assert silently removed) | | `python3 tools/ci/hip_f16_audit.py --find .` | a HIP add-on kernel accumulates in f16, or the gpu-kernels tree is not at the pinned commit; `skip` (the audit did NOT run) when there is no tree: set `GPU_KERNELS_DIR` to a checkout at the pin | | `git grep -l -F "$(basename )" -- '*.md'` | nothing links to the page you just added — measured tonight: 45 docs, one with no inbound link, and it was the page whose whole subject is pre-merge checks | diff --git a/scripts/pre-pr-checks.sh b/scripts/pre-pr-checks.sh index 9b746a454..3e1445805 100755 --- a/scripts/pre-pr-checks.sh +++ b/scripts/pre-pr-checks.sh @@ -67,6 +67,10 @@ checks=( "tools/ci/registration_loss_check.py --check --base $base" "tools/ci/registry_loss_check.py --base $base" "tools/ci/branch_stale_check.py --base $base" + # engine#2429: a refusing/asserting condition deleted in the diff with nothing replacing it. Calibrated on 15 + # open PR heads (one spurious hit, fixed by the head-tree search) and on the real llama.cpp#371 diff; exit 2 when + # it cannot read the refs, so "cannot tell" is never a pass. + "tools/ci/guard_loss_check.py --check --base $base" # engine#2416: the HIP add-on's f16 audit over $GPU_KERNELS_DIR (or third_party/gpu-kernels) at the pin; with no # tree it exits 77 and is listed as `skip`, never `ok` "tools/ci/hip_f16_audit.py --find ." diff --git a/tools/ci/guard_loss_check.py b/tools/ci/guard_loss_check.py index f97b87f5d..80b74fa36 100644 --- a/tools/ci/guard_loss_check.py +++ b/tools/ci/guard_loss_check.py @@ -128,7 +128,11 @@ def check(root, base, head): else: lost.append((path, body, "not in this file and not anywhere at head: " + ", ".join(sorted(missing)))) else: - moved.append((path, body)) + # every `moved` entry is a 3-tuple: the print loop unpacks a destination list. This path + # (guard rewritten in place, identifiers still present) appended 2-tuples and crashed the + # tool - and Python's traceback exits 1, which a runner reads as "guard LOST". Found by + # running the row below against a diff that rewrites a guard. + moved.append((path, body, [])) for path, body, why in lost: print(f"LOST {path}: {body.strip()[:100]}\n {why}") for path, body, elsewhere in moved: @@ -195,6 +199,17 @@ def g(*a): g("add", "-A"); g("commit", "-qm", "head") return td + # 0. THE CRASH ARM: a guard REWRITTEN in place, identifiers still present -> note, rc 0, no unpack + # error. This path appended a 2-tuple into a list the printer unpacks as 3, so the tool raised + # ValueError and exited 1: a crash wearing the LOST exit code. + td0 = scratch({"src/a.cpp": "int f(void*p,size_t n){ if (n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"}, + {"src/a.cpp": "int f(void*p,size_t TENSOR_ALIGNMENT){ if (TENSOR_ALIGNMENT == 0) { return -2; } return 0; }\n"}) + buf0 = io.StringIO() + with contextlib.redirect_stdout(buf0): + rc_rw = check(td0, "HEAD^", "HEAD") + chk("a guard rewritten with its identifiers present is a note, not a crash", rc_rw, 0) + chk(" ... and it is reported as rewritten", "rewritten" in buf0.getvalue(), True) + # 1. a guard deleted outright, nothing else changed -> LOST, rc 1 td = scratch({"src/a.cpp": "int f(void*p,size_t n){ if (p == nullptr || n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"}, {"src/a.cpp": "int f(void*p,size_t n){ return 0; }\n"}) From 3fe83a6e021c1dea3458de8cc8444dd61ec9356c Mon Sep 17 00:00:00 2001 From: t Date: Sat, 14 Nov 2026 17:55:24 -0400 Subject: [PATCH 2/3] docs: the pre-pr-checks counts and order sentence, without a cardinal to age Adding a row made two prose statements wrong, and both were already wrong before this branch: docs/pre-pr-checks.md "runs the first ten" -> the runner has eleven rows CONTRIBUTING.md "the six host-side checks" -> stale by five docs/pre-pr-checks.md "the check that needs a revision (registration_loss_check --base) last" -> four checks take --base, and the last row needs a fetched tree, not a revision The runner enforces that its array and the page's *table* agree in content and order, and that is the check that matters, but it cannot see prose: a number in a sentence is a fact that ages the moment a row is added, and this page has already drifted twice in one night over exactly this. So the numbers are gone rather than bumped -- "runs every command in the table below", "one further check is an author's check", "last the checks that need a revision (--base) or a fetched tree" -- and the page can now gain a row without a doc edit. Measured after: `bash scripts/pre-pr-checks.sh` -> 10 green, 1 skipped, rc 0, including its own page/array agreement step. --- CONTRIBUTING.md | 2 +- docs/pre-pr-checks.md | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 19c98dc63..5cb69fe6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ This repository exists to be reviewable. Five rules keep it that way. template that emits the notice into a generated file) and is left alone; the three such files say so in a comment. -Before you ask for a merge, run `scripts/pre-pr-checks.sh`. It runs the six host-side checks described in +Before you ask for a merge, run `scripts/pre-pr-checks.sh`. It runs the host-side checks described in [docs/pre-pr-checks.md](docs/pre-pr-checks.md) and prints one line each (`--base ` for the registration check, `--list` to see the commands); a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a skip. None of them needs a device or a build, and each answers a question that a green CI tick and a careful read of your own diff --git a/docs/pre-pr-checks.md b/docs/pre-pr-checks.md index 20f339d05..9c20d02d8 100644 --- a/docs/pre-pr-checks.md +++ b/docs/pre-pr-checks.md @@ -21,11 +21,9 @@ Ten commands, all host-side, none needing a device or a build. Every one of them Run them from the repository root on the branch you are about to hand over. -**`scripts/pre-pr-checks.sh` runs the first ten**, one line each (`--base ` for the registration check, `--list` to see the -commands; a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a skip). The -eleventh is an **author's check**, true or false exactly once — when you add a page — so it is not in the runner, and the section -below says why. The table's order is the runner's order: cheapest and most common first, and the check that needs a revision -(`registration_loss_check --base`) last. +**`scripts/pre-pr-checks.sh` runs every command in the table below**, one line each (`--base ` for the registration check, `--list` to see the +commands; a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a skip). One further check is an **author's check**, true or false exactly once — when you add a page — so it is not in the runner, and the section +below says why. The table's order is the runner's order: cheapest and most common first, and last the checks that need a revision (`--base`) or a fetched tree. | command | red means | |---|---| From 4439d1fb05fabe176903f19d24d9ffa2d33dc8e3 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 14 Nov 2026 19:28:12 -0400 Subject: [PATCH 3/3] guard_loss_check: skip tests/, which is what the docstring already claimed SKIP_DIRS had tests/data/ and the docstring said tests/ - so the docstring described a blind spot the code did not have, and the code had one the docstring did not describe: a guard-shaped line deleted from any test file was reported, and would have turned the new pre-pr-checks row red for a deliberate assertion rewrite. The decision, measured rather than argued: * the code was the wrong half. A test's REQUIRE/CHECK is a fixture, not the product's refusal, and the heuristic cannot see that style in any case - REQUIRE is not in GUARD_KEYWORDS, so "REQUIRE(!x)" replaced by "REQUIRE(true)" produced NO hit before or after this change. The skip therefore loses nothing the tool could catch. * what it does remove is noise that is decided on purpose: over 55 no-merge commits of the fork branch, 72 LOST hits, 8 of them in tests/, every sampled one a deliberate assertion rewrite. (Those 72 are not a false-positive rate: the fork branch at that point was a chain of #327's guard-dropping merges, and the first one sampled is #371's alignment guard, a TRUE positive. The number that matters for the row is the engine, where it runs: 0 LOST over 11 open heads.) Two arms pin the boundary in both directions, because the failure mode of a skip is being too wide: a guard deleted under tests/ is not reported, and the SAME guard under src/ still is. Reverting the skip turns the first arm red; adding src/ to SKIP_DIRS turns the second red; both restored green. --- tools/ci/guard_loss_check.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/ci/guard_loss_check.py b/tools/ci/guard_loss_check.py index 80b74fa36..e107c30a7 100644 --- a/tools/ci/guard_loss_check.py +++ b/tools/ci/guard_loss_check.py @@ -41,7 +41,12 @@ GUARD_KEYWORDS = ("refus", "assert", "GGML_ABORT", "!= 0", "== nullptr", "cannot", "must be", "is not set") IDENT = re.compile(r"[A-Za-z_][A-Za-z_0-9]{3,}") -SKIP_DIRS = ("third_party/", "docs/", "registry/", "tests/data/") +# engine#2451: `tests/`, not only `tests/data/`. A test's `REQUIRE`/`CHECK` is a fixture, not the +# product's refusal - and the heuristic cannot see that style anyway (REQUIRE is not a guard keyword), +# so skipping tests/ loses nothing it could catch while removing the case that would redden a PR for +# rewriting an assertion on purpose (measured: 8 of 72 LOST hits over 55 fork commits were in tests/, +# every one a deliberate assertion rewrite; the engine, where the row runs, was 0 over 11 heads). +SKIP_DIRS = ("third_party/", "docs/", "registry/", "tests/") def git(*args, cwd=None): @@ -210,6 +215,22 @@ def g(*a): chk("a guard rewritten with its identifiers present is a note, not a crash", rc_rw, 0) chk(" ... and it is reported as rewritten", "rewritten" in buf0.getvalue(), True) + # 0b. THE SKIP ARM (engine#2451): a guard deleted under tests/ is not reported, and the same guard + # under src/ is - the docstring and SKIP_DIRS must say the same thing, and the skip must not be + # so wide that it silences product code. + guard = "int f(void*p,size_t n){ if (p == nullptr || n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n" + gone = "int f(void*p,size_t n){ return 0; }\n" + td_t = scratch({"tests/a.cpp": guard}, {"tests/a.cpp": gone}) + buf_t = io.StringIO() + with contextlib.redirect_stdout(buf_t): + rc_test = check(td_t, "HEAD^", "HEAD") + chk("a guard deleted under tests/ is skipped (fixtures are not refusals)", rc_test, 0) + td_s = scratch({"src/a.cpp": guard}, {"src/a.cpp": gone}) + buf_s = io.StringIO() + with contextlib.redirect_stdout(buf_s): + rc_src = check(td_s, "HEAD^", "HEAD") + chk("the same guard under src/ is still reported", rc_src, 1) + # 1. a guard deleted outright, nothing else changed -> LOST, rc 1 td = scratch({"src/a.cpp": "int f(void*p,size_t n){ if (p == nullptr || n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"}, {"src/a.cpp": "int f(void*p,size_t n){ return 0; }\n"})