From 36c866010e852c5330e77274c20ed3578d2ddcbc Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Tue, 1 Dec 2026 00:21:02 +0800 Subject: [PATCH 1/2] Ask the check run when a verdict's reply is lost GitHub appends a patch's annotations, so resending a verdict whose report was lost would post every finding twice. The publisher now reads the check run instead: completed means the update landed, anything else is failure. --- scripts/publish-check.sh | 8 +++++++- scripts/recovery.test.ts | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/publish-check.sh b/scripts/publish-check.sh index 3a33b95..4fa4143 100644 --- a/scripts/publish-check.sh +++ b/scripts/publish-check.sh @@ -56,4 +56,10 @@ output: { # Annotations and the PR summary describe the tree the review actually reached, which a CI autofix can move past this head. summary: (if $here then ($review | summary_line($commit.conclusion)) else commit_summary($commit.conclusion) end), annotations: (if $here then [$review.annotations[:50][] | {path, start_line: .line, end_line: .line, annotation_level: .level, message}] else [] end) -}}' | bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID -X PATCH --input - +}}' | bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID -X PATCH --input - || { + # retry.sh never replays a write whose reply was lost, and it must not here: GitHub appends a + # patch's annotations to the ones already on the check run, so a resend would post every finding twice. + # The verdict is only unknown, not necessarily unapplied, so ask the check run itself. + landed=$(bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api "repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID" --jq '.status == "completed"' { + for (const landed of [true, false]) { + const setup = fixture(); + executable(setup.dir, "git", "#!/bin/sh\nprintf 'head\\n'\n"); + executable(setup.dir, "sleep", "#!/bin/sh\nexit 0\n"); + executable(setup.dir, "gh", `#!/bin/sh +case "$*" in + *'/pulls/7 --jq .head.sha'*) printf 'head\\n' ;; + *'/check-runs/10 -X PATCH'*) printf 'Patch "https://api.github.com/repos/owner/repo/check-runs/10": EOF\\n' >&2; exit 1 ;; + *'/check-runs/10 --jq'*) printf '${landed}\\n' ;; + *) exit 1 ;; +esac +`); + writeFileSync(join(setup.dir, "review.json"), JSON.stringify({ summary: "Reviewed", commits: [{ sha: "head", conclusion: "success" }], annotations: [{ path: "a.ts", line: 1, level: "warning", message: "Check this" }] })); + const result = run("Publish check run", setup, { GH_TOKEN: "" }); + // A lost reply never resends: GitHub appends the annotations a second patch carries. + expect(result.exitCode).toBe(landed ? 0 : 1); + expect(result.stdout.toString()).not.toContain("a.ts"); + } +}); + test("a hosted review closes its own check without publishing a verdict", () => { const setup = fixture(); executable(setup.dir, "git", "#!/bin/sh\nprintf 'head\\n'\n"); From 8c2569417f73dc0cecebdf820d75ec37da9403b0 Mon Sep 17 00:00:00 2001 From: "muspi-merol-review[bot]" <349105566+muspi-merol-review[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:24:43 +0000 Subject: [PATCH 2/2] Assert that a lost verdict reply sends one annotated patch --- scripts/recovery.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/recovery.test.ts b/scripts/recovery.test.ts index b0bb282..2701489 100644 --- a/scripts/recovery.test.ts +++ b/scripts/recovery.test.ts @@ -683,8 +683,8 @@ test("a check run that took the verdict keeps it when its reply is lost", () => executable(setup.dir, "gh", `#!/bin/sh case "$*" in *'/pulls/7 --jq .head.sha'*) printf 'head\\n' ;; - *'/check-runs/10 -X PATCH'*) printf 'Patch "https://api.github.com/repos/owner/repo/check-runs/10": EOF\\n' >&2; exit 1 ;; - *'/check-runs/10 --jq'*) printf '${landed}\\n' ;; + *'/check-runs/10 -X PATCH'*) jq -c . >> "$RUNNER_TEMP/patches.jsonl"; printf 'Patch "https://api.github.com/repos/owner/repo/check-runs/10": EOF\\n' >&2; exit 1 ;; + *'/check-runs/10 --jq'*) printf '%s\\n' '{"status":"${landed ? "completed" : "in_progress"}"}' | jq -r "$4" ;; *) exit 1 ;; esac `); @@ -692,7 +692,9 @@ esac const result = run("Publish check run", setup, { GH_TOKEN: "" }); // A lost reply never resends: GitHub appends the annotations a second patch carries. expect(result.exitCode).toBe(landed ? 0 : 1); - expect(result.stdout.toString()).not.toContain("a.ts"); + const patches = readFileSync(join(setup.dir, "patches.jsonl"), "utf8").trim().split("\n").map(line => JSON.parse(line)); + expect(patches).toHaveLength(1); + expect(patches[0].output.annotations).toEqual([{ path: "a.ts", start_line: 1, end_line: 1, annotation_level: "warning", message: "Check this" }]); } });