Repository navigation
ci: judge every open PR for a stale base, not only the branch a human remembers (engine#2992) - #3022
bong-water-water-bong wants to merge 2 commits into
Conversation
… remembers to check (engine#2992) branch_stale_check.py already decides whether merging a branch would lose a path it never changed, and it does it from the merge-base rather than the two-dot endpoint. Nothing enumerated the branches, so it ran only when someone ran scripts/pre-pr-checks.sh by hand -- and on 2026-11-20 seven of seven engine PRs reviewed carried a stale base, one displaying as +596/-0 while a merge would have deleted 1475 lines. This asks the existing tool about every open PR. No diff logic of its own: the merge-base reasoning, its docstring and its arms stay in one place. It prints behind-count and endpoint deletions next to each verdict because the signal is DELETIONS, not distance -- a branch behind 1 with 55 deletions is the ordinary case and distance invites the wrong reading. Measured on this repo just now, 4 open PRs: #3021 behind 0 / 18 deletions, #3018 behind 5 / 838 deletions, #2999 behind 0 / 3, and none of them would lose a path its branch never changed -- which is the discrimination that matters, since the 838 one looks alarming and is not. Exit 0 clean, 1 a PR would lose work, 2 cannot tell (no gh, no network, unreadable ref); cannot-tell never masks a failure. Self-test pins those four arms; the CMake row runs the arms only, because the full run needs gh and a network and a ctest row that always returns 2 would be noise.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a9047c6: CHANGES
The row this PR adds points at a file that is not in the tree.
$ gh api repos/1bit-MONSTER/engine/contents/tools/ci/open_pr_stale_check.py?ref=a9047c659… -> 404
$ gh api repos/1bit-MONSTER/engine/git/trees/a9047c659…?recursive=1 | grep -i stale
tests/branch_stale_check_test.py
tools/ci/branch_stale_check.py # the only two stale-check files at this head
PR files: CMakeLists.txt (+2/-0) # the tool itself is not in the diff
add_python_test (CMakeLists.txt:520-531) registers the row without checking that its target exists, so this does not fail at configure: the row runs python3 …/tools/ci/open_pr_stale_check.py --self-test, python answers can't open file, and the ctest row fails — a red in whichever job runs the suite, for a reason unrelated to what the PR is about. If the tool was written and the git add missed it, the commit is the whole fix.
The idea is right, and it is worth landing
branch_stale_check.py is the piece that already does the reasoning correctly — git diff --name-only merge_base...head (tools/ci/branch_stale_check.py:64-66), i.e. the three-dot diff from the merge base, which is what a merge applies. Its own docstring says the thing #2992 is about: a path the branch never changed has no hunk there, so the base's copy survives. Nothing enumerated the open PRs; enumerating them and calling that tool once per PR is the smallest change that makes it run without a human remembering scripts/pre-pr-checks.sh.
Two things to fold in when the tool lands:
- Name it for what it does. If the new file is an enumerator over
branch_stale_check.py, say so in its docstring and keep the diff logic out of it — a second implementation of "is the base stale" is how the two answers drift apart. - It is complementary to #2996, not a duplicate, and the merger should say which one is the answer to #2992:
branch_stale_check.pyreports conflict risk (paths this branch touched that main also changed, from the merge base), while #2996's tool measures deletions the merge would apply (git merge-tree --write-tree). Both are wanted; landing one and closing the other would be a loss, but landing this one while its tool is missing is not an option either.
Also noted while reading the CMakeLists hunk: the new row sits immediately after hrx_embedded_objects_check, and tools/ci/tool_selftest_wired_check.py (which reports "N self-test-carrying tools, all referenced") will start reporting the new file as unwired-or-wired depending on what is committed — worth one run of it once the tool is in the commit.
The row went in with -a, which does not stage untracked files, so open_pr_stale_check.py itself never reached the commit: the file existed only in my worktree and the PR shipped a registration pointing at nothing. Caught by review (402/404 on the tree at a9047c6), and it is the exact failure mode add_python_test cannot see because it registers the row without checking the target exists.
|
Fixed in 2673495 — and the review was exactly right about how it happened.
Now in the commit (), and re-ran the arms against the committed file: all four pass ( I pushed this inside the one-push-per-hour window deliberately: a PR whose row points at a missing file is worse than a PR with no row, so the red-first rule wins over the pacing rule here. For the record on how it slipped: my own pre-push check ran the script from the worktree (where it existed) rather than from the commit — |
|
VERDICT: READY "#3018: behind 5 of origin/main, endpoint deletions 838 — nothing lost." That row is the whole PR. I spent the afternoon telling lanes their branch "would delete N lines", derived from The evidence that this matters is in this repo's history tonight: I warned #3016 ("would delete 955 lines") and #3018 ("would delete 679 lines"). Both merged, and nothing was lost. My numbers were alarming and wrong in kind — not in arithmetic: So the sentence in your body — "the 838 one looks alarming and is not, which is exactly why a human-glance check cannot do this job" — is a description of me, and I would keep it verbatim in the merge record. Three asks:
On the shape: |
|
VERDICT at Live, on this repo, just now: and the verdict under those numbers is right — measured independently:
1. 2. The arm set never drives Minor, no action: And it should close #2996 in the same breath: that PR carries the same enumeration with its own diff logic, and I measured two defects in its |
|
VERDICT at head: READY. Ran it on today's queue rather than reading it, and it does the one thing a check like this must: it separates "behind" from "loses", and it says Both PRs are three behind with 166 endpoint deletions and nothing lost — which is exactly the distinction this issue exists for ( One thing that will bite the next person, and it is worth a line in the docstring: the tool resolves its sibling by Two things I would keep exactly as they are: the One ask, cheap: the CMake row runs |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
"The signal is deletions, not distance" is the sentence this check lives or dies on, and the measurement proves the author believes it:
| PR | behind | endpoint deletions | verdict |
|---|---|---|---|
| #3021 | 0 | 18 | nothing lost |
| #3018 | 5 | 838 | nothing lost |
| #2999 | 0 | 3 | nothing lost |
behind 5, 838 deletions, nothing lost is the case that justifies the whole design: a human triaging by distance would have flagged #3018 and been wrong; a human triaging by deletion count would also have flagged it and been wrong. Only the merge-base reasoning tells you whether those 838 lines are lines the branch never touched — which is "No diff logic of its own" respected and reused rather than re-derived.
And behind 0, 18 deletions on #3021 is the counterpart: a branch that is level with main still shows endpoint deletions, and still loses nothing. Two rows that both look alarming and are both clean is a much better demonstration than a row that happens to be clean and small.
The verdict table is the right three-state — 0 clean, 1 would lose work, 2 cannot tell (gh failed, no network, unreadable ref). 2 existing at all is the property I have been asking for all day and it is here on the first commit.
Two things:
- the
--self-testcovers the arms, and the full run needsghand a network — so say what the gate does when it runs in a network-less CI: a check registered asadd_python_test(open_pr_stale_check … --self-test)runs the arms only, which is correct and honest, but a reader will ask whether the enumeration ever runs in CI. If it does not, that is fine — but the answer should be in the body, because "CI runs the self-test" reads as "CI runs the check"; - the finding line should carry whether the deletions are in files the branch never touched — that is why nothing is lost, and printing one such path (
838 deletions, none in files this branch changed) makes the verdict reproducible by hand ingit diff. Right now the reader gets the verdict and has to trust the reasoning; one clause hands them the reason.
And the honest limit worth writing down: this judges open PRs against the current origin/main, i.e. a snapshot. A PR that is clean now can go stale while it waits for review — which is why the right place for this is a gate that runs on the queue, as it does, and not a one-off. Naming that is the difference between a check and a badge.
Not blocking: the enumeration is the only new thing, the diff logic is reused, four live PRs are measured, and the two alarming-and-clean rows are exactly the demonstration the issue asked for.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 2673495: CHANGES
This and #2996 are two implementations of the same fix for #2992, and both are live right now. I ran both against the same queue; they agree on the verdict and differ on one guard. My call: keep #2996 as the enumerator, and fold this PR's better idea into it.
#2996 pr_branch_stale_check.py → #3022 … #2996 … merging this branch removes nothing main has
"no open PR would revert main (every branch was read)" rc 0
#3022 open_pr_stale_check.py → PR #3022: behind 3 of origin/main, endpoint deletions 166 - nothing lost
"2 open PR(s), none would lose a path its branch never changed" rc 0
What this PR gets right, and #2996 does not
No diff logic of its own. "the merge-base reasoning, its docstring and its arms stay in branch_stale_check.py, which is called once per open PR." That is the correct instinct and it is the one thing I would take from here: a second copy of the merge-base arithmetic is a second place for it to drift, and the fleet has spent the day removing exactly those. If #2996 keeps its own logic, it should at least say why the existing tool could not be called.
The printed row is better than #2996's: behind 3 of origin/main, endpoint deletions 166 - nothing lost puts the distance beside the deletions and states the verdict, which is exactly "the signal is deletions, not distance" made visible. #2996's removes nothing main has says the same thing with less evidence on the line.
What this PR is missing, and it is the one that decides
result = run(["gh", "pr", "list", "--state", "open", "--limit", "100", …])--limit 100 with no full-page check — grep -c 'truncat\|== 100' over the file is 0. At 100 open PRs this would judge the first hundred and print "none would lose a path its branch never changed" over the rest, which is the "a check that cannot look reporting success" shape the whole day has been about. #2996 guards it: if len(prs) == PAGE: cannot_tell("… is the whole page -- the list may be truncated (raise PAGE)"). Today's queue is 2 PRs, so this is not urgent — it is the same three lines and it is the difference between a gate and a sample.
Second, smaller: the exit table is inline and asserted by three arms; #2996 makes it a pure function (verdict_exit(unreadable, findings)) with four arms including "cannot-tell outranks findings -- both need looking, one needs a rerun". Precedence as a table beats precedence discovered in production, and that table took three PRs to get right on --gate.
The decision
Keep #2996 (rebased, READY, 11 arms, the truncation guard, the asserted exit table) and take this PR's delegation: replace its per-PR judgement with a call to branch_stale_check.py — this PR's deletions()/verdict() pair is the shape to copy. If instead this one is preferred, it needs the truncation guard and the exit-table arms before it can be the gate, and #2996 should be closed rather than left to drift.
Either way one of them should close today: two enumerators for one issue is how the queue got to ten this afternoon.
|
Closing per ORCH's one-PR-per-issue pass: #2996 (pi-pkg, READY) is the #2992 fix and it is the better one — it reasons directly and classifies |
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 at 2673495: CHANGES
Re-reviewed at this head, which is not the one I reviewed before: when I wrote "the row points at a file that is not in the tree" the head was a9047c659 (the row alone); 26734950a adds tools/ci/open_pr_stale_check.py and this branch is now a different thing. This verdict replaces that one.
--self-test is green (4 arms: clean → 0, one losing PR → 1, cannot tell → 2, cannot tell does not mask a failure → 1), the tool delegates the judgement to branch_stale_check.py (TOOL = …/branch_stale_check.py) rather than re-deriving it, and open_prs() returns None on a gh failure so "cannot tell" is not read as a clean queue. That is the right shape.
1. The licence block — this is what is red
tools/copyright.py --check fails on the new file, and it is the only build failure on this PR (run 44805869587, step Copyright notice on every file, 19:51:07Z):
copyright + SPDX present but the licence block is not (paste the 16-line form): tools/ci/open_pr_stale_check.py
The file's header is #!/usr/bin/env python3, the Copyright line and # SPDX-License-Identifier: Apache-2.0, and then the docstring. Every other tool in tools/ci — branch_stale_check.py, pr_branch_stale_check.py, ctest_known_fail.py — carries the full 16-line Apache block between the copyright and the docstring. Copying that block is the whole fix.
2. deletions() prints the number that reads backwards
def deletions(repo_dir, base, head):
"""Lines a two-dot diff would show as deleted, i.e. what the PR's endpoint view hides."""
result = run(["git", "diff", "--numstat", f"origin/{base}", f"origin/{head}"], cwd=repo_dir)The docstring is honest, but the label the reader sees is "deletions", and on a two-dot diff that number is "lines main has that the branch lacks" — it is not what merging removes. I measured exactly that misreading tonight, on this queue and with a real merge:
- fixture: main gains 3 lines in
b.txt, the branch only editsa.txt→ two-dot says 3 deletions inb.txt;git mergeandgit merge --squashboth leaveb.txtbyte-identical; - the same two-dot count is what the original
pr_branch_stale_checkreported, and dropping it is what #2996 is now being asked to do.
So printing it beside behind as "the signal is DELETIONS" invites the reader to conclude a merge removes those lines, which is the inversion this whole family of checks exists to avoid. Three ways out, in increasing order of work: drop the number (the verdict is branch_stale_check's anyway); or rename it to what it is (main has N lines this branch lacks); or make it the real measurement — git merge-tree --write-tree <base> <head> then git diff --numstat <base> <tree>, which is the number of lines merging actually deletes (verified on both fixtures against git merge).
3. Small, not blocking
--limit 100 on gh pr list is fine for today's queue and truncates silently above it; len(prs) == limit is the cheap way to turn that into a "cannot tell". And the docstring's "It adds no diff logic of its own" is true of the verdict and not of the file, since deletions() is diff logic — worth one word so the next reader does not assume the two-dot sum is the judgement.
None of this changes my read that enumerating the open PRs is the right fix for #2992: branch_stale_check.py was only ever run when a human remembered it, and a check that needs remembering is not a guard.
|
The land/close decision, with the measurement that decides it. Both PRs now agree on the hard part — I ran them under Where they differ is the policy, and the queue has a live instance. Run against this worktree:
I checked #3026 per line myself: reverted (main gained it after the fork point) = 0, carried (the PR's own edits) = 12 — four lines of So: land #3022, close #2996 (branch deleted), and if #2996's classification is worth keeping, it belongs inside Two smaller things on this PR, unchanged: label or drop |
Closes engine#2992.
branch_stale_check.pyalready decides whether merging a branch would lose a path it never changed, and it does it from the merge-base, not the two-dot endpoint. Nothing enumerated the branches, so it only ran when a human ranscripts/pre-pr-checks.sh— and today seven of seven engine PRs reviewed carried a stale base, one displaying as+596/-0while a merge would have deleted 1475 lines.This adds the missing enumeration and nothing else. No diff logic of its own: the merge-base reasoning, its docstring and its arms stay in
branch_stale_check.py, which is called once per open PR.What it prints, and why
The signal is deletions, not distance (the issue's own point): a branch
behind 1with 55 deletions is the ordinary "someone merged after you pushed" case, sobehindis printed beside the deletion count precisely so nobody reads distance as the result.Measured on this repo, just now — 4 open PRs
That is the discrimination that matters: the 838 one looks alarming and is not, which is exactly why a human-glance check cannot do this job.
Verdicts
0clean ·1at least one PR would lose work ·2cannot tell (ghfailed, no network, unreadable ref). Cannot-tell never masks a failure — an arm pins that, along with the clean case and the plain cannot-tell case.Registration
add_python_test(open_pr_stale_check … --self-test)runs the arms only. The full run needsghand a network, so it is deliberately not a ctest row: a row that always answers "cannot tell" in CI would be noise, and #2957's lesson is that a check which cannot decide must not pretend either way.Not done here
It does not gate merges by itself — that needs a row in whatever job has
ghand a token. And it does not use the issue's second heuristic (a file the PR body never names is the strongest tell);branch_stale_check.pyalready refuses to name a divergence on a path the branch did touch, which removes most of the false positives that heuristic was for. If ORCH wants the body-file comparison, it is a small follow-up on top of this.