Repository navigation
Conversation
[ghstack-poisoned]
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (6): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202667
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 4c29a55 with merge base 47ffd6f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
we need to think how to handle rebases better
|
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one or when it is the head under review. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty. - A new `review` step, after the size gate and before any credential, fetches that one commit (depth 1, as for the merge base) and writes `/tmp/pr-interdiff.txt`: the diff between it and HEAD, limited to the PR's files with literal pathspecs. When there is no earlier review, the commit is gone after a force-push, the PR changes no files, or the result is over `MAX_DIFF_BYTES`, the file holds a one-line note instead, so the model's read rule always resolves and the review never fails for it. A rebase in between also shows the new base's changes to those files; the header says so. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule and model `PREVIOUS_REVIEW_SHA` as a plain value, like `MERGE_BASE_SHA`. Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given this file and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step's script was also run on that PR's real commits: for rounds 10 -> 11 it wrote the 5 files the author changed (9 KB), and it wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/fetch_pr_comments.py scripts/pr_review/test_fetch_pr_comments.py scripts/pr_review/test_workflow_contract.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Oct 29 14:39:25 2026 -0700 # # On branch pr-review-rereview-converge # Your branch is ahead of 'origin/main' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: .github/workflows/hardened-pr-review-run.yml # modified: scripts/pr_review/fetch_pr_comments.py # modified: scripts/pr_review/test_fetch_pr_comments.py # modified: scripts/pr_review/test_workflow_contract.py # ghstack-source-id: 60c464a Pull-Request: #202667
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one or when it is the head under review. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, a git failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, the notes, the size cap and pathspec-like file names. Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Oct 29 14:39:25 2026 -0700 # # On branch pr-review-rereview-converge # Your branch is ahead of 'origin/main' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: .github/workflows/hardened-pr-review-run.yml # modified: scripts/pr_review/fetch_pr_comments.py # modified: scripts/pr_review/test_fetch_pr_comments.py # modified: scripts/pr_review/test_workflow_contract.py # ghstack-source-id: de28ed4 Pull-Request: #202667
Good point, updated the PR |
izaitsevfb
left a comment
There was a problem hiding this comment.
lgtm, thanks!
there is one bug worth addressing and couple of corner cases you should be aware of.
| text = interdiff(args.previous, args.previous_base, args.base, files) | ||
| except RuntimeError as e: | ||
| print(f"::warning::interdiff not built: {e}") | ||
| text = NOTE_UNAVAILABLE.format(sha=args.previous) |
There was a problem hiding this comment.
looks like a bug, please take a look.
🟡 A changed file whose name is not valid UTF-8 makes `interdiff.py` crash, which fails the review job before the model runs. (ai-generated section)
main reads /tmp/pr-files.z with a strict .decode(), and replay decodes merge-tree's conflicted names the same way. Only RuntimeError is caught, so a name like bad\xffname.txt raises UnicodeDecodeError, the script exits 1 without writing the file, and the step's set -e fails the job. This happens on every run of such a PR that reaches the step, first reviews included, since the decode comes before the no-previous-review check. The file name is chosen by the PR author, and the docstring and description both say the review never fails for this file. Decoding with errors="surrogateescape" (subprocess hands such names back to git unchanged) would keep the contract. Widening the except alone would not, because the file-list read sits before the try.
Reviewed by codex gpt-6-astra + claude-fable-5 at high effort, against 1df3366.
| text = HEADER.format(sha=previous) + diff(tree, clean) | ||
| if both: | ||
| text += CONFLICTED + diff(previous, both) | ||
| return text |
There was a problem hiding this comment.
consider supporting renaming better (perhaps as a followup)
⚪ A file renamed since the last review shows up in the interdiff as entirely new code. (ai-generated section)
The interdiff is limited to the PR's files at HEAD, from git diff --name-only against the merge base, which with git's default rename detection lists a renamed file under its new path only. So the diff of the replayed tree against HEAD never sees the old path: a 50-line file the last review read as a.py, then renamed unchanged to b.py, comes out as 50 added lines in b.py. A re-review then treats code it already covered as new. After the replay, every file outside the author's changes is the same on both sides, so diffing the replayed tree against HEAD with -M and no pathspec, leaving out only the conflicted files, pairs the rename (R100 a.py b.py) and also shows a file the author reverted since the last review.
Reviewed by codex gpt-6-astra + claude-fable-5 at high effort, against 1df3366.
| seen = (latest or {}).get("commit_id") or "" | ||
| head["previous_review_sha"] = ( | ||
| seen if re.fullmatch(r"[0-9a-f]{40}", seen) and seen != head_sha else "" | ||
| ) |
There was a problem hiding this comment.
probably worth adding a check for that corner case.
⚪ On a re-run at an unchanged head, the interdiff file gets the first-review note instead of saying nothing changed. (ai-generated section)
collect blanks previous_review_sha when the latest automated review saw the head under review, so interdiff.py writes "No automated review of an earlier commit to compare with.", the same note a first review gets. A same-head run happens when a maintainer adds the review label again, since a labeled trigger overrides the ready-for-review marker. That note is wrong when earlier reviews exist, and the model has to work out from the conversation that nothing changed since the last review. A distinct note for this case, such as "The last automated review saw this same commit; nothing has changed since", would state it directly.
Reviewed by codex gpt-6-astra + claude-fable-5 at high effort, against 1df3366.
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Oct 29 14:39:25 2026 -0700 # # On branch pr-review-rereview-converge # Your branch is ahead of 'origin/main' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: .github/workflows/hardened-pr-review-run.yml # modified: scripts/pr_review/fetch_pr_comments.py # modified: scripts/pr_review/test_fetch_pr_comments.py # modified: scripts/pr_review/test_workflow_contract.py # ghstack-source-id: e758f74 Pull-Request: #202667
Withdrawn: the automated review of f4cc843 found nothing blocking.
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Oct 29 14:39:25 2026 -0700 # # On branch pr-review-rereview-converge # Your branch is ahead of 'origin/main' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: .github/workflows/hardened-pr-review-run.yml # modified: scripts/pr_review/fetch_pr_comments.py # modified: scripts/pr_review/test_fetch_pr_comments.py # modified: scripts/pr_review/test_workflow_contract.py # ghstack-source-id: a0bde96 Pull-Request: #202667
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Oct 29 14:39:25 2026 -0700 # # On branch pr-review-rereview-converge # Your branch is ahead of 'origin/main' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: .github/workflows/hardened-pr-review-run.yml # modified: scripts/pr_review/fetch_pr_comments.py # modified: scripts/pr_review/test_fetch_pr_comments.py # modified: scripts/pr_review/test_workflow_contract.py # ghstack-source-id: 20d174d Pull-Request: #202667
There was a problem hiding this comment.
Automated review of 75a1244: nothing blocking; ready for human review.
This PR writes /tmp/pr-interdiff.txt for re-reviews: it replays the commit the latest automated review saw onto this run's merge base with git merge-tree and diffs HEAD against the result, so changes that came in through a rebase are left out. Recommendation: Approve. Nothing here blocks merging, but all six earlier automated findings are still present and should be fixed, the Offline-prompt wording and the shared failure note first.
⚪ 6 non-blocking findings
The Offline prompt overstates what the interdiff contains. It tells the model the file holds the author's changes "with changes from a rebase left out". But files that changed on both sides go under CONFLICTED (scripts/pr_review/interdiff.py:43-47) as a plain diff that includes the base's changes. This sentence is the model's only description of the file, so the model will treat upstream lines in that section as the author's. Fix: add "except for files listed under the heading saying they changed both in the base and in this PR", or similar wording.
pytorch/scripts/pr_review/interdiff.py
Line 105 in 75a1244
One note covers unrelated failures. NOTE_UNAVAILABLE ("or its merge base is no longer available") is written in three cases: when the commit really is missing, when merge-tree exits with something other than 0 or 1, and when any exception reaches main() (:138). In the last two cases the model is told the earlier commit was force-pushed away, when in fact the interdiff could not be built. The replay() is None path also prints no ::warning::, unlike the exception path. So a runner whose git lacks merge-tree --write-tree --merge-base (git 2.40) would quietly turn every re-review into "commit no longer available", with nothing in the log. Fix: add a separate note such as # The interdiff could not be built. for the replay() is None and except Exception paths, and print a warning with merge-tree's stderr when replay() fails.
pytorch/scripts/pr_review/interdiff.py
Line 50 in 75a1244
REPO is a mutable module global. main() reassigns it through global REPO (:131), and git() reads it implicitly. No other script in scripts/pr_review/ uses global. The tests only work because they os.chdir into the temporary repo and rely on the "." default. Fix: pass repo explicitly through interdiff() has_commit() / replay() / diff() git().
Half-stale comment on the new job output: it still says "the review job diffs it against HEAD", which describes the approach from before the replay. The very next comment (:128-130) says the earlier version is replayed. Fix: reword line 126 to match.
pytorch/scripts/pr_review/test_interdiff.py
Line 191 in 75a1244
No test covers a failed replay(). Nothing makes merge-tree exit with something other than 0 or 1 and checks that this becomes a note. Add one, for example by passing a tree or blob OID as --merge-base, or by patching interdiff.git, and assert on the new failure note from the fix above.
pytorch/scripts/pr_review/test_interdiff.py
Line 197 in 75a1244
The failure test swaps a module attribute by hand: test_an_unexpected_failure_is_a_note_not_a_failed_step replaces interdiff.interdiff inside a try/finally, using a lambda that throws from a generator. The sibling suites (test_fetch_pr_comments.py, test_post_review.py) use mock.patch throughout. Use mock.patch.object(interdiff, "interdiff", side_effect=ValueError("boom")) instead.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). ghstack-source-id: 0b59367 Pull-Request: #202667
[ghstack-poisoned]
…view ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). ghstack-source-id: 7a4dd7e Pull-Request: #202667
[ghstack-poisoned]
…view Part of pytorch/test-infra#9243 No. Pass the differences between PR after addressing some previous review feedback The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. The files diffed are the PR's current files plus those the earlier version changed, so a file the author reverted shows up. Git reads no attributes from the PR (`--attr-source` is the empty tree), so its `.gitattributes` cannot pick merge or diff drivers. No earlier review, an unavailable commit, no changed files, a rebase with no author change, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it and says to treat the PR's files as changed unless the note says nothing changed. With fan-out the sub-agents get the Offline section, so they are told about the file too. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. Contract tests also run the new shell with stub `gh`, `git` and `python3`: a malformed previous SHA aborts the run, an unusable or failed compare call leaves the merge base empty without failing, no earlier review makes no compare call, a fetch that fails (the commit gone after a force-push) still builds the file, and the step's condition, its position between the size gate and the credentials, its outputs and arguments, and the three spellings of the path are pinned. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides (diffed against the earlier commit, not the replayed tree), the PR's own `.gitattributes` (ignored, so `merge=union` cannot hide a conflict), a file the author reverted (it shows up although the PR no longer changes it), a rebase with no author change, no rebase, a re-run on the same commit (also when the earlier merge base is unknown), `--repo` from another directory, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: the previous PR's numbers are with this interdiff. In that 15-PR replay, half of the re-reviewed rounds (42 of 84) were rebases with no change by the author, and the interdiff said so in one line; the other half got a median of 4.7 KB. The step was also run on #199555's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). ghstack-source-id: 0c06940 Pull-Request: #202667
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ew (#203136) ✴️ iz2: When a PR is over the automated review's size gate (300 changed files or 400 KB of diff), the review only wrote an S3 telemetry row and Dr.CI showed a collapsed "Skipped, PR too large" line with no next step. Authors read that as the review being broken (#203051: 162 files, skipped under the earlier 100-file cap that #203217 raised to 300). The skip now posts a COMMENT review that says the PR is over the limit, suggests splitting it, and gives the opt-out command (`@pytorchbot label "no automated review"`). The bot never applies the label itself; that stays the author's call. - File-count path (decided in `prepare`): `announce` posts the notice with a new `post_review.py --too-large` mode. It already has the right token: `pull-requests: write`, no AWS, no environment, no PR code. - Diff-bytes path (decided in `review`): `publish` posts the same notice from the `skipped_too_large` row. - The notice hides earlier automated reviews like any new review. It dismisses no standing change request, since the large PR was not evaluated; after an opt-out that request stays until a maintainer dismisses it. It is not reposted while the newest visible review is the same notice; one marked in progress gets its body back. `fetch_pr_comments.py` never treats a notice as the latest verdict, so re-review interdiffs (#202667) also start from the last verdict's commit. - The command sits mid-line in a code span. pytorch-bot only runs commands that start a line (`cliParser.ts`), and the label text is validated, so the notice cannot trigger the bot. Test plan: `python3 -m unittest discover -s scripts/pr_review -t .` passes (654 tests). New tests cover the notice body and its bot-command safety, dedupe (including marked and defused notices), head move, opt-out, change-request handling, the interdiff base, and the workflow wiring. Known limit: if a smaller commit's review fails, the old notice is put back with the command defused until the next too-large run replaces it. Dr.CI shows that run's failure. Pull Request resolved: #203136 Approved by: https://github.com/huydhn
…view (pytorch#202667) ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: replaying pytorch#199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). Pull Request resolved: pytorch#202667 Approved by: https://github.com/izaitsevfb ghstack dependencies: pytorch#202634
…ew (pytorch#203136) ✴️ iz2: When a PR is over the automated review's size gate (300 changed files or 400 KB of diff), the review only wrote an S3 telemetry row and Dr.CI showed a collapsed "Skipped, PR too large" line with no next step. Authors read that as the review being broken (pytorch#203051: 162 files, skipped under the earlier 100-file cap that pytorch#203217 raised to 300). The skip now posts a COMMENT review that says the PR is over the limit, suggests splitting it, and gives the opt-out command (`@pytorchbot label "no automated review"`). The bot never applies the label itself; that stays the author's call. - File-count path (decided in `prepare`): `announce` posts the notice with a new `post_review.py --too-large` mode. It already has the right token: `pull-requests: write`, no AWS, no environment, no PR code. - Diff-bytes path (decided in `review`): `publish` posts the same notice from the `skipped_too_large` row. - The notice hides earlier automated reviews like any new review. It dismisses no standing change request, since the large PR was not evaluated; after an opt-out that request stays until a maintainer dismisses it. It is not reposted while the newest visible review is the same notice; one marked in progress gets its body back. `fetch_pr_comments.py` never treats a notice as the latest verdict, so re-review interdiffs (pytorch#202667) also start from the last verdict's commit. - The command sits mid-line in a code span. pytorch-bot only runs commands that start a line (`cliParser.ts`), and the label text is validated, so the notice cannot trigger the bot. Test plan: `python3 -m unittest discover -s scripts/pr_review -t .` passes (654 tests). New tests cover the notice body and its bot-command safety, dedupe (including marked and defused notices), head move, opt-out, change-request handling, the interdiff base, and the workflow wiring. Known limit: if a smaller commit's review fails, the old notice is put back with the command defused until the next too-large run replaces it. Dr.CI shows that run's failure. Pull Request resolved: pytorch#203136 Approved by: https://github.com/huydhn
…view (pytorch#202667) ## Linked issue or supporting maintainer Part of pytorch/test-infra#9243 ## BC-breaking? No. ## Summary (human written only) Pass the differences between PR after addressing some previous review feedback ## Agent details (if applicable) The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading `/tmp/pr-interdiff.txt` when present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again. - `fetch_pr_comments.py` adds `previous_review_sha` to its output: the commit the latest automated review saw (`commit_id` of the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note. - `prepare` passes it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone). - A new `review` step, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the new `scripts/pr_review/interdiff.py` from the trusted checkout, which writes `/tmp/pr-interdiff.txt`. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base with `git merge-tree` (explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result over `MAX_DIFF_BYTES` give a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step. `interdiff.py` is part of the prompt hash, like `fetch_pr_comments.py`. - Stage A may read the file (`Read(//tmp/pr-interdiff.txt)`), and the Offline prompt names it. The contract tests pin the new read rule, list `interdiff.py` among the trusted programs the review job runs, and model `PREVIOUS_REVIEW_SHA` and `PREVIOUS_MERGE_BASE_SHA` as plain values, like `MERGE_BASE_SHA`. `test_interdiff.py` covers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without `--literal-pathspecs`) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up. Evaluation: replaying pytorch#199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA. Test plan: ``` python3 -m unittest discover -s scripts/pr_review -t . lintrunner -a .github/workflows/hardened-pr-review-run.yml scripts/pr_review/*.py ``` actionlint was not run locally (its binary could not be downloaded here); CI runs it. This PR was authored with the help of an AI assistant (Claude). Pull Request resolved: pytorch#202667 Approved by: https://github.com/izaitsevfb ghstack dependencies: pytorch#202634
…ew (pytorch#203136) ✴️ iz2: When a PR is over the automated review's size gate (300 changed files or 400 KB of diff), the review only wrote an S3 telemetry row and Dr.CI showed a collapsed "Skipped, PR too large" line with no next step. Authors read that as the review being broken (pytorch#203051: 162 files, skipped under the earlier 100-file cap that pytorch#203217 raised to 300). The skip now posts a COMMENT review that says the PR is over the limit, suggests splitting it, and gives the opt-out command (`@pytorchbot label "no automated review"`). The bot never applies the label itself; that stays the author's call. - File-count path (decided in `prepare`): `announce` posts the notice with a new `post_review.py --too-large` mode. It already has the right token: `pull-requests: write`, no AWS, no environment, no PR code. - Diff-bytes path (decided in `review`): `publish` posts the same notice from the `skipped_too_large` row. - The notice hides earlier automated reviews like any new review. It dismisses no standing change request, since the large PR was not evaluated; after an opt-out that request stays until a maintainer dismisses it. It is not reposted while the newest visible review is the same notice; one marked in progress gets its body back. `fetch_pr_comments.py` never treats a notice as the latest verdict, so re-review interdiffs (pytorch#202667) also start from the last verdict's commit. - The command sits mid-line in a code span. pytorch-bot only runs commands that start a line (`cliParser.ts`), and the label text is validated, so the notice cannot trigger the bot. Test plan: `python3 -m unittest discover -s scripts/pr_review -t .` passes (654 tests). New tests cover the notice body and its bot-command safety, dedupe (including marked and defused notices), head move, opt-out, change-request handling, the interdiff base, and the workflow wiring. Known limit: if a smaller commit's review fails, the old notice is put back with the command defused until the next too-large run replaces it. Dr.CI shows that run's failure. Pull Request resolved: pytorch#203136 Approved by: https://github.com/huydhn
Stack from ghstack (oldest at bottom):
Linked issue or supporting maintainer
Part of pytorch/test-infra#9243
BC-breaking?
No.
Summary (human written only)
Pass the differences between PR after addressing some previous review feedback
Agent details (if applicable)
The previous PR in this stack tells re-reviews to settle their earlier findings and review what changed since the last review, reading
/tmp/pr-interdiff.txtwhen present. This provides that file. Without it the review sees only the PR's full diff against its base, which does not say which lines are new since its last review, so a re-review reviews all of them again.fetch_pr_comments.pyaddsprevious_review_shato its output: the commit the latest automated review saw (commit_idof the review it already selects), empty without one. A re-run on the same commit gets a "nothing changed" note.preparepasses it on as an output, validated as a 40-hex SHA or empty, together with that commit's merge base with the PR's base, resolved by the compare endpoint on complete history like this run's merge base (empty if the commit is gone).reviewstep, after the size gate and before any credential, fetches those two commits (depth 1, as for the merge base) and runs the newscripts/pr_review/interdiff.pyfrom the trusted checkout, which writes/tmp/pr-interdiff.txt. Diffing the earlier commit against HEAD would show a rebase's upstream changes to the PR's files as the author's, and ghstack PRs are rebased often. So the script replays the earlier version onto this run's merge base withgit merge-tree(explicit merge base, no checkout, no shared history needed) and diffs HEAD against that, so upstream changes cancel out. A file the replay cannot merge changed both upstream and in the PR; it gets the plain diff under a heading saying it includes upstream changes. No earlier review, an unavailable commit, no changed files, any failure or a result overMAX_DIFF_BYTESgive a one-line note instead, so the model's read rule always resolves and the review never fails for this file. File names are literal pathspecs and are decoded losslessly, so a non-UTF-8 name cannot fail the step.interdiff.pyis part of the prompt hash, likefetch_pr_comments.py.Read(//tmp/pr-interdiff.txt)), and the Offline prompt names it.The contract tests pin the new read rule, list
interdiff.pyamong the trusted programs the review job runs, and modelPREVIOUS_REVIEW_SHAandPREVIOUS_MERGE_BASE_SHAas plain values, likeMERGE_BASE_SHA.test_interdiff.pycovers a rebase (upstream changes left out), a file changed on both sides, no rebase, a re-run on the same commit, the notes, an unexpected failure, the size cap, pathspec-like file names (the test fails without--literal-pathspecs) and a non-UTF-8 file name. Renames since the last review show up as new files; detecting them is a follow-up.Evaluation: replaying #199555 rounds 9-11 locally (3 runs each), re-reviews given an interdiff and the previous PR's skill raised 0 new and 0 previously non-blocking blocking findings in round 11, against 1 new with today's skill (see the previous PR). The step was also run on that PR's real commits. Round 10 -> 11 was a rebase: a plain diff of the two commits showed 10 changed lines in 5 files, all of them changes the base made; the rebase-aware interdiff shows none of those, plus the one file both sides changed (965 bytes instead of 9 KB). It wrote notes for no earlier review and an unavailable commit, and failed on a malformed SHA.
Test plan:
actionlint was not run locally (its binary could not be downloaded here); CI runs it.
This PR was authored with the help of an AI assistant (Claude).