Repository navigation
Conversation
Refactor the docker merge gates so their file-matching and check-filtering logic lives in pure, module-level helpers, and cover those helpers with unit tests. - Extract `is_docker_affecting_files(files)`, which decides whether a set of changed files touches the `.ci/docker` tree hash. `GitHubPR.is_docker_affecting` now delegates to it. The matcher requires either an exact `.ci/docker` path or a `.ci/docker/` prefix, so lookalikes like `.ci/docker-something/x` no longer count. - Extract `get_docker_build_checks(checks)`, which selects the checks belonging to the `docker-builds` workflow (the bare workflow name plus its `docker-builds / ...` sub-jobs), and use it in `check_docker_builds_ready`. - Add `TestDockerCiGates` covering both helpers: affecting vs. non-affecting file lists (including the empty list and the lookalike-prefix case) and the workflow-check filtering (excluding unrelated jobs and the `docker-builds-nightly` lookalike). The end-to-end gate functions (`check_docker_builds_ready` / `check_no_docker_merge_skew`) are still best exercised through a real GitHubPR backed by recorded fixtures; that coverage is noted as a follow-up in the test class docstring. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191508
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit b69d0af with merge base 3ee692b ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
…mages PRs that touch .ci/docker generate a new set of CI docker images, keyed by the git tree hash of .ci/docker (see docker-builds.yml, which tags images with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images are missing or stale, every downstream trunk job fails because it can't find the image it needs -- as happened in the #190927 / #186302 land race, where a force-merge bypassed CI and a second docker PR landed in the skew window. Add two hard gates in merge_into (the shared chokepoint for both normal and force merges, so -f no longer bypasses them): 1. check_docker_builds_ready: a docker-affecting PR must have run the docker-builds (ciflow/docker) workflow with all jobs passing, so the images are pre-built and pushed to ECR. Pending builds raise MandatoryChecksMissingError so a normal merge waits; missing/failed builds are refused. 2. check_no_docker_merge_skew: after the merge commit is created locally, its .ci/docker tree hash must match the tree that ciflow/docker actually built and tested on the PR head. A mismatch means another docker change landed in the skew window and the required images were never built, so the merge is refused with a request to rebase. Both gates are intentionally not overridable by -f, matching existing -f-proof invariants like ghstack-out-of-sync and internal-changes-must-land- via-Phabricator. Add unit tests for the pure helpers. ghstack-source-id: a820cfd Pull-Request: #191508
Failing job: lintrunner-noclang-partial / lint Failing lint target: .github/scripts/trymerge.py Failing CI command: spin lint -- --force-color --tee-json=lint.json --skip CLANGTIDY,CLANGTIDY_EXECUTORCH_COMPATIBILITY,CLANGFORMAT,PYREFLY .github/scripts/test_trymerge.py .github/scripts/trymerge.py Error: Warning (PYFMT) format Run `lintrunner -a` to apply this patch. Put the `any` expression on the single line required by PYFMT. This is the exact formatter patch reported by CI and does not change behavior. Test Plan: ``` git diff --check ``` The targeted `spin lint` command could not be run locally because `spin` is unavailable and there is no project or parent `.venv`. AI assistance: This CI fix was prepared with an AI assistant. [ghstack-poisoned]
…mages PRs that touch .ci/docker generate a new set of CI docker images, keyed by the git tree hash of .ci/docker (see docker-builds.yml, which tags images with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images are missing or stale, every downstream trunk job fails because it can't find the image it needs -- as happened in the #190927 / #186302 land race, where a force-merge bypassed CI and a second docker PR landed in the skew window. Add two hard gates in merge_into (the shared chokepoint for both normal and force merges, so -f no longer bypasses them): 1. check_docker_builds_ready: a docker-affecting PR must have run the docker-builds (ciflow/docker) workflow with all jobs passing, so the images are pre-built and pushed to ECR. Pending builds raise MandatoryChecksMissingError so a normal merge waits; missing/failed builds are refused. 2. check_no_docker_merge_skew: after the merge commit is created locally, its .ci/docker tree hash must match the tree that ciflow/docker actually built and tested on the PR head. A mismatch means another docker change landed in the skew window and the required images were never built, so the merge is refused with a request to rebase. Both gates are intentionally not overridable by -f, matching existing -f-proof invariants like ghstack-out-of-sync and internal-changes-must-land- via-Phabricator. Add unit tests for the pure helpers. ghstack-source-id: 58e7dfa Pull-Request: #191508
|
Thinking more about this. Does this check need to be in mergebot? Having the check as a simple job on https://github.com/pytorch/pytorch/blob/main/.github/workflows/docker-builds.yml is cleaner IMO, basically having This would also:
|
|
@huydhn It can't live in ciflow/docker triggered jobs. You need to know exactly what the final hash will be and you only know that as you're getting ready to merge into main. Anything else is subject to race. |
mergedog handoffNote This PR is being shepherded by mergedog, an automation tool run by a maintainer. It watches CI and may push fixes; the PR author does not need to act unless a maintainer asks. All CI is green (or skipped). Ready for human review and Current PR head: Autonomous changes pushed
During shepherding, the configured LLM was invoked 3 times. If any CI shows red, it judged that failure unrelated to this PR's changes — please verify below before merging. Session 1 — fix-CI (2026-07-29T19:35:19+00:00)
LLM transcriptSession 2 — rebase-resolver (2026-07-29T19:37:16+00:00)
LLM transcriptSession 3 — fix-CI (2026-07-29T19:46:57+00:00)
LLM transcript |
That's a fair point. I don't remember we have any land check running at merge, but let me double check that @claude Are there any CI jobs trigger at merge time by pytorchbot? |
|
Claude finished @huydhn's task in 3m 8s —— View job Answer: no, pytorchbot does not launch any CI at merge time
Short answer: the merge path is read-only with respect to CI. DetailsWhat the merge workflow does
The only The one thing that does trigger CI at merge time:
|
| Gate | Location | Behavior |
|---|---|---|
find_matching_merge_rule |
trymerge.py:1553 |
approvals + mandatory checks vs. merge_rules.yaml |
get_classifications |
trymerge.py:2098 |
Dr.CI call to bucket failures as flaky / broken-trunk / unstable |
categorize_checks |
trymerge.py:2449 |
splits pending vs. failing, tolerates up to IGNORABLE_FAILED_CHECKS_THESHOLD |
check_for_sev |
trymerge.py:2423 |
blocks on open merge-blocking SEV |
| internal-changes check | trymerge.py:1715 |
must land via Phabricator; not -f-overridable |
check_docker_builds_ready |
trymerge.py:1744 (this PR) |
reads existing ciflow/docker checkruns |
check_no_docker_merge_skew |
trymerge.py:1798 (this PR) |
compares tree hashes locally after the merge commit exists |
Bearing on @huydhn's suggestion
This confirms @ezyang's reply. check_no_docker_merge_skew has to read HEAD:.ci/docker of the merge commit, which only exists between merge_changes_locally (:1340) and repo.push (:1348). A docker-builds.yml job or a lint-bc.yml-style workflow runs against the PR head and its base at trigger time, so it can't see the tree the merge will actually produce — any such check is racy by construction.
The precedent for a non--f-overridable, merge-commit-dependent invariant living in trymerge.py is the internal-changes check at :1715, so this isn't a new kind of thing being added to mergebot. The genuine cost of the trymerge.py placement is the one @huydhn named: DOCKER_CI_PATH / DOCKER_BUILDS_WORKFLOW_NAME become mergebot-side constants coupled to docker-builds.yml. If those drift, is_docker_affecting() silently returns False and the gate becomes a no-op rather than failing loudly — that seems like the thing worth a consistency test, more than relocating the check.
|
I think there might be a gap here for ghstack depending on if the change to |
|
@claude Check if the change here work with ghstack? |
|
Claude finished @huydhn's task in 15m 34s —— View job Answer: mostly yes, but there is one real ghstack hole — a docker change in a lower diff of the stack bypasses both gates
Summary: the tree-hash comparison itself is sound for ghstack — cherry-picking the stack onto Details — case-by-case, plus a fix sketchWhy the mechanism is otherwise correct for ghstackThe head branch Case matrix
The ❌ row is not exotic: the Fix sketchBoth gates need to consider the whole landed range rather than One subtlety worth getting right: with several docker-affecting PRs in one stack, the images matching the final tree are the ones built by the topmost docker-affecting PR — every PR below it has a stale # in merge_into, replacing check_docker_builds_ready(self)
gated = [p for p, _ in get_ghstack_prs(repo, self)] if self.is_ghstack_pr() else [self]
docker_prs = [p for p in gated if p.is_docker_affecting()]then run Two smaller notes
I have not pushed any changes — this was a read-only investigation of the ghstack path, per the "check if" framing. |
… in a ghstack A ghstack merge lands every open PR below the one being merged, so gating only `self` was wrong: it would miss a docker-affecting PR lower in the stack, and for a stack whose top PR touches `.ci/docker` it checked the top PR's own head rather than the cumulative merge tree that actually needs images. Compute the set of PRs that a merge will land (for ghstack, all open PRs in the stack) and run both gates against the topmost docker-affecting PR via the new `get_topmost_docker_pr` helper. That PR's cumulative head carries the final `.ci/docker` tree, so its images are the ones that must have been built. To avoid resolving the stack twice, `merge_into` now fetches `ghstack_prs` up front and threads it through `merge_changes_locally` and `merge_ghstack_into`, which take an optional `ghstack_prs` argument and only call `get_ghstack_prs` themselves when it isn't supplied. Tests: add `test_get_topmost_docker_pr` for the stack-walk helper, and `test_merge_into_gates_lower_ghstack_docker_pr`, which drives `merge_into` on a ghstack whose top PR is docker-neutral and confirms the lower docker PR is the one passed to `check_docker_builds_ready`. Trim the placeholder docstring on `TestDockerCiGates` now that the gates have real coverage. Minor comment fixes: note that a wholesale deletion of `.ci/docker` intentionally fails the merge-commit tree lookup, and correct the missing-object example from ghstack to fork PRs. [ghstack-poisoned]
…mages PRs that touch .ci/docker generate a new set of CI docker images, keyed by the git tree hash of .ci/docker (see docker-builds.yml, which tags images with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images are missing or stale, every downstream trunk job fails because it can't find the image it needs -- as happened in the #190927 / #186302 land race, where a force-merge bypassed CI and a second docker PR landed in the skew window. Add two hard gates in merge_into (the shared chokepoint for both normal and force merges, so -f no longer bypasses them): 1. check_docker_builds_ready: a docker-affecting PR must have run the docker-builds (ciflow/docker) workflow with all jobs passing, so the images are pre-built and pushed to ECR. Pending builds raise MandatoryChecksMissingError so a normal merge waits; missing/failed builds are refused. 2. check_no_docker_merge_skew: after the merge commit is created locally, its .ci/docker tree hash must match the tree that ciflow/docker actually built and tested on the PR head. A mismatch means another docker change landed in the skew window and the required images were never built, so the merge is refused with a request to rebase. Both gates are intentionally not overridable by -f, matching existing -f-proof invariants like ghstack-out-of-sync and internal-changes-must-land- via-Phabricator. Add unit tests for the pure helpers. ghstack-source-id: 8cfe250 Pull-Request: #191508
mergedog handoff (after merge failure)pytorchmergebot reported Current PR head: Autonomous changes pushed
CI notes at handoffmergedog is treating these still-failing checks as unrelated/spurious. Please verify before merging:
Warning: mergedog's suppressed check list differs from the latest Dr. CI summary. Suppressed by mergedog but not listed by Dr. CI:
Latest Dr. CI summary## :link: Helpful Links
### :test_tube: See artifacts and rendered test results at [hud.pytorch.org/pr/191508](https://hud.pytorch.org/pr/191508)
* :page_facing_up: Preview [Python docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/191508/index.html)
* :page_facing_up: Preview [C++ docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/191508/cppdocs/index.html)
* :question: Need help or want to give feedback on the CI? Visit the [bot commands wiki](https://github.com/pytorch/pytorch/wiki/Bot-commands)
Note: Links to docs will display an error until the docs builds have been completed.
## :hourglass_flowing_sand: No Failures, 4 Pending
As of commit b69d0af28562c15112cd221f058fd256b9320c05 with merge base 3ee692b380206d788625e0a4474d758f93571ee9 (<sub><sub><img alt="image" width=70 src="https://img.shields.io/date/1785351714?label=&color=FFFFFF&style=flat-square"></sub></sub>):
:green_heart: Looks good so far! There are no failures yet. :green_heart:
This comment was automatically generated by Dr. CI and updates every 15 minutes.During shepherding, the configured LLM was invoked 4 times. If any CI shows red, it judged that failure unrelated to this PR's changes — please verify below before merging. Session 1 — fix-CI (2026-07-29T19:35:19+00:00)
LLM transcriptSession 2 — rebase-resolver (2026-07-29T19:37:16+00:00)
LLM transcriptSession 3 — fix-CI (2026-07-29T19:46:57+00:00)
LLM transcriptSession 4 — fix-CI (2026-07-30T07:32:39+00:00)
LLM transcript |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 7, 8, linux.rocm.gpu.gfx950.1) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Follow-up to pytorch#191508. That PR added two gates for docker-affecting PRs. The first, check_docker_builds_ready, requires the PR's own ciflow/docker builds to have run and passed -- that one stays. The second, check_no_docker_merge_skew, additionally required the .ci/docker tree of the *merge commit* to equal the tree ciflow/docker built on the PR head, and refused the merge otherwise: Refusing to merge: this PR modifies the CI docker images, but the .ci/docker tree of the merge commit (...) does not match the tree that ciflow/docker built and tested on the PR head (...) In practice that makes a docker PR win a race against the base branch. Rebasing only helps until the next docker-affecting PR lands, so on a busy day a PR can bounce indefinitely -- pytorch#190639 hit it twice in a row, with the PR-head tree moving (08b9699 -> 75ce86e) while the merge-commit tree stayed the same. Downgrade it to a warning: - The builds-are-green requirement is unchanged: check_docker_builds_ready still blocks (and MandatoryChecksMissingError still makes a normal merge wait). - A missing post-merge image is not fatal. docker-builds.yml runs on push to the default branch, so it publishes the merged tree's images right after the merge, and test-infra's calculate-docker-image polls for the image (docker manifest inspect, up to 120 min) before falling through to rebuilding it locally. So a skew costs time on the first trunk jobs rather than breaking them. - The mismatch is still printed to the merge job log, so a slow or rebuilding trunk job can be correlated with the land race that caused it. Renamed to warn_on_docker_merge_skew so the name matches the behaviour.
…arn (#192522) Follow-up to #191508. ## What #191508 added, and what changes here It added two gates for docker-affecting PRs, both in `merge_into` so force merges cannot bypass them: 1. **`check_docker_builds_ready`** — the PR's own `ciflow/docker` builds must have run and passed. **Unchanged by this PR.** Pending builds still raise `MandatoryChecksMissingError` so a normal merge waits; missing/failed builds are still refused. 2. **`check_no_docker_merge_skew`** — additionally required the `.ci/docker` tree of the *merge commit* to equal the tree `ciflow/docker` built on the PR head, and refused the merge otherwise. **This PR downgrades it to a warning.** So the "all the builds are green" requirement is fully retained; what goes away is the extra requirement that the base branch not have moved. ## Why Requiring the two trees to match means a docker PR has to win a race against the base branch, and a rebase only helps until the next docker-affecting PR lands. On a busy day a PR can bounce indefinitely. #190639 hit it twice in a row — the PR-head tree moved (`08b9699a` → `75ce86e4`) after a rebase while the merge-commit tree stayed `ab961773`: ``` Refusing to merge: this PR modifies the CI docker images, but the .ci/docker tree of the merge commit (ab96177...) does not match the tree that ciflow/docker built and tested on the PR head (75ce86e...) ``` **A missing post-merge image is not fatal**, which is the key point: - `docker-builds.yml` triggers on `push` to `main` / `release/*`, so the merged tree's images get built and pushed right after the merge lands. - test-infra's `calculate-docker-image` polls for the image before giving up — `docker manifest inspect` in a loop, `sleep 300` per iteration, up to 120 minutes for non-docker-build jobs — and then falls through to `rebuild=true` and builds it locally. So a skew costs **time** on the first trunk jobs after the merge (waiting for docker-builds, or a local rebuild with longer TTS), not a hard failure. Trading that against docker PRs being unable to land seems like the better default. ## Kept: the diagnostic The mismatch is still printed to the merge job log, so a slow or rebuilding trunk job can be correlated with the land race that caused it: ``` WARNING: docker land race on PR #NNNNN: the .ci/docker tree of the merge commit (...) does not match the tree that ciflow/docker built and tested on the PR head (...). ... the first trunk jobs after this merge may wait for docker-builds to publish the merged tree's images, or rebuild them locally. Merging anyway. ``` Renamed `check_no_docker_merge_skew` → `warn_on_docker_merge_skew` so the name matches the behaviour. ## Test plan - `python -m pytest .github/scripts/test_trymerge.py` → **74 passed, 2 skipped** (the 4 docker-gate tests included; none referenced the renamed function). - `py_compile` clean; no remaining references to the old name (`grep -rn check_no_docker_merge_skew .github/` → empty). - `MergeRuleFailedError` is still used in 7 other places, so the import is not orphaned. ## Trade-off, stated plainly This intentionally reopens the window that #191508 closed: a docker PR can now land whose post-merge images were never built or tested, which is the shape of the #190927 / #186302 land race cited in that PR. The mitigation is that the images are auto-published by `docker-builds.yml` on the merge and that jobs wait for them, so the failure mode is latency rather than red trunk. If dev-infra would rather keep a hard gate, an alternative is to keep refusing only when `check_docker_builds_ready` did **not** pass, i.e. exactly the unbuilt-image case, and always allow the pure-skew case — happy to switch to that. Pull Request resolved: #192522 Approved by: https://github.com/tinglvv, https://github.com/izaitsevfb, https://github.com/ezyang
…arn (pytorch#192522) Follow-up to pytorch#191508. ## What pytorch#191508 added, and what changes here It added two gates for docker-affecting PRs, both in `merge_into` so force merges cannot bypass them: 1. **`check_docker_builds_ready`** — the PR's own `ciflow/docker` builds must have run and passed. **Unchanged by this PR.** Pending builds still raise `MandatoryChecksMissingError` so a normal merge waits; missing/failed builds are still refused. 2. **`check_no_docker_merge_skew`** — additionally required the `.ci/docker` tree of the *merge commit* to equal the tree `ciflow/docker` built on the PR head, and refused the merge otherwise. **This PR downgrades it to a warning.** So the "all the builds are green" requirement is fully retained; what goes away is the extra requirement that the base branch not have moved. ## Why Requiring the two trees to match means a docker PR has to win a race against the base branch, and a rebase only helps until the next docker-affecting PR lands. On a busy day a PR can bounce indefinitely. pytorch#190639 hit it twice in a row — the PR-head tree moved (`08b9699a` → `75ce86e4`) after a rebase while the merge-commit tree stayed `ab961773`: ``` Refusing to merge: this PR modifies the CI docker images, but the .ci/docker tree of the merge commit (ab96177...) does not match the tree that ciflow/docker built and tested on the PR head (75ce86e...) ``` **A missing post-merge image is not fatal**, which is the key point: - `docker-builds.yml` triggers on `push` to `main` / `release/*`, so the merged tree's images get built and pushed right after the merge lands. - test-infra's `calculate-docker-image` polls for the image before giving up — `docker manifest inspect` in a loop, `sleep 300` per iteration, up to 120 minutes for non-docker-build jobs — and then falls through to `rebuild=true` and builds it locally. So a skew costs **time** on the first trunk jobs after the merge (waiting for docker-builds, or a local rebuild with longer TTS), not a hard failure. Trading that against docker PRs being unable to land seems like the better default. ## Kept: the diagnostic The mismatch is still printed to the merge job log, so a slow or rebuilding trunk job can be correlated with the land race that caused it: ``` WARNING: docker land race on PR #NNNNN: the .ci/docker tree of the merge commit (...) does not match the tree that ciflow/docker built and tested on the PR head (...). ... the first trunk jobs after this merge may wait for docker-builds to publish the merged tree's images, or rebuild them locally. Merging anyway. ``` Renamed `check_no_docker_merge_skew` → `warn_on_docker_merge_skew` so the name matches the behaviour. ## Test plan - `python -m pytest .github/scripts/test_trymerge.py` → **74 passed, 2 skipped** (the 4 docker-gate tests included; none referenced the renamed function). - `py_compile` clean; no remaining references to the old name (`grep -rn check_no_docker_merge_skew .github/` → empty). - `MergeRuleFailedError` is still used in 7 other places, so the import is not orphaned. ## Trade-off, stated plainly This intentionally reopens the window that pytorch#191508 closed: a docker PR can now land whose post-merge images were never built or tested, which is the shape of the pytorch#190927 / pytorch#186302 land race cited in that PR. The mitigation is that the images are auto-published by `docker-builds.yml` on the merge and that jobs wait for them, so the failure mode is latency rather than red trunk. If dev-infra would rather keep a hard gate, an alternative is to keep refusing only when `check_docker_builds_ready` did **not** pass, i.e. exactly the unbuilt-image case, and always allow the pure-skew case — happy to switch to that. Pull Request resolved: pytorch#192522 Approved by: https://github.com/tinglvv, https://github.com/izaitsevfb, https://github.com/ezyang
Stack from ghstack (oldest at bottom):
PRs that touch .ci/docker generate a new set of CI docker images, keyed by
the git tree hash of .ci/docker (see docker-builds.yml, which tags images
with
git rev-parse HEAD:.ci/docker). If such a PR lands while its imagesare missing or stale, every downstream trunk job fails because it can't find
the image it needs -- as happened in the #190927 / #186302 land race, where a
force-merge bypassed CI and a second docker PR landed in the skew window.
Add two hard gates in merge_into (the shared chokepoint for both normal and
force merges, so -f no longer bypasses them):
check_docker_builds_ready: a docker-affecting PR must have run the
docker-builds (ciflow/docker) workflow with all jobs passing, so the
images are pre-built and pushed to ECR. Pending builds raise
MandatoryChecksMissingError so a normal merge waits; missing/failed
builds are refused.
check_no_docker_merge_skew: after the merge commit is created locally,
its .ci/docker tree hash must match the tree that ciflow/docker actually
built and tested on the PR head. A mismatch means another docker change
landed in the skew window and the required images were never built, so
the merge is refused with a request to rebase.
Both gates are intentionally not overridable by -f, matching existing
-f-proof invariants like ghstack-out-of-sync and internal-changes-must-land-
via-Phabricator. Add unit tests for the pure helpers.