Repository navigation
[trymerge] Add greenlight preflight filters and outcome messages - #194839
Closed
jeanschmidt wants to merge 3 commits into
Closed
jeanschmidt wants to merge 3 commits into
jeanschmidt wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194839
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 22 Pending, 2 Unrelated FailuresAs of commit f98c920 with merge base e812f6f ( GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 26, 2026
huydhn
approved these changes
Aug 27, 2026
huydhn
reviewed
Aug 27, 2026
| "until greenlight records a verdict for the exact commit being landed." | ||
| ) | ||
|
|
||
| FIX_HUMAN = ( |
Contributor
There was a problem hiding this comment.
Nit: FIX_HUMAN and FIX_RETRIGGER sounds the same to me
Contributor
jeanschmidt
added a commit
that referenced
this pull request
Aug 27, 2026
`greenlight_preflight.py` detects PRs greenlight will never produce a verdict for, so a merge can refuse immediately instead of waiting out the full budget for an answer that is not coming. It mirrors the upstream filters that drop a PR before it is ever fingerprinted — `review._recency_filter` (excluded labels and the review window, each with an escape for a PR whose recorded status is non-terminal) and both arms of `review_gate.human_review_skip_reason` (changes requested by a non-bot, and an approval from the merge-authorized set). Each mirrored constant is commented with its upstream source in pytorch/test-infra under `greenlight/src/greenlight/`, because drift in either direction either costs a merge an hour of waiting or refuses a PR greenlight would in fact have reviewed. `greenlight_messages.py` is the single place that renders guard outcomes as text. Three surfaces share one set of outcomes: the refusal that ends a merge, the line the retry loop logs while it waits, and the comment posted to the PR the first time a merge waits. Split out from the guard so the mirrored upstream filters can be reviewed against greenlight's own source on their own, and to keep each change under the 2000 LOC infra limit. Both modules sit above the ledger and identity leaves and below the guard itself: preflight reads the ledger's status sets and identity's normalization, messages reads the ledger's route URL and preflight's excluded-labels phrase. The references each makes back to `greenlight_guard` are annotations only, under `TYPE_CHECKING`, so nothing here imports the guard at runtime. Signed-off-by: Jean Schmidt <[email protected]> ghstack-source-id: a5efac2 Pull-Request: #194839
Collaborator
|
Starting merge as part of PR stack under #194841 |
pytorchmergebot
pushed a commit
that referenced
this pull request
Aug 28, 2026
`greenlight_guard.py` is the decision itself. It compares the head SHA greenlight recorded in its ledger against the head actually being landed and returns ALLOW, WAIT or DENY, along with the wait budget (`GreenlightWaitWindow`) a merge carries across re-entries. Everything it needs about a PR arrives as plain data or as a callable on `PRUnderMerge` — the callables stay callables because each one costs a GitHub request that only the minority of PRs greenlight alone authorizes ever needs. It must not import `trymerge`: `trymerge` imports it, and the cycle would break both. Two failure directions are split deliberately. Anything that is only unknown — no ledger row, a verdict for an older commit, a review still running, an unreadable HUD, a reviewer GitHub would not classify — waits, and is refused only once the budget is spent. Anything settled against the head being landed — NO_LAND/CANCELLED/FAILED, an unrecognized status, a review that has outlived greenlight's own timeout — refuses at once. Refusing on first uncertainty would turn a HUD blip into a dead merge; waiting on a settled negative would burn an hour and land nothing. The tests cover the decision table, stack handling, the laziness of the per-PR GitHub lookups, the ledger's transport failure modes against a mocked `gh_fetch_url` (every documented route error code, malformed payloads, batch capping, backoff, recovery on retry), and the preflight mirror. No test touches the network. They land together with the guard because `test_greenlight_guard.py` owns the shared PR fixtures that the ledger and preflight tests build on. Split out from the `trymerge.py` wiring so the verdict logic can be reviewed against greenlight's behaviour independently of the merge path, and to keep each change under the 2000 LOC infra limit. Nothing calls into this yet. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: #194840 Approved by: https://github.com/huydhn ghstack dependencies: #194838, #194839
pytorchmergebot
pushed a commit
that referenced
this pull request
Aug 28, 2026
…194841) **Impact:** mergebot only — PRs whose sole merge authorization is the `pytorchgreenlight` approval **Risk:** medium Depends on pytorch/test-infra#8630 to be merged before merging this one ## What Wires the greenlight land-time guard into `merge_into`: when the only approval that satisfies a merge rule is greenlight's, trymerge reads greenlight's verdict ledger and refuses to land unless greenlight recorded `LAND` for the head commit that is actually being merged. The verdict logic already lives in the `greenlight_*.py` modules next to trymerge; this change only feeds the PR facts in and turns the verdict into the exception the merge loop already understands. Three smaller changes in `trymerge.py` that are worth reading on their own: - `find_matching_merge_rule` gains an `approved_by_override` kwarg, so the guard can ask "would any rule still match if greenlight had not approved?" without duplicating rule evaluation. Default behaviour is unchanged. - The inline approver expansion is extracted to `rule_approvers`, and a malformed team ref (`org/team/extra`) now raises instead of expanding to nobody. Previously `gh_get_team_members` warned, returned `[]`, and the rule then matched *any* approver. - Two REST accessors (`get_updated_at`, `get_bot_reviewers`) added on `GitHubPR`. They are REST rather than fields on `GH_GET_PR_INFO_QUERY` because that query text is the cache key for the recorded GraphQL fixtures — extending it invalidates all of them. ## Why `merge_rules.yaml`'s "Greenlight Review Bot" rule lets a single `pytorchgreenlight` approval authorize a merge of any path, and pytorch/pytorch has no GitHub-native required reviews, so that approval is never dismissed when the author pushes more commits. Today an author can get greenlight's approval on a benign commit, push anything on top, and `@pytorchbot merge` lands unreviewed content. This closes that window by comparing the head SHA greenlight actually evaluated against the head being landed. # Notes Behaviour reviewers should sanity-check: - **Scope.** The guard is skipped entirely when greenlight did not approve, and when any other merge rule still matches after dropping greenlight's approval. A drive-by approval from a random GitHub user does *not* switch it off. - **Waiting.** "greenlight hasn't answered yet" raises `MandatoryChecksMissingError`, so the existing 5-minute retry loop handles it. The 60-minute budget is owned by `merge()` and shared across re-entries, and opens at the first wait (not at command time, since `merge_into` is only reached once CI is green). One comment is posted to the PR the first time it waits. - **Force merge.** `-f` gets no wait window and therefore never waits; it refuses instead if greenlight is the only authority and hasn't verified the head. - **ghstack.** Checked against each open PR's GitHub head, which is what greenlight records, not the `/orig` revision git cherry-picks. - **Failure modes.** A HUD outage is a wait, not a refusal, until the budget runs out; an unreadable `merge_rules.yaml` or an unclassifiable reviewer leaves the guard on rather than inventing an authorization. Depends on the `/api/greenlight/pr_state` route in pytorch/test-infra; `HUD_API_TOKEN` is already plumbed into `trymerge.yml`. This is the last change of the guard and the only one that alters existing behaviour; the modules it calls landed ahead of it so that the merge-path wiring could be reviewed on its own and each change stay under the 2000 LOC infra limit. One test here asserts `merge_rules.yaml` still grants `pytorchgreenlight` merge authority, so a rename there cannot silently disable the guard. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: #194841 Approved by: https://github.com/huydhn ghstack dependencies: #194838, #194839, #194840
orrangetabby17
pushed a commit
to orrangetabby17/pytorch
that referenced
this pull request
Sep 2, 2026
…orch#194839) `greenlight_preflight.py` detects PRs greenlight will never produce a verdict for, so a merge can refuse immediately instead of waiting out the full budget for an answer that is not coming. It mirrors the upstream filters that drop a PR before it is ever fingerprinted — `review._recency_filter` (excluded labels and the review window, each with an escape for a PR whose recorded status is non-terminal) and both arms of `review_gate.human_review_skip_reason` (changes requested by a non-bot, and an approval from the merge-authorized set). Each mirrored constant is commented with its upstream source in pytorch/test-infra under `greenlight/src/greenlight/`, because drift in either direction either costs a merge an hour of waiting or refuses a PR greenlight would in fact have reviewed. `greenlight_messages.py` is the single place that renders guard outcomes as text. Three surfaces share one set of outcomes: the refusal that ends a merge, the line the retry loop logs while it waits, and the comment posted to the PR the first time a merge waits. Split out from the guard so the mirrored upstream filters can be reviewed against greenlight's own source on their own, and to keep each change under the 2000 LOC infra limit. Both modules sit above the ledger and identity leaves and below the guard itself: preflight reads the ledger's status sets and identity's normalization, messages reads the ledger's route URL and preflight's excluded-labels phrase. The references each makes back to `greenlight_guard` are annotations only, under `TYPE_CHECKING`, so nothing here imports the guard at runtime. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194839 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838
orrangetabby17
pushed a commit
to orrangetabby17/pytorch
that referenced
this pull request
Sep 2, 2026
…194840) `greenlight_guard.py` is the decision itself. It compares the head SHA greenlight recorded in its ledger against the head actually being landed and returns ALLOW, WAIT or DENY, along with the wait budget (`GreenlightWaitWindow`) a merge carries across re-entries. Everything it needs about a PR arrives as plain data or as a callable on `PRUnderMerge` — the callables stay callables because each one costs a GitHub request that only the minority of PRs greenlight alone authorizes ever needs. It must not import `trymerge`: `trymerge` imports it, and the cycle would break both. Two failure directions are split deliberately. Anything that is only unknown — no ledger row, a verdict for an older commit, a review still running, an unreadable HUD, a reviewer GitHub would not classify — waits, and is refused only once the budget is spent. Anything settled against the head being landed — NO_LAND/CANCELLED/FAILED, an unrecognized status, a review that has outlived greenlight's own timeout — refuses at once. Refusing on first uncertainty would turn a HUD blip into a dead merge; waiting on a settled negative would burn an hour and land nothing. The tests cover the decision table, stack handling, the laziness of the per-PR GitHub lookups, the ledger's transport failure modes against a mocked `gh_fetch_url` (every documented route error code, malformed payloads, batch capping, backoff, recovery on retry), and the preflight mirror. No test touches the network. They land together with the guard because `test_greenlight_guard.py` owns the shared PR fixtures that the ledger and preflight tests build on. Split out from the `trymerge.py` wiring so the verdict logic can be reviewed against greenlight's behaviour independently of the merge path, and to keep each change under the 2000 LOC infra limit. Nothing calls into this yet. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194840 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838, pytorch#194839
orrangetabby17
pushed a commit
to orrangetabby17/pytorch
that referenced
this pull request
Sep 2, 2026
…ytorch#194841) **Impact:** mergebot only — PRs whose sole merge authorization is the `pytorchgreenlight` approval **Risk:** medium Depends on pytorch/test-infra#8630 to be merged before merging this one ## What Wires the greenlight land-time guard into `merge_into`: when the only approval that satisfies a merge rule is greenlight's, trymerge reads greenlight's verdict ledger and refuses to land unless greenlight recorded `LAND` for the head commit that is actually being merged. The verdict logic already lives in the `greenlight_*.py` modules next to trymerge; this change only feeds the PR facts in and turns the verdict into the exception the merge loop already understands. Three smaller changes in `trymerge.py` that are worth reading on their own: - `find_matching_merge_rule` gains an `approved_by_override` kwarg, so the guard can ask "would any rule still match if greenlight had not approved?" without duplicating rule evaluation. Default behaviour is unchanged. - The inline approver expansion is extracted to `rule_approvers`, and a malformed team ref (`org/team/extra`) now raises instead of expanding to nobody. Previously `gh_get_team_members` warned, returned `[]`, and the rule then matched *any* approver. - Two REST accessors (`get_updated_at`, `get_bot_reviewers`) added on `GitHubPR`. They are REST rather than fields on `GH_GET_PR_INFO_QUERY` because that query text is the cache key for the recorded GraphQL fixtures — extending it invalidates all of them. ## Why `merge_rules.yaml`'s "Greenlight Review Bot" rule lets a single `pytorchgreenlight` approval authorize a merge of any path, and pytorch/pytorch has no GitHub-native required reviews, so that approval is never dismissed when the author pushes more commits. Today an author can get greenlight's approval on a benign commit, push anything on top, and `@pytorchbot merge` lands unreviewed content. This closes that window by comparing the head SHA greenlight actually evaluated against the head being landed. # Notes Behaviour reviewers should sanity-check: - **Scope.** The guard is skipped entirely when greenlight did not approve, and when any other merge rule still matches after dropping greenlight's approval. A drive-by approval from a random GitHub user does *not* switch it off. - **Waiting.** "greenlight hasn't answered yet" raises `MandatoryChecksMissingError`, so the existing 5-minute retry loop handles it. The 60-minute budget is owned by `merge()` and shared across re-entries, and opens at the first wait (not at command time, since `merge_into` is only reached once CI is green). One comment is posted to the PR the first time it waits. - **Force merge.** `-f` gets no wait window and therefore never waits; it refuses instead if greenlight is the only authority and hasn't verified the head. - **ghstack.** Checked against each open PR's GitHub head, which is what greenlight records, not the `/orig` revision git cherry-picks. - **Failure modes.** A HUD outage is a wait, not a refusal, until the budget runs out; an unreadable `merge_rules.yaml` or an unclassifiable reviewer leaves the guard on rather than inventing an authorization. Depends on the `/api/greenlight/pr_state` route in pytorch/test-infra; `HUD_API_TOKEN` is already plumbed into `trymerge.yml`. This is the last change of the guard and the only one that alters existing behaviour; the modules it calls landed ahead of it so that the merge-path wiring could be reviewed on its own and each change stay under the 2000 LOC infra limit. One test here asserts `merge_rules.yaml` still grants `pytorchgreenlight` merge authority, so a rename there cannot silently disable the guard. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194841 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838, pytorch#194839, pytorch#194840
Sanskaaar1
pushed a commit
to Sanskaaar1/pytorch
that referenced
this pull request
Sep 8, 2026
…orch#194839) `greenlight_preflight.py` detects PRs greenlight will never produce a verdict for, so a merge can refuse immediately instead of waiting out the full budget for an answer that is not coming. It mirrors the upstream filters that drop a PR before it is ever fingerprinted — `review._recency_filter` (excluded labels and the review window, each with an escape for a PR whose recorded status is non-terminal) and both arms of `review_gate.human_review_skip_reason` (changes requested by a non-bot, and an approval from the merge-authorized set). Each mirrored constant is commented with its upstream source in pytorch/test-infra under `greenlight/src/greenlight/`, because drift in either direction either costs a merge an hour of waiting or refuses a PR greenlight would in fact have reviewed. `greenlight_messages.py` is the single place that renders guard outcomes as text. Three surfaces share one set of outcomes: the refusal that ends a merge, the line the retry loop logs while it waits, and the comment posted to the PR the first time a merge waits. Split out from the guard so the mirrored upstream filters can be reviewed against greenlight's own source on their own, and to keep each change under the 2000 LOC infra limit. Both modules sit above the ledger and identity leaves and below the guard itself: preflight reads the ledger's status sets and identity's normalization, messages reads the ledger's route URL and preflight's excluded-labels phrase. The references each makes back to `greenlight_guard` are annotations only, under `TYPE_CHECKING`, so nothing here imports the guard at runtime. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194839 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838
Sanskaaar1
pushed a commit
to Sanskaaar1/pytorch
that referenced
this pull request
Sep 8, 2026
…194840) `greenlight_guard.py` is the decision itself. It compares the head SHA greenlight recorded in its ledger against the head actually being landed and returns ALLOW, WAIT or DENY, along with the wait budget (`GreenlightWaitWindow`) a merge carries across re-entries. Everything it needs about a PR arrives as plain data or as a callable on `PRUnderMerge` — the callables stay callables because each one costs a GitHub request that only the minority of PRs greenlight alone authorizes ever needs. It must not import `trymerge`: `trymerge` imports it, and the cycle would break both. Two failure directions are split deliberately. Anything that is only unknown — no ledger row, a verdict for an older commit, a review still running, an unreadable HUD, a reviewer GitHub would not classify — waits, and is refused only once the budget is spent. Anything settled against the head being landed — NO_LAND/CANCELLED/FAILED, an unrecognized status, a review that has outlived greenlight's own timeout — refuses at once. Refusing on first uncertainty would turn a HUD blip into a dead merge; waiting on a settled negative would burn an hour and land nothing. The tests cover the decision table, stack handling, the laziness of the per-PR GitHub lookups, the ledger's transport failure modes against a mocked `gh_fetch_url` (every documented route error code, malformed payloads, batch capping, backoff, recovery on retry), and the preflight mirror. No test touches the network. They land together with the guard because `test_greenlight_guard.py` owns the shared PR fixtures that the ledger and preflight tests build on. Split out from the `trymerge.py` wiring so the verdict logic can be reviewed against greenlight's behaviour independently of the merge path, and to keep each change under the 2000 LOC infra limit. Nothing calls into this yet. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194840 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838, pytorch#194839
Sanskaaar1
pushed a commit
to Sanskaaar1/pytorch
that referenced
this pull request
Sep 8, 2026
…ytorch#194841) **Impact:** mergebot only — PRs whose sole merge authorization is the `pytorchgreenlight` approval **Risk:** medium Depends on pytorch/test-infra#8630 to be merged before merging this one ## What Wires the greenlight land-time guard into `merge_into`: when the only approval that satisfies a merge rule is greenlight's, trymerge reads greenlight's verdict ledger and refuses to land unless greenlight recorded `LAND` for the head commit that is actually being merged. The verdict logic already lives in the `greenlight_*.py` modules next to trymerge; this change only feeds the PR facts in and turns the verdict into the exception the merge loop already understands. Three smaller changes in `trymerge.py` that are worth reading on their own: - `find_matching_merge_rule` gains an `approved_by_override` kwarg, so the guard can ask "would any rule still match if greenlight had not approved?" without duplicating rule evaluation. Default behaviour is unchanged. - The inline approver expansion is extracted to `rule_approvers`, and a malformed team ref (`org/team/extra`) now raises instead of expanding to nobody. Previously `gh_get_team_members` warned, returned `[]`, and the rule then matched *any* approver. - Two REST accessors (`get_updated_at`, `get_bot_reviewers`) added on `GitHubPR`. They are REST rather than fields on `GH_GET_PR_INFO_QUERY` because that query text is the cache key for the recorded GraphQL fixtures — extending it invalidates all of them. ## Why `merge_rules.yaml`'s "Greenlight Review Bot" rule lets a single `pytorchgreenlight` approval authorize a merge of any path, and pytorch/pytorch has no GitHub-native required reviews, so that approval is never dismissed when the author pushes more commits. Today an author can get greenlight's approval on a benign commit, push anything on top, and `@pytorchbot merge` lands unreviewed content. This closes that window by comparing the head SHA greenlight actually evaluated against the head being landed. # Notes Behaviour reviewers should sanity-check: - **Scope.** The guard is skipped entirely when greenlight did not approve, and when any other merge rule still matches after dropping greenlight's approval. A drive-by approval from a random GitHub user does *not* switch it off. - **Waiting.** "greenlight hasn't answered yet" raises `MandatoryChecksMissingError`, so the existing 5-minute retry loop handles it. The 60-minute budget is owned by `merge()` and shared across re-entries, and opens at the first wait (not at command time, since `merge_into` is only reached once CI is green). One comment is posted to the PR the first time it waits. - **Force merge.** `-f` gets no wait window and therefore never waits; it refuses instead if greenlight is the only authority and hasn't verified the head. - **ghstack.** Checked against each open PR's GitHub head, which is what greenlight records, not the `/orig` revision git cherry-picks. - **Failure modes.** A HUD outage is a wait, not a refusal, until the budget runs out; an unreadable `merge_rules.yaml` or an unclassifiable reviewer leaves the guard on rather than inventing an authorization. Depends on the `/api/greenlight/pr_state` route in pytorch/test-infra; `HUD_API_TOKEN` is already plumbed into `trymerge.yml`. This is the last change of the guard and the only one that alters existing behaviour; the modules it calls landed ahead of it so that the merge-path wiring could be reviewed on its own and each change stay under the 2000 LOC infra limit. One test here asserts `merge_rules.yaml` still grants `pytorchgreenlight` merge authority, so a rename there cannot silently disable the guard. Signed-off-by: Jean Schmidt <[email protected]> Pull Request resolved: pytorch#194841 Approved by: https://github.com/huydhn ghstack dependencies: pytorch#194838, pytorch#194839, pytorch#194840
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
greenlight_preflight.pydetects PRs greenlight will never produce a verdict for, so amerge can refuse immediately instead of waiting out the full budget for an answer that
is not coming. It mirrors the upstream filters that drop a PR before it is ever
fingerprinted —
review._recency_filter(excluded labels and the review window, eachwith an escape for a PR whose recorded status is non-terminal) and both arms of
review_gate.human_review_skip_reason(changes requested by a non-bot, and an approvalfrom the merge-authorized set). Each mirrored constant is commented with its upstream
source in pytorch/test-infra under
greenlight/src/greenlight/, because drift in eitherdirection either costs a merge an hour of waiting or refuses a PR greenlight would in
fact have reviewed.
greenlight_messages.pyis the single place that renders guard outcomes as text. Threesurfaces share one set of outcomes: the refusal that ends a merge, the line the retry
loop logs while it waits, and the comment posted to the PR the first time a merge waits.
Split out from the guard so the mirrored upstream filters can be reviewed against
greenlight's own source on their own, and to keep each change under the 2000 LOC infra
limit. Both modules sit above the ledger and identity leaves and below the guard itself:
preflight reads the ledger's status sets and identity's normalization, messages reads
the ledger's route URL and preflight's excluded-labels phrase. The references each makes
back to
greenlight_guardare annotations only, underTYPE_CHECKING, so nothing hereimports the guard at runtime.
Signed-off-by: Jean Schmidt [email protected]