Skip to content

Commit 0e981be

Browse files
authored
fix(gator): handle oversized PR diffs in review ledger (#4309)
Signed-off-by: John Myers <johntmyers@users.noreply.github.com> Co-authored-by: John Myers <johntmyers@users.noreply.github.com>
1 parent 81f712e commit 0e981be

6 files changed

Lines changed: 96 additions & 9 deletions

File tree

‎.agents/skills/launch-openshell-gator/SKILL.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ The launcher streams image-build and provisioning output to the terminal. Import
282282
- `/sandbox/.openshell-agent/history.jsonl` contains the latest 100 supervisor transitions, including active-cycle starts and completed cycle results.
283283
- `openshell-agent: still running watch cycle ...` is a heartbeat during long active model cycles.
284284
- `review_feedback_lookup_failed` means Gator could not build the required cross-SHA feedback ledger and deliberately skipped a context-free review.
285+
- Large PRs use local Git trees for patch identity instead of GitHub's
286+
size-limited full-diff endpoint. An unavailable patch ID alone does not block
287+
the ledger; it disables rebase-equivalence shortcuts. Reviewers should inspect
288+
oversized changes file-by-file locally.
285289

286290
### Inspect Active Sandboxes
287291

‎scripts/agents/gator/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ The launcher:
4545
- Uses the gator image policy copied to `/etc/openshell/policy.yaml`.
4646
- Installs the gator-specific `gh` wrapper from `gator/bin/gh` as `/usr/local/bin/gh` to fail closed when same-head-SHA history cannot be checked, prevent duplicate dispositions, and require versioned review payloads.
4747
- Installs `gator/bin/review-feedback-ledger` as `/usr/local/bin/review-feedback-ledger` so reviews receive tree- and patch-aware scope, prior summaries and findings, resolution state, convergence telemetry, and the three-round Warning budget.
48+
Patch identity uses fetched merge-base/head trees in a temporary bare Git
49+
repository, avoiding GitHub's full-diff size limit without checking out PR
50+
code. If those trees cannot be fetched, the ledger retains feedback and
51+
exact-SHA history but disables rebase-equivalence shortcuts.
4852
- Installs `gator/bin/resolve-gator-review-threads` so a follow-up commit that
4953
demonstrably fixes a Gator inline finding can resolve the corresponding
5054
Gator-owned GitHub review thread without touching human review threads.

‎scripts/agents/gator/agent.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
id: gator
5-
payload_version: 10
5+
payload_version: 11
66
display_name: Gator Gate Agent
77
description: Validate and monitor OpenShell GitHub issues and pull requests through the gator state machine.
88

‎scripts/agents/gator/bin/review-feedback-ledger‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,28 @@ query(
119119
merge_base_sha="$(gh api \
120120
"repos/$owner/$repo/compare/$base_sha...$head_sha" \
121121
--jq '.merge_base_commit.sha')"
122-
patch_id="$(
123-
gh api \
124-
-H 'Accept: application/vnd.github.v3.diff' \
125-
"repos/$owner/$repo/pulls/$pr_number" |
126-
git patch-id --stable |
127-
awk 'NR == 1 { print $1 }'
128-
)"
122+
# GitHub's full-diff endpoint rejects large PRs. Fetch only the two
123+
# immutable trees needed for patch identity; never check out PR code.
124+
# Patch identity is optional: failure disables equivalence shortcuts,
125+
# not the mandatory feedback ledger or its exact-SHA review history.
126+
patch_id=""
127+
if [[ "$merge_base_sha" =~ ^[0-9a-f]{40}$ && "$head_sha" =~ ^[0-9a-f]{40}$ ]] &&
128+
git init --bare --quiet "$tmp/trees.git" &&
129+
GIT_TERMINAL_PROMPT=0 git -C "$tmp/trees.git" \
130+
-c credential.helper='!gh auth git-credential' \
131+
fetch --quiet --no-tags --no-recurse-submodules --depth=1 \
132+
"https://github.com/$owner/$repo.git" "$merge_base_sha" "$head_sha" &&
133+
patch_id="$(
134+
git -C "$tmp/trees.git" diff --no-ext-diff --no-textconv \
135+
--no-renames "$merge_base_sha" "$head_sha" -- |
136+
git patch-id --stable |
137+
awk 'NR == 1 { print $1 }'
138+
)"; then
139+
:
140+
else
141+
patch_id=""
142+
echo "patch identity unavailable; rebase equivalence disabled" >&2
143+
fi
129144

130145
jq -n \
131146
--arg head_sha "$head_sha" \

‎scripts/agents/gator/bin/review_feedback_ledger_test.sh‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,63 @@ if "$LEDGER" --input "$tmp/missing-pr.json" >/dev/null 2>&1; then
341341
exit 1
342342
fi
343343

344+
# Exercise live collection against real local Git trees, including a diff
345+
# larger than GitHub's full-diff limit. No PR code is checked out by the helper.
346+
mkdir -p "$tmp/mock-bin" "$tmp/source"
347+
git -C "$tmp/source" init --quiet
348+
git -C "$tmp/source" -c user.name=Test -c user.email=test@example.test \
349+
commit --quiet --allow-empty -m base
350+
base="$(git -C "$tmp/source" rev-parse HEAD)"
351+
seq 1 30000 > "$tmp/source/schema.json"
352+
git -C "$tmp/source" add schema.json
353+
git -C "$tmp/source" -c user.name=Test -c user.email=test@example.test \
354+
commit --quiet -m schema
355+
head="$(git -C "$tmp/source" rev-parse HEAD)"
356+
expected_patch="$(git -C "$tmp/source" diff "$base" "$head" | git patch-id --stable | awk '{print $1}')"
357+
jq --arg head "$head" --arg base "$base" '
358+
.data.repository.pullRequest.headRefOid = $head |
359+
.data.repository.pullRequest.baseRefOid = $base
360+
' "$tmp/review-threads.json" > "$tmp/live-threads.json"
361+
export LEDGER_TEST_TMP="$tmp" LEDGER_TEST_BASE="$base"
362+
export LEDGER_TEST_REAL_GIT="$(command -v git)"
363+
cat > "$tmp/mock-bin/gh" <<'SH'
364+
#!/usr/bin/env bash
365+
set -euo pipefail
366+
case "$*" in
367+
*graphql*) cat "$LEDGER_TEST_TMP/live-threads.json" ;;
368+
*compare/*) echo "$LEDGER_TEST_BASE" ;;
369+
*reviews\?*) cat "$LEDGER_TEST_TMP/reviews.json" ;;
370+
*comments\?*) cat "$LEDGER_TEST_TMP/issue-comments.json" ;;
371+
*) echo 'unexpected GitHub request (full diffs unavailable)' >&2; exit 1 ;;
372+
esac
373+
SH
374+
cat > "$tmp/mock-bin/git" <<'SH'
375+
#!/usr/bin/env bash
376+
set -euo pipefail
377+
args=()
378+
for arg in "$@"; do
379+
if [[ "$arg" == https://github.com/* ]]; then
380+
[[ "${LEDGER_TEST_FETCH_FAIL:-0}" != 1 ]] || exit 1
381+
arg="$LEDGER_TEST_TMP/source"
382+
fi
383+
args+=("$arg")
384+
done
385+
exec "$LEDGER_TEST_REAL_GIT" "${args[@]}"
386+
SH
387+
chmod +x "$tmp/mock-bin/gh" "$tmp/mock-bin/git"
388+
PATH="$tmp/mock-bin:$PATH" "$LEDGER" NVIDIA OpenShell 4288 > "$tmp/live-ledger.json"
389+
jq -e --arg patch "$expected_patch" --arg head "$head" '
390+
.current_patch_id == $patch and .review_scope.current_head_sha == $head
391+
' "$tmp/live-ledger.json" >/dev/null
392+
PATH="$tmp/mock-bin:$PATH" LEDGER_TEST_FETCH_FAIL=1 \
393+
"$LEDGER" NVIDIA OpenShell 4288 > "$tmp/no-patch-ledger.json"
394+
jq -e '
395+
.current_patch_id == null and
396+
.review_scope.rebase_equivalent == false and
397+
.review_scope.mode != "already_reviewed" and
398+
(.threads | length) > 0
399+
' "$tmp/no-patch-ledger.json" >/dev/null
400+
344401
rg -q 'COPY bin/review-feedback-ledger /usr/local/bin/review-feedback-ledger' \
345402
"$GATOR_DIR/Dockerfile"
346403
rg -q 'COPY bin/resolve-gator-review-threads /usr/local/bin/resolve-gator-review-threads' \
@@ -349,7 +406,7 @@ rg -q 'COPY bin/validate-review-findings /usr/local/bin/validate-review-findings
349406
"$GATOR_DIR/Dockerfile"
350407
ruby -ryaml -e '
351408
manifest = YAML.load_file(ARGV.fetch(0))
352-
abort unless manifest.fetch("payload_version") == 9
409+
abort unless manifest.fetch("payload_version") == 11
353410
resource = manifest.fetch("resources").find {
354411
|entry| entry.fetch("id") == "gator-review-findings-schema"
355412
}

‎scripts/agents/gator/skills/gator-gate/SKILL.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ Treat the ledger as required reviewer input, not optional background:
132132
- Use `current_patch_id`, `previous_reviewed_patch_id`, base SHA, and merge-base
133133
SHA to preserve review identity across rebases and merge-main commits. If
134134
`rebase_equivalent` is true, do not review the same effective patch again.
135+
- A null `current_patch_id` disables patch-equivalence shortcuts; it does not
136+
invalidate the feedback ledger. Preserve exact-SHA history and review the
137+
author-only delta conservatively when the head changed.
138+
- For large PRs, fetch the exact commits and inspect local `git diff` output
139+
file-by-file. Do not depend on `gh pr diff` or GitHub's full-diff endpoint:
140+
those reject oversized diffs. Review schema/generated changes separately
141+
from handwritten behavior, without silently excluding them from scope.
135142
- For a non-equivalent rebase, compare author patch IDs or use `git range-diff`
136143
to isolate the author-only delta. Upstream changes are context, not new PR
137144
findings.

0 commit comments

Comments
 (0)