Skip to content

Commit 6c84eb2

Browse files
committed
fix(github): the PR limits sweep caps its last looks before a close
A last look that finds mergeability not yet known closes nothing, so those looks did not count toward the close cap and could run once per labeled PR. They now stop at 200 a run. The read retry also requires a numeric status.
1 parent 3896cc3 commit 6c84eb2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎.github/scripts/pr-limits.cjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const NOTICE_MS = 72 * HOUR_MS;
88
// limit on how fast a token may comment.
99
const MAX_REQUESTS_PER_RUN = 100;
1010
const MAX_CLOSES_PER_RUN = 50;
11+
// A last look that ends in "not today" closes nothing, so the looks need a cap of their own.
12+
const MAX_RECHECKS_PER_RUN = 200;
1113
const WRITE_PAUSE_MS = 1_000;
1214
// Measured here: about two and a half minutes until every open PR has an answer.
1315
const MERGEABLE_WAIT_MS = 150_000;
@@ -74,7 +76,8 @@ async function read(github, query, variables) {
7476
try {
7577
return await github.graphql(query, variables);
7678
} catch (error) {
77-
if (attempt === READ_ATTEMPTS || !(error.status >= 500)) throw error;
79+
const transient = typeof error.status === "number" && error.status >= 500;
80+
if (attempt === READ_ATTEMPTS || !transient) throw error;
7881
await pause(attempt * READ_RETRY_MS);
7982
}
8083
}
@@ -184,6 +187,7 @@ async function sweep({ github, context, core, dryRun }) {
184187

185188
const now = Date.now();
186189
const count = {};
190+
let rechecks = 0;
187191
for (const pr of prs) {
188192
const { number } = pr;
189193
let action = decide(pr, exemptions, now);
@@ -197,6 +201,8 @@ async function sweep({ github, context, core, dryRun }) {
197201
if ((count["close-conflict"] ?? 0) + (count["close-notice"] ?? 0) >= MAX_CLOSES_PER_RUN) {
198202
continue;
199203
}
204+
if (rechecks >= MAX_RECHECKS_PER_RUN) continue;
205+
rechecks += 1;
200206
// The list is minutes old by now. Closing is the one step worth a second look.
201207
const fresh = (await read(github, RECHECK_QUERY, { ...repo, number })).repository.pullRequest;
202208
if (fresh.state !== "OPEN") continue;

0 commit comments

Comments
 (0)