Repository navigation
[hardened PR review] Declutter replaced reviews: fold, delete unreplied comments, link nearby threads - #201479
izaitsevfb wants to merge 4 commits into
Conversation
…ed comments, link discussions Minimizing a replaced review hides only its body; its inline comments stay listed on the Files tab and in GitHub Mobile, so a PR with many re-reviews shows every old finding at once (GITHUB_TOKEN cannot resolve threads here). When a newer review replaces an earlier one: - its body is folded into a collapsed <details> section (marker kept first); - its inline comments nobody replied to are deleted; replied ones and their replies stay; - a new finding next to an earlier comment someone replied to goes in the body with a link to that discussion instead of a new inline comment. Reviews hidden by earlier runs are folded and emptied by a backfill that runs after any clean-verdict dismissal, capped at 50 writes and 90 seconds a run. A comment any listing in the run saw replied to is never deleted.
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (10): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201479
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 194252b with merge base e5e5dde ( 🟡 GREEN LIGHT - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
… its clock runs out Address the automated review: a comment with reactions is kept like one with replies; running out of time raises OutOfTime, which ends the backfill instead of failing every remaining call one by one; graphql() retry waits honour the clock; hide_earlier lists comments only when it has something to take down.
…e backfill's request gate Address the second automated review: the link to an earlier replied-to thread now says only that it is near this line, since matching is by position; the backfill's change-request gate is tested for a newer request and for one downgraded to a comment; with_discussions skips listing when there are no findings.
…lds; pace the backfill Address the third automated review: a comment is deleted only if its review thread, read by GraphQL cursor (which an overlapping run's deletes cannot shift), holds that one comment; unreadable threads delete nothing. Folded bodies are defused again, a retry wait past the clock raises OutOfTime, and backfill writes pause 1 second apart.
There was a problem hiding this comment.
Automated review of 194252b: nothing blocking; ready for human review.
When a newer automated review replaces an older one, this PR folds the older review's body into a collapsed section, deletes its inline comments that nobody replied to or reacted to, links new blocking findings near replied threads from the review body, and backfills the same fold and delete for reviews that earlier runs already hid. Recommendation: Needs Discussion. The main question is a design one: deleting unreplied comments right after the next automated review races with humans who are replying, and the pacing, state, naming, redundant-read and test gaps should be fixed in the same pass.
⚪ 10 non-blocking findings
pytorch/scripts/pr_review/post_review.py
Line 586 in 194252b
A reply someone is writing can lose the comment it answers, and the timing makes this likely. take_down deletes the previous review's comments within seconds of the next automated review. A new review usually follows a push, which is exactly when a human may be partway through replying in a pending review, and neither replies_seen nor thread_sizes can see a pending reply. The race can be narrowed without new API surface: only delete comments of reviews that a previous run already hid (so the backfill does the deleting), or skip root comments whose created_at is younger than a grace per
pytorch/scripts/pr_review/post_review.py
Line 586 in 194252b
Deletes on the takedown path are not paced. take_down calls delete_unreplied(gh, pr, rid, comments) with the default Budget(), which has no pause, so up to MAX_FINDINGS (25) DELETEs go out back to back, with resolve mutations right after. The backfill waits BACKFILL_PAUSE between writes as GitHub asks, and that rule applies here too. This path is also where throttled retries have no time limit. Pass Budget(pause=BACKFILL_PAUSE) (or a shared constant).
pytorch/scripts/pr_review/post_review.py
Line 134 in 194252b
Run-wide policy state is kept on the GitHub transport object (also lines 136, 146, 202, 750-756). deadline is a mutable on/off flag that backfill sets and resets, and request/graphql read it implicitly. replies_seen is the deletion gate: pr_comments adds to it as a side effect, and delete_unreplied/with_discussions read it. This is hidden coupling, because whether a delete is safe depends on which listings ran earlier on the same client. Make the deadline a context manager (with gh.time_limit(BACKFILL_SECONDS):) and keep the reply set in a run-owned object passed explicitly
pytorch/scripts/pr_review/post_review.py
Line 765 in 194252b
The backfill re-reads everything on every run, even when nothing is left to tidy. If any hidden review exists that is not a standing request, _backfill lists every inline comment and pages through every review thread, even when all hidden reviews are already folded and emptied. One run can list comments up to 4 times, page threads up to 3 times, and list reviews 36 times, all against GITHUB_TOKEN's per-repo rate limit. Record when a review is fully tidied (for example, a separate fold marker written only once every unreplied comment is gone) and skip such reviews before listing anything.
pytorch/scripts/pr_review/post_review.py
Line 604 in 194252b
The new module-level folded() is shadowed by review_body's local folded = \[...\] (line 318) and by _compose's folded parameter (line 339), both of which mean non-blocking findings. "Folded" now also names two different things: FOLDED_MARK (non-blocking findings) and FOLDED_REVIEW (an outdated review). Rename the new pieces, for example outdated_body(), fold collapse_outdated, and OUTDATED_REVIEW.
pytorch/scripts/pr_review/post_review.py
Line 491 in 194252b
ours() is a fourth copy of the "is this our review" check. It repeats the author + MARKER test already in earlier_reviews, standing_requests and latest_is_request. The copies have already drifted: two check isinstance(r.get("id"), int) and two don't. Pull out a single _is_ours(review, author) helper.
pytorch/scripts/pr_review/post_review.py
Line 777 in 194252b
Unclear positional arguments: delete_unreplied(gh, pr, old\["id"\], comments, budget, False, sizes) passes a bare False for refresh. Use keyword arguments (refresh=False, sizes=sizes), or make refresh and sizes keyword-only.
pytorch/scripts/pr_review/test_post_review.py
Line 1190 in 194252b
The NEARBY boundary is never tested. The "far" case puts the finding at line 3 and the comment at line 10, 7 lines apart. Testing a distance of exactly 3 (linked) and 4 (not linked) would pin the <= in note_discussions (post_review.py:532).
pytorch/scripts/pr_review/test_post_review.py
Line 1160 in 194252b
No test covers a non-blocking finding with a discussion link. note_discussions marks every finding, and finding_blocks prints the link inside the collapsed non-blocking section (post_review.py:361), but every discussion test uses major findings.
pytorch/scripts/pr_review/post_review.py
Line 780 in 194252b
latest_is_request is not tested with an overlapping newer run, where our newest review has an id greater than new_id and is a REQUEST_CHANGES or a dismissed review. Whether an older hidden request may be emptied in the backfill depends on this function (post_review.py:762-767), and this input is not covered.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
Withdrawn: the automated review of 194252b found nothing blocking.
|
@claude Review this change |
|
Claude finished @huydhn's task in 1m 58s —— View job Needs Discussion: the logic is careful, but Full reviewPR Review: #201479SummaryWhen a newer automated review replaces an earlier one, this PR folds the earlier review's body, deletes its inline comments that have no replies or reactions, links new blocking findings that sit near replied threads from the review body, and backfills the same cleanup for reviews that are already hidden. No Thread Safety
Code Quality
Testing
Performance
RecommendationNeeds Discussion The decision to delete inline comments right after the next review is irreversible and runs on every PR, so a maintainer should sign off on it. Deferring deletion to a later run is a cheap way to avoid most of the risk. Fix the remaining items in the same pass. |
huydhn
left a comment
There was a problem hiding this comment.
LGTM! The agent mentions a nit race, but I don't think we need to worry about that
|
@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 |
minimizing obsolete automatic reviews did not hide their review comments, meaning the identical comments from different review iterations could pile up on the same line.
this PR deletes obsolete comments (that don't have maintainer replies), and also edits the obsolete review to wrap them in
<details>so they render better on mobile (which doesn't currently support minimization).✴️ iz2: On PRs with many re-reviews (e.g. #201405: 24 automated reviews, 67 open inline threads), minimizing a replaced review hides only its body. Its inline comments stay listed on the Files tab and in GitHub Mobile, because
GITHUB_TOKENcan't resolve threads here.When a newer automated review replaces an earlier one, this change:
<details>section (the marker stays the first line; no cross-links)Reviews hidden by earlier runs get the same fold and delete from a backfill. The backfill runs after any clean-verdict dismissal and is capped at 50 writes, 1 second apart, and 90 seconds per run, so a PR like #201405 is cleaned over a few runs. A change request that may still stand is never folded or emptied.
Known limits:
Test plan:
python3 -m unittest discover -s scripts/pr_review -t .passes all 472 tests, including new cases for overlapping runs, reply, reaction and thread-count protection, retraction, and the backfill's budget, pacing, clock and change-request gate.