ci(integrated-benchmark): list open PRs to find fork-PR head SHA#399
Conversation
The fallback `gh api repos/$REPO/commits/$HEAD_SHA/pulls` lookup only returns PRs whose head commit lives on the base repo — for fork PRs the head SHA exists on the fork (e.g. `Saturate/pacquet`), not the base, so that endpoint returns `[]`. The Stage-2 comment workflow on PR #391 failed at this step: > ##[error]no open PR matches head_sha=b965c5e... in pnpm/pacquet Switch to listing open PRs in the base repo and filtering by `head.sha`. The PRs API records each PR's head SHA on the base-repo side regardless of where the head branch lives, so this works for both same-repo PRs and fork PRs through one code path. Same-repo PRs still bypass the API call entirely via the trusted `workflow_run.pull_requests[0].number` shortcut. The fallback only runs when that array is empty (the fork-PR case).
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe workflow updates PR-number resolution for fork-triggered benchmark runs: when TRIGGER_PR is unset it lists open PRs in the base repo, filters by matching head.sha using the trusted workflow_run.head_sha, and returns a unique PR number; same-repo behavior is unchanged. ChangesFork PR Number Resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/integrated-benchmark-comment.yml (1)
64-77:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
--paginate --jqapplies the filter per page, breaking count/extraction when > 100 open PRs existIn
--paginatemode, each page is a separate JSON array or object;--slurpis needed to wrap all pages into a single outer JSON array before applying a--jqfilter.Without
--slurp, when the repo has > 100 open PRs (triggering a second page),$pris a newline-separated stream of one JSON array per page, e.g.:[200] [] []
count=$(echo "$pr" | jq 'length')then outputs1\n0\n0— a multi-line string. The[[ "$count" != "1" ]]check compares that multi-line string to"1"and is always true, causing a spurious "ambiguous head_sha" error even when exactly one PR matches.jq '.[0]'on the same input would similarly yield200\nnull\nnull, which fails the integer guard.Add
--slurpand flatten with.[][]:🐛 Proposed fix
pr=$( - gh api "repos/$REPO/pulls?state=open&per_page=100" --paginate \ - --jq "[.[] | select(.head.sha == \"$HEAD_SHA\") | .number] | unique" + gh api "repos/$REPO/pulls?state=open&per_page=100" --paginate --slurp \ + --jq "[.[][] | select(.head.sha == \"$HEAD_SHA\") | .number] | unique" )Alternatively, drop
--jqentirely and pipe tojqwith-rs, which also avoids shell-interpolating$HEAD_SHAinto the jq expression (usingenv.HEAD_SHAinstead):pr=$( - gh api "repos/$REPO/pulls?state=open&per_page=100" --paginate \ - --jq "[.[] | select(.head.sha == \"$HEAD_SHA\") | .number] | unique" + gh api "repos/$REPO/pulls?state=open&per_page=100" --paginate \ + | jq -rs "[.[][] | select(.head.sha == env.HEAD_SHA) | .number] | unique" )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/integrated-benchmark-comment.yml around lines 64 - 77, The gh api call using --paginate --jq returns per-page JSON chunks which makes the pr and count variables multiline when >100 PRs exist; update the invocation so pagination is slurped and flattened before filtering (e.g., add --slurp and use a jq filter like .[][] | select(.head.sha == env.HEAD_SHA) | .number or remove --jq and pipe output to jq -rs with env.HEAD_SHA), then compute count and extract pr with a single-array result so the existing checks on count and pr (variables named pr and count and the jq '.[0]' extraction) work correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In @.github/workflows/integrated-benchmark-comment.yml:
- Around line 64-77: The gh api call using --paginate --jq returns per-page JSON
chunks which makes the pr and count variables multiline when >100 PRs exist;
update the invocation so pagination is slurped and flattened before filtering
(e.g., add --slurp and use a jq filter like .[][] | select(.head.sha ==
env.HEAD_SHA) | .number or remove --jq and pipe output to jq -rs with
env.HEAD_SHA), then compute count and extract pr with a single-array result so
the existing checks on count and pr (variables named pr and count and the jq
'.[0]' extraction) work correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fdaca5a4-90d8-4db3-9315-e76faebc5124
📒 Files selected for processing (1)
.github/workflows/integrated-benchmark-comment.yml
There was a problem hiding this comment.
Pull request overview
Updates the Stage-2 integrated benchmark comment workflow to correctly resolve fork PR numbers by querying open PRs and matching on workflow_run.head_sha, avoiding the base-repo-only commits/{sha}/pulls endpoint limitation.
Changes:
- Replace fork-PR fallback from
commits/{sha}/pullstopulls?state=open+head.shafilter. - Expand inline documentation explaining why the previous approach fails for fork PRs and reaffirm the trust model for
HEAD_SHA.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`gh api ... --paginate --jq` runs the jq filter per page, so a query
that returns multiple pages emits one JSON array per page on stdout,
not a single combined array. Reproduced locally with per_page=2:
$ gh api '.../pulls?state=open&per_page=2' --paginate \
--jq '[.[] | .number]'
[399,391]
[385,337]
[333,332]
...
Today pacquet has under 100 open PRs so a single page suffices and
the bug is dormant; past that threshold the downstream
`jq 'length'` would read each line as a separate input and produce
multiple values like `2\n2\n2\n1`, which fails both the `count == 0`
and `count == 1` checks and bottoms out in the "ambiguous" error.
Fix: emit one PR per line with `--paginate --jq '.[]'` so the stream
spans pages cleanly, then `jq -s` slurps the whole thing back into a
single array. `--arg sha` keeps the head SHA out of the jq program
text. Verified with per_page=2 against PR #391's head SHA: returns
`[391]` as expected.
Reported by Copilot on #399.
Summary
Fix the comment-posting workflow's fork-PR fallback. Verified failing on the test rebase of #391: the Stage-2 workflow erred with
no open PR matches head_sha=b965c5e... in pnpm/pacquet.Why the previous fallback failed
The fallback in #398 used
gh api repos/$REPO/commits/$HEAD_SHA/pulls— but that endpoint only returns PRs whose head commit lives on the base repo. For fork PRs, the head SHA only exists on the fork (Saturate/pacquetfor #391), so the base-repo lookup returns[]. The exact case the workflow exists to support hits the wrong endpoint.I tested both endpoints directly against PR #391's head SHA
b965c5ef03ee15caffb65bddcbe43510d5f47f8d:What changes
Switch the fork-PR fallback from
commits/{sha}/pullstopulls?state=open+ jq filter onhead.sha. The PRs API records each PR's head SHA on the base-repo side regardless of where the head branch lives, so one code path covers both same-repo and fork.Same-repo PRs still bypass the API call entirely via
workflow_run.pull_requests[0].number. The fallback only runs when that array is empty (fork PRs).Trust model unchanged
HEAD_SHAstill comes from the trustedworkflow_runevent payload, never from the artifact. The artifact still carries onlySUMMARY.md. The collision-on-SHA check (count != 1⇒ error) still fires loudly if the impossible happens.Test plan
actionlintclean.Written by an agent (Claude Code, claude-opus-4-7).
Summary by CodeRabbit