Skip to content

[trymerge] Wait, bounded, for a failed job's classification that is still on the way - #203462

Closed
izaitsevfb wants to merge 4 commits into
mainfrom
iz/trymerge-wait-ai-pending
Closed

izaitsevfb wants to merge 4 commits into
mainfrom
iz/trymerge-wait-ai-pending

Conversation

@izaitsevfb

@izaitsevfb izaitsevfb commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✴️ 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:

With this change, merge() counts a failed GitHub Actions job as pending, for up to 15 minutes per job, while either:

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).

@izaitsevfb
izaitsevfb requested a review from a team as a code owner November 4, 2026 21:14
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 4, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 4, 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:

The PR makes merge() treat a failed GitHub Actions job as pending for up to 15
minutes while Dr.CI hasn't listed it yet or lists it under AI_PENDING, and for
ghstack stacks it runs the lower-PR rule checks before the GreenLight check.
Recommendation: Approve. Every maintainer request is addressed, and the only
points left are non-blocking cleanup and message wording.

Findings (2):

[minor] .github/scripts/trymerge.py:1746
Non-blocking: the ghstack lower-PR gate in `merge_ghstack_into` (`if pr.pr_num
!= self.pr_num and not skip_all_rule_checks:` at :1564-1571) is now unreachable.
Both production callers of `merge_changes_locally` pass
`skip_all_rule_checks=True`: `merge_into` here and `--check-mergeability` at
:4152-4156. Because this PR dropped `ignore_current_checks=` from this call, no
caller passes `merge_changes_locally(ignore_current_checks=...)` (:1831,
forwarded at :1865) anymore. Tests at test_trymerge.py:1627, :1662, :1692 and
:1725 call `merge_ghstack_into` directly, so they pin a path production no
longer takes, and the docstring at :1701 describes the wrong path. Risk: a
future caller passing `skip_all_rule_checks=False` would rule-check lower PRs a
second time, without the window and after the clone is reset to trunk. Fix:
delete the branch and the `ignore_current_checks`, `skip_mandatory_checks` and
`comment_id` plumbing that only feeds it, then delete those tests or move them
onto `merge_into`.

[minor] .github/scripts/trymerge.py:2274
Non-blocking: lower-PR messages don't say a job is waiting.
`check_stacked_pr_merge_rule` now passes the window into
`find_matching_merge_rule`, so a lower PR's failed non-mandatory job can be
marked `DRCI_PENDING`/`AI_PENDING` and land in `pending`. But the messages at
:2293-2299 print only `x[0]`. "Still waiting for N jobs to finish on stacked PR
#X" is missing the "(failed, waiting for )" label from `with_waiting_reasons`.
"N jobs have failed on stacked PR #X" is missing `waited_note`, even though
`note_retry` has already put those job ids in `waited_on`. This contradicts the
description and the author's reply ("Each waiting job carries its reason").
Those hold only for the top PR and lower-PR mandatory checks. Fix: adding
`waited_note(failing, classification_wait)` is one line. The label needs
`find_matching_merge_rule` to return the classified `checks`. Alternatively,
narrow the description.

Reviewed commit: a3b9ea6

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Cancelled Job, 1 Unrelated Failure

As of commit a3b9ea6 with merge base cb61663 (image):

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

  • Merge authorization
    • Edits .github/scripts/trymerge.py, which decides whether a PR may land; the Never trivial list covers this
    • categorize_checks now counts DRCI_PENDING/AI_PENDING failed jobs as pending rather than failed
  • Behavior change
    • merge() keeps a failed job waiting up to CLASSIFICATION_WAIT_SECONDS (15 min) through ClassificationWaitWindow
    • find_matching_merge_rule and check_stacked_pr_merge_rule thread the window to lower ghstack and native-stack PRs
  • Socialization
    • Changes the shape of the merge reject and retry messages through with_waiting_reasons and waited_note
    • Depends on Dr.CI's AI_PENDING contract from pytorch/test-infra#​9332; that is a cross-repo design question for a human

reason: not_trivial
Reviewed commit: 32e5bae (NOT the current head a3b9ea6)

Inference job

🐛 Report a wrong verdict

NEW FAILURE - The following job has failed:

  • trunk / win-vs2022-cpu-py3 / test (default, 4, 12, windows.4xlarge.nonephemeral) (gh)
    AssertionError: Torch not compiled with CUDA enabled

    AI verdict: AI verdict: probably not related

    The suspect commit only modifies .github/scripts/trymerge.py and its test, neither of which runs in the Windows CPU test shard. The 'Torch not compiled with CUDA' line is benign output from a passing test. The shard actually failed because test_nestedtensor exited with signal 2 after all 1387 tests passed, an isolated process-exit flake on an otherwise green trunk history.

    Full reasoning on HUD →

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:

CANCELLED JOB - The following job was cancelled. Please retry:

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

@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Nov 4, 2026
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 4, 2026
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from 373af48 to ce324bf Compare November 4, 2026 22:26
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from ce324bf to 3a2bebd Compare November 4, 2026 23:16
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from 3a2bebd to 1d257ae Compare November 4, 2026 23:38
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: I've answered the blocking finding in its thread and narrowed the description. Here are replies to the non-blocking findings. Requesting a re-review.
@pytorchbot review

  • The note counts a job whose budget opened in the same iteration. That needs Dr.CI to list the job between the rule check and the loop's own classification call, a few seconds apart. It is rare, and the note is informational. Not changing it in this PR.
  • A non-mandatory failure can be recorded under pending. This only happens if the job fails, unlisted, between the loop's check and merge_into's rule check, which is the same race window. Merge decisions are unaffected. Not changing it in this PR.
  • "Still waiting for N jobs to finish" covers failed jobs. Each waiting job carries its reason, e.g. "(failed, waiting for Dr.CI to classify it)", so the list says what is happening. I'm keeping the existing headlines so log searches on them still match.
  • Rename within_budget to register_wait. The first review asked to drop register_wait, because GreenlightWaitWindow.register_wait returns the opposite truth value. The docstring states the side effect. Keeping the name.
  • Tie CLASSIFICATION_WAIT_SECONDS to the retry interval. The budget is set by the advisor's latency, not by the retry cadence; the comment explains the current numbers. Keeping the constant.

@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
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from 1d257ae to cbf36c3 Compare November 5, 2026 00:34
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from cbf36c3 to cbc5704 Compare November 5, 2026 01:00
@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: I replied in the round-6 threads: one pushback on the zero-retry finding and an explanation of the URL filter. The stack test was added in cbc5704.
@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
@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from cbc5704 to 4f88b94 Compare November 5, 2026 01:10
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb
izaitsevfb force-pushed the iz/trymerge-wait-ai-pending branch from 4f88b94 to 508c621 Compare November 5, 2026 01:30
github-actions[bot]

This comment was marked as outdated.

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: I replied in the round-8 threads. None of the three needs a code change: the near-deadline case behaves like main, and the other two are test-shape requests.
@pytorchbot review

@github-actions
github-actions Bot dismissed stale reviews from themself November 7, 2026 02:05

Withdrawn: the automated review of a3b9ea6 found nothing blocking.

@pytorch-bot
pytorch-bot Bot requested a review from jeanschmidt November 7, 2026 02:46
@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 7, 2026
@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: @jeanschmidt, every point from your review is now addressed. The head is a3b9ea6, CI is green, and the latest automated review finds nothing blocking.

  • Blocker, the cached GreenLight answer on a stack (b6c3cf4): merge_into now runs a ghstack stack's lower-PR rule checks, with the wait window, before the GreenLight check, as it already did for native stacks. A lower PR whose job is still waiting retries first, so is_authorized_without_greenlight is asked, and its answer cached, only once that PR's own checks pass. Covered by test_a_waiting_lower_ghstack_pr_retries_before_the_greenlight_check.
  • is_ai_pending shape (a3b9ea6): a malformed AI_PENDING list is skipped, like in is_unlisted_by_drci, instead of failing the merge.
  • GHA-URL asymmetry (a3b9ea6): the Actions job URL check moved into awaiting_classification, so it covers the unlisted, AI_PENDING and saved-reason paths. App checks such as EasyCLA never wait.
  • Duplicated FAILURE-only rule (a3b9ea6): awaiting_classification takes the window and owns the saved-reason fallback, so the rule is written once.

I also dropped the classification_wait parameters of merge_changes_locally and merge_ghstack_into, since no production caller reaches them after the reorder.

Not in this PR: the two items you marked as reasonable follow-ups, the merge record listing a waiting failure under pending_checks and the within_budget rename.

@izaitsevfb
izaitsevfb dismissed jeanschmidt’s stale review November 10, 2026 00:53

the issue was addressed

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 10, 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: 2 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: restarting the merge. Its only failures are Lint / Test collect_env on the old runner image (no Python 3.8 on Ubuntu 26.04, fixed on main by #203982; this PR doesn't touch lint.yml) and that job's cancelled sibling.
@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: Lint / Test collect_env (older_python_version, linux.24_04.4x), Lint / Test collect_env (with_torch, linux.24_04.4x)

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 jobs have failed, first few of them are: trunk / win-vs2022-cpu-py3 / test (default, 4, 12, windows.4xlarge.nonephemeral)

Details for Dev Infra team

Raised by workflow job

@izaitsevfb

Copy link
Copy Markdown
Contributor Author

✴️ iz2: restarting the merge again. The new failure is a Windows CPU test shard (Torch not compiled with CUDA enabled); this PR only changes .github/scripts/trymerge.py and its test, which that shard doesn't run.
@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: Lint / Test collect_env (older_python_version, linux.24_04.4x), Lint / Test collect_env (with_torch, linux.24_04.4x), trunk / win-vs2022-cpu-py3 / test (default, 4, 12, windows.4xlarge.nonephemeral)

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 pushed a commit that referenced this pull request Nov 19, 2026
…p PR (#205625)

✴️ iz2: `merge_into` runs `check_stacked_pr_merge_rule` on each lower stacked PR, but no test checked that it forwards `skip_mandatory_checks` and `skip_internal_checks`. Hardcoding either to `False` in that loop left `test_trymerge.py` green. The `-i` waivers in the same call were already covered by `test_gates_lower_prs_before_landing`.

This adds `test_lower_prs_skip_the_same_checks_as_the_top_pr`, which sets each flag alone and both together, and checks the internal-skip answer comes from the top PR's merge comment. It also rewords the docstring of `test_merge_ghstack_into_gates_lower_prs_with_the_waivers`: that test covers `merge_ghstack_into`'s own gate, which production skips (every caller passes `skip_all_rule_checks=True` since #203462).

Follow-up to #203140's review. Test-only.

Test plan: `python -m unittest test_trymerge`: the new test passes; it fails with either flag hardcoded to `False` in `merge_into`'s loop, with the two flags swapped, with the internal skip dropped only when both are set, or with `can_skip_internal_checks` called per lower PR. lintrunner (FLAKE8, PYFMT) clean.
Pull Request resolved: #205625
Approved by: https://github.com/pytorchgreenlight, https://github.com/jeanschmidt
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.

5 participants