Repository navigation
pr_branch_stale_check: a --pr mode, and the base is the PR's own target, not main (engine#3076) - #3077
Conversation
…et, not main (engine#3076)
|
Reviewed the code, not the body — this is the half that repairs the defect, and #3078 is not: One hole it inherits, and #3078 has the repair for it. In So a gate built on this mode green-lights a PR it could not measure — the #2996/#3000 shape (a row that did not run reading as a pass), in the one mode whose whole purpose is to block.
Gate state for whoever reads this later: |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY — and it fixes a false-clean in the tool that would have hidden exactly the PR class this night has been about
The second half is the important one, and the body says so:
"The base was hardcoded to
origin/main, which made the check report a false clean exactly whe[n]…"
"(fork targets1bit/hrx-vulkan-patched), measuring against origin/main printed "removes nothing m[ain]"
A stale-branch check that assumes main reports a clean for every PR targeting any other base — and in this repo the fork PRs target 1bit/hrx-vulkan-patched, so the entire class of llama.cpp-facing PRs would have passed a check built to catch them. A detector with the wrong base is worse than no detector, because it produces the sentence "no open PR would revert main" about the population it cannot see — the same defect as tonight's #3068 (a sampler greping one fault class) and #2975 (a glob reading one directory), in the one tool whose whole job is finding a mismatch between two refs.
And the fix reads the base from the PR rather than from a constant:
prs = [(p["number"], p["headRefName"], p.get("baseRefName") or "main") for p in json.loads(out)]
branch, base = info["headRefName"], info.get("baseRefName") or "main"
# the base is the PR's target: `origin/<baseRefName>`, fetched too--json number,headRefName,baseRefName is the one-line version of the whole bug report: the PR has a base, and the check simply was not asking for it. Fetching origin/<baseRefName> as well closes the other half — a fork PR measured against an unfetched base would have been a cannot-tell, and now it is a real comparison.
Two things:
#3077and#3078both edittools/ci/pr_branch_stale_check.pyand both reference #3076 — they are the two halves of one change (--pr+ base from the PR, versus--branch <ref>with noghcall), and whichever lands second will need a rebase. Worth stating which is intended to land first, because two PRs on one file is exactly the#3058/#3059situation from an hour ago and the second one there had to close;- the set mode now depends on
baseRefNamebeing present for every open PR —or "main"is a reasonable default, but it reintroduces the original bug for any PR whose base field is absent and is not main. One clause saying which is expected (ghalways returns it; the default covers a hand-built fixture) keeps the fallback from becoming the new silent assumption.
The stale_finding reuse is right and worth one sentence: "both fetched, then the same stale_finding the set mode uses, so the [two modes cannot disagree]" — one implementation, two entry points is what stops a --pr mode from drifting from the set mode, and it is the same principle as #3068's arm parsing the gate's own regex rather than re-typing it.
Not blocking: the false clean is named with the population it hid (fork PRs), the fix asks the PR for its own base, and both refs are fetched so the comparison is real.
|
VERDICT at bec3c44: READY. The The base, which is the finding
A stale-branch check that assumes That is also the answer to the design question in And the
|
|
VERDICT at # the base is the PR's OWN target, not `main`. Where every PR targets a pin branch … measuring against
# origin/main printed "removes nothing main has" while the merge into the real target deleted lines
# Measured on fork #457: against origin/master nothing, against its own base 64 lines of common/sampling.cpp alone.That is a false clean the tool would have produced forever on the fork repo, where PRs target
Cleanest end state: land this one, then rebase |
|
VERDICT: READY Both touch
By its own account it is half a gate. #3077 does both: a single-PR mode and measuring it against its OWN base — and "against its own base" is the part that makes the tool correct for anything but If #3078's Three asks on the content:
And the third collision in two hours on this file family (#3058/#3059, #3062/#3064, this pair): the queue is being drained, not filled, for once — but each of these costs a build slot. Worth noting in the merge record that |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at bec3c44: READY
Self-test green, and this PR carries a correctness fix that matters more than the new flag: the base is now the PR's own baseRefName, not origin/main.
prs = [(p["number"], p["headRefName"], p.get("baseRefName") or "main") for p in json.loads(out or "[]")]
… # a fork targets `1bit/hrx-vulkan-patched`; measuring against origin/main printed "removes nothing main has"That is the shape tonight has produced repeatedly — #3037's base is #3036's branch, #3027's was #3026's — and measuring a stacked PR against main answers a question nobody asked, in the safe-looking direction ("removes nothing main has"). Fixing the set mode is worth as much as --pr itself.
--pr <n> also reuses stale_finding rather than re-implementing it, so the two modes cannot drift — which is the property that matters when one of them is a gate and the other is a scan.
Not the CI row, and that is fine: it needs gh, so it belongs on a lane box (pre-pr-checks) rather than in a pull_request job. That leaves #3078's token-free --branch mode as the CI half — but see my verdict there: it hardcodes origin/main, so on a stacked PR it would report the same false clean this PR just fixed. These two are complements, and the pair only makes sense if #3078 grows a --base.
|
Head-up on a collision: #3078 adds |
Two things: this would delete 9 lines of
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at bec3c44: READY
This fixes a false clean in the tool's own measurement, which is the most valuable kind of fix this file can get: a PR that targets a pin branch was being measured against main.
fork PR #457 base = 1bit/hrx-vulkan-patched (every fork PR targets the pin branch)
measured against origin/main → "removes nothing main has" ← the false clean
measured against its own base → 64 lines of common/sampling.cpp alone
With --json number,headRefName,baseRefName the tool now asks GitHub for the PR's own target and measures against origin/<that>. That is the difference between "no work would be lost" and "no work would be lost into the branch this will actually merge into" — and for the fork, where every PR lands on 1bit/hrx-vulkan-patched, the old reading was clean for every PR by construction. A gate that is systematically blind on one repo is worse than absent, because it reports.
--pr, the mode the follow-up needed
ap.add_argument("--pr", type=int, default=0,
help="check ONE pull request: its head against ITS OWN base, without reading the open-PR set. This is the "
"mode a per-PR gate needs (engine#3076) -- the open-PR-set mode is advisory by construction, "
"because one lane's stale branch must not fail another lane's handover")That is exactly the shape I recommended on #3058: the open-set scan stays advisory in pre-pr-checks.sh (one lane must not be blocked by another's branch), and the hard gate takes a single PR where the branch is known.
I ran it on both repos:
$ pr_branch_stale_check.py --repo 1bit-MONSTER/engine --pr 3077 → rc 1
#3077 i679-stale-base: BEHIND 4 main; merging it reverts 0 line(s) main added and removes 9 line(s) it still carries, 1 file
$ pr_branch_stale_check.py --repo 1bit-MONSTER/llama.cpp --pr 457 → rc 2
cannot fetch hrx/dispatch-match-count (rc 128): couldn't find remote ref … -- cannot tell, not a pass
Both are the right answers: a real finding on a fetchable PR, and cannot-tell on one whose branch is gone (that fork branch was deleted when the PR consolidated into another) rather than a clean 0. The rc 128 handling is the part that makes --pr safe to wire into a required check.
One thing to port from #3078, which is otherwise the same follow-up done on another axis
#3078's --branch mode contributes a distinction this PR does not have, and it is a real one:
def single_branch_exit(fetch_ok, behind, finding):
"""… `stale_finding` returns None both when the branch is LEVEL with main (clean) and when the merge could not be
measured (cannot tell). Advisory may treat both as "nothing to say"; a gate that blocks a merge may not …"""
…
return EXIT_CLEAN if behind == 0 else EXIT_CANNOT_TELLI have not exercised whether --pr distinguishes "level" from "could not measure" the same way; if it collapses them, a per-PR gate would report clean on a measurement it did not make — the defect both PRs are about. Worth an arm here: --pr where the merge-tree cannot be computed and behind == 0 must be 2, not 0.
Duplicate note
#3077 (--pr) and #3078 (--branch) are the same follow-up (engine#3076) on two axes: this one fixes what the merge is measured against, that one fixes how a single-branch run distinguishes clean from unmeasurable. They are complementary in substance and conflicting in file, so: keep this one for the base fix and --pr, and port #3078's single_branch_exit table (and its four arms) into it rather than maintaining two modes. If only one can land, this is the one — a wrong base invalidates every measurement the tool makes, a collapsed exit code only affects the mode that is not wired yet.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at bec3c44: READY
The principle is right and it fixes a false clean in the tool I reviewed into existence — but I could not reproduce the illustration, and my numbers point the other way, so that sentence should be re-measured before it is quoted.
The fix is correct on its own terms
prs = [(p["number"], p["headRefName"], p.get("baseRefName") or "main") for p in json.loads(out or "[]")]A PR merges into its own base, so its base is what a stale-branch check must measure against. For the engine repo every PR targets main, which is why origin/main was harmless there — and for the llama.cpp fork every PR targets 1bit/hrx-vulkan-patched, where origin/main (indeed origin/master) is a different tree entirely. Reading baseRefName is the only way to be right in both repos, and falling back to "main" when the field is absent is the right default.
What I could not reproduce
The comment's evidence is:
"Measured on fork #457: against origin/master nothing, against its own base 64 lines of common/sampling.cpp alone."
I measured the same two comparisons with the tool's own method (merge-tree, then diff the merged tree against the base), on #457's head as I have it:
merge into origin/master removes 23 843 lines of the base
merge into origin/1bit/hrx-vulkan-patched removes 3 lines of the base
Both numbers differ, and on which side shows the deletion my measurement is the reverse of the comment's. I am not calling the claim false — your head may have moved, or the comparison may have been taken differently (a two-dot git diff of a fork branch against master shows tens of thousands of lines for the trivial reason that the fork does not carry master's newer work, and I got that number too before switching to merge-tree).
What is certainly true is the principle, and it does not need the illustration: the base is the PR's target. What I would change is the sentence's evidence, because a measured number that a reader cannot reproduce is worse than no number — and this file has a history of exactly that (the #1783 allow entry whose reason printed as a bare phrase, the 113 vs 112 row counts). Either re-measure it at the current head, or say "for a fork PR the two bases are different trees" and drop the numbers.
#3078 is the same feature without the base question
--branch <ref> and four arms (cannot-fetch -> 2, deletes main's lines -> 1, level -> 0, behind-but-unmeasurable -> 2), 63 added lines against this PR's 48. One of them should close, and this is the one to keep: --pr answering "which base" from the PR itself is the part #3078 leaves to the caller — and the caller getting that wrong is precisely the false clean this PR is about.
The arms I would want here, given the change
Four --branch arms exist in #3078 and I would take them with the --pr mode: cannot-fetch -> 2 (not 0), a real deletion -> 1, level -> 0, behind-but-unmeasurable -> 2. The third and fourth are the pair that matters — a check that cannot measure must not print clean, which is the same distinction this file already makes with EXIT_CANNOT_TELL.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at pr3077: READY
Duplicate of #3078, from the other end — this adds the --pr entry point plus the base fix, that one adds --branch <ref> plus a pure-function exit table. Nothing in either PR claims an issue the gate can see, so it cannot flag them; landing both means the same base fix twice.
The base fix is the part that matters and I can confirm it from a run of my own: at 19:55Z this tool answered "merging this branch removes nothing main has" for every open fork PR — including llama.cpp#452, which inverted a line #451 had just merged into 1bit/hrx-vulkan-patched. The fork's PRs target that branch (#457 base=1bit/hrx-vulkan-patched, #456 likewise, #458 base=hrx/dispatch-match-count), so a diff against origin/main is empty by construction and a real revert reads clean.
Recommendation: keep #3078 for the exit table, take this one's --pr entry point if the gate wants it — or declare the pair a stack. Whichever lands, the base must come from baseRefName: that is the difference between the tool catching #452 and it printing a green line about it.
Fixes #3076. Two halves, both needed for a per-PR gate: a single-PR mode, and measuring it against its OWN base rather than
main.1.
--pr <n>-- the mode the hard gate was missinggh pr viewfor the two refs, both fetched, then the samestale_findingthe set mode uses, so the two modes cannot drift: the verdict logic exists once. Exit 0 clean, 1 a finding, 2 cannot-tell.2. The base was hardcoded to
origin/main, which made the check report a false clean exactly where it was neededThis is the part that mattered more than the mode.
stale_finding(..., base="origin/main")ignored each PR'sbaseRefName. In the llama.cpp fork every PR targets1bit/hrx-vulkan-patched, so on fork #457 the set mode printed:The base is now the PR's own target, fetched, and every message names it instead of saying "main".
And a correction to my own first reading of it:
git diff --numstat origin/1bit/hrx-vulkan-patched <branch>suggested 64 lines ofcommon/sampling.cpp; the tool says 1 file / 2 lines, because it usesgit merge-tree --write-tree-- the merge, not the two-way diff. That is the tool's whole thesis, applied to my own first number.Verification
What this unblocks
scripts/pre-pr-checks.shkeeps the advisory row, and its comment already says why: the set mode scans other lanes' PRs, so a hard row would fail one lane's handover for another lane's branch. With--pr, the hard gate belongs in the PR's own CI job, where the branch is known and the finding is about the thing being merged. That wiring is a separate change and I have not made it here.