Skip to content

fix(ci): skip automated Claude review for trivial/docs-only PRs - #2117

Merged
carlos-alm merged 4 commits into
mainfrom
fix/gate-claude-automated-review
Jul 17, 2026
Merged

carlos-alm merged 4 commits into
mainfrom
fix/gate-claude-automated-review

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • `automated-review` in `claude.yml` ran a full, deliberately strict Claude review (root-cause analysis, backlog compliance grading against `BACKLOG.md`/`FOUNDATION.md`, etc.) on every PR opened by a non-bot user, unconditionally — 271 PRs in the last 30 days, no size or scope gating
  • Added a `detect-trivial-pr` job that skips the review when the diff is docs-only (every changed file is markdown, `LICENSE`, or under `docs/`) or a single-file diff of 5 lines or fewer
  • Fails open toward reviewing: if the detector can't resolve a usable base SHA, or fails outright, the review still runs — a broken detector can't silently wave through a substantive PR

Why

Part of the broader CI/CD cost-reduction effort (#2108), but distinct from the rest: this is the one confirmed non-discounted cost in that effort. Everything else in this effort is GitHub Actions compute, which is free for this public repo (100% discounted on the actual bill) — this job calls the Anthropic API directly (`anthropic_api_key: secrets.ANTHROPIC_API_KEY`) and that spend is real regardless of repo visibility.

Closes #2112

Test plan

  • YAML parses, `actionlint` reports zero findings
  • Verified the docs-only/non-docs classification logic against synthetic file lists (docs-only, mixed, single-source-file, empty) — all classify correctly
  • Verified the line-count logic (`git diff --numstat` + awk) against a real diff in this repo
  • Next docs-only PR should show `detect-trivial-pr` marking it trivial and `automated-review` skipped
  • Next substantive PR should show `automated-review` still running as before

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.
@greptile-apps

greptile-apps Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR gates the costly automated-review job behind a new detect-trivial-pr job that skips the Anthropic API call for docs-only diffs (every changed file is markdown, LICENSE, or under docs/) or single-file changes of ≤ 5 lines. The detector fails open: any result other than a positive trivial=true leaves the review enabled.

  • detect-trivial-pr job: classifies the diff with git diff --name-only + git diff --numstat, with an awk guard that forces TOTAL_CHANGED=999999 when any binary file is present, preventing silent zero-line miscounting.
  • automated-review condition: uses always() so the review still runs when the detector is skipped (non-PR events) or fails, satisfying the fail-open requirement.
  • Scope: only pull_request: [opened] events are affected; interactive-claude and review-comment flows are unchanged.

Confidence Score: 5/5

Safe to merge — the detector fails open so no substantive PR can silently bypass review, and the binary-sentinel fix prevents the previously identified zero-line miscounting.

The change is purely additive CI gating. The fail-open design (always() + condition that only skips on confirmed trivial=true) means a broken or skipped detector never silently waives the review. Binary files, empty diffs, and missing base SHAs are all handled conservatively. No application logic is touched.

No files require special attention.

Important Files Changed

Filename Overview
.github/workflows/claude.yml Adds detect-trivial-pr gating job with docs-only and single-file/5-line heuristics; fail-open design and binary-sentinel fix are both correctly implemented

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant GH as GitHub (pull_request: opened)
    participant DT as detect-trivial-pr
    participant AR as automated-review
    participant API as Anthropic API

    GH->>DT: trigger (non-Bot PR)
    DT->>DT: git diff --name-only BASE_SHA HEAD
    alt docs-only diff
        DT-->>AR: "trivial=true"
    else single file with binary
        Note over DT: TOTAL_CHANGED=999999
        DT-->>AR: "trivial=false"
    else single file 5 lines or fewer
        DT-->>AR: "trivial=true"
    else multi-file / large diff
        DT-->>AR: "trivial=false"
    else detector fails / no usable SHA
        DT-->>AR: "result != success (fail-open)"
    end

    alt "trivial=true confirmed"
        AR-->>GH: skip (no API call)
    else any other outcome
        AR->>API: Claude review prompt
        API-->>AR: review comments
        AR-->>GH: post review
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant GH as GitHub (pull_request: opened)
    participant DT as detect-trivial-pr
    participant AR as automated-review
    participant API as Anthropic API

    GH->>DT: trigger (non-Bot PR)
    DT->>DT: git diff --name-only BASE_SHA HEAD
    alt docs-only diff
        DT-->>AR: "trivial=true"
    else single file with binary
        Note over DT: TOTAL_CHANGED=999999
        DT-->>AR: "trivial=false"
    else single file 5 lines or fewer
        DT-->>AR: "trivial=true"
    else multi-file / large diff
        DT-->>AR: "trivial=false"
    else detector fails / no usable SHA
        DT-->>AR: "result != success (fail-open)"
    end

    alt "trivial=true confirmed"
        AR-->>GH: skip (no API call)
    else any other outcome
        AR->>API: Claude review prompt
        API-->>AR: review comments
        AR-->>GH: post review
    end
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/gate-claude..." | Re-trigger Greptile

Comment thread .github/workflows/claude.yml Outdated
Comment on lines +51 to +52
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Binary files silently count as 0 lines

git diff --numstat outputs -\t-\t<path> for binary files. AWK treats - as a string, which evaluates to 0 in arithmetic, so a PR that adds or replaces a single binary file (e.g. a compiled artifact, a test fixture image, a lock file in binary format) gets TOTAL_CHANGED=0, passes the NUM_FILES <= 1 && TOTAL_CHANGED <= 5 guard, and is marked trivial — skipping the review entirely. Adding --text would treat binaries as text lines and give a real count, but the cleaner fix is to explicitly detect binary entries in the --numstat output and force TOTAL_CHANGED to a high sentinel value when any are present.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — git diff --numstat now runs through an awk pass that explicitly checks for the - sentinel in the added/deleted fields. If either field is - (binary file), TOTAL_CHANGED is forced to 999999, well above the trivial threshold, so a binary-only single-file change can no longer be miscounted as 0 lines and waved through as trivial. Verified locally against a normal text diff, a binary-only diff, a mixed binary+text diff, and an empty diff.

git diff --numstat prints "-\t-\t<path>" 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.
@carlos-alm

Copy link
Copy Markdown
Contributor Author

Addressed Greptile's review feedback:

  • Binary-file counting gap (the one gap named in the Confidence Score: 4/5 summary and the inline comment on lines 51-52): git diff --numstat prints -\t-\t<path> for binary files, which awk was silently coercing to 0. Added an explicit check for the - sentinel in the awk pass — if either the added or deleted field is -, TOTAL_CHANGED is forced to 999999 (well above the trivial threshold), so a binary-only single-file change can no longer be counted as 0 lines and waved through as trivial. Verified locally against text-only, binary-only, mixed, and empty diffs.

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm
carlos-alm merged commit 500d916 into main Jul 17, 2026
12 checks passed
@carlos-alm
carlos-alm deleted the fix/gate-claude-automated-review branch July 17, 2026 06:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cost: claude.yml automated-review runs unconditionally on every PR with no scope gating

1 participant