Skip to content

Commit 22469cd

Browse files
roomoteedelauna
authored andcommitted
fix(ci): page sweeps, flatten label bootstrap, log concurrency groups
Review follow-ups on the per-PR reconciliation restructure: - Page the sweep's open-PR list (sorted, 200 per window, rotated by run number) so the reconcile matrix never exceeds GitHub's 256-job limit while every open PR is still visited on a bounded hourly cadence; truncation is logged. - Replace per-label getLabel bootstrap calls with one paginated listLabelsForRepo plus a local membership check, keeping the per-shard API budget flat on full sweeps. Tolerate a create 422 only when the payload is the duplicate-label condition (already_exists on name); any other 422 fails the shard. - Log the resolved concurrency group once per job (via env mirrors of the group expressions, drift-pinned by tests) so queue-superseded runs are visible in post-mortems. - Pin the >= blocker-clearing timestamp semantics with an equal-timestamp regression test and align the comment wording. - Add coverage for matrix-suffixed self-referential check names and the resolve-output-to-matrix-to-shard wiring chain. Fixes #1707 Co-authored-by: Roomote <[email protected]>
1 parent 4802f58 commit 22469cd

2 files changed

Lines changed: 243 additions & 32 deletions

File tree

‎.github/workflows/label-pr-review-state.yml‎

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ jobs:
9191
runs-on: ubuntu-latest
9292
outputs:
9393
pr_numbers: ${{ steps.resolve.outputs.pr_numbers }}
94+
env:
95+
# Mirrors the workflow-level concurrency group so the run's queueing
96+
# identity is visible in the logs (kept in sync by the workflow tests).
97+
CONCURRENCY_GROUP: >-
98+
label-pr-review-state-${{
99+
((github.event_name == 'pull_request_review' &&
100+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) ||
101+
github.event.pull_request.number ||
102+
github.event.issue.number ||
103+
github.event.inputs.pull_request_number ||
104+
github.event.workflow_run.id ||
105+
((github.event_name == 'schedule' || github.event_name == 'push') && 'sweep') ||
106+
github.run_id
107+
}}
94108
steps:
95109
- name: Resolve target PR numbers
96110
id: resolve
@@ -100,6 +114,9 @@ jobs:
100114
script: |
101115
const { owner, repo } = context.repo;
102116
117+
// A queue-superseded run leaves no other trace in the logs.
118+
core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`);
119+
103120
if (context.eventName === 'issue_comment' &&
104121
(!context.payload.issue?.pull_request ||
105122
context.payload.comment?.user?.login?.toLowerCase() !== 'coderabbitai[bot]')) {
@@ -149,7 +166,21 @@ jobs:
149166
const openPrs = await github.paginate(github.rest.pulls.list, {
150167
owner, repo, state: 'open', per_page: 100,
151168
});
152-
prNumbers = openPrs.map(pr => pr.number);
169+
// GitHub rejects matrices over 256 jobs, so the sweep pages the
170+
// sorted open-PR list: consecutive runs rotate through
171+
// fixed-size windows by run number, covering every open PR on a
172+
// bounded cadence without ever exceeding the limit.
173+
const allNumbers = openPrs.map(pr => pr.number).sort((a, b) => a - b);
174+
const sweepPageSize = 200;
175+
const pageCount = Math.max(1, Math.ceil(allNumbers.length / sweepPageSize));
176+
const page = context.runNumber % pageCount;
177+
prNumbers = allNumbers.slice(page * sweepPageSize, (page + 1) * sweepPageSize);
178+
if (allNumbers.length > sweepPageSize) {
179+
core.info(
180+
`Sweep page ${page + 1}/${pageCount}: reconciling ` +
181+
`${prNumbers.length} of ${allNumbers.length} open PRs`
182+
);
183+
}
153184
}
154185
155186
core.info(
@@ -199,13 +230,28 @@ jobs:
199230
runs-on: ubuntu-latest
200231
env:
201232
PR_NUMBER: ${{ matrix.pr_number }}
233+
# Mirrors this job's concurrency group so a superseded shard's queueing
234+
# identity is visible in the logs (kept in sync by the workflow tests).
235+
CONCURRENCY_GROUP: >-
236+
label-pr-review-state-reconcile-${{
237+
((github.event_name == 'pull_request_review' &&
238+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && 'ro-') || ''
239+
}}${{
240+
((github.event_name == 'pull_request_review' &&
241+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) ||
242+
matrix.pr_number ||
243+
github.run_id
244+
}}
202245
steps:
203246
- name: Reconcile PR review state labels
204247
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
205248
with:
206249
retries: 3
207250
script: |
208251
const { owner, repo } = context.repo;
252+
253+
// A queue-superseded shard leaves no other trace in the logs.
254+
core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`);
209255
const stateLabels = [
210256
'awaiting-author',
211257
'awaiting-coderabbit',
@@ -284,17 +330,26 @@ jobs:
284330
}
285331
286332
if (!isReadOnlyRun) {
333+
// One paginated list keeps the per-shard API budget flat no matter
334+
// how many labels are managed; per-label getLabel calls would
335+
// multiply across a full sweep against the Actions token pool.
336+
const repoLabels = await github.paginate(github.rest.issues.listLabelsForRepo, {
337+
owner, repo, per_page: 100,
338+
});
339+
const existingLabelNames = new Set(repoLabels.map(label => label.name));
287340
for (const label of labelDefinitions) {
341+
if (existingLabelNames.has(label.name)) continue;
288342
try {
289-
await github.rest.issues.getLabel({ owner, repo, name: label.name });
290-
} catch (error) {
291-
if (error.status !== 404) throw error;
292-
try {
293-
await github.rest.issues.createLabel({ owner, repo, ...label });
294-
} catch (createError) {
295-
// Concurrent shards for other PRs can win the creation race.
296-
if (createError.status !== 422) throw createError;
297-
}
343+
await github.rest.issues.createLabel({ owner, repo, ...label });
344+
} catch (createError) {
345+
// Concurrent shards for other PRs can win the creation race.
346+
// Tolerate only the duplicate-label payload; any other 422
347+
// must fail the shard.
348+
const isDuplicateRace = createError.status === 422 &&
349+
(createError.response?.data?.errors ?? []).some(
350+
error => error.code === 'already_exists' && error.field === 'name'
351+
);
352+
if (!isDuplicateRace) throw createError;
298353
}
299354
}
300355
}
@@ -904,8 +959,10 @@ jobs:
904959
if (!blocker) continue;
905960
const requestedAt = Date.parse(event.created_at ?? '');
906961
const blockedAt = Date.parse(blocker.submitted_at ?? '');
907-
// A re-request only clears blockers it follows; missing or
908-
// unparsable timestamps fail closed and keep the blocker.
962+
// A re-request clears a blocker only when it was created
963+
// at the same time as or after the blocking review;
964+
// missing or unparsable timestamps fail closed and keep
965+
// the blocker.
909966
if (!Number.isNaN(requestedAt) && !Number.isNaN(blockedAt) && requestedAt >= blockedAt) {
910967
maintainerBlockers.delete(requested);
911968
}

0 commit comments

Comments
 (0)