You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pr_branch_stale_check has no single-branch mode, so it cannot be a hard PR gate (engine#2996/#3058 follow-up) #3076
pr_branch_stale_check can only be advisory, because it has no single-branch mode — the hard gate it was built for needs one
#2996 shipped the check; #3058 wired it into scripts/pre-pr-checks.sh, and the wiring comment states the gap precisely:
# ADVISORY, not a gate row, and the reason is scope: it scans the OPEN-PR SET, so a hard row here would block one
# lane's pre-PR run for another lane's stale branch. The hard gate belongs where a single PR's branch is known --
# a CI job on the PR, which needs a `--pr <n>` mode the tool does not have yet (follow-up).
So tonight the instrument reports and nothing enforces. Measured on 2026-11-20/21: #3051 was BEHIND 1 and its merge would have removed 10 lines main carried in the very file it edited; #3054 the same shape (5 lines). Both were caught by a human reading the advisory output. A lane that does not read it merges the revert.
What this asks for
A mode that evaluates one named branch and can therefore be a hard row:
--branch takes the ref name directly, so it needs no gh call and no token: git fetch origin <branch> plus the existing merge measure is enough, which is what makes it usable from a pull_request job.
Exit codes keep the house table: 2 is cannot-tell and must never look like 0 (an unfetchable branch is 2), which is the same rule the advisory path already follows with 77.
The open-PR scan and --advisory stay exactly as they are; scripts/pre-pr-checks.sh keeps its 2.34 s advisory row.
Wiring, so it is a gate rather than a widget
One step in the existing build job in .github/workflows/ci.yml (it already runs on pull_request, and the step costs a fetch plus ~2 s):
- name: A stale base would revert mainrun: python3 tools/ci/pr_branch_stale_check.py --branch "${{ github.head_ref }}"
Acceptance
--branch on a branch that is behind and whose merge deletes main's lines → rc 1, naming the file and the count.
--branch on a branch that is merely behind (merge removes nothing) → rc 0, the ordinary case, no false alarm.
--branch on a branch that cannot be fetched → rc 2, not 0.
--self-test keeps passing and gains the arms above.
The advisory row in pre-pr-checks.sh is unchanged and still exits 0 with findings.
The mode half is up as #3078 (a4f72c7): --branch <ref>, no gh call and no token, with the exit table asserted by 4 self-test arms and the live/fixture cases measured in the PR body.
The wiring half is blocked on this lane's token, not on the design: pushing .github/workflows/ci.yml is refused with "refusing to allow an OAuth App to create or update workflow … without workflow scope". The exact step is written and tested locally and is quoted in #3078's body — one step in the existing build job, same-repo PRs only, git fetch origin main:refs/remotes/origin/main first so a missing base cannot turn the row red for everyone. Whoever holds that scope can add it verbatim; I did not retry, re-scope or work around it.
The mode is done and my own attempt at it is closed — #3077 (aea4bdb) landed --pr N and it is better than what I wrote.--pr measures against the PR's own baseRefName, where my --branch hard-coded origin/main; for a PR targeting a pin branch (the llama.cpp fork targets 1bit/hrx-vulkan-patched) mine would have printed "removes nothing main has" while the merge into the real target deleted lines — the false clean this tool exists to prevent, re-introduced one argument over. #3078 closed, branch deleted.
One narrow residual found while comparing the two implementations (not worth a PR of its own, so it is written down here):
found=stale_finding(root, f"origin/{branch}", f"origin/{base}")
iffoundisNone:
print(f"#{a.pr}{branch}: merging it removes nothing {base} has")
return0# <-- also reached when the merge could not be MEASURED
stale_finding returns None both for level with the base and for no merge base / the tree could not be written — for a conflicting branch that is a "clean" verdict where the honest answer is cannot-tell. It is narrow (GitHub blocks a conflicting merge anyway) and it is about four lines on top of --pr: hold the distance and dispatch on it instead of on None. I am not opening a PR for it at three open PRs; it is here for whoever touches this next.
Still unlanded: the CI wiring (the reason this issue exists). It needs a token with workflow scope — the step is quoted verbatim in #3078's close comment and in my earlier comment, guarded to same-repo PRs with origin/main fetched first. Until it lands the instrument reports and nothing enforces.
lines 343/363 of tools/ci/pr_branch_stale_check.py; arm pinned by a mutant
$ python3 tools/ci/pr_branch_stale_check.py --self-test # on merged main
rc=0, 21 arms ok, 0 FAIL
$ python3 tools/ci/pr_branch_stale_check.py --advisory # live queue
rc=77 #3098 os3-3095: CANNOT READ -- the merge of origin/os3-3095 into origin/main conflicts,
# so what it would delete cannot be measured
$ python3 tools/ci/pr_branch_stale_check.py --pr 3098
rc=2 (the same reason, as cannot-tell rather than as a clean 0)
That pair is the point of the last two PRs: 77 and 2, never 0, on a branch whose merge cannot be measured — the answer a gate must not get wrong. Before #3084 it printed "merging it removes nothing main has" and exited 0; before #3094 it never got that far, because a force-pushed branch could not be fetched at all.
The regression arm is not vacuous: reverting only the + gives rc=1, 1 FAIL.
What is still missing, and why it is not mine
The CI row. Pushing .github/workflows/ci.yml is refused for this lane:
! [remote rejected] … (refusing to allow an OAuth App to create or update workflow
'.github/workflows/ci.yml' without `workflow` scope)
So the step stays here for whoever holds that scope. One step in the existing build job, same-repo PRs only, fetching the base first so a missing ref cannot turn the row red for everyone:
- name: A stale base would revert mainif: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repositoryrun: | git fetch -q origin main:refs/remotes/origin/main python3 tools/ci/pr_branch_stale_check.py --pr ${{ github.event.pull_request.number }}
With #3094 in, the tool mirrors its own refs, so no second fetch line is needed — and --pr is the right entry point because it measures against the PR's own base (a pin-branch PR measured against main is the false clean #3071 fixed).
Until that lands, #3076 is open on exactly one item: the instrument reports, and nothing enforces.
Correction to the YAML I handed over twice: it would have been a false green in CI, and I found that by actually cloning the way actions/checkout does.
In a --depth 1 clone of this repo, the gate answers:
$ python3 tools/ci/pr_branch_stale_check.py --root . --pr 3098
#3098 os3-3095: merging it removes nothing main has rc=0 <- FALSE GREEN
That branch is BEHIND 1 and its merge conflicts; a full clone says so and exits 2. Cause: in a shallow clone git rev-list --count A..B returns 0 for a branch that is behind, and the distance is what decides every verdict in the file.
PR #3105 fixes it two ways: a shallow_guard() (cannot-tell in a shallow clone, 3 arms) and cannot_tell() now exiting 77 under --advisory, which is what the flag's help and the pre-PR runner have always promised — every early cannot-tell used to bypass that mapping and turn a lane's gate red for something it could not see.
So the CI row needs fetch-depth: 0, or the new guard makes it a skip on every run:
- uses: actions/checkout@<pinned>with:
fetch-depth: 0
- name: A stale base would revert mainif: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repositoryrun: python3 tools/ci/pr_branch_stale_check.py --pr ${{ github.event.pull_request.number }}
Lesson worth more than the patch: I had quoted that step twice without ever running it in the checkout shape CI uses. The tool was right on a dev clone and a certifying liar on a CI clone.
A second enforcement point that needs no workflow scope: --pr auto in the pre-PR gate
The blocker on this issue has been "the CI row needs workflow scope". There is a way to enforce it tonight, at the point a lane is already forced through: its own scripts/pre-pr-checks.sh.
The shape
A --pr auto mode on the tool: resolve the current branch's own open PR and gate that one, hard. No gh permission beyond what every lane already uses, no workflow file, no token scope:
rc, out, _=run("gh", "pr", "view", "--json", "number", cwd=root) # the PR for the checked-out branchifrc!=0ornotout.strip():
return77# no PR for this branch: a visible SKIP, not a pass and not a failurereturn<the--prpathforthatnumber>
and one row in the checks array:
"tools/ci/pr_branch_stale_check.py --pr auto"
Why this is the right row and not just a second advisory
Scope is per-lane, so hardness is safe: the existing advisory row scans other lanes' PRs, which is why it must not fail (a hard row there would block one lane for another's branch). --pr auto only ever judges the branch in front of you — the same rule pre-pr-checks.sh already applies to every other check.
It catches the case that actually hurts: a lane is about to push or ask for review on a branch whose merge would delete lines main gained. That is when the rebound is free; after review it costs a re-review.
The CI row. A lane can skip pre-pr-checks.sh entirely, and the merge queue does not run it. This closes the gap for lanes that run their own gate — which is most of the fleet — while the CI row stays the item that closes this issue for everything else.
I am not opening this tonight: #3105 is at a verdicted head and adding scope to it would invalidate that review, and a second PR to the same file within the hour is the duplication this lane has spent the night flagging in others. Recorded here so it is one line of work for whoever picks up the wiring — or for me tomorrow, at a head that can carry it.
Activity
bong-water-water-bong commentedon Nov 21, 2026
The mode half is up as #3078 (
a4f72c7):--branch <ref>, noghcall and no token, with the exit table asserted by 4 self-test arms and the live/fixture cases measured in the PR body.The wiring half is blocked on this lane's token, not on the design: pushing
.github/workflows/ci.ymlis refused with "refusing to allow an OAuth App to create or update workflow … withoutworkflowscope". The exact step is written and tested locally and is quoted in #3078's body — one step in the existingbuildjob, same-repo PRs only,git fetch origin main:refs/remotes/origin/mainfirst so a missing base cannot turn the row red for everyone. Whoever holds that scope can add it verbatim; I did not retry, re-scope or work around it.bong-water-water-bong commentedon Nov 21, 2026
The mode is done and my own attempt at it is closed — #3077 (
aea4bdb) landed--pr Nand it is better than what I wrote.--prmeasures against the PR's ownbaseRefName, where my--branchhard-codedorigin/main; for a PR targeting a pin branch (the llama.cpp fork targets1bit/hrx-vulkan-patched) mine would have printed "removes nothing main has" while the merge into the real target deleted lines — the false clean this tool exists to prevent, re-introduced one argument over. #3078 closed, branch deleted.One narrow residual found while comparing the two implementations (not worth a PR of its own, so it is written down here):
stale_findingreturnsNoneboth for level with the base and for no merge base / the tree could not be written — for a conflicting branch that is a "clean" verdict where the honest answer is cannot-tell. It is narrow (GitHub blocks a conflicting merge anyway) and it is about four lines on top of--pr: hold the distance and dispatch on it instead of onNone. I am not opening a PR for it at three open PRs; it is here for whoever touches this next.Still unlanded: the CI wiring (the reason this issue exists). It needs a token with
workflowscope — the step is quoted verbatim in #3078's close comment and in my earlier comment, guarded to same-repo PRs withorigin/mainfetched first. Until it lands the instrument reports and nothing enforces.pr_branch_stale_check: a conflicted merge is cannot-tell, not a clean…
bong-water-water-bong commentedon Nov 21, 2026
Status: the tool half is complete and verified on main; the CI row is the only thing left
Three PRs resolved this issue's tool surface, and I verified each on merged
mainrather than on its branch:--pr <n>— per-PR mode, measured against the PR's own baseaea4bdb)--helpshows the flag; base isbaseRefName, fetched735a47a)+refs/heads/<b>:refs/remotes/origin/<b>)a91b51d)tools/ci/pr_branch_stale_check.py; arm pinned by a mutantThat pair is the point of the last two PRs: 77 and 2, never 0, on a branch whose merge cannot be measured — the answer a gate must not get wrong. Before #3084 it printed "merging it removes nothing main has" and exited 0; before #3094 it never got that far, because a force-pushed branch could not be fetched at all.
The regression arm is not vacuous: reverting only the
+gives rc=1, 1 FAIL.What is still missing, and why it is not mine
The CI row. Pushing
.github/workflows/ci.ymlis refused for this lane:So the step stays here for whoever holds that scope. One step in the existing
buildjob, same-repo PRs only, fetching the base first so a missing ref cannot turn the row red for everyone:With #3094 in, the tool mirrors its own refs, so no second fetch line is needed — and
--pris the right entry point because it measures against the PR's own base (a pin-branch PR measured againstmainis the false clean #3071 fixed).Until that lands, #3076 is open on exactly one item: the instrument reports, and nothing enforces.
pr_branch_stale_check --pr: fetch the pull ref, rebased over #3094 (e…
pr_branch_stale_check: a shallow clone answers cannot-tell, and an ad…
bong-water-water-bong commentedon Nov 21, 2026
Correction to the YAML I handed over twice: it would have been a false green in CI, and I found that by actually cloning the way
actions/checkoutdoes.In a
--depth 1clone of this repo, the gate answers:That branch is BEHIND 1 and its merge conflicts; a full clone says so and exits 2. Cause: in a shallow clone
git rev-list --count A..Breturns 0 for a branch that is behind, and the distance is what decides every verdict in the file.PR #3105 fixes it two ways: a
shallow_guard()(cannot-tell in a shallow clone, 3 arms) andcannot_tell()now exiting 77 under--advisory, which is what the flag's help and the pre-PR runner have always promised — every early cannot-tell used to bypass that mapping and turn a lane's gate red for something it could not see.So the CI row needs
fetch-depth: 0, or the new guard makes it a skip on every run:Lesson worth more than the patch: I had quoted that step twice without ever running it in the checkout shape CI uses. The tool was right on a dev clone and a certifying liar on a CI clone.
pr_branch_stale_check: a shallow clone answers cannot-tell, and an ad…
pr_branch_stale_check --pr: fetch the pull ref, rebased over #3094 (e…
bong-water-water-bong commentedon Nov 21, 2026
A second enforcement point that needs no
workflowscope:--pr autoin the pre-PR gateThe blocker on this issue has been "the CI row needs
workflowscope". There is a way to enforce it tonight, at the point a lane is already forced through: its ownscripts/pre-pr-checks.sh.The shape
A
--pr automode on the tool: resolve the current branch's own open PR and gate that one, hard. Noghpermission beyond what every lane already uses, no workflow file, no token scope:and one row in the checks array:
"tools/ci/pr_branch_stale_check.py --pr auto"Why this is the right row and not just a second advisory
--pr autoonly ever judges the branch in front of you — the same rulepre-pr-checks.shalready applies to every other check.What it does not replace
The CI row. A lane can skip
pre-pr-checks.shentirely, and the merge queue does not run it. This closes the gap for lanes that run their own gate — which is most of the fleet — while the CI row stays the item that closes this issue for everything else.I am not opening this tonight: #3105 is at a verdicted head and adding scope to it would invalidate that review, and a second PR to the same file within the hour is the duplication this lane has spent the night flagging in others. Recorded here so it is one line of work for whoever picks up the wiring — or for me tomorrow, at a head that can carry it.
pr_branch_stale_check: a shallow clone answers cannot-tell, and an ad…