From 465ba237d8a24fb0e9c55bd23f8f2a09f8cfef4e Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 2 Nov 2026 14:23:39 -0500 Subject: [PATCH 1/5] perf(ci): skip a main-run review of a head both lanes already reviewed pr-review-main ran both model reviews on every pr-require-checks completion at a lane-source head, re-runs and label or body edits included. The trigger job now reads each lane's verdict artifacts, their runs and the head's record check runs, and sets judged=true only when babysit_review_evidence._main_bound binds both lanes there; the gate and both legs then skip. A failed or cancelled review, another head of the same tree, or a failed read reviews again, so the verdict binding is unchanged. No leg or record job starts for a pull request with no lane source either. Refs: #12448 Co-Authored-By: Claude Opus 5.5 --- ...skip-repeat-workflow-run-wakes-64b6cc4d.md | 7 + .../scripts/pr-review-main/workflow.test.mjs | 135 +++++++++++++++++- .github/workflows/pr-review-main.yml | 92 +++++++++++- docs/conventions/pr-pipeline/README.md | 7 +- 4 files changed, 229 insertions(+), 12 deletions(-) create mode 100644 .changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md diff --git a/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md b/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md new file mode 100644 index 00000000000..b341f6f79ca --- /dev/null +++ b/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Changed + +- The main-run review (`pr-review-main.yml`) no longer reviews a head again when both lanes already have a verdict the merge gate binds there: pr-require-checks completes several times on one head, and each completion started both model reviews. The trigger job reads each lane's verdict artifacts, their runs and the head's record check runs, and decides with the gate's own predicate; a failed or cancelled review, another head of the same tree, or any failed read reviews again. No review leg or record job starts for a pull request that changes no lane source, or for a head already reviewed. diff --git a/.github/scripts/pr-review-main/workflow.test.mjs b/.github/scripts/pr-review-main/workflow.test.mjs index df98d2cea01..33db7f8d202 100644 --- a/.github/scripts/pr-review-main/workflow.test.mjs +++ b/.github/scripts/pr-review-main/workflow.test.mjs @@ -899,13 +899,14 @@ test("the key leg takes the trigger job's gate only from this attempt, and every "pr-number=${{ steps.gate.outputs.pr-number }}", "head-sha=${{ steps.gate.outputs.head-sha }}", "base-sha=${{ steps.gate.outputs.base-sha }}", + "judged=${{ steps.judged.outputs.judged }}", ], ); assert.doesNotMatch(trigger, /head-ref/); // Its gate is the legs' gate, skipped under the kill switch or when both lanes are off. const gateOf = (block) => block.split(/\n(?= - name: )/).find((s) => s.startsWith(" - name: Check the trigger\n")); const triggerGate = gateOf(trigger); - assert.match(triggerGate, /^ {8}if: steps\.kill\.outputs\.proceed == 'true' && \(vars\.CLAUDE_REVIEW_DISABLED != 'true' \|\| vars\.CLAUDE_SECURITY_REVIEW_DISABLED != 'true'\) && steps\.files\.outputs\.review != 'false'$/m); + assert.match(triggerGate, /^ {8}if: steps\.kill\.outputs\.proceed == 'true' && \(vars\.CLAUDE_REVIEW_DISABLED != 'true' \|\| vars\.CLAUDE_SECURITY_REVIEW_DISABLED != 'true'\) && steps\.files\.outputs\.review != 'false' && steps\.judged\.outputs\.judged != 'true'$/m); const gateWith = (block) => block.slice(block.indexOf(" uses: ")).replace(/\n\n {6}#[\s\S]*$/, ""); assert.equal(gateWith(triggerGate), gateWith(step("Check the trigger"))); // Its calls reach the api-budget notice. @@ -946,7 +947,9 @@ test("the trigger job reads the files first and gates every lane-source pull req assert.match(files, /^ {8}id: files$/m); // The read runs under the gate's own kill-switch and lane conditions. assert.match(files, /^ {8}if: steps\.kill\.outputs\.proceed == 'true' && \(vars\.CLAUDE_REVIEW_DISABLED != 'true' \|\| vars\.CLAUDE_SECURITY_REVIEW_DISABLED != 'true'\)$/m); - assert.match(blocks[at("Check the trigger")], /^ {8}if: .* && steps\.files\.outputs\.review != 'false'$/m); + assert.match(blocks[at("Check the trigger")], /^ {8}if: .* && steps\.files\.outputs\.review != 'false' && steps\.judged\.outputs\.judged != 'true'$/m); + assert.ok(at("Read the changed files") < at("Find a head both lanes already reviewed"), names.join(", ")); + assert.ok(at("Find a head both lanes already reviewed") < at("Check the trigger"), names.join(", ")); // The select reads again unless the read found a lane source in the gate's own PR. assert.match(blocks[at("Select a lane-source pull request")], /^ {8}if: steps\.gate\.outputs\.proceed == 'true' && \(steps\.files\.outputs\.review != 'true' \|\| steps\.files\.outputs\.pr-number != steps\.gate\.outputs\.pr-number\)$/m); assert.equal(input(files, "PULLS"), "${{ toJSON(github.event.workflow_run.pull_requests) }}"); @@ -997,6 +1000,122 @@ test("the trigger job reads the files first and gates every lane-source pull req } }); +// The key leg's job-level skip: no leg starts when this attempt's trigger job +// found no lane source, or a head both lanes already reviewed. +const KEY_SKIP = " && (needs.trigger.outputs.run-attempt != github.run_attempt\n || needs.trigger.outputs.review != 'false' && needs.trigger.outputs.judged != 'true')\n"; + +test("no leg starts, and nothing records, for a head with no lane source or one both lanes reviewed", () => { + assert.ok(/^ {4}if: >-\n((?: {6}.*\n)+)/m.exec(jobText(KEY))[1].endsWith(KEY_SKIP)); + assert.match(jobText("record"), /^ {4}if: \$\{\{ !cancelled\(\) && github\.ref == 'refs\/heads\/main' && needs\.review\.result != 'skipped' \}\}$/m); +}); + +// The trigger job's judged-head read: judged=true only when the merge gate's +// own predicate binds both lanes at the event's head; anything less, or any +// failed read, leaves no output and the review runs. +test("a head both lanes reviewed in a successful main run, recorded on the head, is judged; anything less is not", () => { + const block = jobText("trigger").split(/\n(?= - name: )/).find((s) => s.startsWith(" - name: Find a head both lanes already reviewed\n")); + assert.ok(block, "the trigger job reads the judged head"); + assert.match(block, /^ {8}id: judged$/m); + assert.match(block, /^ {8}if: steps\.files\.outputs\.review == 'true'$/m); + assert.equal(input(block, "PR_NUMBER"), "${{ steps.files.outputs.pr-number }}"); + assert.equal(input(block, "HEAD_SHA"), "${{ github.event.workflow_run.head_sha }}"); + assert.equal(input(block, "TREE_SHA"), "${{ github.event.workflow_run.head_commit.tree_id }}"); + const run = /^ {8}run: \|\n((?: {10}.*\n|\n)+)/m.exec(`${block}\n`)[1].replace(/^ {10}/gm, ""); + assert.doesNotMatch(run, /\$\{\{/); + // Its reads go through the api-budget gh wrapper, so they are counted. + assert.match(run, /\{ \. \.base\/\.github\/actions\/log-api-budget\/api-budget\.bash 2>\/dev\/null && api_budget_wrap_gh github-token; \} \|\| true\n/); + // The record title the gate reads as counts is the one this step reads. + const gh = readFileSync(new URL("../../../plugins/source-control/skills/babysit-prs/scripts/babysit_gh.py", import.meta.url), "utf8"); + assert.ok(gh.includes(`MAIN_REVIEW_CHECK_TITLE = re.compile(r"findings=(\\d{1,6}) critical=(\\d{1,6})")`)); + assert.ok(run.includes(`title = re.compile(r"findings=(\\d{1,6}) critical=(\\d{1,6})")`)); + const TREE = "c".repeat(40); + const PR = 7; + const dir = mkdtempSync(path.join(tmpdir(), "pr-review-main-judged-")); + try { + mkdirSync(path.join(dir, ".base")); + symlinkSync(new URL("../../../plugins", import.meta.url).pathname, path.join(dir, ".base", "plugins")); + const bin = path.join(dir, "bin"); + const fixtures = path.join(dir, "fixtures"); + mkdirSync(bin); + // Answers `gh api [--jq ]` from a fixture file named after + // the url; a url with no fixture fails as a failed read does. + writeFileSync( + path.join(bin, "gh"), + '#!/bin/bash\necho "$*" >>"$GH_LOG"\nf="$GH_FIXTURES/$(printf %s "$2" | tr -c "A-Za-z0-9" _)"\n[ -f "$f" ] || exit 1\nif [ "$3" = --jq ]; then jq -c "$4" "$f"; else cat "$f"; fi\n', + ); + chmodSync(path.join(bin, "gh"), 0o755); + const key = (url) => url.replace(/[^A-Za-z0-9]/g, "_"); + const lanes = ["claude-review", "claude-security-review"]; + const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1 } = {}) => { + rmSync(fixtures, { recursive: true, force: true }); + mkdirSync(fixtures); + lanes.forEach((lane, i) => { + if (missing.includes(lane)) return; + const name = `pr-review-main-${lane}-${PR}-${TREE}`; + const artifact = 100 + i; + const runId = 200 + i; + const at = (url, body) => writeFileSync(path.join(fixtures, key(url)), typeof body === "string" ? body : JSON.stringify(body)); + at(`repos/o/r/actions/artifacts?name=${name}&per_page=100`, { total_count: total, artifacts: [{ id: artifact, name, expired: false, workflow_run: { id: runId } }] }); + at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: ".github/workflows/pr-review-main.yml", event: "workflow_run", head_branch: branch, head_sha: SHA_B, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); + const verdict = path.join(dir, "verdict.json"); + writeFileSync(verdict, JSON.stringify({ schema: 1, lane, pr: PR, tree: TREE, head_sha: head, findings: 2, critical: 0, max_line_bytes: 80 })); + const zipped = spawnSync("python3", ["-I", "-c", "import sys, zipfile; zipfile.ZipFile(sys.argv[1], 'w').write(sys.argv[2], 'verdict.json')", path.join(fixtures, key(`repos/o/r/actions/artifacts/${artifact}/zip`)), verdict], { encoding: "utf8" }); + assert.equal(zipped.status, 0, zipped.stderr); + at(`repos/o/r/commits/${SHA_A}/check-runs?check_name=pr-review-main%3A%20${lane}&filter=all&per_page=100`, { total_count: 2, check_runs: [{ app: { slug: "github-actions" }, output: { title } }, { app: { slug: "someone" }, output: { title: "findings=2 critical=0" } }] }); + }); + }; + const runWith = (env = {}) => { + const out = path.join(dir, "out"); + const log = path.join(dir, "gh.log"); + writeFileSync(out, ""); + writeFileSync(log, ""); + const result = spawnSync("bash", ["--noprofile", "--norc", "-e", "-o", "pipefail", "-c", run], { + cwd: dir, + encoding: "utf8", + env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, GITHUB_OUTPUT: out, GITHUB_REPOSITORY: "o/r", GH_LOG: log, GH_FIXTURES: fixtures, PR_NUMBER: String(PR), HEAD_SHA: SHA_A, TREE_SHA: TREE, DIR: path.join(dir, "work"), ...env }, + }); + assert.equal(result.status, 0, result.stderr + result.stdout); + return { out: readFileSync(out, "utf8"), calls: readFileSync(log, "utf8").split("\n").filter(Boolean) }; + }; + write(); + const judged = runWith(); + assert.equal(judged.out, "judged=true\n"); + // Per lane: the listing, the run, the zip and the head's check runs. + assert.equal(judged.calls.length, 8, judged.calls.join("\n")); + // A run that did not succeed, a verdict for another head of the tree, a + // record whose counts differ, a run off main, a lane with no verdict, a + // listing past one page: no output, so the review runs. + for (const [why, setup] of [ + ["failed run", { conclusion: "failure" }], + ["other head", { head: SHA_B }], + ["counts differ", { title: "findings=3 critical=0" }], + ["off main", { branch: "feature" }], + ["security lane unreviewed", { missing: ["claude-security-review"] }], + ["more than one page", { total: 101 }], + ]) { + write(setup); + assert.equal(runWith().out, "", why); + } + // No verdict for the first lane: one listing read and no more. + write({ missing: ["claude-review"] }); + const none = runWith(); + assert.equal(none.out, ""); + assert.equal(none.calls.length, 1, none.calls.join("\n")); + // A failed read: no output, and the step stays green. + write(); + rmSync(path.join(fixtures, key(`repos/o/r/actions/runs/201`))); + assert.equal(runWith().out, ""); + // No tree in the event, or a malformed number: no read at all. + for (const env of [{ TREE_SHA: "" }, { PR_NUMBER: "7; x" }]) { + const bad = runWith(env); + assert.equal(bad.out, "", JSON.stringify(env)); + assert.equal(bad.calls.length, 0, JSON.stringify(env)); + } + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + // The review lanes' credential order, read from their callers' `secrets:` // blocks, never from this workflow: each names the reusable's secret and the // repository secret it passes. @@ -1160,9 +1279,10 @@ test("a later leg runs only for the lanes the previous leg handed on", () => { assert.equal(input(step(`Review chunk ${k}`, SUB), "fallback-ready"), "${{ steps.credential.outputs.fallback-ready }}"); assert.doesNotMatch(step(`Review chunk ${k}`, FB), /fallback-ready/); } - // The record job waits for every leg and runs when a later one skipped. + // The record job waits for every leg and runs when a later one skipped, + // but not when the key leg did (its own test above). assert.match(jobText("record"), /^ {4}needs: \[review, review-subscription, review-fallback\]$/m); - assert.match(jobText("record"), /^ {4}if: \$\{\{ !cancelled\(\) && github\.ref == 'refs\/heads\/main' \}\}$/m); + assert.match(jobText("record"), /^ {4}if: \$\{\{ !cancelled\(\) && github\.ref == 'refs\/heads\/main' && needs\.review\.result != 'skipped' \}\}$/m); }); test("the handoff step names its lane and a closed reason, and a handed-off leg stays green", () => { @@ -1234,7 +1354,12 @@ test("every later leg repeats the key leg's steps but for its credential and why } // Its gates are the key leg's. // Past the route checks, its gates are the key leg's. - const gates = (id) => /^ {4}if: >-\n((?: {6}.*\n)+)/m.exec(jobText(id))[1].replace(/^ {6}!cancelled\(\)\n {6}&& needs\.[a-z-]+\.result == 'success'\n {6}&& /, " "); + // The key leg's skip on the trigger job's answer (its own test below). + const gates = (id) => + /^ {4}if: >-\n((?: {6}.*\n)+)/m + .exec(jobText(id))[1] + .replace(/^ {6}!cancelled\(\)\n {6}&& needs\.[a-z-]+\.result == 'success'\n {6}&& /, " ") + .replace(KEY_SKIP, ""); assert.equal(gates(job), gates(KEY)); } assert.equal(input(step("Report chunk 1's outcome", KEY), "fallback-reason"), undefined); diff --git a/.github/workflows/pr-review-main.yml b/.github/workflows/pr-review-main.yml index 6e3478e5a9f..2a8fc891217 100644 --- a/.github/workflows/pr-review-main.yml +++ b/.github/workflows/pr-review-main.yml @@ -44,7 +44,8 @@ name: pr-review-main # next push reviews again. # # The trigger job reads the PR's files, then runs the trigger gate only for a -# lane-source PR, once per run; the key leg takes its result, a boolean, the +# lane-source PR whose head both lanes have not already reviewed (a verdict the +# merge gate binds), once per run; no leg starts otherwise. The key leg takes its result, a boolean, the # PR number and two SHAs # checked against fixed shapes, only from the same run attempt, and gates # itself otherwise. The later legs gate themselves at their own start. @@ -103,6 +104,7 @@ jobs: pr-number: ${{ steps.gate.outputs.pr-number }} head-sha: ${{ steps.gate.outputs.head-sha }} base-sha: ${{ steps.gate.outputs.base-sha }} + judged: ${{ steps.judged.outputs.judged }} steps: - name: Check out the default branch tip uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -163,12 +165,86 @@ jobs: { echo "pr-number=$pr"; echo "review=$review"; } >>"$GITHUB_OUTPUT" echo "lane source changed: $review" + # A head both lanes already reviewed from main is not reviewed again: + # pr-require-checks completes several times on one head (a re-run after + # each review, a label or body edit), and each completion starts this + # run. judged=true only when the merge gate's own predicate + # (babysit_review_evidence `_main_bound`) binds both lanes at this head + # on what this step reads as the gate does (babysit_gh + # collect_main_reviews, collect_main_review_counts): a verdict artifact + # for the PR and the head's tree, from a pr-review-main run on main that + # completed with success, naming this head, beside the record job's + # check run with its counts. A failed or cancelled run, a verdict for + # another head of the same tree, a lane with no verdict, or any failed + # read leaves no output, and the review runs as before. The run head's + # place on main is not compared: this file runs only from main's tip, and + # main's history is linear. The tree is the event's, for the event's head. + - name: Find a head both lanes already reviewed + id: judged + if: steps.files.outputs.review == 'true' + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ steps.files.outputs.pr-number }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + TREE_SHA: ${{ github.event.workflow_run.head_commit.tree_id }} + DIR: ${{ runner.temp }}/pr-review-main-judged + run: | + if ! [[ $PR_NUMBER =~ ^[1-9][0-9]{0,9}$ && $HEAD_SHA =~ ^[0-9a-f]{40}$ && $TREE_SHA =~ ^[0-9a-f]{40}$ ]]; then + echo "the event names no tree for its head; the review runs" + exit 0 + fi + mkdir -p "$DIR" + # Each call the gh wrapper sends counts toward the api-calls notice. + { . .base/.github/actions/log-api-budget/api-budget.bash 2>/dev/null && api_budget_wrap_gh github-token; } || true + unread() { + echo "::warning::$1 did not read; the review runs" + exit 0 + } + for lane in claude-review claude-security-review; do + name="pr-review-main-$lane-$PR_NUMBER-$TREE_SHA" + gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$name&per_page=100" >"$DIR/listing.json" || unread "the $lane verdict listing" + # One page holds every review of the tree, or the review runs. + pairs=$(jq -r --arg name "$name" 'if .total_count > 100 then error("more than one page") else .artifacts[] | select(.name == $name and .expired == false) | "\(.id) \(.workflow_run.id)" end' "$DIR/listing.json") || unread "the $lane verdict listing" + if [ -z "$pairs" ]; then + echo "$lane has no verdict for this tree; the review runs" + exit 0 + fi + : >"$DIR/$lane-records.jsonl" + while read -r artifact run; do + [[ $artifact =~ ^[1-9][0-9]{0,19}$ && $run =~ ^[1-9][0-9]{0,19}$ ]] || unread "the $lane verdict listing" + gh api "repos/$GITHUB_REPOSITORY/actions/runs/$run" >"$DIR/run.json" || unread "run $run" + gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact/zip" >"$DIR/verdict.zip" || unread "artifact $artifact" + unzip -p "$DIR/verdict.zip" verdict.json >"$DIR/verdict.json" || unread "artifact $artifact" + jq -nc --arg lane "$lane" --slurpfile listing "$DIR/listing.json" --slurpfile run "$DIR/run.json" --slurpfile verdict "$DIR/verdict.json" --argjson id "$artifact" \ + '{lane: $lane, artifact: first($listing[0].artifacts[] | select(.id == $id)), run: $run[0], verdict: $verdict[0], on_branch: true}' >>"$DIR/$lane-records.jsonl" || unread "artifact $artifact" + done <<<"$pairs" + gh api "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs?check_name=pr-review-main%3A%20$lane&filter=all&per_page=100" \ + --jq 'if .total_count > 100 then error("more than one page") else [.check_runs[] | select(.app.slug == "github-actions") | .output.title // ""] end' >"$DIR/$lane-titles.json" || unread "the $lane check runs" + done + judged=$(python3 -I -c ' + import json, re, sys + sys.path.insert(0, ".base/plugins/source-control/skills/babysit-prs/scripts") + import babysit_review_evidence as ev + directory, repo, pr, tree, head = sys.argv[1:] + # babysit_gh MAIN_REVIEW_CHECK_TITLE: a record title the gate reads as counts. + title = re.compile(r"findings=(\d{1,6}) critical=(\d{1,6})") + def bound(lane): + records = [json.loads(line) for line in open(f"{directory}/{lane}-records.jsonl", encoding="utf-8")] + titles = json.load(open(f"{directory}/{lane}-titles.json", encoding="utf-8")) + counts = [[int(m[1]), int(m[2])] for t in titles if (m := title.fullmatch(t))] + context = {"repo": repo, "pr": int(pr), "tree": tree, "branch": "main", "head_records": {lane: counts}} + return ev._main_bound(lane, head, records, context) is not None + print("true" if all(bound(lane) for lane in ev.LANES) else "false") + ' "$DIR" "$GITHUB_REPOSITORY" "$PR_NUMBER" "$TREE_SHA" "$HEAD_SHA") || unread "a verdict" + echo "both lanes already reviewed this head: $judged" + if [ "$judged" = true ]; then echo "judged=true" >>"$GITHUB_OUTPUT"; fi + # The upstream run's actors, the re-runner and the PR author must all be - # on the trusted-actor list. Skipped when no lane would review, or when - # the PR changes no lane source. + # on the trusted-actor list. Skipped when no lane would review, when + # the PR changes no lane source, or when both lanes reviewed this head. - name: Check the trigger id: gate - if: steps.kill.outputs.proceed == 'true' && (vars.CLAUDE_REVIEW_DISABLED != 'true' || vars.CLAUDE_SECURITY_REVIEW_DISABLED != 'true') && steps.files.outputs.review != 'false' + if: steps.kill.outputs.proceed == 'true' && (vars.CLAUDE_REVIEW_DISABLED != 'true' || vars.CLAUDE_SECURITY_REVIEW_DISABLED != 'true') && steps.files.outputs.review != 'false' && steps.judged.outputs.judged != 'true' env: API_BUDGET_TOKEN: github-token uses: ./.base/.github/actions/check-trusted-trigger # zizmor: ignore[self-repository] @@ -212,6 +288,9 @@ jobs: with: tokens: github-token + # No leg starts when the trigger job of this attempt found no lane source + # or a head both lanes already reviewed: the leg would review nothing. A + # leg re-run alone in a later attempt starts and gates itself. review: needs: trigger if: >- @@ -219,6 +298,8 @@ jobs: && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_repository.full_name == github.repository + && (needs.trigger.outputs.run-attempt != github.run_attempt + || needs.trigger.outputs.review != 'false' && needs.trigger.outputs.judged != 'true') strategy: fail-fast: false matrix: @@ -2689,7 +2770,8 @@ jobs: # write-verdict.mjs checked, from this run's own artifacts. record: needs: [review, review-subscription, review-fallback] - if: ${{ !cancelled() && github.ref == 'refs/heads/main' }} + # A skipped key leg reviewed nothing, so no later leg ran: nothing to record. + if: ${{ !cancelled() && github.ref == 'refs/heads/main' && needs.review.result != 'skipped' }} runs-on: ubuntu-24.04 timeout-minutes: 5 permissions: diff --git a/docs/conventions/pr-pipeline/README.md b/docs/conventions/pr-pipeline/README.md index 5bbebfeea7f..27e716487e6 100644 --- a/docs/conventions/pr-pipeline/README.md +++ b/docs/conventions/pr-pipeline/README.md @@ -1260,8 +1260,11 @@ the rules that only tighten in completion through `workflow_run`, so its definition is main's, gates the trigger as pr-verify does, and for a pull request whose changed files include a lane source runs both lanes on the head's diff as data, each lane's criteria and the standards copied from main, with a read-only - token and a model that may only Read its data directory. The diff is `git diff --text`, so a file - git would call binary is shown as text, and a patch that still holds a binary file gets no + token and a model that may only Read its data directory. A head both lanes already reviewed, + where the merge gate's own predicate (`_main_bound`) binds each lane on what the trigger job + reads, is not reviewed again, and no leg starts for a pull request with no lane source; a failed + or cancelled review, another head of the same tree, or a failed read reviews again. The diff is + `git diff --text`, so a file git would call binary is shown as text, and a patch that still holds a binary file gets no verdict. A patch over 300000 bytes is split into chunks of at most 300000 bytes, cut at file boundaries with each file whole (`split-diff.py`); each chunk is reviewed by its own run, in order, and the lane's one verdict sums the chunks' findings and takes the most CRITICAL ones From cc9c806844b03fbe03989eac0af467247efa8f7f Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 2 Nov 2026 14:27:59 -0500 Subject: [PATCH 2/5] fix(ci): let pr-review-main's trigger job read the head's record check runs The judged-head read lists the record job's check runs on the head, and a job that lists permissions gets none for an omitted scope, so without checks: read the read was refused and the step always fell open to a review. Also moves the outage audit's pr-review-main.yml line citations to where the cited lines now sit. Refs: #12448 Co-Authored-By: Claude Opus 5.5 --- .../scripts/pr-review-main/workflow.test.mjs | 10 +++++++--- .github/workflows/pr-review-main.yml | 3 ++- docs/outage-posture-audit.md | 18 +++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/scripts/pr-review-main/workflow.test.mjs b/.github/scripts/pr-review-main/workflow.test.mjs index 33db7f8d202..0b86207b391 100644 --- a/.github/scripts/pr-review-main/workflow.test.mjs +++ b/.github/scripts/pr-review-main/workflow.test.mjs @@ -129,10 +129,14 @@ test("the model's jobs can only read, and the one writer runs no model", () => { assert.match(route, /^ {4}permissions: \{\}$/m, job); assert.doesNotMatch(route, /run-claude-cli|secrets\.|actions\/checkout@|uses:/, job); } - // The trigger job reads with the key leg's grants, holds no secret and runs - // no model. + // The trigger job reads with the key leg's grants and checks: read, for the + // record job's check runs its judged-head read takes; it holds no secret + // and runs no model. const trigger = jobText("trigger"); - assert.deepEqual(grantsOf(trigger).map(([, scope, level]) => `${scope}:${level}`), grantsOf(jobText(KEY)).map(([, scope, level]) => `${scope}:${level}`)); + assert.deepEqual( + grantsOf(trigger).map(([, scope, level]) => `${scope}:${level}`), + [...grantsOf(jobText(KEY)).map(([, scope, level]) => `${scope}:${level}`), "checks:read"], + ); assert.doesNotMatch(trigger, /run-claude-cli|secrets\./); const record = jobText("record"); assert.deepEqual(grantsOf(record).map(([, scope, level]) => `${scope}:${level}`), ["checks:write"]); diff --git a/.github/workflows/pr-review-main.yml b/.github/workflows/pr-review-main.yml index 2a8fc891217..6906cf90f57 100644 --- a/.github/workflows/pr-review-main.yml +++ b/.github/workflows/pr-review-main.yml @@ -96,7 +96,8 @@ jobs: permissions: contents: read # check out main pull-requests: read # the PR and its files - actions: read # the upstream run the trigger gate reads + actions: read # the upstream run the trigger gate reads; the verdicts already uploaded + checks: read # the record job's check runs on the head outputs: run-attempt: ${{ github.run_attempt }} proceed: ${{ steps.gate.outputs.proceed }} diff --git a/docs/outage-posture-audit.md b/docs/outage-posture-audit.md index 6039c1c853c..3a0c88aeb8b 100644 --- a/docs/outage-posture-audit.md +++ b/docs/outage-posture-audit.md @@ -107,12 +107,12 @@ The lane runs from `.github/workflows/pr-review-hosted.yml`, a caller of the ext | Element | Verdict | Evidence | Why | |---|---|---|---| -| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:194` | The shared client sends up to 4 attempts with equal jitter, and the file-list read is never retried. | -| 2 | gap | `.github/workflows/pr-review-main.yml:194`, `.github/workflows/pr-review-main.yml:1007` | A failed read fails the step, and "no verdict" exits 1. | +| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:271` | The shared client sends up to 4 attempts with equal jitter, and the file-list read is never retried. | +| 2 | gap | `.github/workflows/pr-review-main.yml:271`, `.github/workflows/pr-review-main.yml:1089` | A failed read fails the step, and "no verdict" exits 1. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-hosted.yml:183` | Recovery is a recorded one-time re-run by the reconciler, gated on the status page. That is a re-arm and a status-page trigger. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2656` | A later clean review never clears a CRITICAL check run. | -| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:287` | `check-upstream-status` stops the review with exit 1. | -| 6 | gap | `.github/workflows/pr-review-main.yml:222`, `.github/workflows/pr-review-main.yml:503` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2738` | A later clean review never clears a CRITICAL check run. | +| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:369` | `check-upstream-status` stops the review with exit 1. | +| 6 | gap | `.github/workflows/pr-review-main.yml:304`, `.github/workflows/pr-review-main.yml:585` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | ## pr-review-security @@ -121,12 +121,12 @@ The lane runs from `.github/workflows/pr-review-security-hosted.yml` and the | Element | Verdict | Evidence | Why | |---|---|---|---| -| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:194` | It shares pr-review's code, so it has the same gap. | -| 2 | gap | `.github/workflows/pr-review-main.yml:194`, `.github/workflows/pr-review-main.yml:1007` | A failed read or "no verdict" makes the run red. | +| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:271` | It shares pr-review's code, so it has the same gap. | +| 2 | gap | `.github/workflows/pr-review-main.yml:271`, `.github/workflows/pr-review-main.yml:1089` | A failed read or "no verdict" makes the run red. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-security-hosted.yml:188` | Resume depends on the reconciler's status-gated re-run. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2656` | A later complete read never closes a filed CRITICAL count. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2738` | A later complete read never closes a filed CRITICAL count. | | 5 | gap | `.github/workflows/pr-review-security-hosted.yml:173`, `.github/workflows/pr-review-security-hosted.yml:193` | The status page gates the run and turns it red. | -| 6 | gap | `.github/workflows/pr-review-main.yml:222`, `.github/workflows/pr-review-main.yml:503` | Matrix legs run in parallel and repeat the same reads with no `etag`. | +| 6 | gap | `.github/workflows/pr-review-main.yml:304`, `.github/workflows/pr-review-main.yml:585` | Matrix legs run in parallel and repeat the same reads with no `etag`. | ## pr-verify From 6c4165219a73bcb71dd10893a8d583bfd46187d7 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:05:58 -0500 Subject: [PATCH 3/5] fix(ci): count a main-run verdict only under main's current review criteria The trigger job's judged-head skip bound a head on the merge gate's predicate, which never compares the criteria a verdict was judged under with main's. Before the skip, a pr-require-checks completion after main's lane criteria changed produced a fresh verdict under the new criteria; with it, the old verdict stood. The step now keeps a verdict record only when its run's main commit (the run's head_sha) has no diff from main's tip over the review's inputs: it fetches that commit into the one-commit checkout when absent and runs git diff --quiet over the paths. A changed path drops the record, so the review runs; a failed fetch or diff takes the existing unread path. The run need not be at main's tip, so the skip still saves the repeat reviews. The paths live in one file, .github/scripts/pr-review-main/criteria.txt, which the three legs' copy steps now loop over and the trigger job reads, so the copied criteria and the compared paths cannot drift apart. The prompt, scripts and this workflow are listed as read in place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VcupojVgxFqBnrah9DwFLE --- ...skip-repeat-workflow-run-wakes-64b6cc4d.md | 2 +- .github/scripts/pr-review-main/criteria.txt | 14 +++ .../scripts/pr-review-main/workflow.test.mjs | 98 ++++++++++++++++- .github/workflows/pr-review-main.yml | 101 ++++++++++++------ docs/conventions/pr-pipeline/README.md | 7 +- 5 files changed, 179 insertions(+), 43 deletions(-) create mode 100644 .github/scripts/pr-review-main/criteria.txt diff --git a/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md b/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md index b341f6f79ca..84c662215e7 100644 --- a/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md +++ b/.changes/pr-pipeline/perf-skip-repeat-workflow-run-wakes-64b6cc4d.md @@ -4,4 +4,4 @@ bump: patch ### Changed -- The main-run review (`pr-review-main.yml`) no longer reviews a head again when both lanes already have a verdict the merge gate binds there: pr-require-checks completes several times on one head, and each completion started both model reviews. The trigger job reads each lane's verdict artifacts, their runs and the head's record check runs, and decides with the gate's own predicate; a failed or cancelled review, another head of the same tree, or any failed read reviews again. No review leg or record job starts for a pull request that changes no lane source, or for a head already reviewed. +- The main-run review (`pr-review-main.yml`) no longer reviews a head again when both lanes already have a verdict the merge gate binds there: pr-require-checks completes several times on one head, and each completion started both model reviews. The trigger job reads each lane's verdict artifacts, their runs and the head's record check runs, and decides with the gate's own predicate, counting a verdict only when its run's main commit has main's current review criteria (`criteria.txt`, which the copy steps also read); a verdict judged under other criteria, a failed or cancelled review, another head of the same tree, or any failed read reviews again. No review leg or record job starts for a pull request that changes no lane source, or for a head already reviewed. diff --git a/.github/scripts/pr-review-main/criteria.txt b/.github/scripts/pr-review-main/criteria.txt new file mode 100644 index 00000000000..87ab10ed898 --- /dev/null +++ b/.github/scripts/pr-review-main/criteria.txt @@ -0,0 +1,14 @@ +# What a pr-review-main review reads from main: the lane's criteria, the +# standards, and the prompt, scripts and workflow that run it. Each line is +# ` []`; {skill} is the +# lane's skill. `copy` must exist, `copy-if-present` may be absent, and `read` +# runs in place from the main checkout. The copy steps copy these; the trigger +# job counts a verdict only when none of them differs from main's tip. +copy plugins/review/skills/{skill} review/skills/{skill} +copy plugins/review/reference review/reference +copy REVIEW.md standards/REVIEW.md +copy docs/standards standards/standards +copy-if-present docs/review standards/review +copy-if-present .claude/rules standards/rules +read .github/scripts/pr-review-main +read .github/workflows/pr-review-main.yml diff --git a/.github/scripts/pr-review-main/workflow.test.mjs b/.github/scripts/pr-review-main/workflow.test.mjs index 0b86207b391..1631ae64e7b 100644 --- a/.github/scripts/pr-review-main/workflow.test.mjs +++ b/.github/scripts/pr-review-main/workflow.test.mjs @@ -837,7 +837,7 @@ test("the model reads its data directory alone", () => { // never applies the per-concern rules. test("the prompt names the per-concern review rules the criteria step copies", () => { assert.ok(prompt.includes("its per-concern review rules (`review/`, when present;")); - assert.ok(step("Copy the review criteria").includes('cp -R .base/docs/review "$DATA/standards/review"')); + assert.match(readFileSync(new URL("./criteria.txt", import.meta.url), "utf8"), /^copy-if-present docs\/review standards\/review$/m); }); test("the verdict uploads once, after it is written, under the writer's name", () => { @@ -1036,7 +1036,31 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const PR = 7; const dir = mkdtempSync(path.join(tmpdir(), "pr-review-main-judged-")); try { - mkdirSync(path.join(dir, ".base")); + // main's history: OLD, then CHANGED (REVIEW.md, a criterion, changes), + // then the tip (only a file outside criteria.txt changes). The step's + // checkout is a one-commit clone of the tip, as actions/checkout makes. + const gitEnv = { ...process.env, GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1", GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@example.com", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@example.com" }; + const git = (...args) => { + const result = spawnSync("git", args, { encoding: "utf8", env: gitEnv }); + assert.equal(result.status, 0, result.stderr); + return result.stdout.trim(); + }; + const origin = path.join(dir, "origin"); + mkdirSync(path.join(origin, ".github", "scripts", "pr-review-main"), { recursive: true }); + git("-C", origin, "init", "--quiet"); + writeFileSync(path.join(origin, ".github", "scripts", "pr-review-main", "criteria.txt"), readFileSync(new URL("./criteria.txt", import.meta.url))); + const commit = (file, text) => { + writeFileSync(path.join(origin, file), text); + git("-C", origin, "add", "-A"); + git("-C", origin, "commit", "--quiet", "-m", file); + return git("-C", origin, "rev-parse", "HEAD"); + }; + const OLD = commit("REVIEW.md", "old criteria\n"); + const CHANGED = commit("REVIEW.md", "new criteria\n"); + const TIP = commit("notes.txt", "not a criterion\n"); + git("clone", "--quiet", "--depth=1", `file://${origin}`, path.join(dir, ".base")); + const has = (sha) => spawnSync("git", ["-C", path.join(dir, ".base"), "cat-file", "-e", `${sha}^{commit}`], { env: gitEnv }).status === 0; + assert.ok(!has(CHANGED) && !has(OLD), "the checkout holds the tip alone"); symlinkSync(new URL("../../../plugins", import.meta.url).pathname, path.join(dir, ".base", "plugins")); const bin = path.join(dir, "bin"); const fixtures = path.join(dir, "fixtures"); @@ -1050,7 +1074,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, chmodSync(path.join(bin, "gh"), 0o755); const key = (url) => url.replace(/[^A-Za-z0-9]/g, "_"); const lanes = ["claude-review", "claude-security-review"]; - const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1 } = {}) => { + const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1, main = TIP } = {}) => { rmSync(fixtures, { recursive: true, force: true }); mkdirSync(fixtures); lanes.forEach((lane, i) => { @@ -1060,7 +1084,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const runId = 200 + i; const at = (url, body) => writeFileSync(path.join(fixtures, key(url)), typeof body === "string" ? body : JSON.stringify(body)); at(`repos/o/r/actions/artifacts?name=${name}&per_page=100`, { total_count: total, artifacts: [{ id: artifact, name, expired: false, workflow_run: { id: runId } }] }); - at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: ".github/workflows/pr-review-main.yml", event: "workflow_run", head_branch: branch, head_sha: SHA_B, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); + at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: ".github/workflows/pr-review-main.yml", event: "workflow_run", head_branch: branch, head_sha: main, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); const verdict = path.join(dir, "verdict.json"); writeFileSync(verdict, JSON.stringify({ schema: 1, lane, pr: PR, tree: TREE, head_sha: head, findings: 2, critical: 0, max_line_bytes: 80 })); const zipped = spawnSync("python3", ["-I", "-c", "import sys, zipfile; zipfile.ZipFile(sys.argv[1], 'w').write(sys.argv[2], 'verdict.json')", path.join(fixtures, key(`repos/o/r/actions/artifacts/${artifact}/zip`)), verdict], { encoding: "utf8" }); @@ -1076,7 +1100,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const result = spawnSync("bash", ["--noprofile", "--norc", "-e", "-o", "pipefail", "-c", run], { cwd: dir, encoding: "utf8", - env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, GITHUB_OUTPUT: out, GITHUB_REPOSITORY: "o/r", GH_LOG: log, GH_FIXTURES: fixtures, PR_NUMBER: String(PR), HEAD_SHA: SHA_A, TREE_SHA: TREE, DIR: path.join(dir, "work"), ...env }, + env: { ...gitEnv, PATH: `${bin}:${process.env.PATH}`, GITHUB_OUTPUT: out, GITHUB_REPOSITORY: "o/r", GH_LOG: log, GH_FIXTURES: fixtures, PR_NUMBER: String(PR), HEAD_SHA: SHA_A, TREE_SHA: TREE, DIR: path.join(dir, "work"), ...env }, }); assert.equal(result.status, 0, result.stderr + result.stdout); return { out: readFileSync(out, "utf8"), calls: readFileSync(log, "utf8").split("\n").filter(Boolean) }; @@ -1100,6 +1124,27 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, write(setup); assert.equal(runWith().out, "", why); } + // A run from an older main commit with the tip's criteria counts: that + // commit is fetched, and only a path outside criteria.txt differs. + write({ main: CHANGED }); + const older = runWith(); + assert.equal(older.out, "judged=true\n"); + assert.equal(older.calls.length, 8, older.calls.join("\n")); + assert.ok(has(CHANGED), "the run's main commit was fetched"); + // A run from a commit whose criteria differ (REVIEW.md) does not count, + // and its verdict is never downloaded: per lane, the listing, the run and + // the check runs. + write({ main: OLD }); + const stale = runWith(); + assert.equal(stale.out, ""); + assert.equal(stale.calls.length, 6, stale.calls.join("\n")); + assert.ok(!stale.calls.some((call) => call.includes("/zip")), stale.calls.join("\n")); + // A commit main does not have (the fetch fails), or a run head that is no + // SHA: no output, and the step stays green. + for (const main of ["d".repeat(40), "main"]) { + write({ main }); + assert.equal(runWith().out, "", main); + } // No verdict for the first lane: one listing read and no more. write({ missing: ["claude-review"] }); const none = runWith(); @@ -1120,6 +1165,49 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, } }); +// Every leg copies what criteria.txt lists, to the places the prompt names: +// the skill without its evals beside the plugin's reference, and REVIEW.md, +// the standards and the rules under standards; docs/review and the rules may +// be absent, REVIEW.md may not. +test("each leg copies the review criteria criteria.txt lists", () => { + const run = /^ {8}run: \|\n((?: {10}.*\n|\n)+)/m.exec(`${step("Copy the review criteria")}\n`)[1].replace(/^ {10}/gm, ""); + for (const job of LEGS) assert.equal(step("Copy the review criteria", job), step("Copy the review criteria"), job); + assert.equal(input(step("Copy the review criteria"), "SKILL"), "${{ matrix.skill }}"); + const dir = mkdtempSync(path.join(tmpdir(), "pr-review-main-criteria-")); + try { + const files = { + ".github/scripts/pr-review-main/criteria.txt": readFileSync(new URL("./criteria.txt", import.meta.url), "utf8"), + "plugins/review/skills/code-review/SKILL.md": "skill", + "plugins/review/skills/code-review/evals/case.md": "eval", + "plugins/review/skills/security-review/SKILL.md": "other lane", + "plugins/review/reference/ref.md": "ref", + "REVIEW.md": "review", + "docs/standards/s.md": "standard", + ".claude/rules/r.md": "rule", + }; + for (const [file, body] of Object.entries(files)) { + mkdirSync(path.dirname(path.join(dir, ".base", file)), { recursive: true }); + writeFileSync(path.join(dir, ".base", file), body); + } + const data = path.join(dir, "data"); + const copy = () => spawnSync("bash", ["--noprofile", "--norc", "-e", "-o", "pipefail", "-c", run], { cwd: dir, encoding: "utf8", env: { ...process.env, SKILL: "code-review", DATA: data } }); + const result = copy(); + assert.equal(result.status, 0, result.stderr); + assert.deepEqual(readdirSync(data, { recursive: true }).filter((f) => f.endsWith(".md")).sort(), [ + "review/reference/ref.md", + "review/skills/code-review/SKILL.md", + "standards/REVIEW.md", + "standards/rules/r.md", + "standards/standards/s.md", + ]); + rmSync(data, { recursive: true, force: true }); + rmSync(path.join(dir, ".base", "REVIEW.md")); + assert.notEqual(copy().status, 0, "a main with no REVIEW.md fails the copy"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + // The review lanes' credential order, read from their callers' `secrets:` // blocks, never from this workflow: each names the reusable's secret and the // repository secret it passes. diff --git a/.github/workflows/pr-review-main.yml b/.github/workflows/pr-review-main.yml index 6906cf90f57..964be8294c9 100644 --- a/.github/workflows/pr-review-main.yml +++ b/.github/workflows/pr-review-main.yml @@ -175,11 +175,15 @@ jobs: # collect_main_reviews, collect_main_review_counts): a verdict artifact # for the PR and the head's tree, from a pr-review-main run on main that # completed with success, naming this head, beside the record job's - # check run with its counts. A failed or cancelled run, a verdict for - # another head of the same tree, a lane with no verdict, or any failed - # read leaves no output, and the review runs as before. The run head's - # place on main is not compared: this file runs only from main's tip, and - # main's history is linear. The tree is the event's, for the event's head. + # check run with its counts. A verdict counts only when its run's main + # commit (the run's head_sha) has no diff from main's tip over the paths + # criteria.txt lists, so one judged under other criteria reviews again; + # the run need not be at the tip itself. That commit is fetched, when the + # one-commit checkout lacks it, anonymously, since this repository is + # public. A failed or cancelled run, a verdict for another head of the + # same tree, a lane with no verdict, or any failed read, fetch or diff + # leaves no output, and the review runs as before. The tree is the + # event's, for the event's head. - name: Find a head both lanes already reviewed id: judged if: steps.files.outputs.review == 'true' @@ -201,6 +205,24 @@ jobs: echo "::warning::$1 did not read; the review runs" exit 0 } + tip=$(git -C .base rev-parse --verify HEAD) || unread "the main checkout" + paths=$(awk '$1 ~ /^(copy|copy-if-present|read)$/ { sub("/[{]skill[}].*", "", $2); print $2 }' .base/.github/scripts/pr-review-main/criteria.txt) && [ -n "$paths" ] || unread "criteria.txt" + mapfile -t paths <<<"$paths" + declare -A diffs + # 0 when main commit $1 has the tip's criteria, 1 when it differs. + criteria_diff() { + if [ "$1" = "$tip" ]; then return 0; fi + if [ -z "${diffs[$1]:-}" ]; then + local rc=0 + if ! git -C .base cat-file -e "$1^{commit}" 2>/dev/null; then + git -C .base fetch --quiet --no-tags --depth=1 origin "$1" || unread "main commit $1" + fi + git -C .base diff --quiet "$1" "$tip" -- "${paths[@]}" || rc=$? + [ "$rc" -le 1 ] || unread "the criteria diff from $1" + diffs[$1]=$rc + fi + return "${diffs[$1]}" + } for lane in claude-review claude-security-review; do name="pr-review-main-$lane-$PR_NUMBER-$TREE_SHA" gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$name&per_page=100" >"$DIR/listing.json" || unread "the $lane verdict listing" @@ -214,6 +236,12 @@ jobs: while read -r artifact run; do [[ $artifact =~ ^[1-9][0-9]{0,19}$ && $run =~ ^[1-9][0-9]{0,19}$ ]] || unread "the $lane verdict listing" gh api "repos/$GITHUB_REPOSITORY/actions/runs/$run" >"$DIR/run.json" || unread "run $run" + sha=$(jq -r '.head_sha' "$DIR/run.json") || unread "run $run" + [[ $sha =~ ^[0-9a-f]{40}$ ]] || unread "run $run" + if ! criteria_diff "$sha"; then + echo "run $run reviewed under other criteria than main's tip; its $lane verdict does not count" + continue + fi gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact/zip" >"$DIR/verdict.zip" || unread "artifact $artifact" unzip -p "$DIR/verdict.zip" verdict.json >"$DIR/verdict.json" || unread "artifact $artifact" jq -nc --arg lane "$lane" --slurpfile listing "$DIR/listing.json" --slurpfile run "$DIR/run.json" --slurpfile verdict "$DIR/verdict.json" --argjson id "$artifact" \ @@ -602,10 +630,11 @@ jobs: output-path: ${{ github.workspace }}/pr-review-main-data/context.json github-token: ${{ github.token }} - # The lane's criteria and the repository's standards, from main. The - # skill keeps its place under the plugin's layout, so a relative pointer - # in it (`../../reference/...`) resolves inside the data directory; the - # rules the code lane names go beside the standards. + # The lane's criteria and the repository's standards, from main, as + # criteria.txt lists them. The skill keeps its place under the plugin's + # layout, so a relative pointer in it (`../../reference/...`) resolves + # inside the data directory; the rules the code lane names go beside the + # standards. - name: Copy the review criteria if: steps.diff.outcome == 'success' && steps.diff.outputs.stop == '' env: @@ -613,13 +642,13 @@ jobs: DATA: ${{ github.workspace }}/pr-review-main-data run: | mkdir -p "$DATA/review/skills" "$DATA/standards" - cp -R .base/plugins/review/skills/"$SKILL" "$DATA/review/skills/" + while read -r how src dest; do + case $how in copy | copy-if-present) ;; *) continue ;; esac + src=${src//"{skill}"/$SKILL} + if [ "$how" = copy-if-present ] && ! [ -e ".base/$src" ]; then continue; fi + cp -R ".base/$src" "$DATA/${dest//"{skill}"/$SKILL}" + done <.base/.github/scripts/pr-review-main/criteria.txt rm -rf "$DATA/review/skills/$SKILL/evals" - cp -R .base/plugins/review/reference "$DATA/review/reference" - cp .base/REVIEW.md "$DATA/standards/" - cp -R .base/docs/standards "$DATA/standards/standards" - if [ -d .base/docs/review ]; then cp -R .base/docs/review "$DATA/standards/review"; fi - if [ -d .base/.claude/rules ]; then cp -R .base/.claude/rules "$DATA/standards/rules"; fi - name: Resolve the review's model id: models @@ -1437,10 +1466,11 @@ jobs: output-path: ${{ github.workspace }}/pr-review-main-data/context.json github-token: ${{ github.token }} - # The lane's criteria and the repository's standards, from main. The - # skill keeps its place under the plugin's layout, so a relative pointer - # in it (`../../reference/...`) resolves inside the data directory; the - # rules the code lane names go beside the standards. + # The lane's criteria and the repository's standards, from main, as + # criteria.txt lists them. The skill keeps its place under the plugin's + # layout, so a relative pointer in it (`../../reference/...`) resolves + # inside the data directory; the rules the code lane names go beside the + # standards. - name: Copy the review criteria if: steps.diff.outcome == 'success' && steps.diff.outputs.stop == '' env: @@ -1448,13 +1478,13 @@ jobs: DATA: ${{ github.workspace }}/pr-review-main-data run: | mkdir -p "$DATA/review/skills" "$DATA/standards" - cp -R .base/plugins/review/skills/"$SKILL" "$DATA/review/skills/" + while read -r how src dest; do + case $how in copy | copy-if-present) ;; *) continue ;; esac + src=${src//"{skill}"/$SKILL} + if [ "$how" = copy-if-present ] && ! [ -e ".base/$src" ]; then continue; fi + cp -R ".base/$src" "$DATA/${dest//"{skill}"/$SKILL}" + done <.base/.github/scripts/pr-review-main/criteria.txt rm -rf "$DATA/review/skills/$SKILL/evals" - cp -R .base/plugins/review/reference "$DATA/review/reference" - cp .base/REVIEW.md "$DATA/standards/" - cp -R .base/docs/standards "$DATA/standards/standards" - if [ -d .base/docs/review ]; then cp -R .base/docs/review "$DATA/standards/review"; fi - if [ -d .base/.claude/rules ]; then cp -R .base/.claude/rules "$DATA/standards/rules"; fi - name: Resolve the review's model id: models @@ -2276,10 +2306,11 @@ jobs: output-path: ${{ github.workspace }}/pr-review-main-data/context.json github-token: ${{ github.token }} - # The lane's criteria and the repository's standards, from main. The - # skill keeps its place under the plugin's layout, so a relative pointer - # in it (`../../reference/...`) resolves inside the data directory; the - # rules the code lane names go beside the standards. + # The lane's criteria and the repository's standards, from main, as + # criteria.txt lists them. The skill keeps its place under the plugin's + # layout, so a relative pointer in it (`../../reference/...`) resolves + # inside the data directory; the rules the code lane names go beside the + # standards. - name: Copy the review criteria if: steps.diff.outcome == 'success' && steps.diff.outputs.stop == '' env: @@ -2287,13 +2318,13 @@ jobs: DATA: ${{ github.workspace }}/pr-review-main-data run: | mkdir -p "$DATA/review/skills" "$DATA/standards" - cp -R .base/plugins/review/skills/"$SKILL" "$DATA/review/skills/" + while read -r how src dest; do + case $how in copy | copy-if-present) ;; *) continue ;; esac + src=${src//"{skill}"/$SKILL} + if [ "$how" = copy-if-present ] && ! [ -e ".base/$src" ]; then continue; fi + cp -R ".base/$src" "$DATA/${dest//"{skill}"/$SKILL}" + done <.base/.github/scripts/pr-review-main/criteria.txt rm -rf "$DATA/review/skills/$SKILL/evals" - cp -R .base/plugins/review/reference "$DATA/review/reference" - cp .base/REVIEW.md "$DATA/standards/" - cp -R .base/docs/standards "$DATA/standards/standards" - if [ -d .base/docs/review ]; then cp -R .base/docs/review "$DATA/standards/review"; fi - if [ -d .base/.claude/rules ]; then cp -R .base/.claude/rules "$DATA/standards/rules"; fi - name: Resolve the review's model id: models diff --git a/docs/conventions/pr-pipeline/README.md b/docs/conventions/pr-pipeline/README.md index e787c187399..892386fae2b 100644 --- a/docs/conventions/pr-pipeline/README.md +++ b/docs/conventions/pr-pipeline/README.md @@ -1262,8 +1262,11 @@ the rules that only tighten in head's diff as data, each lane's criteria and the standards copied from main, with a read-only token and a model that may only Read its data directory. A head both lanes already reviewed, where the merge gate's own predicate (`_main_bound`) binds each lane on what the trigger job - reads, is not reviewed again, and no leg starts for a pull request with no lane source; a failed - or cancelled review, another head of the same tree, or a failed read reviews again. The diff is + reads, is not reviewed again, and no leg starts for a pull request with no lane source. A verdict + counts there only when its run's main commit has no diff from main's tip over what the review + reads from main (`.github/scripts/pr-review-main/criteria.txt`, which the copy steps also read), + so a verdict judged under other criteria reviews again; a failed or cancelled review, another + head of the same tree, or a failed read, fetch or diff reviews again. The diff is `git diff --text`, so a file git would call binary is shown as text, and a patch that still holds a binary file gets no verdict. A patch over 300000 bytes is split into chunks of at most 300000 bytes, cut at file boundaries with each file whole (`split-diff.py`); each chunk is reviewed by its own run, in From fc619d3eb98888f6a155902a481d322792f687c0 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:23:54 -0500 Subject: [PATCH 4/5] fix(ci): widen pr-review-main's criteria and filter verdict runs before reading them criteria.txt left out main-side inputs that shape what the model reads: the legs' local composite actions (select-trusted-text writes the context file the model reads) and the trusted-actors list. Both are now read rows, which the copy loop skips. The model setting stays out, so a model change alone does not review again. The judged step now drops a record whose run is not this workflow's workflow_run run on main right after reading the run, before the criteria fetch and the artifact download, so no other run's artifact is fetched or unzipped. The tests gain one main commit per criterion kind (the skill's {skill} row, a copy-if-present row, a read row), each of which must review again, and a run of another workflow that must not download its artifact. Each case fails against the mutant it guards. The outage posture audit's line references into pr-review-main.yml point at the current lines again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VcupojVgxFqBnrah9DwFLE --- .github/scripts/pr-review-main/criteria.txt | 15 ++++++--- .../scripts/pr-review-main/workflow.test.mjs | 33 ++++++++++++++++--- .github/workflows/pr-review-main.yml | 8 +++++ docs/outage-posture-audit.md | 18 +++++----- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/.github/scripts/pr-review-main/criteria.txt b/.github/scripts/pr-review-main/criteria.txt index 87ab10ed898..92841c1fe6e 100644 --- a/.github/scripts/pr-review-main/criteria.txt +++ b/.github/scripts/pr-review-main/criteria.txt @@ -1,9 +1,12 @@ # What a pr-review-main review reads from main: the lane's criteria, the -# standards, and the prompt, scripts and workflow that run it. Each line is -# ` []`; {skill} is the -# lane's skill. `copy` must exist, `copy-if-present` may be absent, and `read` -# runs in place from the main checkout. The copy steps copy these; the trigger -# job counts a verdict only when none of them differs from main's tip. +# standards, and the prompt, scripts, actions, trusted actors and workflow +# that run it; the model setting (docs/conventions/pr-pipeline.yaml) is left +# out, so a model change alone does not review again. +# Each line is ` []`; +# {skill} is the lane's skill. `copy` must exist, `copy-if-present` may be +# absent, and `read` runs in place from the main checkout. The copy steps copy +# these; the trigger job counts a verdict only when none of them differs from +# main's tip. copy plugins/review/skills/{skill} review/skills/{skill} copy plugins/review/reference review/reference copy REVIEW.md standards/REVIEW.md @@ -11,4 +14,6 @@ copy docs/standards standards/standards copy-if-present docs/review standards/review copy-if-present .claude/rules standards/rules read .github/scripts/pr-review-main +read .github/actions +read .github/standards/trusted-actors read .github/workflows/pr-review-main.yml diff --git a/.github/scripts/pr-review-main/workflow.test.mjs b/.github/scripts/pr-review-main/workflow.test.mjs index 1631ae64e7b..13b14717d0e 100644 --- a/.github/scripts/pr-review-main/workflow.test.mjs +++ b/.github/scripts/pr-review-main/workflow.test.mjs @@ -1037,7 +1037,9 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const dir = mkdtempSync(path.join(tmpdir(), "pr-review-main-judged-")); try { // main's history: OLD, then CHANGED (REVIEW.md, a criterion, changes), - // then the tip (only a file outside criteria.txt changes). The step's + // then the tip (only a file outside criteria.txt changes). Off the tip, + // one commit per SIDE file changes that criterion alone: the skill (a + // {skill} row), a copy-if-present row and a read row. The step's // checkout is a one-commit clone of the tip, as actions/checkout makes. const gitEnv = { ...process.env, GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1", GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@example.com", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@example.com" }; const git = (...args) => { @@ -1050,18 +1052,27 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, git("-C", origin, "init", "--quiet"); writeFileSync(path.join(origin, ".github", "scripts", "pr-review-main", "criteria.txt"), readFileSync(new URL("./criteria.txt", import.meta.url))); const commit = (file, text) => { + mkdirSync(path.dirname(path.join(origin, file)), { recursive: true }); writeFileSync(path.join(origin, file), text); git("-C", origin, "add", "-A"); git("-C", origin, "commit", "--quiet", "-m", file); return git("-C", origin, "rev-parse", "HEAD"); }; + const SIDE = ["plugins/review/skills/code-review/SKILL.md", "docs/review/x.md", ".github/workflows/pr-review-main.yml"]; const OLD = commit("REVIEW.md", "old criteria\n"); + for (const file of SIDE) commit(file, "criterion\n"); const CHANGED = commit("REVIEW.md", "new criteria\n"); const TIP = commit("notes.txt", "not a criterion\n"); + const trunk = git("-C", origin, "symbolic-ref", "--short", "HEAD"); + const side = SIDE.map((file, i) => { + git("-C", origin, "switch", "--quiet", "-c", `side-${i}`, TIP); + return [file, commit(file, "changed criterion\n")]; + }); + git("-C", origin, "switch", "--quiet", trunk); git("clone", "--quiet", "--depth=1", `file://${origin}`, path.join(dir, ".base")); const has = (sha) => spawnSync("git", ["-C", path.join(dir, ".base"), "cat-file", "-e", `${sha}^{commit}`], { env: gitEnv }).status === 0; assert.ok(!has(CHANGED) && !has(OLD), "the checkout holds the tip alone"); - symlinkSync(new URL("../../../plugins", import.meta.url).pathname, path.join(dir, ".base", "plugins")); + symlinkSync(new URL("../../../plugins/source-control", import.meta.url).pathname, path.join(dir, ".base", "plugins", "source-control")); const bin = path.join(dir, "bin"); const fixtures = path.join(dir, "fixtures"); mkdirSync(bin); @@ -1074,7 +1085,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, chmodSync(path.join(bin, "gh"), 0o755); const key = (url) => url.replace(/[^A-Za-z0-9]/g, "_"); const lanes = ["claude-review", "claude-security-review"]; - const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1, main = TIP } = {}) => { + const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1, main = TIP, workflow = ".github/workflows/pr-review-main.yml" } = {}) => { rmSync(fixtures, { recursive: true, force: true }); mkdirSync(fixtures); lanes.forEach((lane, i) => { @@ -1084,7 +1095,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const runId = 200 + i; const at = (url, body) => writeFileSync(path.join(fixtures, key(url)), typeof body === "string" ? body : JSON.stringify(body)); at(`repos/o/r/actions/artifacts?name=${name}&per_page=100`, { total_count: total, artifacts: [{ id: artifact, name, expired: false, workflow_run: { id: runId } }] }); - at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: ".github/workflows/pr-review-main.yml", event: "workflow_run", head_branch: branch, head_sha: main, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); + at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: workflow, event: "workflow_run", head_branch: branch, head_sha: main, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); const verdict = path.join(dir, "verdict.json"); writeFileSync(verdict, JSON.stringify({ schema: 1, lane, pr: PR, tree: TREE, head_sha: head, findings: 2, critical: 0, max_line_bytes: 80 })); const zipped = spawnSync("python3", ["-I", "-c", "import sys, zipfile; zipfile.ZipFile(sys.argv[1], 'w').write(sys.argv[2], 'verdict.json')", path.join(fixtures, key(`repos/o/r/actions/artifacts/${artifact}/zip`)), verdict], { encoding: "utf8" }); @@ -1139,6 +1150,20 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, assert.equal(stale.out, ""); assert.equal(stale.calls.length, 6, stale.calls.join("\n")); assert.ok(!stale.calls.some((call) => call.includes("/zip")), stale.calls.join("\n")); + // A run whose main commit changes one criterion alone, whatever its row's + // kind, does not count either. + for (const [file, main] of side) { + write({ main }); + const one = runWith(); + assert.equal(one.out, "", file); + assert.equal(one.calls.length, 6, `${file}\n${one.calls.join("\n")}`); + } + // Another workflow's run is dropped before any fetch or download, even + // at the tip. + write({ workflow: ".github/workflows/other.yml" }); + const other = runWith(); + assert.equal(other.out, ""); + assert.equal(other.calls.length, 6, other.calls.join("\n")); // A commit main does not have (the fetch fails), or a run head that is no // SHA: no output, and the step stays green. for (const main of ["d".repeat(40), "main"]) { diff --git a/.github/workflows/pr-review-main.yml b/.github/workflows/pr-review-main.yml index 964be8294c9..62dd71b967e 100644 --- a/.github/workflows/pr-review-main.yml +++ b/.github/workflows/pr-review-main.yml @@ -236,6 +236,14 @@ jobs: while read -r artifact run; do [[ $artifact =~ ^[1-9][0-9]{0,19}$ && $run =~ ^[1-9][0-9]{0,19}$ ]] || unread "the $lane verdict listing" gh api "repos/$GITHUB_REPOSITORY/actions/runs/$run" >"$DIR/run.json" || unread "run $run" + # Only this workflow's main run counts, so no other run's artifact is fetched or unzipped. + rc=0 + jq -e '.path == ".github/workflows/pr-review-main.yml" and .event == "workflow_run" and .head_branch == "main"' "$DIR/run.json" >/dev/null || rc=$? + [ "$rc" -le 1 ] || unread "run $run" + if [ "$rc" = 1 ]; then + echo "run $run is not a pr-review-main run on main; its $lane verdict does not count" + continue + fi sha=$(jq -r '.head_sha' "$DIR/run.json") || unread "run $run" [[ $sha =~ ^[0-9a-f]{40}$ ]] || unread "run $run" if ! criteria_diff "$sha"; then diff --git a/docs/outage-posture-audit.md b/docs/outage-posture-audit.md index f93dcdf6fb9..bb2883eeae4 100644 --- a/docs/outage-posture-audit.md +++ b/docs/outage-posture-audit.md @@ -107,12 +107,12 @@ The lane runs from `.github/workflows/pr-review-hosted.yml`, a caller of the ext | Element | Verdict | Evidence | Why | |---|---|---|---| -| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:271` | The shared client sends up to 4 attempts with equal jitter, and the file-list read is never retried. | -| 2 | gap | `.github/workflows/pr-review-main.yml:271`, `.github/workflows/pr-review-main.yml:1089` | A failed read fails the step, and "no verdict" exits 1. | +| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:307` | The shared client sends up to 4 attempts with equal jitter, and the file-list read is never retried. | +| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1136` | A failed read fails the step, and "no verdict" exits 1. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-hosted.yml:183` | Recovery is a recorded one-time re-run by the reconciler, gated on the status page. That is a re-arm and a status-page trigger. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2738` | A later clean review never clears a CRITICAL check run. | -| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:369` | `check-upstream-status` stops the review with exit 1. | -| 6 | gap | `.github/workflows/pr-review-main.yml:304`, `.github/workflows/pr-review-main.yml:585` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2858` | A later clean review never clears a CRITICAL check run. | +| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:405` | `check-upstream-status` stops the review with exit 1. | +| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:621` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | ## pr-review-security @@ -121,12 +121,12 @@ The lane runs from `.github/workflows/pr-review-security-hosted.yml` and the | Element | Verdict | Evidence | Why | |---|---|---|---| -| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:271` | It shares pr-review's code, so it has the same gap. | -| 2 | gap | `.github/workflows/pr-review-main.yml:271`, `.github/workflows/pr-review-main.yml:1089` | A failed read or "no verdict" makes the run red. | +| 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:307` | It shares pr-review's code, so it has the same gap. | +| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1136` | A failed read or "no verdict" makes the run red. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-security-hosted.yml:188` | Resume depends on the reconciler's status-gated re-run. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2738` | A later complete read never closes a filed CRITICAL count. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2858` | A later complete read never closes a filed CRITICAL count. | | 5 | gap | `.github/workflows/pr-review-security-hosted.yml:173`, `.github/workflows/pr-review-security-hosted.yml:193` | The status page gates the run and turns it red. | -| 6 | gap | `.github/workflows/pr-review-main.yml:304`, `.github/workflows/pr-review-main.yml:585` | Matrix legs run in parallel and repeat the same reads with no `etag`. | +| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:621` | Matrix legs run in parallel and repeat the same reads with no `etag`. | ## pr-verify From e6a70725028ecc1778a5fb04105067c95a497f4d Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:30:21 -0500 Subject: [PATCH 5/5] test(ci): make pr-review-main's judged-head cases fail for the rows they guard The side-file commits landed after OLD, so OLD differed from the tip in those files too and the REVIEW.md case stayed red with the REVIEW.md row gone. They now come first, so OLD differs only in REVIEW.md, and the plugin's reference joins them as a second copy row. The run filter's cases (another workflow, off main, a pull_request event) now assert that no verdict is downloaded, so each fails without its jq clause, not only through the gate's own predicate. The outage posture audit's references point at the line each row claims: the exit 1 with no verdict, the check-run POST, the upstream-outage exit 1 and the legs' file-list read. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VcupojVgxFqBnrah9DwFLE --- .../scripts/pr-review-main/workflow.test.mjs | 31 ++++++++++++------- docs/outage-posture-audit.md | 14 ++++----- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/scripts/pr-review-main/workflow.test.mjs b/.github/scripts/pr-review-main/workflow.test.mjs index 13b14717d0e..c44b28354f1 100644 --- a/.github/scripts/pr-review-main/workflow.test.mjs +++ b/.github/scripts/pr-review-main/workflow.test.mjs @@ -1058,9 +1058,9 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, git("-C", origin, "commit", "--quiet", "-m", file); return git("-C", origin, "rev-parse", "HEAD"); }; - const SIDE = ["plugins/review/skills/code-review/SKILL.md", "docs/review/x.md", ".github/workflows/pr-review-main.yml"]; - const OLD = commit("REVIEW.md", "old criteria\n"); + const SIDE = ["plugins/review/skills/code-review/SKILL.md", "plugins/review/reference/x.md", "docs/review/x.md", ".github/workflows/pr-review-main.yml"]; for (const file of SIDE) commit(file, "criterion\n"); + const OLD = commit("REVIEW.md", "old criteria\n"); const CHANGED = commit("REVIEW.md", "new criteria\n"); const TIP = commit("notes.txt", "not a criterion\n"); const trunk = git("-C", origin, "symbolic-ref", "--short", "HEAD"); @@ -1085,7 +1085,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, chmodSync(path.join(bin, "gh"), 0o755); const key = (url) => url.replace(/[^A-Za-z0-9]/g, "_"); const lanes = ["claude-review", "claude-security-review"]; - const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", total = 1, main = TIP, workflow = ".github/workflows/pr-review-main.yml" } = {}) => { + const write = ({ missing = [], conclusion = "success", head = SHA_A, title = "findings=2 critical=0", branch = "main", event = "workflow_run", total = 1, main = TIP, workflow = ".github/workflows/pr-review-main.yml" } = {}) => { rmSync(fixtures, { recursive: true, force: true }); mkdirSync(fixtures); lanes.forEach((lane, i) => { @@ -1095,7 +1095,7 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, const runId = 200 + i; const at = (url, body) => writeFileSync(path.join(fixtures, key(url)), typeof body === "string" ? body : JSON.stringify(body)); at(`repos/o/r/actions/artifacts?name=${name}&per_page=100`, { total_count: total, artifacts: [{ id: artifact, name, expired: false, workflow_run: { id: runId } }] }); - at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: workflow, event: "workflow_run", head_branch: branch, head_sha: main, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); + at(`repos/o/r/actions/runs/${runId}`, { id: runId, path: workflow, event, head_branch: branch, head_sha: main, status: "completed", conclusion, repository: { full_name: "o/r" }, head_repository: { full_name: "o/r" } }); const verdict = path.join(dir, "verdict.json"); writeFileSync(verdict, JSON.stringify({ schema: 1, lane, pr: PR, tree: TREE, head_sha: head, findings: 2, critical: 0, max_line_bytes: 80 })); const zipped = spawnSync("python3", ["-I", "-c", "import sys, zipfile; zipfile.ZipFile(sys.argv[1], 'w').write(sys.argv[2], 'verdict.json')", path.join(fixtures, key(`repos/o/r/actions/artifacts/${artifact}/zip`)), verdict], { encoding: "utf8" }); @@ -1122,13 +1122,12 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, // Per lane: the listing, the run, the zip and the head's check runs. assert.equal(judged.calls.length, 8, judged.calls.join("\n")); // A run that did not succeed, a verdict for another head of the tree, a - // record whose counts differ, a run off main, a lane with no verdict, a + // record whose counts differ, a lane with no verdict, a // listing past one page: no output, so the review runs. for (const [why, setup] of [ ["failed run", { conclusion: "failure" }], ["other head", { head: SHA_B }], ["counts differ", { title: "findings=3 critical=0" }], - ["off main", { branch: "feature" }], ["security lane unreviewed", { missing: ["claude-security-review"] }], ["more than one page", { total: 101 }], ]) { @@ -1158,12 +1157,20 @@ test("a head both lanes reviewed in a successful main run, recorded on the head, assert.equal(one.out, "", file); assert.equal(one.calls.length, 6, `${file}\n${one.calls.join("\n")}`); } - // Another workflow's run is dropped before any fetch or download, even - // at the tip. - write({ workflow: ".github/workflows/other.yml" }); - const other = runWith(); - assert.equal(other.out, ""); - assert.equal(other.calls.length, 6, other.calls.join("\n")); + // A run of another workflow, off main, or for another event is dropped + // before any fetch or download, even at the tip: per lane, the listing, + // the run and the check runs. + for (const [why, setup] of [ + ["other workflow", { workflow: ".github/workflows/other.yml" }], + ["off main", { branch: "feature" }], + ["pull_request event", { event: "pull_request" }], + ]) { + write(setup); + const other = runWith(); + assert.equal(other.out, "", why); + assert.equal(other.calls.length, 6, `${why}\n${other.calls.join("\n")}`); + assert.ok(!other.calls.some((call) => call.includes("/zip")), why); + } // A commit main does not have (the fetch fails), or a run head that is no // SHA: no output, and the step stays green. for (const main of ["d".repeat(40), "main"]) { diff --git a/docs/outage-posture-audit.md b/docs/outage-posture-audit.md index bb2883eeae4..0a8a6332836 100644 --- a/docs/outage-posture-audit.md +++ b/docs/outage-posture-audit.md @@ -108,11 +108,11 @@ The lane runs from `.github/workflows/pr-review-hosted.yml`, a caller of the ext | Element | Verdict | Evidence | Why | |---|---|---|---| | 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:307` | The shared client sends up to 4 attempts with equal jitter, and the file-list read is never retried. | -| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1136` | A failed read fails the step, and "no verdict" exits 1. | +| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1139` | A failed read fails the step, and "no verdict" exits 1. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-hosted.yml:183` | Recovery is a recorded one-time re-run by the reconciler, gated on the status page. That is a re-arm and a status-page trigger. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2858` | A later clean review never clears a CRITICAL check run. | -| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:405` | `check-upstream-status` stops the review with exit 1. | -| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:621` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2874` | A later clean review never clears a CRITICAL check run. | +| 5 | gap | `.github/workflows/pr-review-hosted.yml:168`, `.github/workflows/pr-review-main.yml:426` | `check-upstream-status` stops the review with exit 1. | +| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:457` | Matrix legs run in parallel and repeat the same PR reads with no `etag`. Concurrency per PR is fine. | ## pr-review-security @@ -122,11 +122,11 @@ The lane runs from `.github/workflows/pr-review-security-hosted.yml` and the | Element | Verdict | Evidence | Why | |---|---|---|---| | 1 | gap | `.github/actions/check-trusted-trigger/check-trusted-trigger.mjs:145`, `.github/workflows/pr-review-main.yml:307` | It shares pr-review's code, so it has the same gap. | -| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1136` | A failed read or "no verdict" makes the run red. | +| 2 | gap | `.github/workflows/pr-review-main.yml:307`, `.github/workflows/pr-review-main.yml:1139` | A failed read or "no verdict" makes the run red. | | 3 | gap | `.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:79`, `.github/workflows/pr-review-security-hosted.yml:188` | Resume depends on the reconciler's status-gated re-run. | -| 4 | gap | `.github/workflows/pr-review-main.yml:2858` | A later complete read never closes a filed CRITICAL count. | +| 4 | gap | `.github/workflows/pr-review-main.yml:2874` | A later complete read never closes a filed CRITICAL count. | | 5 | gap | `.github/workflows/pr-review-security-hosted.yml:173`, `.github/workflows/pr-review-security-hosted.yml:193` | The status page gates the run and turns it red. | -| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:621` | Matrix legs run in parallel and repeat the same reads with no `etag`. | +| 6 | gap | `.github/workflows/pr-review-main.yml:340`, `.github/workflows/pr-review-main.yml:457` | Matrix legs run in parallel and repeat the same reads with no `etag`. | ## pr-verify