@@ -157,11 +157,25 @@ runs:
157157 # Uses github.token (has contents:read) instead of the App token (used for posting reviews).
158158 # Uses the full PR URL instead of just the number — gh can't resolve a bare number
159159 # from a detached HEAD (refs/pull/N/head).
160- if GH_TOKEN="$READ_TOKEN" gh pr diff "$PR_URL" > pr.diff 2>/dev/null; then
161- echo "✅ Pre-fetched PR diff ($(wc -l < pr.diff | tr -d ' ') lines)"
160+ if GH_TOKEN="$READ_TOKEN" gh pr diff "$PR_URL" > pr.diff 2>pr_diff_stderr.txt; then
161+ echo "✅ Pre-fetched PR diff via gh pr diff ($(wc -l < pr.diff | tr -d ' ') lines)"
162+ rm -f pr_diff_stderr.txt
162163 else
163- echo "::warning::Failed to pre-fetch PR diff — agent will use git diff as fallback"
164- rm -f pr.diff
164+ echo "::warning::gh pr diff failed: $(cat pr_diff_stderr.txt 2>/dev/null)"
165+ rm -f pr.diff pr_diff_stderr.txt
166+
167+ # Fallback: git diff with merge-base (repo is checked out with full history)
168+ MERGE_BASE=$(git merge-base origin/main HEAD 2>/dev/null || git merge-base origin/master HEAD 2>/dev/null || echo "")
169+ if [ -n "$MERGE_BASE" ]; then
170+ if git diff "$MERGE_BASE"...HEAD > pr.diff; then
171+ echo "✅ Pre-fetched PR diff via git diff ($(wc -l < pr.diff | tr -d ' ') lines)"
172+ else
173+ echo "::warning::git diff failed — agent will fetch diff itself"
174+ rm -f pr.diff
175+ fi
176+ else
177+ echo "::warning::Could not determine merge base — agent will fetch diff itself"
178+ fi
165179 fi
166180
167181 - name : Ensure cache directory exists
@@ -173,8 +187,9 @@ runs:
173187 uses : actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
174188 with :
175189 path : ${{ github.workspace }}/.cache/pr-review-memory.db
176- key : pr-review-memory-${{ github.repository }}-${{ github.run_id }}
190+ key : pr-review-memory-${{ github.repository }}-${{ github.job }}-${{ github. run_id }}
177191 restore-keys : |
192+ pr-review-memory-${{ github.repository }}-${{ github.job }}-
178193 pr-review-memory-${{ github.repository }}-
179194
180195 # ========================================
@@ -356,7 +371,7 @@ runs:
356371 uses : actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
357372 with :
358373 path : ${{ github.workspace }}/.cache/pr-review-memory.db
359- key : pr-review-memory-${{ github.repository }}-${{ github.run_id }}
374+ key : pr-review-memory-${{ github.repository }}-${{ github.job }}-${{ github. run_id }}
360375
361376 # ========================================
362377 # POST-REVIEW: Clean summary & reactions
0 commit comments