Skip to content

Checkout determinator script from base ref, not PR head - #189782

Closed
zxiiro wants to merge 1 commit into
mainfrom
zxiiro/runner-determinator-stale-script
Closed

zxiiro wants to merge 1 commit into
mainfrom
zxiiro/runner-determinator-stale-script

Conversation

@zxiiro

@zxiiro zxiiro commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

_runner-determinator.yml checked out .github/scripts/runner_determinator.py from github.event.pull_request.head.sha, so PRs whose branch predates a change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2 build-path removal in #189113/#189171) run a stale copy. That stale copy can emit a runner-label prefix main's build workflow no longer knows how to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix glued onto a post-#189113 ARC-only label), leaving the job stuck unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in #182579 only so ci-docker-hash reflects the PR's own .ci/docker tree, not to let PRs self-test determinator changes. Split the checkout in two: the script now comes from the default ref (main, or the merge commit for pull_request events, which still includes the PR's own edits to the script), while .ci/docker keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the script is no longer stale relative to main and always supports the flag.

_runner-determinator.yml checked out .github/scripts/runner_determinator.py
from github.event.pull_request.head.sha, so PRs whose branch predates a
change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2
build-path removal in #189113/#189171) run a stale copy. That stale copy
can emit a runner-label prefix main's build workflow no longer knows how
to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix
glued onto a post-#189113 ARC-only label), leaving the job stuck
unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in #182579 only so ci-docker-hash reflects
the PR's own .ci/docker tree, not to let PRs self-test determinator
changes. Split the checkout in two: the script now comes from the
default ref (main, or the merge commit for pull_request events, which
still includes the PR's own edits to the script), while .ci/docker
keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the
script is no longer stale relative to main and always supports the flag.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thanh Ha <[email protected]>
@zxiiro
zxiiro requested review from huydhn and jeanschmidt July 13, 2026 21:54
@zxiiro
zxiiro requested a review from a team as a code owner July 13, 2026 21:54
@pytorch-bot

pytorch-bot Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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:

⏳ No Failures, 3 Pending

As of commit 831d605 with merge base 5869005 (image):
💚 Looks good so far! There are no failures yet. 💚

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

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

Oh, good catch! Is my understanding correct that this would help fix pytorch/ci-infra#895 too as the runner determination script and the workflow are now in sync?

@jeanschmidt

Copy link
Copy Markdown
Contributor

@claude

please review this PR and answer a few questions:

  1. does it points to main specifically or the target branch? How will this plays out with ghstack diffs that set up those branches to create the stacked PRs?
  2. I suspect runner determinator also depends on other files, like the ALI->OSDC name conversion and others, are those correctly being checked out and used by the target determinator script into the target version?

@claude

claude Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Claude finished @jeanschmidt's task in 3m 15s —— View job


Review: Checkout determinator script from base ref, not PR head

Good, well-scoped change. Splitting the single sparse-checkout into two (script from the default ref, .ci/docker from PR head under pr-head/) correctly decouples "which script runs" from "which docker tree gets hashed." Answers to your two questions below.

Detailed answers & review

1) Does it point to main specifically, or the target branch? And how does this interact with ghstack?

It points to the target (base) branch, not main specifically.

The first checkout no longer passes a ref:, so actions/checkout uses its default, which is github.ref:

  • For pull_request events that is refs/pull/<N>/merge — the merge commit of the PR head into the PR's base branch. So the script reflects <base branch> + this PR's own edits to the script, not literally main.
  • For non-PR events it falls back to github.sha (the pushed ref).

The commit message's phrasing "the default ref (main, or the merge commit...)" is slightly loose — the accurate statement is "the base branch the PR targets," which only equals main for the common case of a PR opened directly against main. The in-code comment on lines 92-97 is the correct one ("the merge commit for pull_request events").

ghstack interaction — this is actually the important nuance: ghstack PRs are not based on main. PR #k in a stack targets gh/<user>/<k>/base, whose head is the previous stack entry (which in turn descends from main at stack-creation/restack time). Because the checkout resolves the merge ref against that base:

  • You get the determinator script as it exists on gh/<user>/<k>/base (i.e. main-at-restack-time + all lower stack entries' edits), merged with this entry's own edits. That is the semantically correct "what will this look like once merged" view — strictly better than the old head.sha, which took the raw PR-head blob with no merge at all.
  • Residual caveat (worth a mention, not a blocker): the guarantee is "in sync with the PR's merge target," not "in sync with main." If a ghstack base branch is itself stale — an old stack that hasn't been restacked onto current main — the script can still be behind main. That's inherent to any PR sitting on a stale base and is exactly the same exposure a normal long-lived PR has; this PR closes the far more common and severe gap (PR head arbitrarily behind its own base) rather than eliminating staleness entirely. If you want the stronger invariant you'd have to hardcode ref: main, but that would break the legitimate case of a PR that edits the determinator script and wants its own edit exercised — the merge ref preserves that, so I'd keep it as written.

2) Does the determinator depend on other files (e.g. the ALI→OSDC name conversion) that also need to be checked out at the target version?

No — the script is fully self-contained, so the single-file sparse checkout is sufficient. I checked runner_determinator.py:

  • Imports are stdlib only plus yaml and PyGithub (installed via pip in the workflow) — there are no imports of sibling files in .github/scripts/.
  • The fleet/name mappings you're thinking of are hardcoded constants inside this one file, not a separate data file: META_LABEL_PREFIX = "mt-" (Meta/OSDC), LF_LABEL_PREFIX = "lf-", META_CANARY_LABEL_PREFIX = "c-mt-", AMD_DO_LABEL_PREFIX = "amd-do-" (lines ~91-96). So the prefix logic travels with the script version you check out — exactly the thing this PR is fixing.
  • The rollout/experiment config is fetched at runtime over the network, not read from the checkout: get_rollout_state_from_issue() pulls the first comment of pytorch/test-infra#5132 via the GitHub API, and download_json() uses urlopen. Nothing is read off local disk except $GITHUB_OUTPUT.

So checking out only runner_determinator.py from the base ref pulls in everything the script itself needs; there is no second local file that could silently remain stale.

Other observations

  • Dropping the --help probe (lines removed at 122-133 of the old file) is safe and a nice cleanup — it only existed to tolerate a script older than main, which can no longer happen now that the script comes from the base ref. The unconditional --workflow-name is correct.
  • sparse-checkout-cone-mode: false is correctly present on both checkouts.
  • The .ci/docker hash is now git -C pr-head rev-parse HEAD:.ci/docker, preserving the Compute .ci/docker tree hash to runner_determinator #182579 behavior of hashing the PR's own docker tree. Good.

Verdict: LGTM. Both concerns check out. The only thing I'd tweak is optional: the commit-message wording "main, or the merge commit" could say "the PR's base branch (via the merge commit)" to avoid implying it's always main — relevant precisely for the ghstack case you asked about.

Summary: The checkout resolves to the PR's base branch via the merge ref (not literally main, which matters for ghstack — it tracks each entry's gh/.../base), and the determinator script is self-contained (prefix mappings are in-file constants, rollout config is fetched from test-infra#5132 at runtime), so the single-file base-ref checkout is correct and complete.
· branch zxiiro/runner-determinator-stale-script

@zxiiro

zxiiro commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Oh, good catch! Is my understanding correct that this would help fix pytorch/ci-infra#895 too as the runner determination script and the workflow are now in sync?

This does not touch lint or ghstack so I'm not sure if it solves those specific items mentioned in your issue.

But because it uses merge commit, it does solve the runner determinator python script and workflow issue so both can be merged in the same commit now. If someone proposes a change to either workflow or python script (or both). It will then use the PR's version so the script and workflow are now in sync with this change.

@jeanschmidt

jeanschmidt commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

we probably need to rethink, as this won't work with ghstack. So maybe we should target main directly.

I mean, when the author uses ghstack, they will never see a run from a different version of runner determinator. Due to a quirk on how ghstack works.

@jeanschmidt

Copy link
Copy Markdown
Contributor

see #189795 for example, the base is a synthetic base that is fixed and does not follow main

@jeanschmidt jeanschmidt 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.

use of ghstack is very common on pytorch, lets make sure to use main and not base to avoid the same problem on most of the PRs

@huydhn

huydhn commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

we probably need to rethink, as this won't work with ghstack. So maybe we should target main directly.

I mean, when the author uses ghstack, they will never see a run from a different version of runner determinator. Due to a quirk on how ghstack works.

Hmm, I'm a bit confuse on why this is not what we need on ghstack. If I understand this correctly, ghstack PRs will use whatever the runner script / workflows are on the stack. The problem is not really old runner determinator script, but that the script and the workflows are out of sync. And this change address this discrepancy by pointing them both to the "default" merge commit.

We can test this using ghstack to confirm, for example adding a new parameter to the script?

@jeanschmidt

Copy link
Copy Markdown
Contributor

Ok, not following:

Isn't the problem that runner determinator is running from PR head, and this changes to base ref? If this is the case, assuming the author is not introducing runner determinator or workflow changes this should not change the situation.

Correct?

@zxiiro

zxiiro commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Ok, not following:

Isn't the problem that runner determinator is running from PR head, and this changes to base ref? If this is the case, assuming the author is not introducing runner determinator or workflow changes this should not change the situation.

Correct?

Not sure if this makes it more clear. It uses a merge of base & PR head. So when an ghaction job runs it starts with the latest "main" for example (or whatever the merge branch is), and then adds PR changes on top of main.

So my understand of how this works is:

  1. PR does not touch .github/scripts/runner_determinator.py -> job uses main's version
  2. PR modifies .github/scripts/runner_determinator.py -> job uses PR's version

@huydhn

huydhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Ok, not following:

Isn't the problem that runner determinator is running from PR head, and this changes to base ref? If this is the case, assuming the author is not introducing runner determinator or workflow changes this should not change the situation.

Correct?

I always thought that the runner determinator is from main because of this line https://github.com/pytorch/pytorch/blob/main/.github/workflows/pull.yml#L60, and the log shows https://github.com/pytorch/pytorch/actions/runs/29296467089/job/86970972910?pr=189797#step:1:30. But, as @zxiiro points out here, the checkout step inside actually get from PR head https://github.com/pytorch/pytorch/actions/runs/29296467089/job/86970972866?pr=189797#step:2:113. The regression here came from #182579. This change effectively reverts / redos #182579. This is the part that makes sense.

On ghstack, the same principal applies, but the script and the workflow would come from the stack base, which could be very old, but "should" work as long as they are consistent

@jeanschmidt

Copy link
Copy Markdown
Contributor

ahh so we don't want runner determinator from main? Why not use PR head instead?

What is the discrepancy we care about runner determinator script vs current main or runner determinator script vs pr head/base?

@huydhn

huydhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

Another note is that I think the proposals from pytorch/ci-infra#895 still stands though as detecting the discrepancy (AI linter) and refuse to run PR whose base commit is too old (might be a controversy) can be useful feature to have

@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

@huydhn

huydhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@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 jobs have failed, first few of them are: Auto Request Review, docs-build

Details for Dev Infra team Raised by workflow job

@huydhn

huydhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@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

@huydhn

huydhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -f 'CI signals look a-ok'

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@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

vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
_runner-determinator.yml checked out .github/scripts/runner_determinator.py from github.event.pull_request.head.sha, so PRs whose branch predates a change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2 build-path removal in pytorch#189113/pytorch#189171) run a stale copy. That stale copy can emit a runner-label prefix main's build workflow no longer knows how to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix glued onto a post-pytorch#189113 ARC-only label), leaving the job stuck unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in pytorch#182579 only so ci-docker-hash reflects the PR's own .ci/docker tree, not to let PRs self-test determinator changes. Split the checkout in two: the script now comes from the default ref (main, or the merge commit for pull_request events, which still includes the PR's own edits to the script), while .ci/docker keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the script is no longer stale relative to main and always supports the flag.
Pull Request resolved: pytorch#189782
Approved by: https://github.com/huydhn, https://github.com/jeanschmidt

Co-authored-by: Claude Sonnet 5 <[email protected]>
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
_runner-determinator.yml checked out .github/scripts/runner_determinator.py from github.event.pull_request.head.sha, so PRs whose branch predates a change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2 build-path removal in pytorch#189113/pytorch#189171) run a stale copy. That stale copy can emit a runner-label prefix main's build workflow no longer knows how to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix glued onto a post-pytorch#189113 ARC-only label), leaving the job stuck unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in pytorch#182579 only so ci-docker-hash reflects the PR's own .ci/docker tree, not to let PRs self-test determinator changes. Split the checkout in two: the script now comes from the default ref (main, or the merge commit for pull_request events, which still includes the PR's own edits to the script), while .ci/docker keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the script is no longer stale relative to main and always supports the flag.
Pull Request resolved: pytorch#189782
Approved by: https://github.com/huydhn, https://github.com/jeanschmidt

Co-authored-by: Claude Sonnet 5 <[email protected]>
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
_runner-determinator.yml checked out .github/scripts/runner_determinator.py from github.event.pull_request.head.sha, so PRs whose branch predates a change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2 build-path removal in pytorch#189113/pytorch#189171) run a stale copy. That stale copy can emit a runner-label prefix main's build workflow no longer knows how to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix glued onto a post-pytorch#189113 ARC-only label), leaving the job stuck unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in pytorch#182579 only so ci-docker-hash reflects the PR's own .ci/docker tree, not to let PRs self-test determinator changes. Split the checkout in two: the script now comes from the default ref (main, or the merge commit for pull_request events, which still includes the PR's own edits to the script), while .ci/docker keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the script is no longer stale relative to main and always supports the flag.
Pull Request resolved: pytorch#189782
Approved by: https://github.com/huydhn, https://github.com/jeanschmidt

Co-authored-by: Claude Sonnet 5 <[email protected]>
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
_runner-determinator.yml checked out .github/scripts/runner_determinator.py from github.event.pull_request.head.sha, so PRs whose branch predates a change to the script (e.g. the "lf." -> "lf-" prefix rename, or the EC2 build-path removal in pytorch#189113/pytorch#189171) run a stale copy. That stale copy can emit a runner-label prefix main's build workflow no longer knows how to route (e.g. "lf.l-x86iavx512-8-64" - a dead EC2-era dotted prefix glued onto a post-pytorch#189113 ARC-only label), leaving the job stuck unroutable instead of just landing on the wrong fleet.

The PR-head ref was introduced in pytorch#182579 only so ci-docker-hash reflects the PR's own .ci/docker tree, not to let PRs self-test determinator changes. Split the checkout in two: the script now comes from the default ref (main, or the merge commit for pull_request events, which still includes the PR's own edits to the script), while .ci/docker keeps using head.sha via a separate sparse checkout under pr-head/.

This also removes the --help probing for --workflow-name, since the script is no longer stale relative to main and always supports the flag.
Pull Request resolved: pytorch#189782
Approved by: https://github.com/huydhn, https://github.com/jeanschmidt

Co-authored-by: Claude Sonnet 5 <[email protected]>
@github-actions
github-actions Bot deleted the zxiiro/runner-determinator-stale-script branch August 14, 2026 02:24
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 Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants