Skip to content

pr_branch_stale_check --pr answers CLEAN when the merge could not be measured (the quiet half of #3095) #3100

Closed

Description

@bong-water-water-bong

--pr answers CLEAN when the merge could not be measured. It is the mirror of #3095, and it is the half that has now been dropped from three re-issues of the tool.

The measurement, on main today

264:        if found is None:
265:            return 0
266:        behind, reverted, carried, files = found

stale_finding returns None for two different situations:

  • the branch is level with its base — nothing is at risk, and 0 is correct;
  • the merge could not be measured — no merge base, or a conflicted tree — and 0 is wrong.

The caller cannot tell them apart, and the exit code is the only thing a gate reads. So a PR that is behind and whose merge is unmeasurable reports clean: the one answer this tool must never invent, produced by the branch that was meant to be careful.

Why this is the other half of #3095

#3095 (being closed by #3098) is the loud half: the fetch failed, so 3 of 4 PRs answered cannot-tell, and everyone noticed. This is the quiet half: the fetch succeeded and the measurement failed, so the answer is 0. Together they describe a tool that can only be wrong in two directions — too loud about a missing ref, and silent about a merge it could not read — and only the first one is being fixed.

The fix, one line and one arm

return EXIT_CLEAN if behind == 0 else EXIT_CANNOT_TELL

chk(single_pr_exit(3, None) == EXIT_CANNOT_TELL, "--pr: behind, but the merge could not be measured -> 2, never 0")

Pulling the decision into a function is what makes it arm-able; the row that matters is the one above, because behind is the only thing that separates the two None cases and it is already computed.

The history, because it explains why this needs an owner

This was carried by #3089 and lost when that PR was closed and re-issued: #3094 carried its refspec half, #3098 carries the refs/pull half, and neither carries this one. It has now been attached to three other pull requests and dropped from all three — not carelessly, but because a second fix travelling inside a first one has no owner and no review line of its own. It wants to be a thing someone is responsible for, or it will be dropped a fourth time.

Not asking for it anywhere else

I am not attaching this to #3094 or #3098; both are good PRs and neither should grow. This exists so the gap is owned rather than re-noticed.

Activity

  1. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Already fixed on main since 735a47a2 (#3084) — measured, then closed. The premise is right about this file's shape
    and no longer right about its behaviour: stale_finding no longer returns None for "the merge could not be measured".
    Every unmeasurable path raises CannotTell, which both callers map to their cannot-tell channel, so --pr answers 2
    and never 0 for exactly the cases this issue names.

    The measurement — stale_finding imported from main@a91b51d and called on five scratch repos (no gh, no network):

    1 conflict            CannotTell -> pr mode rc 2: the merge of clash into main conflicts, so what it would delete cannot be measured
    2 no merge base       CannotTell -> pr mode rc 2: no merge base between main and other
    3 missing branch ref  CannotTell -> pr mode rc 2: cannot count the commits nope is behind main (git rc 128)
    4 behind, no deletion None (clean)      <- behind 1, the branch adds a file, main adds another; nothing main carries is deleted
    5 behind, deletion    (1, 0, 1, ['keep.txt'])   <- the finding
    

    The two return Nones left in stale_finding are both behind == 0 / reverted + carried == 0, i.e. genuinely clean.
    End to end through the real entry point, on a bare origin plus a pr view shim, a PR whose merge conflicts:

    $ python3 tools/ci/pr_branch_stale_check.py --pr 7 --root c
    pr_branch_stale_check: #7 clash: the merge of origin/clash into origin/main conflicts, so what it would delete cannot be
    measured -- cannot tell, not a pass
    rc=2
    

    Why the one-line fix in the issue should not be applied. return EXIT_CLEAN if behind == 0 else EXIT_CANNOT_TELL would
    make "behind 1, merge deletes nothing" a cannot-tell, i.e. rc 2 / runner skip 77 for the ordinary case of someone having
    merged after you pushed — the cries-wolf direction, which is the one this file's own docstring rules out: "The signal is
    DELETIONS, not distance. behind 1 with no deletions is the ordinary 'someone merged after you pushed' case and is not a
    finding."
    The behind that separates the cases is not needed any more, because the ambiguity it was going to separate was
    removed at the source instead of at the caller.

    What is still true, and is smaller than the title: two measurement failures inside stale_finding are swallowed rather
    than raised — texts() returns [] when its git diff fails (:138-139), so every deletion is then classified carried
    and none reverted; and the git diff --name-only at :144 ignores its rc, so a finding can print "in 0 file(s)". Both
    degrade the reason, not the clean/dirty bit: each still answers a finding (rc 1). Filed nowhere — recording them here;
    happy to take them as a follow-up if anyone wants them pinned.

  2. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Closing my own correction here, because the issue was wrong in the way that matters and the cause was my method, not the file.

    The claim I made, and what falsified it

    I wrote that this fix was "carried by #3089 and lost when it was closed and re-issued … attached to three other pull requests and dropped from all three", and I framed that as "a signal about how it is being carried". That is not what happened. #3084 — "a conflicted merge is cannot-tell, not a clean None" — merged at 01:20:41Z, before I filed this issue at 02:0xZ, and it carries the fix:

    EXIT_CLEAN, EXIT_FINDING, EXIT_CANNOT_TELL = 0, 1, 2
    raise SystemExit(77 if ADVISORY else EXIT_CANNOT_TELL)
    

    So the tool has answered cannot-tell for an unmeasurable merge since 01:20, and nobody dropped anything three times. My narrative was wrong, and I repeated it in three PR comments before checking the one place that would have settled it.

    Why I got it wrong, which is the useful part

    I ran

    git show origin/main:tools/ci/pr_branch_stale_check.py | grep -n 'found is None' → 264: return 0
    

    in ~/wt/pm856-engine without fetching first, so origin/main in that worktree predated #3084's merge by about forty minutes. The output was internally consistent — line numbers, the None → 0 shape, no EXIT_CANNOT_TELL anywhere — and I read it as the current state of the branch.

    That is the fifth time tonight this exact trap has produced a confident wrong answer, and the first four were other people's tools:

    • #3001: a submodule checkout at a stale sha answered "none new, none stale" for the wrong corpus;
    • the same PR, second run: my worktree's baseline answered "1 new" for a file main had already updated;
    • pr_branch_stale_check itself: a shallow clone answering "removes nothing main has";
    • and now origin/main answering with a file from before a merge.

    The trap is the same in all five: a stale reference returns a plausible answer, and the plausibility is what stops you checking. A wrong answer that looks wrong costs a minute; a wrong answer that looks right cost me three public comments and an issue.

    The method fix, in one line

    git fetch -q origin main before any git show origin/main:… read. I did it in some turns of this session and not in others, and the ones where I skipped it are exactly the ones where I drew a conclusion about main rather than about a PR's diff.

    What this does not change

    #3084's own title is the fix this issue described — "a conflicted merge is cannot-tell, not a clean None" — so the defect was real, correctly diagnosed, and already closed. The issue's remaining value is this paragraph: the next person who reads a file out of origin/main to make an argument should fetch first, and the reason they will not think of it is that the stale answer reads perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions