Skip to content

Commit 266f6c3

Browse files
committed
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 d0b6beb commit 266f6c3

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
@@ -80,6 +80,20 @@ jobs:
8080
runs-on: ubuntu-latest
8181
outputs:
8282
pr_numbers: ${{ steps.resolve.outputs.pr_numbers }}
83+
env:
84+
# Mirrors the workflow-level concurrency group so the run's queueing
85+
# identity is visible in the logs (kept in sync by the workflow tests).
86+
CONCURRENCY_GROUP: >-
87+
label-pr-review-state-${{
88+
((github.event_name == 'pull_request_review' &&
89+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) ||
90+
github.event.pull_request.number ||
91+
github.event.issue.number ||
92+
github.event.inputs.pull_request_number ||
93+
github.event.workflow_run.id ||
94+
((github.event_name == 'schedule' || github.event_name == 'push') && 'sweep') ||
95+
github.run_id
96+
}}
8397
steps:
8498
- name: Resolve target PR numbers
8599
id: resolve
@@ -89,6 +103,9 @@ jobs:
89103
script: |
90104
const { owner, repo } = context.repo;
91105
106+
// A queue-superseded run leaves no other trace in the logs.
107+
core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`);
108+
92109
if (context.eventName === 'issue_comment' &&
93110
(!context.payload.issue?.pull_request ||
94111
context.payload.comment?.user?.login?.toLowerCase() !== 'coderabbitai[bot]')) {
@@ -138,7 +155,21 @@ jobs:
138155
const openPrs = await github.paginate(github.rest.pulls.list, {
139156
owner, repo, state: 'open', per_page: 100,
140157
});
141-
prNumbers = openPrs.map(pr => pr.number);
158+
// GitHub rejects matrices over 256 jobs, so the sweep pages the
159+
// sorted open-PR list: consecutive runs rotate through
160+
// fixed-size windows by run number, covering every open PR on a
161+
// bounded cadence without ever exceeding the limit.
162+
const allNumbers = openPrs.map(pr => pr.number).sort((a, b) => a - b);
163+
const sweepPageSize = 200;
164+
const pageCount = Math.max(1, Math.ceil(allNumbers.length / sweepPageSize));
165+
const page = context.runNumber % pageCount;
166+
prNumbers = allNumbers.slice(page * sweepPageSize, (page + 1) * sweepPageSize);
167+
if (allNumbers.length > sweepPageSize) {
168+
core.info(
169+
`Sweep page ${page + 1}/${pageCount}: reconciling ` +
170+
`${prNumbers.length} of ${allNumbers.length} open PRs`
171+
);
172+
}
142173
}
143174
144175
core.info(
@@ -188,13 +219,28 @@ jobs:
188219
runs-on: ubuntu-latest
189220
env:
190221
PR_NUMBER: ${{ matrix.pr_number }}
222+
# Mirrors this job's concurrency group so a superseded shard's queueing
223+
# identity is visible in the logs (kept in sync by the workflow tests).
224+
CONCURRENCY_GROUP: >-
225+
label-pr-review-state-reconcile-${{
226+
((github.event_name == 'pull_request_review' &&
227+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && 'ro-') || ''
228+
}}${{
229+
((github.event_name == 'pull_request_review' &&
230+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) ||
231+
matrix.pr_number ||
232+
github.run_id
233+
}}
191234
steps:
192235
- name: Reconcile PR review state labels
193236
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
194237
with:
195238
retries: 3
196239
script: |
197240
const { owner, repo } = context.repo;
241+
242+
// A queue-superseded shard leaves no other trace in the logs.
243+
core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`);
198244
const stateLabels = [
199245
'awaiting-author',
200246
'awaiting-coderabbit',
@@ -265,17 +311,26 @@ jobs:
265311
}
266312
267313
if (!isReadOnlyRun) {
314+
// One paginated list keeps the per-shard API budget flat no matter
315+
// how many labels are managed; per-label getLabel calls would
316+
// multiply across a full sweep against the Actions token pool.
317+
const repoLabels = await github.paginate(github.rest.issues.listLabelsForRepo, {
318+
owner, repo, per_page: 100,
319+
});
320+
const existingLabelNames = new Set(repoLabels.map(label => label.name));
268321
for (const label of labelDefinitions) {
322+
if (existingLabelNames.has(label.name)) continue;
269323
try {
270-
await github.rest.issues.getLabel({ owner, repo, name: label.name });
271-
} catch (error) {
272-
if (error.status !== 404) throw error;
273-
try {
274-
await github.rest.issues.createLabel({ owner, repo, ...label });
275-
} catch (createError) {
276-
// Concurrent shards for other PRs can win the creation race.
277-
if (createError.status !== 422) throw createError;
278-
}
324+
await github.rest.issues.createLabel({ owner, repo, ...label });
325+
} catch (createError) {
326+
// Concurrent shards for other PRs can win the creation race.
327+
// Tolerate only the duplicate-label payload; any other 422
328+
// must fail the shard.
329+
const isDuplicateRace = createError.status === 422 &&
330+
(createError.response?.data?.errors ?? []).some(
331+
error => error.code === 'already_exists' && error.field === 'name'
332+
);
333+
if (!isDuplicateRace) throw createError;
279334
}
280335
}
281336
}
@@ -834,8 +889,10 @@ jobs:
834889
if (!blocker) continue;
835890
const requestedAt = Date.parse(event.created_at ?? '');
836891
const blockedAt = Date.parse(blocker.submitted_at ?? '');
837-
// A re-request only clears blockers it follows; missing or
838-
// unparsable timestamps fail closed and keep the blocker.
892+
// A re-request clears a blocker only when it was created
893+
// at the same time as or after the blocking review;
894+
// missing or unparsable timestamps fail closed and keep
895+
// the blocker.
839896
if (!Number.isNaN(requestedAt) && !Number.isNaN(blockedAt) && requestedAt >= blockedAt) {
840897
maintainerBlockers.delete(requested);
841898
}

0 commit comments

Comments
 (0)