Skip to content

Commit 0f531be

Browse files
kyle-sextonclaude
andauthored
fix(pr-pipeline): match pr-merge adoption candidates by actor id (#13852)
No related issue: removes the login coupling ahead of the release App rename (owner decision Q11) ## Summary pr-merge's candidate listing matched trusted actors by login: it turned each `login` in `.github/standards/trusted-actors/trusted-actors.json` into `app/<slug>` and compared it with the `author.login` that `gh pr list` returns, which carries no numeric id. Once the release App is renamed from `melodic-plugin-release` to `melodic-release`, its pull requests would stop being listed until the json changed. The listing now matches trusted actors by numeric id, so a rename has no effect on it. ## Fix - The step `List the candidate PRs` in `.github/workflows/pr-merge.yml` now does one paginated `gh api graphql` read of open pull requests into main: - `first: 100`, a hard cap of 10 pages, and `orderBy: CREATED_AT DESC`, the same order `gh pr list` uses ([lister.go](https://github.com/cli/cli/blob/trunk/pkg/cmd/pr/shared/lister.go)). - `totalCount` comes back on every page. - It reads the same fields as before (`id`, `number`, `headRefOid`, `isDraft`, `updatedAt`, `labels`, `body`), plus `author { __typename login ... on Bot { databaseId } ... on User { databaseId } }`. Labels are normalized to the old `[{name}]` shape, so the prefilter and the later steps are unchanged. - Trusted actors (with `adoption.idle-hours` set) match on `author.databaseId` against the json `id`. Only positive integers count, which replaces the old login-shape regex. - The lanes App (`merge.agent-identity`) and Dependabot are matched as Bots by login and kept only by their own switches (`merge.lane-prs`, `merge.dependabot.mode`), whatever their ids. So `lane-prs: native` and Dependabot `off` still drop them even though both ids are on the trusted list. Basis: this matches today's exclusion of `app/<slug>` and `app/dependabot` from the adoption set (pr-merge.yml at origin/main), and both of those come from config logins, not from trusted-actors.json. - An author with no id (a deleted account, a mannequin) matches nothing. - The try fails and is retried, keeping today's fail-safe green hold, when: - a 200 response carries `errors` or lacks the connection, or a page has no `totalCount`; - the count changes between pages; - the listing holds a different number of unique PRs than the count. - More than 10 pages holds the run green with `listing full` and is not retried, as before. Exactly 1000 open PRs now lists; before, it held, because `gh pr list --limit 1000` could not tell 1000 apart from more. - Live check: GraphQL `Bot.databaseId` for the author of #13829 (`melodic-plugin-release`) returned 337859524, which is the `id` in trusted-actors.json. ### API calls per run N is the number of open PRs into main. Counts are per listing try; a try retries at most 3 times. | | Old | New | |---|---|---| | N < 1000 | ⌈N/100⌉ `gh pr list` pages (min 1) + 1 `totalCount` read | ⌈N/100⌉ GraphQL pages (min 1) | | N ≥ 1000 | 10 pages, held | 10 pages (N = 1000 lists; N > 1000 held) | The delta is −1 call per try below the cap, and 0 at the cap. Over a run with retries that is up to −3. Basis: `gh pr list` pages 100 at a time (`pageLimit := min(limit, 100)` in [lister.go](https://github.com/cli/cli/blob/trunk/pkg/cmd/pr/shared/lister.go)), and the old step made the separate `totalCount` read only when N was below the limit (pr-merge.yml at origin/main). Each new page is a separate call through the rate guard's `gh api` wrapper, so header readings are now observed on every page. Unchanged: permissions, tokens, which actors are trusted, and every later step. ## Verification - `node --test .github/scripts/pr-merge/merge-job.test.mjs`: 97/97 pass (the three per-page failure cases were added after the local code review: an open count that moves between pages, a 200 that carries GraphQL errors, and a next page with no cursor; each holds the run after three tries). The fake `gh` now serves GraphQL pages keyed by cursor. New and changed cases: - a trusted App renamed to a new login but with a matching id is listed (`renamed-release`, id 2); - a trusted login under an untrusted id is dropped, for both a User and a Bot; - a null author and a mannequin are dropped; - a string id in the json is ignored; - under `lane-prs: native` the lanes App is dropped even with its id trusted; - 1000 PRs list in 10 calls with 9 cursors; - 1001 and 1500 PRs hold after 10 calls with no retry. - `scripts/check-affected.sh --tests`: exit 0, "11 passed, 110 skipped over 4 changed files"; the pre-push check-affected hook passed on the pushed head. - Local code and security reviews ran on the diff because both CI review lanes were failing. Security review: no findings. Code review: the test gaps above, plus two stale comments, all fixed. ## Related - #13826 (the tracker-binding move this builds on) - `docs/conventions/pr-pipeline/README.md` documents the listing and is updated to match. The changelog fragment is in `.changes/pr-pipeline/`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent dee3a05 commit 0f531be

4 files changed

Lines changed: 194 additions & 94 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
bump: patch
3+
---
4+
5+
### Fixed
6+
7+
- pr-merge's candidate listing matches trusted-actors.json's accounts by numeric id (`User.databaseId`, `Bot.databaseId`) instead of login, so a renamed App's pull requests stay candidates without a change to the list. It reads the open pull requests in one paginated GraphQL query, at most 10 pages of 100, with the open count on each page, which drops the separate count read: one call fewer per try. A list of exactly 1000 open pull requests now lists; more than 1000 still holds the run green.

‎.github/scripts/pr-merge/merge-job.test.mjs‎

Lines changed: 100 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// pr-merge.yml's merge job: the post-merge check and its re-dispatch do not
2-
// wait on the gate loop (#8299), the listing retries a failed `gh pr list`, an
2+
// wait on the gate loop (#8299), the listing retries a failed GraphQL read, an
33
// unknown listing holds the job green and every later acting step, the
44
// post-merge check included, waits on that hold, the run logs its API cost
55
// through the shared action, and the run cache carries the verdict reads that
@@ -117,35 +117,46 @@ test("the early re-dispatch keeps the trusted mechanics and skips untrusted even
117117
assert.doesNotMatch(job, /dispatch: .*needs-dispatch/);
118118
});
119119

120-
// Runs the listing step's script against a fake `gh` whose `gh pr list`
120+
// Runs the listing step's script against a fake `gh` whose GraphQL listing
121121
// fails its first `failures` calls and then answers `prs` (by default one pull
122-
// request of the lanes App's) and whose open-count read answers `total` (by
123-
// default as many as `prs`; null fails it), with `.base` pointing at this checkout,
122+
// request of the lanes App's) 100 a page, each page counting `total` open pull
123+
// requests (by default as many as `prs`; null leaves the count out), with
124+
// `.base` pointing at this checkout,
124125
// or, given `edit`, at a copy whose pr-pipeline.yaml is `edit(text)` and whose
125126
// trusted-actors.json is `actors`, when given, else this checkout's.
126127
// `env` overrides the step's environment: merge.lane-prs is `gate` unless it
127128
// says otherwise, the mode that lists the lanes App's own pull requests.
128-
// `attempts` scripts each `gh pr list` in turn: `502` fails that one.
129-
const listed = (number, login, isDraft = false) => ({ id: `PR_${number}`, number, headRefOid: "abc", isDraft, updatedAt: "2026-10-18T00:00:00Z", labels: [], body: "", author: { login } });
130-
const LANES_PR = [listed(7, "app/melodic-automation-lanes")];
131-
const runListing = (failures, edit, actors, env = {}, failure = "HTTP 502: Bad Gateway", prs = LANES_PR, total = prs.length, attempts = []) => {
129+
// `attempts` scripts each call in turn: `502` fails that one. `editPage(page, p)`
130+
// returns page `p`'s response in place of the one built.
131+
const bot = (login, databaseId) => ({ __typename: "Bot", login, databaseId });
132+
const user = (login, databaseId) => ({ __typename: "User", login, databaseId });
133+
const LANES = bot("melodic-automation-lanes", 337595936);
134+
const listed = (number, author, isDraft = false) => ({ id: `PR_${number}`, number, headRefOid: "abc", isDraft, updatedAt: "2026-10-18T00:00:00Z", labels: { nodes: [] }, body: "", author });
135+
const LANES_PR = [listed(7, LANES)];
136+
const runListing = (failures, edit, actors, env = {}, failure = "HTTP 502: Bad Gateway", prs = LANES_PR, total = prs.length, attempts = [], editPage = (page) => page) => {
132137
const dir = tempDir("pr-merge-listing-");
133138
try {
134139
const bin = join(dir, "bin");
135140
execFileSync("mkdir", [bin]);
136-
writeFileSync(join(dir, "prs.json"), JSON.stringify(prs));
141+
const pages = Math.max(1, Math.ceil(prs.length / 100));
142+
for (let p = 0; p < pages; p++) {
143+
const connection = {
144+
...(total === null ? {} : { totalCount: total }),
145+
pageInfo: { hasNextPage: p + 1 < pages, endCursor: `p${p + 1}` },
146+
nodes: prs.slice(p * 100, p * 100 + 100),
147+
};
148+
writeFileSync(join(dir, `page-p${p}.json`), JSON.stringify(editPage({ data: { repository: { pullRequests: connection } } }, p)));
149+
}
137150
writeFileSync(
138151
join(bin, "gh"),
139152
`#!/usr/bin/env bash\n` +
140-
`if [ "$1" = api ]; then\n` +
141-
` [[ "$*" == *.totalCount* && "$*" == *'pullRequests(states: OPEN, baseRefName: "main")'* ]] || { echo "unexpected query: $*" >&2; exit 1; }\n` +
142-
` ${total === null ? 'echo "HTTP 502: Bad Gateway" >&2; exit 1' : `echo ${total}; exit 0`}\n` +
143-
`fi\n` +
153+
`[[ "$1" = api && "$*" == *graphql* && "$*" == *'pullRequests(states: OPEN, baseRefName: "main", first: 100'* ]] || { echo "unexpected call: $*" >&2; exit 1; }\n` +
144154
`echo "$*" >>"${dir}/args"\n` +
145155
`n=$(($(cat "${dir}/calls" 2>/dev/null || echo 0) + 1))\necho "$n" >"${dir}/calls"\n` +
146156
`attempts=(${attempts.join(" ")})\n` +
147157
`if [ "$n" -le ${failures} ] || [ "\${attempts[$((n - 1))]:-}" = 502 ]; then echo "${failure}" >&2; exit 1; fi\n` +
148-
`cat "${dir}/prs.json"\n`,
158+
`page=p0\nfor arg; do [[ $arg == after=* ]] && page=\${arg#after=}; done\n` +
159+
`cat "${dir}/page-$page.json"\n`,
149160
);
150161
writeFileSync(join(bin, "sleep"), `#!/usr/bin/env bash\necho "$1" >>"${dir}/sleeps"\n`);
151162
chmodSync(join(bin, "gh"), 0o755);
@@ -203,7 +214,7 @@ const runListing = (failures, edit, actors, env = {}, failure = "HTTP 502: Bad G
203214
}
204215
};
205216

206-
test("the listing retries a failed gh pr list", () => {
217+
test("the listing retries a failed GraphQL read", () => {
207218
const run = runListing(2);
208219
assert.equal(run.status, 0, run.stderr);
209220
// Three tries of the one list.
@@ -221,7 +232,7 @@ test("the listing retries a failed gh pr list", () => {
221232
const assertHeld = (run) => {
222233
assert.equal(run.status, 0, run.stderr);
223234
assert.match(run.stdout, /^::notice title=Merge lane hold::/m);
224-
assert.doesNotMatch(run.stdout, /^::error title=GitHub rate limit::gh pr list/m);
235+
assert.doesNotMatch(run.stdout + run.stderr, /^::error::/m);
225236
assert.match(run.output, /^held=true$/m);
226237
assert.doesNotMatch(run.output, /^(count|listed)=/m);
227238
assert.equal(run.prefiltered, false);
@@ -233,7 +244,7 @@ test("a listing with pull requests missing from a 200 holds the job, and the nex
233244
assertHeld(degraded);
234245
// A count that moved between the two reads gets the retries before it holds.
235246
assert.equal(degraded.calls, 3);
236-
assert.match(degraded.stderr, /gh pr list holds 1 of 2 open pull requests/);
247+
assert.match(degraded.stderr, /the listing holds 1 of 2 open pull requests/);
237248
assert.match(degraded.output, /^held-reason=failed 3 times \(count mismatch\)$/m);
238249
const next = runListing(0, undefined, undefined, {}, undefined, LANES_PR, 1);
239250
assert.equal(next.status, 0, next.stderr);
@@ -254,13 +265,43 @@ test("the hold names only the last try's fault", () => {
254265
});
255266

256267
test("a repeated pull request does not stand in for a missing one", () => {
257-
assertHeld(runListing(0, undefined, undefined, {}, undefined, [listed(7, "app/melodic-automation-lanes"), listed(7, "app/melodic-automation-lanes")], 2));
268+
assertHeld(runListing(0, undefined, undefined, {}, undefined, [listed(7, LANES), listed(7, LANES)], 2));
258269
});
259270

260-
test("a listing whose open count cannot be read holds the job", () => {
271+
test("a page with no open count holds the job", () => {
261272
assertHeld(runListing(0, undefined, undefined, {}, undefined, LANES_PR, null));
262273
});
263274

275+
// Each try fails, so each holds after three tries of page 1 (and page 2).
276+
const lanes150 = Array.from({ length: 150 }, (_, i) => listed(i + 1, LANES));
277+
test("an open count that moves between pages holds the job", () => {
278+
const run = runListing(0, undefined, undefined, {}, undefined, lanes150, 150, [], (page, p) => {
279+
if (p === 1) page.data.repository.pullRequests.totalCount = 151;
280+
return page;
281+
});
282+
assertHeld(run);
283+
assert.equal(run.calls, 6);
284+
assert.match(run.stderr, /the open count moved from 150 to 151 while listing/);
285+
assert.match(run.output, /^held-reason=failed 3 times \(count mismatch\)$/m);
286+
});
287+
288+
test("a 200 that carries GraphQL errors holds the job", () => {
289+
const run = runListing(0, undefined, undefined, {}, undefined, LANES_PR, 1, [], (page) => ({ ...page, errors: [{ message: "x" }] }));
290+
assertHeld(run);
291+
assert.equal(run.calls, 3);
292+
assert.match(run.output, /^held-reason=failed 3 times$/m);
293+
});
294+
295+
test("a next page with no cursor holds the job", () => {
296+
const run = runListing(0, undefined, undefined, {}, undefined, lanes150, 150, [], (page, p) => {
297+
if (p === 0) page.data.repository.pullRequests.pageInfo.endCursor = null;
298+
return page;
299+
});
300+
assertHeld(run);
301+
assert.equal(run.calls, 3);
302+
assert.match(run.output, /^held-reason=failed 3 times$/m);
303+
});
304+
264305
// A step's `if:` as GitHub evaluates it on the schedule, with `steps` and
265306
// `needs` as given. No `if:` runs it. Takes a step block, since the credential
266307
// scans share one name.
@@ -322,32 +363,42 @@ test("no step after the listing acts on a held listing", () => {
322363

323364
// GitHub Support's audit item 7: one listing of every open pull request into
324365
// main, filtered by author, in place of one `gh pr list --author` (a search
325-
// call) per author.
366+
// call) per author. Trusted actors match by numeric id, never by login.
326367
const AUTHORED = [
327-
listed(1, "app/melodic-automation-lanes"),
328-
listed(2, "a-person"),
329-
listed(3, "app/some-release"),
330-
listed(4, "app/dependabot"),
331-
listed(5, "a-stranger"),
332-
listed(6, "app/melodic-automation-lanes", true),
368+
listed(1, LANES),
369+
listed(2, user("a-person", 1)),
370+
listed(3, bot("some-release", 2)),
371+
listed(4, bot("dependabot", 49699333)),
372+
listed(5, user("a-stranger", 99)),
373+
listed(6, LANES, true),
374+
// A trusted App renamed since trusted-actors.json was written: its id holds.
375+
listed(7, bot("renamed-release", 2)),
376+
// A trusted login under an id the list does not hold.
377+
listed(8, user("a-person", 77)),
378+
listed(9, bot("some-release", 55)),
379+
// No id: a deleted account and a mannequin.
380+
listed(10, null),
381+
listed(11, { __typename: "Mannequin", login: "a-person" }),
382+
listed(12, user("a-shape", 5)),
333383
];
334384

335385
// Owner decision 2026-10-22: every trusted actor's PR is a candidate.
336-
test("the listing keeps each trusted actor's pull requests, a person by login and an App as app/<slug>, from one list", () => {
386+
test("the listing keeps each trusted actor's pull requests by id, a renamed one included, from one list", () => {
337387
const actors = [
338388
{ id: 1, login: "a-person", kind: "human" },
339389
{ id: 2, login: "some-release[bot]", kind: "bot" },
340-
{ id: 3, login: "melodic-automation-lanes[bot]", kind: "bot" },
341-
{ id: 4, login: "dependabot[bot]", kind: "bot" },
342-
{ id: 5, login: "bad login; rm", kind: "human" },
390+
{ id: 337595936, login: "melodic-automation-lanes[bot]", kind: "bot" },
391+
{ id: 49699333, login: "dependabot[bot]", kind: "bot" },
392+
{ id: "5", login: "a-shape", kind: "human" },
343393
];
344394
const run = runListing(0, (config) => config, actors, {}, undefined, AUTHORED);
345395
assert.equal(run.status, 0, run.stderr);
346396
assert.equal(run.calls, 1);
347397
assert.doesNotMatch(run.args, /--author/);
348-
assert.deepEqual(run.listed, [1, 2, 3]);
398+
// Dependabot's id is listed, but merge.dependabot.mode off still drops it.
399+
assert.deepEqual(run.listed, [1, 2, 3, 7]);
349400
assert.deepEqual(run.draftsListed, [6]);
350-
assert.doesNotMatch(run.args, /^api /m);
401+
assert.match(run.args, /^api -i graphql /m);
351402
});
352403

353404
test("without an adoption section no trusted actor is listed", () => {
@@ -361,11 +412,12 @@ test("without an adoption section no trusted actor is listed", () => {
361412
});
362413

363414
// merge.lane-prs: native leaves the lanes App's pull requests to GitHub's
364-
// auto-merge: the listing drops them, so the gate never reads them.
415+
// auto-merge: the listing drops them, so the gate never reads them, even with
416+
// the lanes App's id on the trusted-actor list.
365417
test("under lane-prs native the listing skips the lanes App and keeps every other author", () => {
366418
const actors = [
367419
{ id: 1, login: "a-person", kind: "human" },
368-
{ id: 3, login: "melodic-automation-lanes[bot]", kind: "bot" },
420+
{ id: 337595936, login: "melodic-automation-lanes[bot]", kind: "bot" },
369421
];
370422
const native = runListing(0, (config) => config, actors, { LANE_PRS: "native", DEPENDABOT: "enforce" }, undefined, AUTHORED);
371423
assert.equal(native.status, 0, native.stderr);
@@ -401,32 +453,33 @@ test("an event run lists only its own pull request", () => {
401453
assert.match(step("List the candidate PRs"), /\n {10}EVENT_PR: \$\{\{ github\.event\.pull_request\.number \}\}\n/);
402454
});
403455

404-
// gh pr list's --limit is 1000: a listing that long may be cut short whatever
405-
// the count says, so it holds after one call; one short of it still lists.
406-
const lanePrs = (n) => Array.from({ length: n }, (_, i) => listed(i + 1, "app/melodic-automation-lanes"));
407-
test("a listing that reaches the limit holds the job green after one call, never retried", () => {
408-
for (const total of [1000, 1500]) {
409-
const run = runListing(0, undefined, undefined, {}, undefined, lanePrs(1000), total);
456+
// The listing reads at most 10 pages of 100: a list with an 11th page is cut
457+
// short, so it holds after those 10 calls; 1000 still lists.
458+
const lanePrs = (n) => Array.from({ length: n }, (_, i) => listed(i + 1, LANES));
459+
test("a listing past the page cap holds the job green after ten calls, never retried", () => {
460+
for (const total of [1001, 1500]) {
461+
const run = runListing(0, undefined, undefined, {}, undefined, lanePrs(total), total);
410462
assertHeld(run);
411-
assert.equal(run.calls, 1);
463+
assert.equal(run.calls, 10);
412464
assert.deepEqual(run.sleeps, []);
413465
assert.doesNotMatch(run.stdout, /^::error/m);
414-
assert.match(run.output, /^held-reason=listing full: gh pr list returned the limit, so it may be cut short$/m);
466+
assert.match(run.output, /^held-reason=listing full: more than 1000 open pull requests, so it is cut short$/m);
415467
}
416468
// The hold and its reason reach the sweep summary, whose listing_held
417469
// monitor signal 12 counts.
418470
assert.match(step("Count the sweep's refusals"), /\n {10}LISTING_HELD: \$\{\{ steps\.candidates\.outputs\.held \}\}\n {10}LISTING_HELD_REASON: \$\{\{ steps\.candidates\.outputs\.held-reason \}\}\n/);
419471
});
420472

421-
test("a complete listing one short of the limit still lists every candidate", () => {
422-
const run = runListing(0, undefined, undefined, {}, undefined, lanePrs(999), 999);
473+
test("a complete listing at the page cap still lists every candidate", () => {
474+
const run = runListing(0, undefined, undefined, {}, undefined, lanePrs(1000), 1000);
423475
assert.equal(run.status, 0, run.stderr);
424-
assert.equal(run.calls, 1);
476+
assert.equal(run.calls, 10);
477+
assert.equal((run.args.match(/after=p\d+/g) ?? []).length, 9);
425478
assert.doesNotMatch(run.stdout, /Merge lane hold/);
426479
assert.doesNotMatch(run.output, /held/);
427480
assert.match(run.output, /^listed=true$/m);
428-
assert.match(run.output, /^count=999$/m);
429-
assert.equal(run.listed.length, 999);
481+
assert.match(run.output, /^count=1000$/m);
482+
assert.equal(run.listed.length, 1000);
430483
});
431484

432485
test("a held listing files no failed lane merge; a run that listed goes by its own check", () => {

0 commit comments

Comments
 (0)