Skip to content

[pr-review] Tell the author when a PR is too large for automated review - #203136

Closed
izaitsevfb wants to merge 4 commits into
mainfrom
izaitsevfb/pr-review-size-skip-comment
Closed

izaitsevfb wants to merge 4 commits into
mainfrom
izaitsevfb/pr-review-size-skip-comment

Conversation

@izaitsevfb

@izaitsevfb izaitsevfb commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✴️ 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 ([pr-review] Give re-reviews the interdiff since the last automated review #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.

@pytorch-bot

pytorch-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

When a PR is over the size gate, the automated review now posts a COMMENT notice
(from `announce --too-large` or from `publish` on a `skipped_too_large` row)
that explains the limit and gives the opt-out command, and
`fetch_pr_comments.py` skips that notice when picking the latest verdict.
Recommendation: Approve. Every blocking finding from earlier rounds is fixed or
answered, and the points that remain are non-blocking hardening.

Findings (5):

[minor] scripts/pr_review/fetch_pr_comments.py:281
Non-blocking. The model can be handed an "Outdated" verdict as the latest
review. When a notice replaces a COMMENT verdict, `replace_earlier`
`hide_earlier`  `take_down` folds that verdict with the default `SUPERSEDED`
reason ("Outdated automated review of <sha>; a newer one replaces it").
`collect` then picks that folded verdict as `latest` and passes its body through
unchanged (:351), so the next review's model sees a body whose "newer one" is
the notice that was filtered out. Before this PR, the latest verdict was never
folded. Fix options: use a fold reason specific to the notice, unwrap folded
bodies in `collect`, or at least note this next to `TOO_LARGE_TAG`. This is
separate from the round-8 reply about losing unreplied inline findings.

[minor] scripts/pr_review/post_review.py:1220
Non-blocking. `decline(gh, pr, sha, author, opt_out, limits)` takes `author` and
`opt_out` in the opposite order from `run(gh, row, pr, sha, opt_out, author,
limits)`. Both are plain `str` and are passed positionally from `run()` and
`main()`. Both call sites are correct today and tests pin them, but a future
swap would fail quietly: `opted_out` would check for a label named after the bot
login, `too_large_body` would fall back to the default label, and
`earlier_reviews` would find no reviews. Fix: make the arguments after `sha`
keyword-only (`*, author, opt_out, limits`) and add type hints like its
neighbours `notice_stands` and `too_large_body` have.

[minor] scripts/pr_review/post_review.py:1241
Non-blocking. `decline` never calls `backfill(...)`, which `run()` calls after
every verdict it posts (:1295). Older hidden reviews that were never folded or
emptied stay that way until the next verdict run. If this is so the notice fits
inside `announce`'s 5-minute timeout, say so in `decline`'s docstring.

[minor] scripts/pr_review/post_review.py:1241
Non-blocking. No test reaches the branch where the id is not an int.
`FakeGitHub`'s POST `/reviews` always returns `"id": 999`
(test_post_review.py:137-159). Removing the `isinstance` guard leaves every test
green. In production, `hide_earlier` would then raise `KeyError` on `new["id"]`.
That is not a `GitHubError`, so `decline`'s `except` misses it, and `main`'s
catch-all warns "automated review not posted" even though the notice was posted.

[minor] scripts/pr_review/post_review.py:1203
Non-blocking. No notice test uses a CRLF body; the only CRLF test checks a
marked verdict. Deleting `.replace("rn", "n")` leaves every test green. An
unmarked CRLF notice (for example, one edited in the web UI) would then be
reposted once and the old one hidden. Add a case with `NOTICE.replace("n",
"rn")` as the newest review.

Reviewed commit: 2fe8088

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203136

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 2fe8088 with merge base 2501aef (image):
💚 Looks good so far! There are no failures yet. 💚

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Triviality
    • New feature: decline, too_large_body, notice_stands and a --too-large mode in scripts/pr_review/post_review.py, not a trivial class
    • notice_stands rewrites review bodies via PUT and decline hides earlier reviews; dedupe and restore logic needs a human read
  • CI and token plumbing
    • .github/workflows/hardened-pr-review-run.yml widens the announce job if: and adds a step using secrets.GITHUB_TOKEN with pull-requests: write
    • The notice embeds an @pytorchbot label command; its safety rests on the _PLAIN_LABEL check and pytorch-bot's line-start parsing
  • Socialization
    • Changes what authors see on oversized PRs, and fetch_pr_comments.py now skips TOO_LARGE_TAG reviews when picking the latest verdict
    • The PR thread shows open automated-review findings left for the human reviewer

reason: not_trivial
Reviewed commit: 5417007 (NOT the current head 2fe8088)

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 3, 2026
@izaitsevfb
izaitsevfb marked this pull request as ready for review November 3, 2026 21:27
@izaitsevfb
izaitsevfb requested a review from a team as a code owner November 3, 2026 21:27
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 3, 2026
@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Nov 3, 2026
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the automated review's non-blocking findings on 7967924. Taken in 2ffc4aa: a notice is no longer picked as the latest automated review in fetch_pr_comments.py; "and" is now "or"; the stale comments are fixed; announce's job if: is pinned exactly.

Not changed, deliberately:

  • An earlier change request survives an opt-out or a split. That is intended. The large PR was never evaluated, so growing it past the cap must not clear a change request. A maintainer can dismiss it.
  • The notice deletes unreplied inline findings of earlier COMMENT reviews. Every new automated review does the same when it hides the previous one, and those findings were on an older, smaller commit.
  • Silent label fallback and a configured-label test. The configured label passes _PLAIN_LABEL today, so this is latent. I'm keeping the PR minimal and leaving it for a follow-up if the label ever changes.

github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the round-2 non-blocking findings on 2ffc4aa. Not changed, to keep this PR minimal:

  • notice_stands writes. Its docstring says it puts a marked notice's body back.
  • decline repeats run()'s head and opt-out checks. run() hands off before those checks, so decline needs its own for the --too-large path.
  • Default label copies, and limits not passed per step. The limits come from workflow-level env, like the rest of that block. Without them the notice still posts, just without the numbers.
  • Configured-label test. See the label-fallback thread.

github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the round-3 non-blocking findings on 5417007. None of them is a defect in this change, so to keep the PR minimal I'm leaving these for the human reviewer: naming the limit that tripped, renaming notice_stands, a DEFAULT_OPT_OUT constant, and extra tests (a marked change request, marked or folded notices in fetch_pr_comments, and a minimized assert in the PUT-failure test). That was the third automated round, so this PR now waits for human review.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Requesting one more automated review of 5417007 with the round-3 replies above in view; no code change since.
@pytorchbot review

@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 4, 2026
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the final automated review on 5417007. I'm not making code changes for it, and this PR now waits for human review.

  • SKILL.md Local CLI line: my reason for leaving it is scope, not prompt-hash cost. SKILL.md is the prompt for every automated review. The stale fetch_pr_comments.py docstring wording ("latest review" should say "latest verdict") and the misplaced By id comment are fair, and they're comment-only. The human reviewer can choose to take them in this PR.
  • skipped_too_large contract test: same answer as in its thread. The string predates this PR, and three existing readers already depend on it.
  • Cleanup retry: answered in its thread.
  • Non-blocking findings (gate wording in comments, naming the limit that tripped, helper naming and duplication, step-gate parsing, test placement and extra tests): left for the human reviewer.

@huydhn huydhn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@izaitsevfb
izaitsevfb dismissed stale reviews from github-actions[bot], github-actions[bot], github-actions[bot], and github-actions[bot] November 4, 2026 19:27

✴️ iz2: Dismissing the automated review at Ivan's request: Huy approved, and the remaining findings were answered in-thread.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Merging at Ivan's request.
@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 4, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re-merging at Ivan's request; Dr.CI now classifies the lint failure as not related.
@pytorchbot merge

A PR over the size gate (100 changed files or 400 KB of diff) was skipped
with only an S3 telemetry row and a collapsed Dr.CI line, so authors read it
as the review being broken. Post a COMMENT review instead that says why,
suggests splitting the PR, and gives the pytorchbot command to opt out.
The bot never applies the opt-out label itself.
Skip reposting only when the newest automated review is this exact notice.
A notice marked in progress by `announce` on the diff-size path gets its
body back instead of a new notice on every run, and a notice put back
defused is replaced. fetch_pr_comments no longer treats a notice as the
latest verdict. The limit sentence says "or".
A failed write-back left the marked notice for --restore-pending, which put it back with the command defused. Post a fresh notice instead. Test the guard that keeps a marked verdict from being overwritten, and state that a change request stays after an opt-out until a maintainer dismisses it.
@izaitsevfb
izaitsevfb force-pushed the izaitsevfb/pr-review-size-skip-comment branch from 5707942 to 2fe8088 Compare November 5, 2026 02:06
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the automated review on 2fe8088: the new findings are answered in their threads with no code change (doc wording and test hardening, none a behaviour bug); the rest repeat findings answered earlier. Requesting a re-review to read the replies.
@pytorchbot review

@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 5, 2026
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Re the automated review of 2fe8088 (round 8): every blocking finding repeats one already answered in its thread; replies to the three new non-blocking ones are below. No code change.
@pytorchbot review

  • Notice hiding a dismissed change request's findings: deliberate. The notice hides earlier reviews like any new review, and a dismissed request is no longer standing, so it is treated like any superseded verdict (a standing one is left alone and tested). The next review of a smaller commit still covers the whole PR; it only loses that verdict's unreplied findings as prior context, which it re-derives from the code.
  • if: gate read in the contract test: fair hardening of a test, not a behaviour issue; a follow-up.
  • Saying the opt-out label is one-way: a reasonable wording addition to the notice; left for the human reviewer rather than another push and CI round.

@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of 2fe8088: nothing blocking; ready for human review.

When a PR is over the size gate, the automated review now posts a COMMENT notice (from announce --too-large or from publish on a skipped_too_large row) that explains the limit and gives the opt-out command, and fetch_pr_comments.py skips that notice when picking the latest verdict. Recommendation: Approve. Every blocking finding from earlier rounds is fixed or answered, and the points that remain are non-blocking hardening.

⚪ 5 non-blocking findings

Non-blocking. The model can be handed an "Outdated" verdict as the latest review. When a notice replaces a COMMENT verdict, replace_earlier hide_earlier take_down folds that verdict with the default SUPERSEDED reason ("Outdated automated review of <sha>; a newer one replaces it"). collect then picks that folded verdict as latest and passes its body through unchanged (:351), so the next review's model sees a body whose "newer one" is the notice that was filtered out. Before this PR, the latest verdict was never folded. Fix options: use a fold reason specific to the notice, unwrap folded bodies in collect, or at least note this next to TOO_LARGE_TAG. This is separate from the round-8 reply about losing unreplied inline findings.

An earlier comment near this line has replies: #203136 (comment)


def decline(gh, pr, sha, author, opt_out, limits) -> int:

Non-blocking. decline(gh, pr, sha, author, opt_out, limits) takes author and opt_out in the opposite order from run(gh, row, pr, sha, opt_out, author, limits). Both are plain str and are passed positionally from run() and main(). Both call sites are correct today and tests pin them, but a future swap would fail quietly: opted_out would check for a label named after the bot login, too_large_body would fall back to the default label, and earlier_reviews would find no reviews. Fix: make the arguments after sha keyword-only (*, author, opt_out, limits) and add type hints like its neighbours notice_stands and too_large_body have.


if isinstance(new.get("id"), int):

Non-blocking. decline never calls backfill(...), which run() calls after every verdict it posts (:1295). Older hidden reviews that were never folded or emptied stay that way until the next verdict run. If this is so the notice fits inside announce's 5-minute timeout, say so in decline's docstring.

An earlier comment near this line has replies: #203136 (comment)


if isinstance(new.get("id"), int):

Non-blocking. No test reaches the branch where the id is not an int. FakeGitHub's POST /reviews always returns "id": 999 (test_post_review.py:137-159). Removing the isinstance guard leaves every test green. In production, hide_earlier would then raise KeyError on new\["id"\]. That is not a GitHubError, so decline's except misses it, and main's catch-all warns "automated review not posted" even though the notice was posted.

An earlier comment near this line has replies: #203136 (comment)


text = (review.get("body") or "").replace("\r\n", "\n")

Non-blocking. No notice test uses a CRLF body; the only CRLF test checks a marked verdict. Deleting .replace("rn", "n") leaves every test green. An unmarked CRLF notice (for example, one edited in the web UI) would then be reposted once and the old one hidden. Add a case with NOTICE.replace("n", "rn") as the newest review.

An earlier comment near this line has replies: #203136 (comment)

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@github-actions
github-actions Bot dismissed stale reviews from themself November 5, 2026 03:06

Withdrawn: the automated review of 2fe8088 found nothing blocking.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: Merging at Ivan's request after the second rebase; CI on 2fe8088 is green and the head merges cleanly into main.
@pytorchbot merge

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 5, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…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
izaitsevfb added a commit to pytorch/test-infra that referenced this pull request Nov 6, 2026
…DING) (#9332)

✴️ iz2: opened for @izaitsevfb, who asked for this change.

trymerge fails a merge on the first check that sees a failed job, even
when an AI CI Advisor verdict that would clear the job is minutes away.
On pytorch/pytorch#203136 the merge failed at 11:55am PST and the
`not_related` verdict landed by 12:03pm PST. trymerge's live Dr.CI call
already dispatches the advisor; it just can't tell "verdict coming" from
"no verdict".

This adds an `AI_PENDING` key to Dr.CI's answer: failures still blocking
whose latest advisor dispatch was made after the run finished, within
the last 20 minutes, and has no verdict yet. Only failures a verdict
could clear count (a conclusive `failure`, not a PR-state gate), and
only while `DRCI_ADVISOR_SUPPRESSION_ENABLED` is on.

- The jobs stay in FAILED/UNKNOWN, and the comment does not change.
- The key is left out of the check-run summary, a snapshot that can lag
the live answer.
- A failed verdict or dispatch-state read, or any error, yields no key,
which is today's behavior.
- A failed dispatch, even one auto-dispatch may retry, and a dispatch
made before the run finished don't count. Whether a retry or re-dispatch
happens is decided by guards elsewhere, and a wrong "pending" costs a
merge a pointless wait.
- The 20-minute bound comes from 14 days of dispatches: 99.9% of
answered ones were answered within 15 minutes, and 31 of 34 left in
`dispatching` were never answered.

Known limit: verdicts are read per PR and dispatch states per head, so
two open PRs sharing a head could see a pending dispatch the other PR
already got an answer for. In the last 30 days, 0 of 3,652 dispatched
heads belonged to more than one PR, and the cost is a bounded wait.

pytorch/pytorch#203462 makes trymerge wait on these jobs for up to 15
minutes each. Nothing reads the key until that lands. No ClickHouse
query is added or changed.

Test plan: new jest cases for `isAwaitingVerdict` /
`awaitingVerdictJobIds` and the summary filter. Mutating the
eligibility, live-dispatch, after-run, age, answered and null-read
checks, or the summary filter, each fails a test. torchci gates pass:
prettier, next lint, tsc, jest. Not covered: an end-to-end test through
`updateDrciComments`, which has no test harness.
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…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
pytorchmergebot pushed a commit that referenced this pull request Nov 10, 2026
…till on the way (#203462)

✴️ iz2: opened for @izaitsevfb, who asked for this change.

A merge fails on the first loop iteration that sees a failed job outside Dr.CI's ignorable categories, even when Dr.CI is about to classify it:

- #202436 failed 41 s after its macOS job did. Dr.CI's live answer didn't list the job in any category yet, and Dr.CI later classed it as flaky.
- #203136 failed while the AI CI Advisor verdict that later cleared the job was still running.

With this change, `merge()` counts a failed GitHub Actions job as pending, for up to 15 minutes per job, while either:
- Dr.CI's live answer lists the job in no category (Dr.CI reads jobs from a database that lags GitHub), or
- Dr.CI lists it under `AI_PENDING` (pytorch/test-infra#9332): a verdict that may clear it is on the way.

As soon as the job is classified, or after 15 minutes, it is handled as today. Waiting clears nothing; only Dr.CI's existing categories do. Check names in the merge record are unchanged. For the PR being merged, and for a stacked PR's mandatory checks, the retry and reject messages say a job is waiting on its classification, and a failure message says when the merge waited on a job that still blocks it. A stacked PR's other failed or pending jobs keep today's messages.

Scope:
- Only plain `FAILURE` conclusions of GitHub Actions jobs. App check runs such as EasyCLA never wait.
- Only a non-empty live Dr.CI answer starts a wait. The check-run summary fallback never does. An empty answer doesn't either, because Dr.CI also answers `{}` for a repo it has no data for. Once open, a wait survives a failed or empty Dr.CI call until its 15 minutes run out.
- Only `merge()`, including the lower PRs of ghstack and native stacks. Other callers of `get_classifications` / `find_matching_merge_rule` pass no window and skip the wait logic entirely.
- `merge_into` now runs a ghstack stack's lower-PR rule checks before the GreenLight check, as it already did for native stacks. Whether a lower PR's human approvals suffice without GreenLight's can depend on its CI, and that answer is cached for the merge, so it is asked only once the PR's own checks pass; a waiting job retries first. Lower ghstack PRs are now checked against the clone's rules file before it is reset to trunk, as the top PR already was.

Cost: a merge whose failure is real reports later if Dr.CI hasn't listed the job or its verdict comes back `related`: at most about 20 minutes, since the 15-minute budget is checked on 5-minute retries. Usually that is one or two retries, since the advisor's p95 is 6 minutes from dispatch.

Known limits:
- The unlisted check matches Dr.CI's answer by job id. When trymerge holds a different run's id for a job than Dr.CI lists (a newer run dropped the job, or an older run's entry overwrote the newer one), that failure, which blocks today, reports 15 minutes late.

Test plan: `python -m unittest test_trymerge`, with new `TestClassificationWait` tests: the matchers (including a malformed `AI_PENDING` list and checks that are not Actions jobs), precedence over arrived classifications and `-i`, the real `find_matching_merge_rule` with a waiting and an expired mandatory job, a wait surviving a failed Dr.CI call, one window shared by a stack, and `merge()` (on a clock its sleeps advance) looping until the job is classified or the budget runs out, with the failure note only for jobs it slept on, plus a test that a waiting lower ghstack PR retries before the GreenLight check is asked. Removing any window hand-off, wait condition, waiting reason or expiry note fails a test. The full suite passes (274 tests).
Pull Request resolved: #203462
Approved by: https://github.com/jeanschmidt, https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes Merged ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants