Skip to content

fix: reduce wasted Copilot code review credit usage - #86

Open
lihsaa591 wants to merge 5 commits into
masterfrom
tg-autopilot/reduce-copilot-review-cost
Open

fix: reduce wasted Copilot code review credit usage#86
lihsaa591 wants to merge 5 commits into
masterfrom
tg-autopilot/reduce-copilot-review-cost

Conversation

@lihsaa591

Copy link
Copy Markdown
Contributor

Summary

The org exhausted its entire monthly Copilot Pro Plus credit allotment this month, with 98%+ of usage from the Code Review model. Three changes to the shared assign-copilot/request-review logic:

  • Skip drafts: a PR opened as draft isn't ready for review, but the trigger fired anyway. Draft status is re-checked live via the API (retried briefly for a possible short read delay right after creation) rather than trusting the opened event's own payload.
  • Skip bot-authored PRs (dependabot etc.): these don't need an AI review. tg-autopilot's own PRs are unaffected since it's a User account, not a Bot — no special-casing needed.
  • copilot_present() now uses curl instead of gh api, consistent with this repo's existing pattern elsewhere, to avoid a stale cached GET right after our own mutation causing an unnecessary duplicate review request.

Important testing note for future changes here

pull_request_target-triggered workflows always read the triggering workflow file from the base/default branch, never from the PR's own branch — confirmed for real after four failed attempts to test this change via a temporary caller-branch trick, which silently kept running the old master code every time. Any future change to assign-copilot needs to be verified after merging to master, not via a caller pointed at a test branch.

Test plan

  • YAML validated
  • Verify with one real PR against colormag (or similar) after merging, since pre-merge testing isn't reliable for this trigger type

tg-autopilot and others added 5 commits September 11, 2026 15:01
The org exhausted its entire monthly Copilot Pro Plus credit allotment
this month, almost all of it (98%+) from the Code Review model. Three
changes to the shared assign-copilot/request-review logic:

- Skip drafts: a PR opened as draft isn't ready for review yet, but the
  trigger fired anyway, spending a review on code likely to change before
  it's ready.
- Skip bot-authored PRs (dependabot etc.): these don't need an AI review.
  tg-autopilot's own PRs are unaffected -- it's a User account, not a Bot.
- copilot_present() now uses curl instead of `gh api`, which can serve a
  cached GET right after our own mutation and falsely report "not present
  yet" -- a false negative here causes the retry step to re-issue a
  second real review request on a PR that was already reviewed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Confirmed for real: a PR created with --draft still triggered the
job with github.event.pull_request.draft == false in the opened
event, so the job-level if: check let it through. Moved the check
inside the step instead, re-fetched live via `gh pr view`, before
any Copilot API call happens.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Same caching pattern as gh api -- gh pr view served a stale (non-draft)
result for a PR created with --draft, confirmed for real: the previous
fix's re-check still let a draft PR through. curl bypasses it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…erified

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants