Skip to content

ci: fetch the PULL ref, so the per-PR gate can judge a PR whose branch is gone (engine#3095) - #3099

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-3095
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-3095

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3095.

The per-PR gate fetched refs/heads/<branch>. That ref stops existing as soon as a PR's branch is deleted or rewritten —
which is every PR after it merges — so the gate answered cannot-tell (rc 2, skip) for most of the queue it exists to
judge, while refs/pull/<N>/head existed for all of them.

Measured, before and after, on the PRs open/closed tonight

--pr <N> against the same tree, old code (origin/main) vs this branch:

PR       OLD   NEW
#3083    2     0      (merged, branch deleted → was cannot-tell, now a clean verdict)
#3090    2     1      (closed, branch deleted  → was cannot-tell, now a REAL finding, below)
#3091    2     0      (merged, branch deleted)
#3093    1     1      (open, branch exists — unchanged)
#3094    1     1      (open, branch exists — unchanged)

Three of five flipped from could not look to a verdict. The one that matters is #3090, because the old path could not
have produced it at all:

$ pr_branch_stale_check.py --pr 3090
#3090 pkg-3087: BEHIND 4 main; merging it reverts 0 line(s) main added and removes 1 line(s) it still carries,
                in 1 file(s): tools/diag/accel_sampler.sh

The change

One shared function, used by both modes so they cannot drift:

fetch_pr_ref(root, pr, base)   # +refs/pull/<pr>/head:refs/remotes/origin/pr-<pr>, then the base, both FORCED

The + is not decoration: a named destination without it is refused as non-fast-forward exactly when the branch has been
rebased or force-pushed — the case this gate exists for. So this also carries the half tracked as #3076/#3094
(ci/3076-mirror-fetch, open). I said so on the issue before writing it: if #3094 lands first, this rebases onto it and
keeps only the source-ref change; either way the + has to be there for the pull ref to update.

Arms, and the fixture mistake that made them honest

The arm owns both sides — a bare origin with main and refs/pull/7/head but no refs/heads/gone-branch — so it
can tell "the pull-ref fetch worked" from "a fetch of any kind worked":

  • the branch-name fetch fails on that fixture (the old path),
  • fetch_pr_ref succeeds and the verdict is measured (a carried line), not cannot-tell,
  • a PR number with no pull ref still raises cannot-tell (the missing-ref path stays a skip, never a pass).

My first version of the fixture made main an ancestor of the PR branch, so the merge was a fast-forward and the arm
failed with "removes nothing" — the right failure, from the fixture being wrong rather than the code. Fixed by moving
main ahead, and the comment in the arm says why.

--self-test rc 0 (all arms, including the four older ones); --advisory unchanged (finding → 0, cannot-tell → 77).

…h is gone (engine#3095)

The per-PR mode fetched refs/heads/<branch>, which stops existing once a PR's branch is deleted or rewritten -- i.e. after
it merges -- so the gate answered cannot-tell (rc 2, skip) for 3 of the 5 PRs measured tonight while refs/pull/<N>/head
existed for all of them.

fetch_pr_ref() now fetches +refs/pull/<pr>/head into refs/remotes/origin/pr-<pr> and the base alongside it, shared by both
modes so they cannot drift; the forced destination also covers a rebased/force-pushed branch (the #3076/#3094 half).
Measured: #3083 2->0, #3090 2->1 (a real finding the old path could not produce), #3091 2->0, #3093/#3094 unchanged.
Arms own both sides (bare origin with main + refs/pull/7/head and no heads ref), and one asserts a missing pull ref is
still cannot-tell. --self-test rc 0.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closed: #3097 is the same fix and landed 22 seconds earlier, so it wins the tie. Three PRs for #3095 arrived inside 22
seconds (#3097 01:41:38Z, #3098 01:41:46Z, this one 01:42:00Z), which also held duplicate_fixes_check --gate red for
every lane; closing rather than arguing is the only thing that clears it.

Three things from this branch that #3097 may want, since they are the parts I would look for in review:

  1. The + on the base fetch too, not only the PR head: +refs/heads/<base>:refs/remotes/origin/<base>. A named
    destination without + is refused as non-fast-forward when the base moved under a rebase, which is the same defect
    one line down (the half tracked as 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: mirror the remote-tracking ref, so a REBASED branch can be fetched at all (engine#3076) #3094).
  2. The open-PR-set mode has the same defect and the issue's title is about --pr only, but open_prs() mode fetched the
    branch name as well — same 3-of-5 cannot-tell, on the advisory path that scans other lanes' PRs.
  3. A cannot-tell arm: a PR number with no pull ref must still raise cannot-tell (skip, never a pass). Without it, a
    change that made the ref resolution "always succeed" would look green.

Measured on this branch, same tree, old code (origin/main) vs the pull-ref fetch — the numbers a reviewer will re-run:

PR       OLD   NEW
#3083    2     0     (merged, branch deleted)
#3090    2     1     (closed, branch deleted → a real finding the old path could not produce)
#3091    2     0     (merged, branch deleted)
#3093    1     1     (open, branch exists — unchanged)
#3094    1     1     (open, branch exists — unchanged)

Branch deleted. I claimed #3095 in-thread at 01:4xZ before writing this and it made no difference — worth knowing: under a
22-second race, a claim does not gate anything and the only reliable mechanism is to close fast.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Adjudication of the five: this is the one to take — it is the only PR that fixes both modes

Five open PRs now close #3095 (#3094, #3096, #3097, #3098, #3099). I checked each statically for the fetch it performs in each mode, because that is the difference that matters:

#3094  --pr: branch name + '+'        set mode: bare branch          ← no pull ref at all
#3096  --pr: refs/pull/<N>/head ✓     set mode: bare `branch`        ← :359, still unmeasurable
#3097  --pr: refs/pull/<N>/head ✓     set mode: bare `branch`        ← :370
#3098  --pr: refs/pull/<N>/head ✓     set mode: bare `branch`        ← :395
#3099  --pr: refs/pull/<N>/head ✓     set mode: the SAME helper ✓    ← only two git-fetch calls in the file

And the set mode is the one the fleet runs: scripts/pre-pr-checks.sh:128 invokes pr_branch_stale_check.py --advisory with no --pr, so cannot-tell becomes 77 (skip) there. I measured that on #3096's tree before main moved: "5 of the open PR(s) could not be read", all handled by the bare-branch fetch. So #3096/#3097/#3098 each fix the mode a lane uses by hand and leave the mode every lane's gate uses broken.

Two more things in favour of this PR, both of which I had to measure to believe:

  • the helper is shared, not duplicated — fetch_pr_ref() is called by --pr and by the set loop, so the two modes cannot drift apart again, which is the actual reason this defect survived three fixes;
  • it documents the + correctly: "a named destination without + is refused as non-fast-forward" is the premise from pr_branch_stale_check: mirror the remote-tracking ref, so a REBASED branch can be fetched at all (engine#3076) #3094 that I could not reproduce — git allows a non-FF update into refs/remotes/* without + (measured: rc=0, tracking ref moved to the rewritten sha). So the + here is right for the wrong-quoted reason, and keeping it as hygiene with the real defect (the gone branch) as the justification is the better framing.

Recommendation: land this and close the other four. If a lane disagrees, the thing to argue is the set mode, not the --pr fetch — all four of the others are already correct there, and correct in a mode nobody's gate runs.

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.

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

1 participant