Reduce redundant PR diff/file-list API reads with head-SHA-aware prefetch caching in top review workflows - #47997
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Hey
Once the work is complete and the PR is ready, you can mark it as ready for review (remove the draft status). The core team will pick it up from there!
|
There was a problem hiding this comment.
Pull request overview
Adds head-SHA-aware caching to reduce repeated PR metadata and diff API reads.
Changes:
- Persists and validates PR head-SHA cache markers.
- Adds caching to Test Quality Sentinel and normalizes Matt reviewer keys.
- Adds contract tests and recompiles generated workflows.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/pr_prefetch_cache_contract_test.go |
Adds cache contract checks. |
.github/workflows/test-quality-sentinel.md |
Adds Sentinel prefetch caching. |
.github/workflows/test-quality-sentinel.lock.yml |
Recompiles Sentinel workflow. |
.github/workflows/shared/pr-diff-data-fetch.md |
Validates shared cache head SHA. |
.github/workflows/pr-data-prefetch.yml |
Persists producer head metadata. |
.github/workflows/pr-code-quality-reviewer.lock.yml |
Recompiles shared prefetch logic. |
.github/workflows/mattpocock-skills-reviewer.md |
Adds slash-command cache fallback. |
.github/workflows/mattpocock-skills-reviewer.lock.yml |
Recompiles Matt reviewer. |
.github/workflows/impeccable-skills-reviewer.lock.yml |
Recompiles shared prefetch logic. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
.github/workflows/test-quality-sentinel.md:39
- The issue-number fallback makes slash commands reach this step, but
github.event.pull_request.base.shais empty for those events and the compiled checkout has no PR ref. Consequently the localgit diffcalls at lines 81 and 109 fail and|| truesilently produces incomplete analysis inputs that can be cached. Resolve/check out the PR head and base for slash events, or derive these analyses from the API diff instead.
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
EXPR_GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
.github/workflows/shared/pr-diff-data-fetch.md:55
- The metadata payload now includes
headRefOid, but the output contract below still lists the old field set at line 105. Update that documentation so consumers know the head OID is available.
--json number,title,body,headRefName,headRefOid,additions,deletions,changedFiles,files \
- Files reviewed: 9/9 changed files
- Comments generated: 4
- Review effort level: Medium
| cache: | ||
| key: pr-test-prefetch-${{ github.event.pull_request.head.sha || github.event.issue.number }} | ||
| path: /tmp/gh-aw/agent | ||
| restore-keys: | ||
| - pr-test-prefetch-${{ github.event.pull_request.number || github.event.issue.number }}- |
| --- | ||
| cache: | ||
| key: pr-prefetch-${{ github.event.pull_request.head.sha }} | ||
| key: pr-prefetch-${{ github.event.pull_request.head.sha || github.event.issue.number }} |
| CACHE_HEAD_SHA="$(tr -d '\n' < /tmp/gh-aw/agent/pr-data-head-sha.txt)" | ||
| fi | ||
| # Skip fetch only when cache data matches current PR head commit. | ||
| if [ -n "$CURRENT_HEAD_SHA" ] && [ "$CURRENT_HEAD_SHA" = "$CACHE_HEAD_SHA" ] && [ -f /tmp/gh-aw/agent/pr-diff.patch ] && [ -f /tmp/gh-aw/agent/pr-meta.json ] && [ -f /tmp/gh-aw/agent/pr-review-comments.json ]; then |
| assert.Contains(t, text, "key: pr-test-prefetch-${{ github.event.pull_request.head.sha || github.event.issue.number }}", "Test Quality Sentinel should define a head-aware cache key") | ||
| assert.Contains(t, text, "test-data-head-sha.txt", "Test Quality Sentinel should persist cache head SHA marker") |
|
🎉 This pull request is included in a new release. Release: |
REST API usage has grown sharply, with PR review workflows repeatedly re-fetching the same PR diff/file metadata on each run. This change makes prefetch reuse deterministic per PR head commit so repeated reviewers consume cached data instead of reissuing equivalent API reads.
Shared prefetch helper: head-SHA cache validation
shared/pr-diff-data-fetch.mdto gate cache hits on a persisted head-SHA marker (/tmp/gh-aw/agent/pr-data-head-sha.txt) matching the current PR head.headRefOidin pre-fetched metadata and fallback head resolution, so stale cache reuse is avoided when the PR advances.Prefetch producer alignment
pr-data-prefetch.ymlto write the head-SHA marker alongside existing prefetch artifacts and includeheadRefOidin metadata payloads.Top reviewer workflow key consistency
pull_request.head.sha || issue.number, matching shared prefetch behavior and slash-command compatibility.Test Quality Sentinel cache adoption
test-quality-sentinel.md, keyed by PR head SHA (with issue fallback).test-data-head-sha.txt) to short-circuit redundantgh pr view/gh pr difffetches on repeated runs of the same head commit.Contract coverage for cache invariants
pkg/cli/pr_prefetch_cache_contract_test.goto lock in: