From 4b6b566642d41e2b84461d2bc2001aa2eaa7c9d5 Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Thu, 16 Jul 2026 00:56:33 -0600 Subject: [PATCH 1/2] fix(ci): skip automated Claude review for trivial/docs-only PRs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit automated-review ran an unconditional, deliberately expensive Claude review (root-cause analysis, backlog compliance grading, etc.) on every human- authored PR — 271 in the last 30 days, no size or scope gating. Unlike the GitHub Actions compute discussed elsewhere in this cost-reduction effort, this is real, non-discounted Anthropic API spend. Add a detect-trivial-pr job that skips the review for docs-only diffs and single-file diffs under 5 changed lines, while failing open (still reviewing) if the detector itself fails or is inconclusive — a broken detector can't silently wave through a substantive PR. --- .github/workflows/claude.yml | 55 +++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 25a3c6355..ea64116d8 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -13,9 +13,62 @@ on: types: [submitted] jobs: - automated-review: + detect-trivial-pr: + name: Detect trivial PR diff if: github.event_name == 'pull_request' && github.event.pull_request.user.type != 'Bot' runs-on: ubuntu-latest + permissions: + contents: read + outputs: + trivial: ${{ steps.check.outputs.trivial }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Check whether this diff needs a full review + id: check + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: | + if [ -z "$BASE_SHA" ] || ! git cat-file -e "$BASE_SHA" 2>/dev/null; then + echo "No usable base SHA — treating as non-trivial to be safe" + echo "trivial=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + CHANGED_FILES=$(git diff --name-only "$BASE_SHA" HEAD) + NUM_FILES=$(printf '%s\n' "$CHANGED_FILES" | grep -c . || true) + + # Docs-only: every changed file is markdown, LICENSE, or under docs/. + NON_DOCS=$(printf '%s\n' "$CHANGED_FILES" | grep -vE '(\.md$|^LICENSE$|^docs/)' | grep -c . || true) + if [ "$NON_DOCS" -eq 0 ]; then + echo "Docs-only diff (${NUM_FILES} file(s)) — skipping automated review" + echo "trivial=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + + TOTAL_CHANGED=$(git diff --numstat "$BASE_SHA" HEAD | awk '{a+=$1; d+=$2} END {print a+d+0}') + if [ "$NUM_FILES" -le 1 ] && [ "${TOTAL_CHANGED:-0}" -le 5 ]; then + echo "Trivial single-file diff (${TOTAL_CHANGED} line(s)) — skipping automated review" + echo "trivial=true" >> "$GITHUB_OUTPUT" + else + echo "Substantive diff (${NUM_FILES} file(s), ${TOTAL_CHANGED} line(s)) — running automated review" + echo "trivial=false" >> "$GITHUB_OUTPUT" + fi + + automated-review: + needs: detect-trivial-pr + # Fail open toward reviewing: only skip when detect-trivial-pr positively + # confirmed a trivial diff. Any other outcome (failure, skip for a + # non-PR event) still reviews, so a broken detector can't silently wave + # through a substantive PR. + if: | + always() && + github.event_name == 'pull_request' && + github.event.pull_request.user.type != 'Bot' && + (needs.detect-trivial-pr.result != 'success' || needs.detect-trivial-pr.outputs.trivial != 'true') + runs-on: ubuntu-latest concurrency: group: claude-review-${{ github.event.pull_request.number }} cancel-in-progress: true From 0e83d24ec61f6980287cc130d40f9b7ce9cc88ed Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Thu, 16 Jul 2026 01:33:59 -0600 Subject: [PATCH 2/2] fix: count binary-file diffs as non-trivial in detect-trivial-pr (#2117) git diff --numstat prints "-\t-\t" for binary files, which awk silently coerces to 0 in arithmetic. A single-file binary-only change was therefore counted as 0 lines and could pass the trivial guard, skipping the automated review. Detect the "-" sentinel explicitly and force TOTAL_CHANGED to a value above the threshold when any binary entry is present. --- .github/workflows/claude.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index ea64116d8..d1ecb89d0 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -48,7 +48,14 @@ jobs: exit 0 fi - TOTAL_CHANGED=$(git diff --numstat "$BASE_SHA" HEAD | awk '{a+=$1; d+=$2} END {print a+d+0}') + # git diff --numstat prints "-\t-\t" for binary files. Detect + # that explicitly and force a high sentinel so a binary-only change + # can't be silently counted as 0 lines and waved through as trivial. + TOTAL_CHANGED=$(git diff --numstat "$BASE_SHA" HEAD | awk ' + $1 == "-" || $2 == "-" { binary=1; next } + { a += $1; d += $2 } + END { if (binary) print 999999; else print a + d + 0 } + ') if [ "$NUM_FILES" -le 1 ] && [ "${TOTAL_CHANGED:-0}" -le 5 ]; then echo "Trivial single-file diff (${TOTAL_CHANGED} line(s)) — skipping automated review" echo "trivial=true" >> "$GITHUB_OUTPUT"