Skip to content

mergebot: identify failing PR in ghstack merge rule errors - #181506

Closed
wdvr wants to merge 1 commit into
pytorch:mainfrom
wdvr:improve-ghstack-merge-rule-error
Closed

wdvr wants to merge 1 commit into
pytorch:mainfrom
wdvr:improve-ghstack-merge-rule-error

Conversation

@wdvr

@wdvr wdvr commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a ghstack PR fails to merge because a parent PR in the stack lacks required approvals (or required checks), the error surfaced by merge_ghstack_into gives no hint about which PR in the stack is the problem. The user sees something like:

Approvers from one of the following sets are needed:

  • superuser (pytorch/metamates)
  • Core Reviewers (...)
  • Core Maintainers (...)

…posted on the top PR — even though it's actually a parent that needs the approval.

This just hit #181437: the top PR only changes .github/workflows/pull.yml (covered by the OSS CI rule, fully approved), but the parent #181434 only changes torchgen/gen.py, which has no specific merge rule and falls through to the catch-all * rules requiring Core Reviewers / Core Maintainers / superuser. None of the parent's reviewers were in those sets, but the merge bot only ever named the top PR.

Change

Wrap the per-PR find_matching_merge_rule call inside merge_ghstack_into to re-raise with the failing PR number prefixed, preserving the original exception subclass (so callers that distinguish MandatoryChecksMissingError from MergeRuleFailedError keep working — that distinction drives retry behavior at trymerge.py:2391/2444).

After this PR, the same failure surfaces as:

Merge rule check failed for stacked PR #181434:

Approvers from one of the following sets are needed: …

Test plan

  • Added test_merge_ghstack_into_wraps_parent_rule_error — verifies the failing parent's PR number appears in the message and the exception is MergeRuleFailedError but not the MandatoryChecksMissingError subclass.
  • Added test_merge_ghstack_into_preserves_mandatory_checks_subclass — verifies a MandatoryChecksMissingError from a parent stays a MandatoryChecksMissingError so retry behavior keeps working.
  • pytest .github/scripts/test_trymerge.py::TestGitHubPRGhstackDependencies — 4 passed, 1 skipped (pre-existing).

Authored with Claude.

@wdvr
wdvr requested a review from a team as a code owner April 26, 2026 03:49
@pytorch-bot

pytorch-bot Bot commented Apr 26, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 1 Pending

As of commit 28f92bb with merge base a528959 (image):

NEW FAILURE - The following job has failed:

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 Apr 26, 2026
When a ghstack PR fails to merge because a parent PR in the stack lacks
required approvals, the error surfaced from `find_matching_merge_rule`
gives no hint about which PR in the stack is missing approval. The user
sees "Approvers from one of the following sets are needed: ..." on the
top PR even though the parent is the one missing reviewers, which makes
it confusing to debug (e.g. PR pytorch#181437 hit this where the parent PR
pytorch#181434 was the one without core approval).

Wrap the per-PR `find_matching_merge_rule` call in `merge_ghstack_into`
to re-raise with the failing PR number prefixed, preserving the original
exception type so callers that distinguish `MandatoryChecksMissingError`
from `MergeRuleFailedError` keep working.

Authored with Claude.
@wdvr
wdvr force-pushed the improve-ghstack-merge-rule-error branch from bfc9fee to 28f92bb Compare April 26, 2026 03:58

@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!

@wdvr

wdvr commented Apr 26, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -f "don't care about XPU tests for this infra change"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…81506)

## Summary

When a ghstack PR fails to merge because a parent PR in the stack lacks required approvals (or required checks), the error surfaced by `merge_ghstack_into` gives no hint about which PR in the stack is the problem. The user sees something like:

> Approvers from one of the following sets are needed:
> - superuser (pytorch/metamates)
> - Core Reviewers (...)
> - Core Maintainers (...)

…posted on the top PR — even though it's actually a parent that needs the approval.

This just hit pytorch#181437: the top PR only changes `.github/workflows/pull.yml` (covered by the OSS CI rule, fully approved), but the parent pytorch#181434 only changes `torchgen/gen.py`, which has no specific merge rule and falls through to the catch-all `*` rules requiring Core Reviewers / Core Maintainers / superuser. None of the parent's reviewers were in those sets, but the merge bot only ever named the top PR.

## Change

Wrap the per-PR `find_matching_merge_rule` call inside `merge_ghstack_into` to re-raise with the failing PR number prefixed, preserving the original exception subclass (so callers that distinguish `MandatoryChecksMissingError` from `MergeRuleFailedError` keep working — that distinction drives retry behavior at trymerge.py:2391/2444).

After this PR, the same failure surfaces as:

> Merge rule check failed for stacked PR pytorch#181434:
>
> Approvers from one of the following sets are needed: …

## Test plan

- [x] Added `test_merge_ghstack_into_wraps_parent_rule_error` — verifies the failing parent's PR number appears in the message and the exception is `MergeRuleFailedError` but **not** the `MandatoryChecksMissingError` subclass.
- [x] Added `test_merge_ghstack_into_preserves_mandatory_checks_subclass` — verifies a `MandatoryChecksMissingError` from a parent stays a `MandatoryChecksMissingError` so retry behavior keeps working.
- [x] `pytest .github/scripts/test_trymerge.py::TestGitHubPRGhstackDependencies` — 4 passed, 1 skipped (pre-existing).

Authored with Claude.
Pull Request resolved: pytorch#181506
Approved by: https://github.com/huydhn
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…81506)

## Summary

When a ghstack PR fails to merge because a parent PR in the stack lacks required approvals (or required checks), the error surfaced by `merge_ghstack_into` gives no hint about which PR in the stack is the problem. The user sees something like:

> Approvers from one of the following sets are needed:
> - superuser (pytorch/metamates)
> - Core Reviewers (...)
> - Core Maintainers (...)

…posted on the top PR — even though it's actually a parent that needs the approval.

This just hit pytorch#181437: the top PR only changes `.github/workflows/pull.yml` (covered by the OSS CI rule, fully approved), but the parent pytorch#181434 only changes `torchgen/gen.py`, which has no specific merge rule and falls through to the catch-all `*` rules requiring Core Reviewers / Core Maintainers / superuser. None of the parent's reviewers were in those sets, but the merge bot only ever named the top PR.

## Change

Wrap the per-PR `find_matching_merge_rule` call inside `merge_ghstack_into` to re-raise with the failing PR number prefixed, preserving the original exception subclass (so callers that distinguish `MandatoryChecksMissingError` from `MergeRuleFailedError` keep working — that distinction drives retry behavior at trymerge.py:2391/2444).

After this PR, the same failure surfaces as:

> Merge rule check failed for stacked PR pytorch#181434:
>
> Approvers from one of the following sets are needed: …

## Test plan

- [x] Added `test_merge_ghstack_into_wraps_parent_rule_error` — verifies the failing parent's PR number appears in the message and the exception is `MergeRuleFailedError` but **not** the `MandatoryChecksMissingError` subclass.
- [x] Added `test_merge_ghstack_into_preserves_mandatory_checks_subclass` — verifies a `MandatoryChecksMissingError` from a parent stays a `MandatoryChecksMissingError` so retry behavior keeps working.
- [x] `pytest .github/scripts/test_trymerge.py::TestGitHubPRGhstackDependencies` — 4 passed, 1 skipped (pre-existing).

Authored with Claude.
Pull Request resolved: pytorch#181506
Approved by: https://github.com/huydhn
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…81506)

## Summary

When a ghstack PR fails to merge because a parent PR in the stack lacks required approvals (or required checks), the error surfaced by `merge_ghstack_into` gives no hint about which PR in the stack is the problem. The user sees something like:

> Approvers from one of the following sets are needed:
> - superuser (pytorch/metamates)
> - Core Reviewers (...)
> - Core Maintainers (...)

…posted on the top PR — even though it's actually a parent that needs the approval.

This just hit pytorch#181437: the top PR only changes `.github/workflows/pull.yml` (covered by the OSS CI rule, fully approved), but the parent pytorch#181434 only changes `torchgen/gen.py`, which has no specific merge rule and falls through to the catch-all `*` rules requiring Core Reviewers / Core Maintainers / superuser. None of the parent's reviewers were in those sets, but the merge bot only ever named the top PR.

## Change

Wrap the per-PR `find_matching_merge_rule` call inside `merge_ghstack_into` to re-raise with the failing PR number prefixed, preserving the original exception subclass (so callers that distinguish `MandatoryChecksMissingError` from `MergeRuleFailedError` keep working — that distinction drives retry behavior at trymerge.py:2391/2444).

After this PR, the same failure surfaces as:

> Merge rule check failed for stacked PR pytorch#181434:
>
> Approvers from one of the following sets are needed: …

## Test plan

- [x] Added `test_merge_ghstack_into_wraps_parent_rule_error` — verifies the failing parent's PR number appears in the message and the exception is `MergeRuleFailedError` but **not** the `MandatoryChecksMissingError` subclass.
- [x] Added `test_merge_ghstack_into_preserves_mandatory_checks_subclass` — verifies a `MandatoryChecksMissingError` from a parent stays a `MandatoryChecksMissingError` so retry behavior keeps working.
- [x] `pytest .github/scripts/test_trymerge.py::TestGitHubPRGhstackDependencies` — 4 passed, 1 skipped (pre-existing).

Authored with Claude.
Pull Request resolved: pytorch#181506
Approved by: https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants