From 5493b0c3584b6e995458e879cbbbea847f163939 Mon Sep 17 00:00:00 2001 From: Tom Riglar Date: Tue, 6 Oct 2026 17:31:56 +0100 Subject: [PATCH] ci(claude-review): keep the review in the foreground and fail if nothing is posted Headless runs can background the bug-review subagents and end the turn to 'wait' for them. In -p mode that ends the session, so no comment is posted and the job still goes green. Port of devicecloud-dev/dcd#1536. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude-code-review.yml | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 3f0740f..1e27862 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -32,6 +32,9 @@ jobs: id-token: write steps: + - name: Record start time + run: echo "REVIEW_STARTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_ENV" + - name: Checkout repository uses: actions/checkout@v7 with: @@ -55,7 +58,29 @@ jobs: # doesn't reach the inline-comment MCP tool: PR #9's review hit 46 # permission denials and posted nothing despite finding issues. claude_args: | - --model claude-opus-5-5 --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)" + --model claude-opus-5-5 --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)" --append-system-prompt "You are running non-interactively. Never run subagents in the background and never schedule wakeups: ending your turn ends the session. Wait for every reviewer to finish, then post the review comment before you stop." # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md # or https://code.claude.com/docs/en/cli-reference for available options + # The action exits green even when Claude ends its turn before posting + # anything (e.g. it backgrounded its reviewer subagents and stopped to + # "wait" for them). Fail loudly instead of leaving a silent green check. + - name: Check a review comment was posted + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR: ${{ github.event.pull_request.number }} + run: | + count=$( + { + gh api "repos/$REPO/issues/$PR/comments" --paginate \ + --jq ".[] | select(.user.login == \"claude[bot]\" and .created_at >= \"$REVIEW_STARTED_AT\") | .id" + gh api "repos/$REPO/pulls/$PR/comments" --paginate \ + --jq ".[] | select(.user.login == \"claude[bot]\" and .created_at >= \"$REVIEW_STARTED_AT\") | .id" + } | wc -l + ) + if [ "$count" -eq 0 ]; then + echo "::error::Claude finished without posting a review comment on this PR." + exit 1 + fi + echo "Claude posted $count comment(s)."