diff --git a/.claude-jobs/review-issue.yaml b/.claude-jobs/review-issue.yaml index 34435e6..a162ab2 100644 --- a/.claude-jobs/review-issue.yaml +++ b/.claude-jobs/review-issue.yaml @@ -5,13 +5,17 @@ schedule: "*/5 * * * *" enabled: true auth: subscription +# The 1800 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: `timeout` below plus 5 minutes. Keep it above `timeout`, and keep both +# call sites in step with each other and with the script's default and header. preflight: - run: .claude/skills/review-issue/scripts/find-review-candidate.sh > /dev/null + run: .claude/skills/review-issue/scripts/find-review-candidate.sh 1800 > /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 1800) echo "/review-issue $pr" append_system_prompt: | @@ -24,6 +28,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 +51,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,10 +65,18 @@ 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: "." -timeout: 10m +# A full review of a medium-sized PR, including the second-opinion reviewer +# subagent, takes well over 10 minutes (#178). +timeout: 25m logging: retention_days: 30 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..b0bbc4e 100755 --- a/.claude/skills/review-issue/scripts/find-review-candidate.sh +++ b/.claude/skills/review-issue/scripts/find-review-candidate.sh @@ -5,19 +5,58 @@ # - 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 1800 (30 minutes): the review-issue job's 25-minute `timeout` +# plus 5 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:-1800}" +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 "