From 1baf5e903c0fc753e6bf4046643d7c642dbb2d28 Mon Sep 17 00:00:00 2001 From: pb <5535435+pekth@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:06:51 -0500 Subject: [PATCH 1/2] fix(closure-comment): skip a superseded closure event If one person closes without a comment and another reopens, comments and closes before the first run starts, the first run reopened the valid later closure. Skip when the item's current state is not closed at the event's closed_at. Found by CodeRabbit on tilorahdotco/meterusage#135. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/closure-comment.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/closure-comment.yml b/.github/workflows/closure-comment.yml index b9ffdf3..e1687be 100644 --- a/.github/workflows/closure-comment.yml +++ b/.github/workflows/closure-comment.yml @@ -60,6 +60,15 @@ jobs: *"[bot]") echo "skip: closed by $CLOSER"; exit 0 ;; esac + # Skip a superseded event: if the item was reopened, or closed again later, since + # this closure, a newer run owns the newer state. Without this, a delayed run could + # reopen someone else's valid closure. + current=$(gh api "repos/$REPO/issues/$NUMBER" --jq '[.state, (.closed_at // "")] | join(" ")') + if [ "$current" != "closed $CLOSED_AT" ]; then + echo "skip: state is now '$current', not the closure at $CLOSED_AT" + exit 0 + fi + if [ "$KIND" = "issue" ]; then # Closed by a merged pull request or a commit: the PR is the record. Ask GraphQL # for the closer: the REST timeline leaves commit_id and source empty when a From e8f427a13632832c2ce524e9b615cff273f826ee Mon Sep 17 00:00:00 2001 From: pb <5535435+pekth@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:12:35 -0500 Subject: [PATCH 2/2] fix(closure-comment): check the closure state right before the reopen CodeRabbit: a later closure during the other API calls made the early snapshot stale. One check, placed just before the action, covers that. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/closure-comment.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/closure-comment.yml b/.github/workflows/closure-comment.yml index e1687be..63bb394 100644 --- a/.github/workflows/closure-comment.yml +++ b/.github/workflows/closure-comment.yml @@ -60,15 +60,6 @@ jobs: *"[bot]") echo "skip: closed by $CLOSER"; exit 0 ;; esac - # Skip a superseded event: if the item was reopened, or closed again later, since - # this closure, a newer run owns the newer state. Without this, a delayed run could - # reopen someone else's valid closure. - current=$(gh api "repos/$REPO/issues/$NUMBER" --jq '[.state, (.closed_at // "")] | join(" ")') - if [ "$current" != "closed $CLOSED_AT" ]; then - echo "skip: state is now '$current', not the closure at $CLOSED_AT" - exit 0 - fi - if [ "$KIND" = "issue" ]; then # Closed by a merged pull request or a commit: the PR is the record. Ask GraphQL # for the closer: the REST timeline leaves commit_id and source empty when a @@ -133,6 +124,16 @@ jobs: See ${GUIDE:-CONTRIBUTING.md}." + # Skip a superseded event, checked right before the reopen: if the item was reopened, + # or closed again, since this closure, a newer run owns the newer state. Without this, + # a delayed run could reopen someone else's valid closure. A closure in the second + # between this read and the reopen is not covered; its own run then asks again. + current=$(gh api "repos/$REPO/issues/$NUMBER" --jq '[.state, (.closed_at // "")] | join(" ")') + if [ "$current" != "closed $CLOSED_AT" ]; then + echo "skip: state is now '$current', not the closure at $CLOSED_AT" + exit 0 + fi + if [ "$KIND" = "pr" ]; then gh pr reopen "$NUMBER" -R "$REPO" else