From c12b4880a4fdac6377191fc65d02650d15de7a28 Mon Sep 17 00:00:00 2001 From: Garret Premo Date: Mon, 19 Oct 2026 14:39:13 -0400 Subject: [PATCH 1/2] chore: take back stranded `review in progress` and never wait on CI (#178) A review-issue cron run that died before posting a verdict (timeout, crash) left the PR labeled `review in progress`, which find-review-candidate.sh never selected again. - find-review-candidate.sh takes a stale `review in progress` back once its label is older than the new [stale-after-seconds] argument (default 900). It allows at most one take-back per head commit, counted from `labeled` events after the head commit or the last reset to `needs review`. - It defers PRs whose head check runs haven't completed and moves on to the next PR. - Issue-events lookups (including the existing `changes requested` one) now read every page. - New pending-checks.sh prints the number of pending check runs. Both the candidate query and the skill's cron-mode CI check use it, so the two can't disagree. - set-review-label.sh re-applies `review in progress` even when it's already present, so each attempt leaves a `labeled` event. - review-issue SKILL.md and the job's append_system_prompt now say never to wait for CI: if checks are pending, set `needs review` and stop. The job also disallows ScheduleWakeup and Monitor. - Tests use a fake gh driven by a JSON fixture. --- .claude-jobs/review-issue.yaml | 26 +- .claude/skills/review-issue/SKILL.md | 4 + .../scripts/find-review-candidate.sh | 124 +++++- .../review-issue/scripts/pending-checks.sh | 32 ++ .../review-issue/scripts/set-review-label.sh | 10 + tests/find-review-candidate.test.ts | 354 ++++++++++++++++++ tests/fixtures/fake-gh-review.sh | 167 +++++++++ tests/fixtures/fake-gh-review.ts | 185 +++++++++ tests/pending-checks.test.ts | 86 +++++ tests/set-review-label.test.ts | 55 +++ 10 files changed, 1021 insertions(+), 22 deletions(-) create mode 100755 .claude/skills/review-issue/scripts/pending-checks.sh create mode 100644 tests/find-review-candidate.test.ts create mode 100755 tests/fixtures/fake-gh-review.sh create mode 100644 tests/fixtures/fake-gh-review.ts create mode 100644 tests/pending-checks.test.ts create mode 100644 tests/set-review-label.test.ts diff --git a/.claude-jobs/review-issue.yaml b/.claude-jobs/review-issue.yaml index 34435e6..0478661 100644 --- a/.claude-jobs/review-issue.yaml +++ b/.claude-jobs/review-issue.yaml @@ -5,13 +5,16 @@ schedule: "*/5 * * * *" enabled: true auth: subscription +# The 900 passed to find-review-candidate.sh is how long (in seconds) a +# `review in progress` label must sit before the PR is taken back from a dead +# run. Keep it above `timeout` below, and keep both call sites in step. preflight: - run: .claude/skills/review-issue/scripts/find-review-candidate.sh > /dev/null + run: .claude/skills/review-issue/scripts/find-review-candidate.sh 900 > /dev/null timeout: 30s claude: prompt_cmd: | - pr=$(.claude/skills/review-issue/scripts/find-review-candidate.sh) + pr=$(.claude/skills/review-issue/scripts/find-review-candidate.sh 900) echo "/review-issue $pr" append_system_prompt: | @@ -24,6 +27,18 @@ claude: to other skills like next-deployer. If the skill suggests merging or handing off, skip those steps and exit. + Never wait for CI. This run is killed at its timeout, and a wait throws + the finished review away. Right before deciding, run + `.claude/skills/review-issue/scripts/pending-checks.sh ` once, + instead of reading `gh pr checks`; it prints how many check runs have + not completed. If that's more than 0, or the script fails without + printing a number, post nothing, set the label back to `needs review` + with set-review-label.sh, and stop (skill step 4, + "Cron mode"). If it prints 0, decide normally: zero check runs, and + checks that finished as failed, skipped or cancelled, are not pending. + No `gh pr checks --watch`, sleep or poll loops, background watchers, + Monitor, or ScheduleWakeup. + allowed_tools: - "Bash(gh pr view*)" - "Bash(gh pr list*)" @@ -35,6 +50,7 @@ claude: - "Bash(.claude/skills/review-issue/scripts/set-review-label.sh*)" - "Bash(.claude/skills/review-issue/scripts/ensure-review-labels.sh*)" - "Bash(.claude/skills/review-issue/scripts/post-review.sh*)" + - "Bash(.claude/skills/review-issue/scripts/pending-checks.sh*)" # Write is allowed so the agent can produce the review-body file that # post-review.sh consumes (avoids the backtick-escaping artifact that # happens when markdown is shoved into `gh pr review --body "..."`). @@ -48,6 +64,12 @@ claude: - "Read" - "Grep" + # A one-shot cron run can't be woken up later or wait out CI, so these can + # only strand the review (#178). + disallowed_tools: + - "ScheduleWakeup" + - "Monitor" + permission_mode: auto cwd: "." diff --git a/.claude/skills/review-issue/SKILL.md b/.claude/skills/review-issue/SKILL.md index fd411b3..72089a2 100644 --- a/.claude/skills/review-issue/SKILL.md +++ b/.claude/skills/review-issue/SKILL.md @@ -48,6 +48,8 @@ Move the PR into the "review in progress" state. This single call removes any of .claude/skills/review-issue/scripts/set-review-label.sh "review in progress" ``` +Run it even when the PR already shows `review in progress`. That means an earlier review died before posting a verdict and the cron took the PR back. The script re-applies the label so this attempt is recorded, which is how the cron knows not to take the PR back a second time. + ### 2. Establish acceptance criteria - **Explicit** — issue lists them → use those @@ -73,6 +75,8 @@ Skill(skill="superpowers:requesting-code-review") ### 4. Decide +> **Cron mode:** when running non-interactively, never wait for CI. Run `.claude/skills/review-issue/scripts/pending-checks.sh ` once, right before deciding; use it instead of reading `gh pr checks`. It prints how many check runs on the head commit have not completed. If that's more than 0, or the script fails without printing a number, post nothing, move the label back with `.claude/skills/review-issue/scripts/set-review-label.sh "needs review"`, and stop. The cron skips PRs with pending checks (using the same script), so the next run picks this one up after CI finishes. If it prints 0, nothing is pending, so decide normally. That includes a PR with no check runs at all (`gh pr checks` then says "no checks reported") and checks that finished as failed, skipped or cancelled. A failed check is a review finding, not a reason to wait. Don't use `gh pr checks --watch`, sleep or poll loops, background watchers, `Monitor`, or `ScheduleWakeup`: the run is killed at the job's timeout and the finished review is lost. + **If ANY blocking issue is found OR any acceptance criterion is unmet:** Build the review body using GitHub-flavored markdown. Blocking items appear at the top; non-blocking observations and nits are hidden in collapsible `
` blocks. Omit any section that has no items. diff --git a/.claude/skills/review-issue/scripts/find-review-candidate.sh b/.claude/skills/review-issue/scripts/find-review-candidate.sh index 39ff252..1a10f6b 100755 --- a/.claude/skills/review-issue/scripts/find-review-candidate.sh +++ b/.claude/skills/review-issue/scripts/find-review-candidate.sh @@ -5,19 +5,57 @@ # - labeled `needs review`, or # - labeled `changes requested` AND at least one commit has been pushed to # the PR head after the `changes requested` label was applied (i.e., the -# author has responded to feedback and the PR is ready for re-review). +# author has responded to feedback and the PR is ready for re-review), or +# - labeled `review in progress` AND the label was applied more than +# stale-after seconds ago (the run that applied it died without posting a +# verdict). Taken back at most once per head commit, so a review that dies +# every time isn't retried forever; a new commit or a reset to +# `needs review` re-arms it. +# +# ...and every check run on the PR's head commit has completed (see +# pending-checks.sh). A pending PR is deferred, not dropped: the script moves +# on to the next PR, and the deferred one qualifies on the first tick after its +# checks finish. A review can't pass without green CI, so a run started +# earlier could only wait out its timeout. # # Skips PRs labeled `first pass reviewed` or `approved` — those belong to the # final-review cron or are already done. # # Exits 0 with the PR number on stdout when a candidate is found. -# Exits 1 silently when nothing is ready. +# Exits 1 when nothing is ready. Deferred and capped PRs are noted on stderr. +# +# Usage: find-review-candidate.sh [stale-after-seconds] +# Defaults to 900 (15 minutes). The cron's overlap lock already keeps a live +# review-issue run from being taken back; the threshold protects interactive +# `/review-issue` sessions, so keep it above the job's `timeout`. set -euo pipefail source "$(git rev-parse --show-toplevel)/scripts/gh-pin-account.sh" +stale_after="${1:-900}" +if ! [[ "$stale_after" =~ ^[0-9]+$ ]]; then + echo "usage: $0 [stale-after-seconds]" >&2 + exit 2 +fi + repo="normalled/apijack" +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +now=$(date -u +%s) + +# Every `labeled` event on PR $1 as "