fix(code-review): post review comment deterministically#26
Open
Satendra-SR wants to merge 1 commit into
Open
Conversation
In agent mode (the auto-detected mode for label-triggered reviews), claude-code-action does not manage a PR comment. Whether a review comment appeared therefore depended on Claude voluntarily running `gh pr comment` as its final step. Most runs did; some did not — those only wrote the review to the Actions step summary and left the PR with no comment (observed on dost-ai-voicebot #21). Make posting deterministic: - Reframe the prompt so Claude returns the review as its final message rather than instructing it to post a comment itself. - Drop `gh pr comment` from the model's allowed-tools (prevents a duplicate comment now that the workflow posts). - Add a "Post review comment" step that reads the action's execution_file output, extracts the final result, and publishes it as one PR comment using the action's github_token (keeps claude[bot] authorship). Honors use_sticky_comment by updating the same comment on re-runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The automated code review reusable workflow is flaky about whether it actually posts a PR comment. On
dost-ai-voicebot#21 the review ran successfully but never appeared on the PR — it only landed in the Actions step summary. The same workflow posts fine on other repos (admindashboard#1935,iages-backend#936).Root cause, confirmed by reading the run logs on all three repos:
claude-code-actionas agent mode (Auto-detected mode: agent).use_sticky_commentis effectively a no-op. There is no action step that posts the review.gh pr comment(it's in--allowed-tools, and the prompt asked for it).gh pr comment?Same caller workflow, same
@mainreusable workflow, same action version, sameclaude[bot]auth on every repo. The difference was a single non-deterministic model decision per run. (Re-applying the label on #21 produced a run where the model did post — confirming it's run-to-run flakiness, not a repo misconfiguration.)Fix
Stop leaving the comment to the model's discretion:
Bash(gh pr comment:*)from the default allowed-tools, so we don't get a duplicate comment now that the workflow posts.Post review commentstep that reads the action'sexecution_fileoutput, extracts the finalresult, and publishes it as one PR comment via the action'sgithub_tokenoutput (preservesclaude[bot]authorship). It honorsuse_sticky_commentby updating the same marked comment on re-runs.Net effect: "the model usually posts" → "the workflow always posts."
Notes / risk
@main.execution_fileandgithub_tokenare documented outputs ofanthropics/claude-code-action@v1.0.8(already pinned here).if: always() && execution_file != '' && pull_request.numberso it still runs if Claude's turn ends without an error, and no-ops cleanly when there's no result text.github.tokenif the App token output is empty.🤖 Generated with Claude Code