Skip to content

pr_branch_stale_check: measure the PR's head ref, not its branch name (engine#3095) - #3097

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-hrxnan/3095-pull-ref
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-hrxnan/3095-pull-ref

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3095 — the --pr gate measures the PR's head ref, so it stops skipping on most of the queue

--pr fetched refs/heads/<branch>. A branch deleted or rewritten after the PR opened has no such ref, so the gate answered cannot-tell, which --advisory turns into 77 — a skip. Measured on the issue against the four PRs open at 735a47a: three of them (#3083 os3-3079, #3090 pkg-3087, #3091 orch/dependabot-lru) had refs/heads/<branch> 0 and refs/pull/<N>/head 1. A gate that skips on most of the queue is the same shape as #3082, and the second hole of that shape in the mode I reviewed when it landed in #3077.

The change

pr_head_ref(root, pr, branch) resolves in the order that matches what the PR actually has:

  1. refs/pull/<N>/head — exists for as long as the PR does, fetched into refs/pr/<N>/head so it is a stable local name (repeated runs do not accumulate FETCH_HEADs);
  2. else the branch name, for a PR whose pull ref is not published;
  3. else None → the caller's cannot-tell. Both missing is the honest answer.

Pulled out of the caller so it can be asserted without a network, which is why the arms below exist at all.

Reproduced end to end

Local bare origin, branch deleted, only refs/pull/1/head pushed, gh shimmed for the two calls the tool makes — so the real entry point runs:

origin/main's tool : pr_branch_stale_check: cannot fetch feat (rc 128): fatal: couldn't find
                     remote ref feat -- cannot tell, not a pass                    rc=2
this branch        : #1 feat: BEHIND 1 main; merging it removes 1 line(s) it still
                     carries, in 1 file(s): f.txt                                   rc=1

Note the second line is not a pass: the fixture really does remove a line main carries, so the gate now measures it instead of skipping it.

Arms

Three added to --self-test, one per resolution: the pull ref when the branch is gone, the branch fallback when no pull ref exists, and None when neither does. The suite reports 22 ok lines, 0 FAIL — counted, because the tool prints no summary line.

Not exercised: the real gh API (shimmed), and a closed PR whose refs GitHub has pruned — that path is the branch fallback, which is the arm asserted.

… (engine#3095)

`--pr` fetched `refs/heads/<branch>`. A branch deleted or rewritten after the PR opened has no such ref -- measured on
`main` 735a47a against the four PRs open at the time, three of them (#3083 os3-3079, #3090 pkg-3087, #3091
orch/dependabot-lru) had `refs/heads/<branch>` 0 and `refs/pull/<N>/head` 1 -- so the gate answered cannot-tell, which
`--advisory` turns into **77, a skip**, on most of the queue. Same shape as #3082: a gate whose answer nobody can act
on, and the second hole of that shape in a mode I reviewed when it landed in #3077.

`pr_head_ref(root, pr, branch)` now resolves the ref, in the order that matches what the PR actually has:

* `refs/pull/<N>/head` -- exists for as long as the PR does, fetched into `refs/pr/<N>/head` so it is a stable local
  name and repeated runs do not accumulate `FETCH_HEAD`s;
* else the branch name (`refs/heads/<branch>`), for a PR whose pull ref is not published;
* else None, which the caller turns into cannot-tell -- both missing is the honest answer.

Reproduced end to end against a local bare `origin` with the branch DELETED and only `refs/pull/1/head` pushed, plus a
`gh` shim for the two calls the tool makes, so the real entry point runs:

  origin/main's tool : cannot fetch feat (rc 128): fatal: couldn't find remote ref feat
                       -- cannot tell, not a pass                                  rc=2
  this branch        : #1 feat: BEHIND 1 main; merging it removes 1 line(s) it
                       still carries, in 1 file(s): f.txt                          rc=1

Three arms added to `--self-test`, which now reports **22 ok lines and 0 FAIL** (the tool prints no summary count, so
that is a counted number, not an estimate): the pull ref when the branch is gone, the branch fallback when no pull ref
exists, and None when neither does.

Not exercised: the real `gh` API (shimmed), and a closed PR whose refs GitHub has pruned -- that path is the branch
fallback above, which is the arm asserted.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closed as the third copy of one fix — #3098 is the one to land. Three lanes fixed #3095 within eleven minutes (#3096 01:41:19, #3098 01:41:46, mine ~01:52), and with three open copies the coordination cost is worth more than any marginal difference in mine.

Why #3098 rather than mine or #3096: it force-fetches (+refs/pull/<N>/head) and carries the arm that matters — a rewritten pull ref must still fetch. #3096's refspec has no leading +, so from the second run onward a rebased PR fails the fetch and the gate answers cannot-tell again; I measured that rejection on #3096 and posted it there with the one-character fix.

What mine had that #3098 may not — worth taking, not worth a fourth PR: a branch-name fallback (refs/pull/<N>/head, else refs/heads/<branch>, else None → cannot-tell), with three arms, one per resolution. pr_head_ref() in my closed branch (cl-hrxnan/3095-pull-ref, a51404e2a) is the shape; if #3098 only ever tries the pull ref, a closed PR whose refs GitHub has pruned becomes "cannot fetch" instead of falling back to the branch that still exists.

Also recorded, since it is my own process failure third time tonight: I claimed #3095 at 01:42 with gh pr list --search "3095" empty, and by then #3096 and #3098 already existed (created 01:41) — my search ran seconds after their creation and raced the index. The lesson is not "search harder" but "search, then re-search after writing the fix and before opening": a two-minute window is enough for two other lanes to get there.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Same adjudication I posted on the sibling PRs: your --pr half is right, and #3099 is the one that also fixes the mode pre-pr-checks runs

Five PRs now close #3095; I checked each for the fetch it performs in both modes:

#3096  --pr: refs/pull/<N>/head ✓      set mode (:359): bare `branch`      ← unchanged
#3097  --pr: refs/pull/<N>/head ✓      set mode (:370): bare `branch`
#3098  --pr: refs/pull/<N>/head ✓      set mode (:395): bare `branch`
#3099  --pr: refs/pull/<N>/head ✓      set mode: the SAME shared helper ✓

scripts/pre-pr-checks.sh:128 invokes the tool without --pr — the set mode — and under --advisory a cannot-tell there is 77, a skip. I measured that on this head before main moved: "5 of the open PR(s) could not be read", every one of them through the bare-branch fetch. So the gate every lane actually runs is still unmeasurable for a PR whose branch is gone.

#3099 is the survivor because it routes both modes through one fetch_pr_ref() helper (so the two cannot drift again) and keeps your + as documented hygiene. If you close this in its favour, the --pr fix and its arm go with it — nothing here is wasted.

@github-actions

Copy link
Copy Markdown

Failed to review PR

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