From 9e2a53a16ab57a16aff29b75a525383cdf7d3501 Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:20:26 +0800 Subject: [PATCH 1/5] ci(label-review-state): stop reconcile workflow self-amplification Measured on 2026-11-18 between 01:00Z and 02:18Z: this repo created 678 Actions runs; 243 were runs of the fork review follow-up and 126 parent reconcile runs came from issue_comment, while each real PR CI workflow ran 6 times. Three changes, both only in these two workflow files: 1. Reconcile no longer runs when the event is only its own label write. The reconciliation writes the labels it listens for, so each mutating run started one more run through the labeled/unlabeled pull_request_target events it caused itself. The guard skips a labeled/unlabeled event only when github-actions[bot] authored it and the label is one this workflow manages; human edits and other bots still reconcile. 2. The fork review follow-up coalesces per PR (or per head SHA for fork runs whose pull_requests GitHub leaves empty) instead of per triggering run. Keying by workflow_run.id gave every completion its own group, so nothing coalesced and a burst of six required checks completing for one PR queued six identical dispatches. 3. workflow_run is trimmed to the two workflows whose completion can change a required status check: Code QA Roo Code (check-translations, compile, knip, both platform-unit-test rows) and E2E Tests (Mocked) (e2e-mock). Webview Visual Regression never matched any workflow (the display name is Visual Regression), and CodeQL Advanced publishes none of the six required checks. --- ...l-pr-review-state-fork-review-followup.yml | 20 +++++++++-- .github/workflows/label-pr-review-state.yml | 35 +++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/.github/workflows/label-pr-review-state-fork-review-followup.yml b/.github/workflows/label-pr-review-state-fork-review-followup.yml index 3bcd55dc210..391de46d08a 100644 --- a/.github/workflows/label-pr-review-state-fork-review-followup.yml +++ b/.github/workflows/label-pr-review-state-fork-review-followup.yml @@ -20,10 +20,24 @@ 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 by the PR the completed run +# evaluated (or, for fork runs whose pull_requests GitHub leaves empty, by the +# head SHA, which resolves to the same PR set) collapses a burst into a single +# dispatch of the freshest state. Two PRs never share a PR number, and two +# distinct commits never share a head SHA, so an unrelated PR still keeps its +# own group and its queued dispatch is never superseded. cancel-in-progress +# stays false: a running dispatch must finish every PR it resolved. The run id +# stays as the fallback so a payload with neither a PR number nor a head 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_sha || github.event.workflow_run.id }} cancel-in-progress: false jobs: diff --git a/.github/workflows/label-pr-review-state.yml b/.github/workflows/label-pr-review-state.yml index 459dcf50bd4..1d8adbd220a 100644 --- a/.github/workflows/label-pr-review-state.yml +++ b/.github/workflows/label-pr-review-state.yml @@ -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: @@ -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)) runs-on: ubuntu-latest outputs: pr_numbers: ${{ steps.resolve.outputs.pr_numbers }} From f78cf4379052223acf6d7af86001b58fe72967a0 Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:05:56 +0800 Subject: [PATCH 2/5] fix(ci): key the fork review follow-up by branch identity and test the resolve guard CodeRabbit 4608868348: the fork fallback keyed on head_sha alone, but two fork PRs can carry the same commit on different branches (a cherry-picked stack), and the resolver distinguishes them by head branch. A later completion for one branch could then supersede the other branch's pending run, losing that PR's dispatch. The key now uses the resolver's branch identity - head repository owner plus head branch plus head SHA - after the associated PR number, so branches never share a group and repeated completions for one target still coalesce. The file comment no longer claims that distinct commits never share a SHA as the reason branches cannot collide; it states the branch is part of the key and that two branches carrying the same commit intentionally do not coalesce. CodeRabbit 4608868359: the workflow harness executed the embedded scripts but never evaluated jobs.resolve.if, so the new label guard had no coverage. The expression evaluator now supports unary negation, contains, fromJSON and format, and two new describes evaluate the real YAML: 8 tests for the resolve guard (labeled and unlabeled, managed and unrelated labels, github-actions[bot] versus human and other bot senders, events with no label field, plus the issue_comment and other-trigger regressions and a drift guard on both fromJSON lists) and 5 tests for the follow-up key (same commit on two branches, coalescing, PR-number preference, run-id fallback). Negative controls: removing one managed label from the guard fails 2 tests; restoring the SHA-only key fails the branch test. --- ...l-pr-review-state-fork-review-followup.yml | 40 ++- .../pr-review-state-workflow.test.ts | 280 +++++++++++++++++- 2 files changed, 308 insertions(+), 12 deletions(-) diff --git a/.github/workflows/label-pr-review-state-fork-review-followup.yml b/.github/workflows/label-pr-review-state-fork-review-followup.yml index 391de46d08a..e3f7235ddb1 100644 --- a/.github/workflows/label-pr-review-state-fork-review-followup.yml +++ b/.github/workflows/label-pr-review-state-fork-review-followup.yml @@ -25,19 +25,39 @@ permissions: # 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 by the PR the completed run -# evaluated (or, for fork runs whose pull_requests GitHub leaves empty, by the -# head SHA, which resolves to the same PR set) collapses a burst into a single -# dispatch of the freshest state. Two PRs never share a PR number, and two -# distinct commits never share a head SHA, so an unrelated PR still keeps its -# own group and its queued dispatch is never superseded. cancel-in-progress -# stays false: a running dispatch must finish every PR it resolved. The run id -# stays as the fallback so a payload with neither a PR number nor a head SHA +# 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. +# +# 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.pull_requests[0].number - || github.event.workflow_run.head_sha || github.event.workflow_run.id }} + 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: diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index af8ad70f3d0..a64db6fc141 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -10,6 +10,12 @@ const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)) const workflow = parse( fs.readFileSync(path.join(repositoryRoot, ".github/workflows/label-pr-review-state.yml"), "utf8"), ) +const forkReviewFollowupWorkflow = parse( + fs.readFileSync( + path.join(repositoryRoot, ".github/workflows/label-pr-review-state-fork-review-followup.yml"), + "utf8", + ), +) const codeRabbitConfig = parse(fs.readFileSync(path.join(repositoryRoot, ".coderabbit.yaml"), "utf8")) const workflowScript = workflow.jobs.reconcile.steps[0].with.script as string const resolveScript = workflow.jobs.resolve.steps[0].with.script as string @@ -3581,9 +3587,19 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { head?: { repo?: { full_name?: string } | null } base?: { repo?: { full_name?: string } | null } } - issue?: { number: number } - workflow_run?: { id?: number; pull_requests?: Array<{ number: number }> } + issue?: { number: number; pull_request?: unknown } + workflow_run?: { + id?: number + pull_requests?: Array<{ number: number }> + head_branch?: string | null + head_sha?: string | null + head_repository?: { owner?: { login?: string } | null } | null + } inputs?: { pull_request_number: number } + action?: string + label?: { name?: string } | null + sender?: { login?: string } | null + comment?: { user?: { login?: string } | null } | null } } @@ -3633,6 +3649,57 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { return left === right } + /** + * Splits a function call's argument source on top-level commas. Strings are + * skipped so a JSON array literal inside fromJSON stays one argument. + */ + function splitArguments(source: string): string[] { + const args: string[] = [] + let depth = 0 + let inString = false + let start = 0 + for (let index = 0; index < source.length; index++) { + const char = source[index] + if (char === "'") { + inString = !inString + } else if (!inString && char === "(") { + depth++ + } else if (!inString && char === ")") { + depth-- + } else if (!inString && depth === 0 && char === ",") { + args.push(source.slice(start, index)) + start = index + 1 + } + } + args.push(source.slice(start)) + return args.map((argument) => argument.trim()).filter((argument) => argument.length > 0) + } + + /** Evaluates the GitHub expression functions the job conditions use. */ + function evaluateFunctionCall(name: string, source: string, roots: ExpressionRoots): unknown { + const args = splitArguments(source).map((argument) => evaluateExpression(argument, roots)) + if (name === "contains") { + const [haystack, needle] = args + if (Array.isArray(haystack)) { + return haystack.some((item) => looseEquals(item, needle)) + } + if (typeof haystack === "string" && typeof needle === "string") { + return haystack.includes(needle) + } + return false + } + if (name === "fromJSON") { + return JSON.parse(String(args[0])) + } + if (name === "format") { + const [template, ...values] = args + return String(template).replace(/\{(\d+)\}/g, (_match, index: string) => + String(values[Number(index)] ?? ""), + ) + } + throw new Error(`Unsupported expression function: ${name}`) + } + function resolvePath(path: string, roots: ExpressionRoots): unknown { let value: unknown = roots for (const segment of path.split(".")) { @@ -3656,6 +3723,10 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { function evaluatePrimary(expression: string, roots: ExpressionRoots): unknown { const current = expression.trim() + // GitHub's unary ! negates loose truthiness, exactly like the && and || chains. + if (current.startsWith("!")) { + return !isTruthy(evaluatePrimary(current.slice(1), roots)) + } if (current.startsWith("(")) { // Strip the parentheses only when the first one wraps the whole expression. let depth = 0 @@ -3682,6 +3753,10 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { if (/^(github|matrix)\./.test(current)) { return resolvePath(current, roots) } + const functionCall = /^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/.exec(current) + if (functionCall) { + return evaluateFunctionCall(functionCall[1], functionCall[2], roots) + } return evaluateExpression(current, roots) } @@ -4144,4 +4219,205 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { "Create label failed", ) }) + + describe("resolve job loop guard on self-triggered label writes", () => { + // Mirrors the labels the reconciliation itself writes. The guard only refuses + // to wake on this workflow's own writes for these labels. + const MANAGED_LABELS = [ + "awaiting-author", + "awaiting-coderabbit", + "awaiting-ready", + "awaiting-maintainer", + "awaiting-review", + "coderabbit-review-active", + "community-approved", + "has-conflicts", + "stale-inactive", + "stale-awaiting-author", + ] + + // GitHub evaluates a job-level if as an expression, without the + // dollar-brace wrapper, so the template evaluator is applied to the raw + // condition. This is the public entry point the harness previously never + // exercised: the embedded scripts were run, the job predicate was not. + function resolveIfFor(github: GithubExpressionContext): boolean { + return isTruthy(evaluateExpression(String(workflow.jobs.resolve.if), { github })) + } + + function labelEvent(options: { action: string; sender: string; labelName?: string }): GithubExpressionContext { + return contextFor({ + event_name: "pull_request_target", + event: { + pull_request: { number: 1664 }, + action: options.action, + sender: { login: options.sender }, + ...(options.labelName === undefined ? {} : { label: { name: options.labelName } }), + }, + }) + } + + it("keeps the guard's actions and label list in sync with the workflow", () => { + // Drift guard: the two fromJSON lists in the condition are the guard's + // whole input vocabulary, so pin them explicitly. + const lists = [...String(workflow.jobs.resolve.if).matchAll(/fromJSON\('(\[[^']*\])'\)/g)].map((match) => + JSON.parse(match[1]), + ) + + expect(lists[0]).toEqual(["labeled", "unlabeled"]) + expect(lists[1]).toEqual(MANAGED_LABELS) + }) + + it("rejects labeled and unlabeled events the reconciliation wrote itself", () => { + for (const action of ["labeled", "unlabeled"]) { + for (const labelName of MANAGED_LABELS) { + expect(resolveIfFor(labelEvent({ action, labelName, sender: "github-actions[bot]" }))).toBe(false) + } + } + }) + + it("accepts those label events when a human or another bot wrote them", () => { + for (const sender of ["edelauna", "MarkSwanson", "coderabbitai[bot]", "codecov[bot]"]) { + for (const action of ["labeled", "unlabeled"]) { + expect(resolveIfFor(labelEvent({ action, labelName: "awaiting-author", sender }))).toBe(true) + } + } + }) + + it("accepts a github-actions label event for a label this workflow does not manage", () => { + for (const labelName of ["dependencies", "bug", "pinned", "do-not-close"]) { + expect(resolveIfFor(labelEvent({ action: "labeled", labelName, sender: "github-actions[bot]" }))).toBe( + true, + ) + } + }) + + it("accepts a labeled event whose payload carries no label name", () => { + // Boundary: an unclassifiable label event must not be rejected, or a + // payload change would silently stop reconciliation. + expect(resolveIfFor(labelEvent({ action: "labeled", sender: "github-actions[bot]" }))).toBe(true) + expect(resolveIfFor(labelEvent({ action: "unlabeled", sender: "github-actions[bot]" }))).toBe(true) + }) + + it("accepts pull_request_target events that carry no label at all", () => { + for (const action of [ + "opened", + "reopened", + "ready_for_review", + "converted_to_draft", + "synchronize", + "review_requested", + "review_request_removed", + ]) { + expect(resolveIfFor(labelEvent({ action, sender: "github-actions[bot]" }))).toBe(true) + } + }) + + it("still gates issue_comment on the CodeRabbit author", () => { + const issueComment = (login: string | null, onPullRequest = true): GithubExpressionContext => + contextFor({ + event_name: "issue_comment", + event: { + issue: { number: 1664, ...(onPullRequest ? { pull_request: {} } : {}) }, + comment: { user: { login } }, + }, + }) + + // GitHub's == is case-insensitive for strings. + expect(resolveIfFor(issueComment("coderabbitai[bot]"))).toBe(true) + expect(resolveIfFor(issueComment("CodeRabbitAI[bot]"))).toBe(true) + expect(resolveIfFor(issueComment("edelauna"))).toBe(false) + expect(resolveIfFor(issueComment("github-actions[bot]"))).toBe(false) + expect(resolveIfFor(issueComment("coderabbitai[bot]", false))).toBe(false) + }) + + it("accepts every other trigger unchanged", () => { + expect(resolveIfFor(contextFor({ event_name: "pull_request_review" }))).toBe(true) + expect( + resolveIfFor( + contextFor({ event_name: "workflow_run", event: { workflow_run: { id: 7, pull_requests: [] } } }), + ), + ).toBe(true) + expect(resolveIfFor(contextFor({ event_name: "schedule" }))).toBe(true) + expect(resolveIfFor(contextFor({ event_name: "push" }))).toBe(true) + expect( + resolveIfFor( + contextFor({ event_name: "workflow_dispatch", event: { inputs: { pull_request_number: 1664 } } }), + ), + ).toBe(true) + }) + }) + + describe("fork review follow-up concurrency key", () => { + // GitHub keeps one running plus one pending run per group, so the group key + // decides which completions coalesce and which may supersede each other. + function followupGroupFor(github: GithubExpressionContext): string { + return evaluateTemplate(String(forkReviewFollowupWorkflow.concurrency.group), { github }) + } + + function forkRun(options: { + branch?: string | null + sha?: string | null + owner?: string | null + associatedPrNumbers?: number[] + runId?: number + }): GithubExpressionContext { + return contextFor({ + event_name: "workflow_run", + run_id: 99000, + event: { + workflow_run: { + id: options.runId ?? 777000111, + pull_requests: (options.associatedPrNumbers ?? []).map((number) => ({ number })), + head_branch: options.branch ?? null, + head_sha: options.sha ?? null, + head_repository: { owner: { login: options.owner ?? "Zoo-Code-Org" } }, + }, + }, + }) + } + + it("keeps cancel-in-progress disabled", () => { + expect(forkReviewFollowupWorkflow.concurrency["cancel-in-progress"]).toBe(false) + }) + + it("keys two branches carrying the same commit to different groups", () => { + // A cherry-picked stack puts one commit on two branches. A SHA-only key + // would put both fork PRs in one group, so a later completion for one + // branch would supersede the other branch's pending dispatch and that + // PR would never be reconciled. + const branchA = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA })) + const branchB = followupGroupFor(forkRun({ branch: "feature/b", sha: SHA })) + + expect(branchA).toContain("feature/a") + expect(branchB).toContain("feature/b") + expect(branchA).not.toBe(branchB) + }) + + it("coalesces repeated completions for the same target onto one group", () => { + const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 1 })) + const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 2 })) + + expect(second).toBe(first) + // A push to the same branch is a new target: its pending dispatch must + // not be cancelled by an older head's queued run. + expect(followupGroupFor(forkRun({ branch: "feature/a", sha: OLD_SHA, runId: 3 }))).not.toBe(first) + }) + + it("prefers the associated PR number over the branch fallback", () => { + const withPr = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, associatedPrNumbers: [1662] })) + expect(withPr).toMatch(/-1662$/) + expect(withPr).not.toContain("feature/a") + expect( + followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, associatedPrNumbers: [1662], runId: 5 })), + ).toBe(withPr) + }) + + it("keeps a unique group when the payload has neither an associated PR nor a branch and SHA", () => { + const missing = followupGroupFor(forkRun({})) + expect(missing).toMatch(/-777000111$/) + expect(followupGroupFor(forkRun({ runId: 777000222 }))).not.toBe(missing) + // Half a pair is not enough: the fallback must not fabricate a target. + expect(followupGroupFor(forkRun({ branch: "feature/a", sha: null }))).toMatch(/-777000111$/) + }) + }) }) From 029ca44990c38c9468cd15a2a71577b6bb8e514c Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:16:25 +0800 Subject: [PATCH 3/5] test(ci): type the issue-comment helper's login as string The compile job's pnpm check-types failed on the new test at the issue_comment helper: the local signature accepted string or null while the payload type declares login as an optional string, so passing null was not assignable. The helper is only called with real logins, so the parameter is now a plain string; behaviour and coverage are unchanged. --- src/services/__tests__/pr-review-state-workflow.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index a64db6fc141..2007ccbf5f9 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -4313,7 +4313,7 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { }) it("still gates issue_comment on the CodeRabbit author", () => { - const issueComment = (login: string | null, onPullRequest = true): GithubExpressionContext => + const issueComment = (login: string, onPullRequest = true): GithubExpressionContext => contextFor({ event_name: "issue_comment", event: { From 571d59af0759fa072d379ea60e52674b0a4148ed Mon Sep 17 00:00:00 2001 From: "user.email" <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:39:27 +0800 Subject: [PATCH 4/5] test(ci): cover the head owner in the follow-up concurrency key CodeRabbit 4609203178: every concurrency test used the default head owner, so dropping head_repository.owner.login from the group expression or mis-wiring its unknown fallback would not have failed a test. Adds three cases: two owners with the same branch and commit must land in different groups and each group must carry its own owner; a payload with no head repository must use the unknown fallback and must not collide with a known owner; and repeated completions with an unknown owner must still coalesce rather than each getting a unique key. forkRun now models an absent head repository with owner: null. Negative control: dropping the owner component from the format expression fails exactly these two owner tests (2 failed, 331 passed) and the file was restored byte-identically (sha256 f906ee9d). --- .../pr-review-state-workflow.test.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index 2007ccbf5f9..920d0441b60 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -4370,7 +4370,9 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { pull_requests: (options.associatedPrNumbers ?? []).map((number) => ({ number })), head_branch: options.branch ?? null, head_sha: options.sha ?? null, - head_repository: { owner: { login: options.owner ?? "Zoo-Code-Org" } }, + // owner: null models a payload with no head repository at all. + head_repository: + options.owner === null ? null : { owner: { login: options.owner ?? "Zoo-Code-Org" } }, }, }, }) @@ -4393,6 +4395,32 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { expect(branchA).not.toBe(branchB) }) + it("includes the head owner in the fallback group", () => { + const upstream = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "Zoo-Code-Org" })) + const contributor = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "contributor" })) + + expect(upstream).toContain("Zoo-Code-Org:feature/a") + expect(contributor).toContain("contributor:feature/a") + expect(contributor).not.toBe(upstream) + }) + + it("uses the unknown owner fallback when the payload carries no head repository", () => { + // Review runs report the base repository as head_repository (issue #2133), so + // this covers the key expression's fallback rather than a production split. + const missingOwner = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null })) + const knownOwner = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "Zoo-Code-Org" })) + + expect(missingOwner).toContain("unknown:feature/a") + expect(missingOwner).not.toBe(knownOwner) + }) + + it("still coalesces repeated completions when the owner is unknown", () => { + const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null, runId: 11 })) + const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: null, runId: 12 })) + + expect(second).toBe(first) + }) + it("coalesces repeated completions for the same target onto one group", () => { const first = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 1 })) const second = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, runId: 2 })) From e06aefb236ba5162df4a7568d255e2c295e564ba Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:49:43 +0800 Subject: [PATCH 5/5] fix(ci): match the fork review follow-up resolver case-insensitively GitHub compares concurrency group names case-insensitively, so two fork PRs that carry one commit on branches whose names differ only by letter case land in the same follow-up group and only one completion survives. The resolver compared head branches case-sensitively, so the run that survived reconciled only its own branch's PR and the other target lost its reconciliation - the very loss the branch-keyed group was added to prevent. The comparison now folds case, as GitHub compares group names and usernames, and the shared group is documented as accepted on purpose rather than overlooked. CodeRabbit thread PRRT_kwDOSK-bwM63Sv5V asked for a case-insensitive comparison of the groups. That test is added in pr-review-state-workflow.test.ts, and fork-review-followup-workflow.test.ts runs the dispatch script itself against two case-variant PRs so the claim is behavioural, not textual. Verified on win32, node v25.9.0, junctioned install from .wt-u917-ci (identical pnpm-lock blob): vitest run --config vitest.workflow.config.ts = 4 files, 335 tests passed (333 before this commit); the two touched specs alone 248/248; reverting only the resolver line fails the new dispatch test 1 failed / 10 passed; prettier --check on all three files exit 0; eslint --max-warnings=0 on both specs exit 0, and neither file has an entry in src/eslint-suppressions.json. --- ...l-pr-review-state-fork-review-followup.yml | 27 ++++++++++++++----- .../fork-review-followup-workflow.test.ts | 26 ++++++++++++++++-- .../pr-review-state-workflow.test.ts | 14 ++++++++++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/.github/workflows/label-pr-review-state-fork-review-followup.yml b/.github/workflows/label-pr-review-state-fork-review-followup.yml index e3f7235ddb1..580bca98a4c 100644 --- a/.github/workflows/label-pr-review-state-fork-review-followup.yml +++ b/.github/workflows/label-pr-review-state-fork-review-followup.yml @@ -43,6 +43,13 @@ permissions: # 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 @@ -97,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); @@ -116,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` ); } diff --git a/src/services/__tests__/fork-review-followup-workflow.test.ts b/src/services/__tests__/fork-review-followup-workflow.test.ts index b681e4d7d9a..7b3f1c3f934 100644 --- a/src/services/__tests__/fork-review-followup-workflow.test.ts +++ b/src/services/__tests__/fork-review-followup-workflow.test.ts @@ -24,7 +24,7 @@ const OLD_SHA = "b".repeat(40) interface HarnessOptions { workflowRunEvent?: string associatedPrNumbers?: number[] - fallback?: "match" | "sha-mismatch" | "ref-mismatch" | "base-mismatch" | "none" + fallback?: "match" | "sha-mismatch" | "ref-mismatch" | "case-variant" | "base-mismatch" | "none" headBranch?: string | null headSha?: string | null failDispatchFor?: number @@ -49,6 +49,12 @@ async function runFollowup(options: HarnessOptions = {}) { if (head !== undefined && head !== `fork-owner:${HEAD_BRANCH}`) return [] if (options.fallback === "match") return [pr] if (options.fallback === "sha-mismatch") return [{ ...pr, head: { ...pr.head, sha: OLD_SHA } }] + if (options.fallback === "case-variant") { + // Two forks can carry one commit on branches whose names differ only by + // letter case, and GitHub's case-insensitive group comparison puts both + // targets in a single concurrency group for this workflow. + return [pr, { ...pr, number: 1663, head: { ...pr.head, ref: HEAD_BRANCH.toUpperCase() } }] + } if (options.fallback === "ref-mismatch") { return [{ ...pr, head: { ...pr.head, ref: "some-other-branch" } }] } @@ -133,7 +139,7 @@ describe("fork review follow-up workflow (#2046, #2086, #2133)", () => { it("dispatches a privileged reconciliation for the fork PR a read-only review run targeted", async () => { // Fork runs backfill pull_requests empty, and head_repository is the // base repository (issue #2133), so the follow-up resolves the PR by - // exact head branch, SHA, and base repository. + // case-insensitive head branch, the head SHA, and the base repository. const result = await runFollowup({ associatedPrNumbers: [], fallback: "match" }) expect(result.listPullRequests).toHaveBeenCalledWith({ @@ -207,6 +213,22 @@ describe("fork review follow-up workflow (#2046, #2086, #2133)", () => { } }) + it("dispatches both PRs when one commit sits on branches differing only by case", async () => { + // GitHub compares this workflow's concurrency group names case-insensitively, so + // `feature/a` and `feature/A` are one group and only one completion survives. + // A case-sensitive resolver would reconcile only the PR whose spelling matched + // the payload and silently drop the other target, which is the very loss the + // branch-keyed group was added to prevent. + const result = await runFollowup({ fallback: "case-variant", headBranch: HEAD_BRANCH }) + + expect(result.listPullRequests).toHaveBeenCalledTimes(1) + expect(result.createWorkflowDispatch).toHaveBeenCalledTimes(2) + expect( + result.createWorkflowDispatch.mock.calls.map(([args]) => args.inputs.pull_request_number).sort(), + ).toEqual(["1662", "1663"]) + expect(result.setFailed).not.toHaveBeenCalled() + }) + it("dispatches nothing when the matching PR targets another base repository", async () => { const result = await runFollowup({ fallback: "base-mismatch" }) diff --git a/src/services/__tests__/pr-review-state-workflow.test.ts b/src/services/__tests__/pr-review-state-workflow.test.ts index 920d0441b60..60722ee1fc6 100644 --- a/src/services/__tests__/pr-review-state-workflow.test.ts +++ b/src/services/__tests__/pr-review-state-workflow.test.ts @@ -4395,6 +4395,20 @@ describe("PR review-state workflow concurrency groups (#1707)", () => { expect(branchA).not.toBe(branchB) }) + it("collapses branches that differ only by case, as GitHub compares group names", () => { + // GitHub's scheduler compares concurrency group names case-insensitively, so + // `feature/a` and `feature/A` are one group no matter how the key is spelled: + // the two strings below differ, and folded to one case they are equal. The + // group being shared is accepted, not fought, because the resolver the key + // points at compares head branches case-insensitively too, so the run that + // survives reconciles both targets rather than the one whose spelling won. + const lower = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA })) + const upper = followupGroupFor(forkRun({ branch: "feature/A", sha: SHA })) + + expect(lower.toLowerCase()).toBe(upper.toLowerCase()) + expect(lower).not.toBe(upper) + }) + it("includes the head owner in the fallback group", () => { const upstream = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "Zoo-Code-Org" })) const contributor = followupGroupFor(forkRun({ branch: "feature/a", sha: SHA, owner: "contributor" }))