Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 57 additions & 10 deletions .github/workflows/label-pr-review-state-fork-review-followup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,51 @@ permissions:
actions: write
pull-requests: read

# Each completed run gets its own group: one run can resolve several PRs, and
# a shared key would let an unrelated completion supersede queued dispatches.
# Coalesce by target, not by triggering run (2026-11-18 storm: this workflow
# started 243 runs in 78 minutes and dispatched 73 of them). Keying per
# triggering run id gave every completion its own group, so nothing ever
# coalesced: the six required checks of one PR all completing at the same head
# meant six queued dispatches of the same work. GitHub keeps at most one
# running plus one pending run per group, so keying the group by the target the
# completed run evaluated collapses a burst into a single dispatch of the
# freshest state: first by the PR number GitHub associates with the run, then,
# for fork runs whose pull_requests GitHub leaves empty (issue #2133), by the
# branch identity the resolver below actually matches on.
#
# The fork fallback must include the branch, not just the head SHA. Two fork PRs
# can carry the same commit on different branches (a cherry-picked stack does
# exactly that), and the resolver distinguishes them only by head branch: a
# SHA-only key would put both PRs in one group, so a pending run for the second
# branch would be superseded by a later completion for the first and its
# reconciliation would never dispatch. head_branch, together with the head
# repository owner it belongs to, is the resolver's branch identity, so two
# branches never share a group. Two distinct branches carrying the same commit
# do not coalesce, which is the intended correction: they are different PR
# targets. Repeated completions for one target share branch and SHA and still
# coalesce.
#
# GitHub compares group names case-insensitively, so two branches that differ
# only by letter case - feature/a and feature/A, which two forks can hold at
# the same commit - do share a group. That is accepted instead of fought: the
# resolver below compares head branches case-insensitively as well, so
# whichever run survives reconciles every PR the group stands for rather than
# only the one whose spelling happened to arrive first.
#
# cancel-in-progress stays false: a running dispatch must finish every PR it
# resolved, so only pending duplicates are dropped. The run id is the last
# fallback so a payload with neither an associated PR nor a head branch and SHA
# keeps a unique group instead of every such run colliding on one key.
concurrency:
group: label-pr-review-state-fork-review-followup-${{ github.event.workflow_run.id }}
group: >-
label-pr-review-state-fork-review-followup-${{
github.event.workflow_run.pull_requests[0].number ||
((github.event.workflow_run.head_branch && github.event.workflow_run.head_sha) &&
format('{0}:{1}@{2}',
github.event.workflow_run.head_repository.owner.login || 'unknown',
github.event.workflow_run.head_branch,
github.event.workflow_run.head_sha)) ||
github.event.workflow_run.id
}}
cancel-in-progress: false

jobs:
Expand Down Expand Up @@ -63,11 +104,17 @@ jobs:
// Resolve which PRs the completed run targeted. Review runs
// backfill pull_requests empty for fork PRs, and the head
// owner is not recoverable from head_repository, so the
// fallback lists open PRs and matches the exact head branch,
// SHA, and base repository. The workflow_run branch of
// label-pr-review-state.yml keeps an owner-and-branch query
// instead: its runs are CI runs triggered by pull_request,
// whose head_repository is the real fork.
// fallback lists open PRs and matches the head branch
// case-insensitively, the head SHA, and the base repository.
// Group names are compared case-insensitively above, so a
// case-sensitive match here would let the run that survived the
// shared group reconcile only its own branch's PR and drop the
// other target - the failure the key exists to avoid. GitHub's
// own identity comparisons (usernames, the base repository
// below) are case-insensitive too.
// The workflow_run branch of label-pr-review-state.yml keeps an
// owner-and-branch query instead: its runs are CI runs triggered
// by pull_request, whose head_repository is the real fork.
let prNumbers = [];
if (run.pull_requests?.length > 0) {
prNumbers = run.pull_requests.map(pr => pr.number);
Expand All @@ -82,13 +129,13 @@ jobs:
prNumbers = candidates
.filter(pr =>
pr.head?.sha === run.head_sha &&
pr.head?.ref === run.head_branch &&
pr.head?.ref?.toLowerCase() === run.head_branch?.toLowerCase() &&
pr.base?.repo?.full_name?.toLowerCase() === baseRepository
)
.map(pr => pr.number);
core.info(
`Resolved workflow_run ${run.id ?? '(unknown)'} to ` +
`${prNumbers.length} PR(s) by exact head branch, SHA, and base repository`
`${prNumbers.length} PR(s) by case-insensitive head branch, SHA, and base repository`
);
}

Expand Down
35 changes: 32 additions & 3 deletions .github/workflows/label-pr-review-state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ on:
# writes (issue #2046). The privileged follow-up for those runs lives in
# label-pr-review-state-fork-review-followup.yml: GitHub rejects a workflow
# that lists itself in workflow_run.workflows (issue #2086).
#
# A workflow belongs in this list only when its completion can change the
# answer for a required status check, because the reconcile below reads
# only the required checks from the branch ruleset and never inspects which
# workflow completed, its conclusion, or its outputs. "Code QA Roo Code"
# publishes check-translations, compile, knip and both platform-unit-test
# rows; "E2E Tests (Mocked)" publishes e2e-mock. Those six are the entire
# required set on main, so no completion of any other workflow can change a
# label this workflow writes.
#
# "Webview Visual Regression" was in this list but no workflow has that
# display name: the visual workflow is "Visual Regression"
# (visual-regression.yml), so the entry never matched anything and only
# looked like coverage. "CodeQL Advanced" does run, but it publishes none of
# the six required checks, so each of its completions started a full
# reconciliation that could only recompute the labels already written.
workflow_run:
workflows: ["Code QA Roo Code", "E2E Tests (Mocked)", "Webview Visual Regression", "CodeQL Advanced"]
workflows: ["Code QA Roo Code", "E2E Tests (Mocked)"]
types: [completed]

permissions:
Expand Down Expand Up @@ -94,9 +110,22 @@ concurrency:
jobs:
resolve:
name: Zoo Code / resolve PRs to reconcile
# Loop guard (self-triggered label writes): the reconciliation writes the
# labels it also listens for, so every mutating run used to start one
# more run through the labeled/unlabeled pull_request_target events it
# caused itself. Reconciliation is idempotent, so a run woken only by
# this workflow's own label write would recompute the state it just
# wrote and write it again; skipping it breaks that loop. Only label
# events authored by github-actions[bot] for a label this workflow
# manages are skipped: a human edit to one of those labels, and any
# other bot or workflow label write, still reconciles.
if: >-
github.event_name != 'issue_comment' ||
(github.event.issue.pull_request && github.event.comment.user.login == 'coderabbitai[bot]')
(github.event_name != 'issue_comment' ||
(github.event.issue.pull_request && github.event.comment.user.login == 'coderabbitai[bot]')) &&
!(github.event_name == 'pull_request_target' &&
contains(fromJSON('["labeled", "unlabeled"]'), github.event.action) &&
github.event.sender.login == 'github-actions[bot]' &&
contains(fromJSON('["awaiting-author", "awaiting-coderabbit", "awaiting-ready", "awaiting-maintainer", "awaiting-review", "coderabbit-review-active", "community-approved", "has-conflicts", "stale-inactive", "stale-awaiting-author"]'), github.event.label.name))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
runs-on: ubuntu-latest
outputs:
pr_numbers: ${{ steps.resolve.outputs.pr_numbers }}
Expand Down
26 changes: 24 additions & 2 deletions src/services/__tests__/fork-review-followup-workflow.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading