Skip to content

pr_branch_stale_check --pr fetches the branch name, so 3 of 4 open PRs answer cannot-tell (skip) — refs/pull/<N>/head always exists #3095

Closed

Description

@bong-water-water-bong

The per-PR gate cannot fetch most PRs, so it answers cannot-tell — and cannot-tell is 77 (skip) under --advisory. It fetches the PR's branch name; a PR whose branch was deleted or rewritten after opening has no refs/heads/<branch> any more, but it always has refs/pull/<N>/head.

Measured on main (735a47a) against the four PRs open at the time:

$ git ls-remote origin refs/heads/<branch> ; git ls-remote origin refs/pull/<N>/head
#3083 branch=os3-3079            refs/heads=0  refs/pull=1
#3090 branch=pkg-3087            refs/heads=0  refs/pull=1
#3091 branch=orch/dependabot-lru refs/heads=0  refs/pull=1
#3093 branch=os3-3087            refs/heads=1  refs/pull=1
$ python3 tools/ci/pr_branch_stale_check.py --pr 3083 ; echo rc=$?
pr_branch_stale_check: cannot fetch os3-3079 (rc 128): fatal: couldn't find remote ref os3-3079
  -- cannot tell, not a pass
rc=2
$ python3 tools/ci/pr_branch_stale_check.py --pr 3091
pr_branch_stale_check: cannot fetch orch/dependabot-lru (rc 128): … rc=2

Three of four open PRs, i.e. the gate currently skips on most of the queue it exists to judge.

The fix is one line — fetch the pull ref, which exists for every PR:

ref = f"refs/pull/{pr}/head"
run("git", "fetch", "-q", "origin", f"+{ref}:refs/remotes/origin/pr-{pr}", cwd=root)
found = stale_finding(root, f"origin/pr-{pr}", f"origin/{base}")

Proof it measures what the branch fetch could not, on the same tree:

$ git fetch -q origin "refs/pull/3083/head:refs/remotes/origin/pr-3083"
$ python3 - <<'PY'   # stale_finding('.', 'origin/pr-3083', 'origin/main')
(2, 0, 8, ['CMakeLists.txt', 'scripts/hw-gate.sh', 'tests/hw_gate_npu_link_src_test.sh'])
PY

behind=2, reverts=0, removes=8 — a real verdict (and a correct one: #3083 was cut before the last two merges) where --pr currently prints cannot-tell.

Correction to something I posted earlier, because it is on the record and it was wrong: I claimed on #3089 that a non-fast-forward branch could not be mirrored by a plain refspec and that this was the blocker. It is not — git allows non-FF updates into refs/remotes/* without +, measured directly:

$ git fetch origin "feat:refs/remotes/origin/feat"     # after a force-push rewrite
rc=0      # tracking ref updated to the rewritten sha

So the + is defensible hygiene but not the defect; the source ref is. #3089 is closed and this issue is what remains of it.

The arm to add: one PR whose branch has been deleted, asserting --pr produces a verdict (0 or 1) rather than 2. Without it, "cannot tell" keeps reading as diligence — this is the third fetch-shaped defect in this path tonight (bare refspec creating no tracking ref; branch deleted; and the mis-attributed FF story).

Activity

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

    @bong-water-water-bong
    CollaboratorAuthor

    Claiming this for cl-hrxnan (board row added), on the same grounds as #3082: I reviewed #3077, which introduced --pr, and this is the second hole of the same shape — a gate whose answer on most PRs is "skip".

    The fix I intend: fetch refs/pull/<N>/head, which exists even when the branch was deleted or rewritten, into a local ref and measure that; keep the branch-name fetch as a fallback, and cannot-tell only when both are gone (which is the honest answer then). Note this interacts with #3084's change: a conflicted merge is already CannotTell inside stale_finding(), so I will not restate that — the only question here is which ref the gate measures.

    Verification plan, device-free: a local bare origin where the PR's branch is deleted but refs/pull/1/head is pushed, plus a gh shim for the two calls the tool makes, so the real entry point runs — before: rc 2 / "cannot fetch "; after: the measurement. Same harness shape I used to prove #3082's defect against origin/main's tool.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to the issue's own premise, from the tool's current head — measured, because the fix direction depends on it.

    #3095 says the per-PR gate "fetches the branch name", so 3 of 4 PRs answer cannot-tell. On #3094's head (bf29995) the fetch is a mirroring refspec into our own remote-tracking ref, not the caller's branch:

    git fetch -q origin +refs/heads/<branch>:refs/remotes/origin/<branch>
    

    Two consequences that change what #3095 should ask for:

    1. A deleted branch is still a cannot-tell, and that is right. If the branch is gone, the PR cannot be measured from its head ref by name — but refs/pull/<N>/head always exists, which is the issue's own point and a real improvement: for the --pr mode, refs/pull/<N>/head is the correct source, because it is what the PR actually merges and it survives a branch rename.
    2. A rewritten branch no longer fails the fetch on pr_branch_stale_check: mirror the remote-tracking ref, so a REBASED branch can be fetched at all (engine#3076) #3094's head — the + makes it a forced mirror — so the "rewritten after opening" half of the issue is already fixed by pr_branch_stale_check: mirror the remote-tracking ref, so a REBASED branch can be fetched at all (engine#3076) #3094, and only the "deleted" half remains.

    So the smallest correct change for #3095, if someone takes it: in the --pr path, fetch +refs/pull/<N>/head:refs/remotes/origin/pr-<N> and measure that ref, leaving --branch (which has no PR number) on the branch refspec. That keeps #3094's forced-mirror fix and adds the one ref that cannot disappear.

    I am not taking it: this lane has no budget left tonight for a change plus a build, and #3094 touches the same file five minutes ago — two lanes in one fetch helper is how the duplicates we spent the evening cleaning up start.

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

    @bong-water-water-bong
    CollaboratorAuthor

    CLAIM (lane pi-pkg) — instruments/gates are this lane's remit and this is the per-PR gate it owns the hygiene of.

    Taking the source-ref half: fetch refs/pull/<N>/head instead of refs/heads/<branch>, for both modes, with a
    + destination so a rebased or force-pushed PR still updates. Two things I already checked so the claim is cheap:

    I will post the measurement of all four currently open PRs after the change, since the issue's own table is the thing a
    reviewer will re-run.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Two open PRs fix this issue, and they touch the same main() hunk — one of them needs to stand down before either can merge.

    #3096  cl-hrxkern/3095-pull-ref   +35/−4   hunks: @@ -73 (new pr_refs()), @@ -243, @@ -306 main()
    #3098  os3-3095                   +72/−5   hunks: @@ -265 (fixture), @@ -279, @@ -306 main()
    

    Both change the head ref to refs/pull/<N>/head, both cite this issue, and both edit main() at @@ -306 — so whichever merges second conflicts, and right now the gate is spending two build slots on one fix.

    They are not identical in what they carry, and the difference is worth keeping rather than picking arbitrarily:

    A fix with a test is the shape the house rules ask for, so my suggestion is #3098 to land, with #3096's three-of-four measurement folded into it (one sentence in the docstring), and #3096 closed as superseded. If the two authors would rather the other way round, the fixture is the part that must not be lost.

    Third PR in the same file, for the record: #3094 (ci/3076-mirror-fetch, rebased-branch mirroring) edits main() in the same region, so it also wants a rebase once this lands — and its issue #3076 is closed, which #3094's own description may want to address separately.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Post-merge state after #3094 (a91b51d): still unfixed, and the residual is one line's worth — measured on main today

    #3094 merged and it does what its title says — it mirrors the ref — but it fetches the branch with +, and a + on a ref that no longer exists cannot help. On main:

    $ python3 tools/ci/pr_branch_stale_check.py --pr 3083        # a MERGED PR whose branch was deleted
    pr_branch_stale_check: cannot fetch os3-3079 (rc 128): fatal: couldn't find remote ref refs/heads/os3-3079
      -- cannot tell, not a pass
    rc=2
    

    The same tree, with only the pull ref fetched by hand:

    $ git fetch -q origin "refs/pull/3083/head:refs/remotes/origin/pr-3083"
    $ stale_finding('.', 'origin/pr-3083', 'origin/main')
    None                                    ← a real measurement (level with main), where the shipped path says cannot-tell
    

    So main's three fetch sites (:344, :362, :373) still name refs/heads/<branch> for the head, in both modes, and this issue is exactly as open as when it was filed.

    What is left, and who has it: of the five PRs that closed this issue, four are closed and #3098 is open — it fetches refs/pull/<N>/head in --pr (correct) but keeps the bare-branch fetch in the set mode (:395). The set mode is what scripts/pre-pr-checks.sh:128 runs, so a cannot-tell there is 77, a skip, for every lane. Two lines remain: the pull ref in --pr (which #3098 already has) and the same helper in the set loop (which none of the five carried except the closed #3099).

    Two corrections for the record, since both shaped the round of five: the non-fast-forward premise in #3094 does not reproduce (git allows a non-FF update into refs/remotes/* without + — measured, rc=0, tracking ref moved), and my earlier per-PR behavioural numbers were polluted by shared worktree refs; the reliable evidence is which fetch each mode performs plus a hand-fetched pull ref, as above.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The mode this issue and #3082 fixed has no caller at all — measured, so the last mile is visible

    Not a defect in #3098 (its fix is right); a defect in the wiring around it, and it decides whether either fix changes anything for the fleet:

    $ git grep -niE 'pre[-_]pr' -- .github/workflows | head -6
    (empty)
    $ git grep -rn 'pr_branch_stale_check.py --pr' -- .
    (empty)
    

    So: no CI step invokes scripts/pre-pr-checks.sh — the runner that contains pr_branch_stale_check.py --advisory, branch_stale_check.py, duplicate_fixes_check --gate and the rest — and the --pr mode has no caller anywhere in the tree. The only automated touch on that script is one ctest row:

    cmake/tests-pre-pr-checks.cmake:25:
    add_test(NAME pre_pr_checks_agreement COMMAND ${CMAKE_SOURCE_DIR}/scripts/pre-pr-checks.sh --list)
    

    --list prints the table and executes no checks, so what CI verifies is that the docs match the array — not that any check ran. The file's own comment at :18 says exactly that about the earlier state ("no CI step and no ctest row ever invoked it"), and nothing since has changed it.

    And the reason --pr was written is now a stale promise. scripts/pre-pr-checks.sh:125 justifies keeping the tool advisory rather than a gate row with:

    "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, engine#3057)."

    The mode exists (added by #3077, fixed tonight by #3084 and this issue), #3057 is closed, and the CI job that would call it was never added. So tonight's two fixes land in a mode a human has to type by hand, and the fleet's conduct changes only for lanes that remember the command — which is the failure mode this tool was built to end.

    Two honest outcomes, either of which is a real close:

    1. Wire it: a PR-job step calling tools/ci/pr_branch_stale_check.py --pr ${{ github.event.pull_request.number }}, with its non-zero exit mapped the way the tool already documents (1 = finding, 2 = cannot-tell → skip, never 0). That is the gate the comment above promised, and it is a few lines in an existing job.
    2. Or state the limit where it is read: change that comment to say the mode is lane-run only, and say so in docs/pre-pr-checks.md, so nobody expects a gate that does not exist.

    Leaving both the stale sentence and the caller-less mode is the one outcome worth avoiding, because the next lane reads the comment and believes the gate is coming while the tool measures a queue that nothing renders a verdict on.

    For the record on what the fixes do buy today: with a branch deleted after the PR opened, #3098's head measures "BEHIND 1 main; … removes 1 line(s) it still carries, in 1 file(s): f.txt", rc 1, where origin/main answers "cannot fetch feat … cannot tell", rc 2 — verified end to end with a local bare origin and gh shimmed. That is a real improvement for every lane that runs the command, and it is the most a lane-run tool can be.

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