Skip to content

Make stable shim linters reliable in partial clones - #191364

Closed
janeyx99 wants to merge 3 commits into
gh/janeyx99/396/basefrom
gh/janeyx99/396/head
Closed

janeyx99 wants to merge 3 commits into
gh/janeyx99/396/basefrom
gh/janeyx99/396/head

Conversation

@janeyx99

@janeyx99 janeyx99 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

We've tried a lot of partial fixes to this partial clone problem, which then caused more holes that required patching. The latest was: #191228 which attempted to enforce certain git commands be local only. This was too strict, where the historical versions of files would error (see https://github.com/pytorch/pytorch/actions/runs/30380274127/job/90346227990).

Codex and I tried to solve this problem once and for all with a small redesign. We have separated out the git commands that should require network, and the ones that should not:

Must remain offline: refs + commits, which we should trust our checkout.

  • merge_base_with_main() GIT_NO_LAZY_FETCH=1 git merge-base HEAD refs/remotes/origin/main
  • Working-tree diff: GIT_NO_LAZY_FETCH=1 git diff HEAD -- <file>
  • First attempt of every historical object command.

May contact the network: actual file content.

  • Latter attempts of every historical object command, assuming the first local attempt failed:
git diff <merge-base>..HEAD -- <file>
git ls-tree -z <revision> -- <path>
git cat-file blob <oid>

Removed:

  • git ls-remote: trust the local main, do not refetch main.
  • Explicit git fetch origin <object-oid>: GitHub can reject this request if it's a blob vs a commit/branch. We replace this with cat-file.
  • Fetching or updating origin/main or any linter-managed ref updates: lint runs concurrently, don't step over each other's toes

I'm relatively confident about the must remain offline, because our checkout for lint does the following:

  • setup-linux defaults to checkout-mode: treeless.
  • checkout-pytorch defaults to fetch-depth: 0, meaning full commit history.
  • origin/main is fetched by checkout.

The stable-shim linters resolved and fetched individual blob OIDs when a historical diff needed objects missing from a partial clone. GitHub rejects that fetch shape without the promisor negotiation path, and resolving main through adapter-level network operations also exposed concurrent linters to ref and network races.

Resolve the merge base strictly from the checkout's existing origin/main ref. For historical object access, first prove the high-level Git command works locally, then retry that same command with native promisor hydration enabled. Read historical files with ls-tree and cat-file so a genuinely absent path remains distinct from a Git or network failure.

This keeps object-class decisions inside Git instead of adding another blob/tree special case or increasing timeouts.

Test Plan:
```
python tools/test/test_stable_shim_utils.py
python tools/test/test_stable_shim_version_linter.py
python tools/test/test_generated_shims_version_linter.py
spin quicklint
```

The partial-clone integration methods were exercised for blob:none, tree:0, concurrent hydration, and a full clone with an unreachable remote. The standard common_utils entry point is blocked in this checkout before test collection by duplicate GradBucket registration. spin quicklint found no issues in the changed files and remained nonzero on unrelated pre-existing Pyrefly errors.

AI assistance disclosure: This change was authored with an AI assistant and requires human review before submission.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit a239d1f with merge base 04b311a (image):
💚 Looks good so far! There are no failures yet. 💚

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

The stable-shim linters resolved and fetched individual blob OIDs when a historical diff needed objects missing from a partial clone. GitHub rejects that fetch shape without the promisor negotiation path, and resolving main through adapter-level network operations also exposed concurrent linters to ref and network races.

Resolve the merge base strictly from the checkout's existing origin/main ref. For historical object access, first prove the high-level Git command works locally, then retry that same command with native promisor hydration enabled. Read historical files with ls-tree and cat-file so a genuinely absent path remains distinct from a Git or network failure.

This keeps object-class decisions inside Git instead of adding another blob/tree special case or increasing timeouts.

Test Plan:
```
python tools/test/test_stable_shim_utils.py
python tools/test/test_stable_shim_version_linter.py
python tools/test/test_generated_shims_version_linter.py
spin quicklint
```

The partial-clone integration methods were exercised for blob:none, tree:0, concurrent hydration, and a full clone with an unreachable remote. The standard common_utils entry point is blocked in this checkout before test collection by duplicate GradBucket registration. spin quicklint found no issues in the changed files and remained nonzero on unrelated pre-existing Pyrefly errors.

AI assistance disclosure: This change was authored with an AI assistant and requires human review before submission.

[ghstack-poisoned]
@janeyx99
janeyx99 requested a review from ezyang July 28, 2026 21:18
@janeyx99
janeyx99 marked this pull request as ready for review July 28, 2026 21:18

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds ok!

raise RuntimeError(
f"Git command failed first attempt with no lazy fetching: {local_error}. "
f"Second, slower, attempt while allowing fetching over the network also "
"failed, even with retries: {e}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f string missing

We've tried a lot of partial fixes to this partial clone problem,  which then caused more holes that required patching. The latest was: #191228 which attempted to enforce certain git commands be local only. This was too strict, where the historical versions of files would error (see https://github.com/pytorch/pytorch/actions/runs/30380274127/job/90346227990).

Codex and I tried to solve this problem once and for all with a small redesign. We have separated out the git commands that should require network, and the ones that should not:

Must remain offline: refs + commits, which we should trust our checkout.
  - merge_base_with_main() `GIT_NO_LAZY_FETCH=1 git merge-base HEAD refs/remotes/origin/main`
  - Working-tree diff: `GIT_NO_LAZY_FETCH=1 git diff HEAD -- <file>`
  - First attempt of every historical object command.

May contact the network: actual file content.
  - Latter attempts of every historical object command, assuming the first local attempt failed:
```
git diff <merge-base>..HEAD -- <file>
git ls-tree -z <revision> -- <path>
git cat-file blob <oid>
```

Removed:
  - `git ls-remote`: trust the local main, do not refetch main.
  - Explicit `git fetch origin <object-oid>`: GitHub can reject this request if it's a blob vs a commit/branch. We replace this with cat-file.
  - Fetching or updating origin/main or any linter-managed ref updates: lint runs concurrently, don't step over each other's toes

I'm relatively confident about the must remain offline, because our checkout for lint does the following:
  - setup-linux defaults to checkout-mode: treeless.
  - checkout-pytorch defaults to fetch-depth: 0, meaning full commit history.
  - origin/main is fetched by checkout.

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #191266

MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
We've tried a lot of partial fixes to this partial clone problem,  which then caused more holes that required patching. The latest was: pytorch#191228 which attempted to enforce certain git commands be local only. This was too strict, where the historical versions of files would error (see https://github.com/pytorch/pytorch/actions/runs/30380274127/job/90346227990).

Codex and I tried to solve this problem once and for all with a small redesign. We have separated out the git commands that should require network, and the ones that should not:

Must remain offline: refs + commits, which we should trust our checkout.
  - merge_base_with_main() `GIT_NO_LAZY_FETCH=1 git merge-base HEAD refs/remotes/origin/main`
  - Working-tree diff: `GIT_NO_LAZY_FETCH=1 git diff HEAD -- <file>`
  - First attempt of every historical object command.

May contact the network: actual file content.
  - Latter attempts of every historical object command, assuming the first local attempt failed:
```
git diff <merge-base>..HEAD -- <file>
git ls-tree -z <revision> -- <path>
git cat-file blob <oid>
```

Removed:
  - `git ls-remote`: trust the local main, do not refetch main.
  - Explicit `git fetch origin <object-oid>`: GitHub can reject this request if it's a blob vs a commit/branch. We replace this with cat-file.
  - Fetching or updating origin/main or any linter-managed ref updates: lint runs concurrently, don't step over each other's toes

I'm relatively confident about the must remain offline, because our checkout for lint does the following:
  - setup-linux defaults to checkout-mode: treeless.
  - checkout-pytorch defaults to fetch-depth: 0, meaning full commit history.
  - origin/main is fetched by checkout.
Pull Request resolved: pytorch#191364
Approved by: https://github.com/albanD
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