Repository navigation
Conversation
…d-diff lazy fetch Rework the fix into a shared helper and apply it uniformly across both stable-shim linter adapters. Add `ensure_diff_blob_local(commit, filename)` to `_stable_shim_utils.py`. It resolves the blob OID offline (trees are present under a blobless partial clone) and, only when that object is missing locally, fetches exactly that one blob through the existing retrying network helper. `GIT_NO_LAZY_FETCH=1` guards the rev-parse and cat-file probes so the local resolution and presence checks cannot themselves trigger a fetch. Paths outside the repo, files that don't exist at the merge-base, and full (non-partial) clones all short-circuit to a no-op with no network access. Wire the helper into both adapters ahead of the git command that reads the merge-base contents: - `stable_shim_version_linter.py`: prefetch before the `git diff <merge_base>..HEAD` in `get_added_lines()`. - `generated_shims_version_linter.py`: prefetch before the `git show` in `_read_at_merge_base()`, and drop that command's prior 60s lazy-fetch workaround back to a short 5s timeout now that the blob is guaranteed local beforehand. This keeps the git commands running entirely from local objects behind an honest short timeout, rather than waiting out an uncontrolled mid-command lazy fetch. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191228
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 14 PendingAs of commit 6fb848a with merge base 9a036ca ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| ["git", "rev-parse", f"{commit}:{rel}"], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=5, |
There was a problem hiding this comment.
I do wonder if gitpython bindings would give us more info so we did not need to rely on these timeouts?
|
@claude would gitpython library or something similar give us more signal and prevent us from having to rely on timeouts? |
|
Claude finished @Skylion007's task in 4m 44s —— View job Would GitPython (or similar) give more signal and remove the timeout reliance?Short answer: it would remove one timeout, but not by virtue of being a library — and this PR already removes that same timeout more cheaply with Details1. GitPython's 2. The part that would give a clean signal is the pure-Python object DB — But that is exactly what 3. Dependency cost is not zero. Every adapter under So: the timeout reliance worth eliminating is the "timeout means missing" probe, not the timeouts on local commands. After this PR the 5s timeouts on One concrete follow-up in the same spirit (no new dep): the last remaining timeout-as-signal is the pre-existing commit probe in no_lazy = {**os.environ, "GIT_NO_LAZY_FETCH": "1"}
commit_missing = subprocess.run(
["git", "cat-file", "-e", f"{main_sha}^{{commit}}"],
capture_output=True, timeout=5, env=no_lazy,
).returncode != 0( Answering @Skylion007's question — no: GitPython's |
|
@pytorchbot merge -f "linter-only change (stable-shim adapter scripts); Lint is green, other CI not required" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…y fetch (pytorch#191228) The STABLE_SHIM_VERSION linter intermittently fails in CI with `subprocess.TimeoutExpired` on `git diff <merge_base>..HEAD -- shim.h`, reported as an internal linter bug. Root cause: CI checks out a blobless partial clone (`--filter=blob:none`, added in pytorch#172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff timeout predates that (added with the linter in pytorch#166995) and was correct then -- the diff was purely local. `merge_base_with_main()` fetches the merge-base *commit* ahead of time, but the blobless filter deliberately omits file contents even for explicitly fetched commits, so the merge-base blob of the linted file is never local. When `git diff` needs it, git triggers an on-demand lazy fetch in the middle of the command -- an uncontrolled network round-trip that races the 5s timeout under the network contention of lintrunner running adapters concurrently. This is the same partial-clone symptom pytorch#189419 already fixed for the sibling `git cat-file` probe in `merge_base_with_main()`, which was simply never applied to the `git diff`/`git show` paths. pytorch#189419 established the design: keep a short timeout as a fast "is it local?" probe and, on absence, fall back to an explicit, controlled `git fetch`. pytorch#189444 tried to instead bump the probe timeout to wait the lazy fetch out; pytorch#189946 reverted that, on the grounds that a timeout is the signal that the object is not present, not something to wait out. So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to wait it out) would repeat the already-reverted mistake. Fix: apply pytorch#189419's design to the missing blob. `ensure_diff_blob_local()` resolves the blob OID offline (trees are present under blob:none) and, only if it is missing locally, fetches that single object through the existing retrying network helper; the diff/show then runs entirely from local objects with a short, honest timeout. `GIT_NO_LAZY_FETCH=1` guards the resolution and presence checks so they cannot themselves trigger a fetch -- a deterministic improvement over the cat-file probe's timeout race. In a full clone the blob is already present and this is a no-op with no network access. The generated-shims linter's prior 60s `git show` workaround is replaced by the same prefetch + 5s timeout. Test Plan: Verified locally in a full clone that the helper is a no-op and the git command stays local and fast: ``` python tools/linter/adapters/stable_shim_version_linter.py \ torch/csrc/inductor/aoti_torch/c/shim.h ``` End-to-end validation on a blobless partial clone still needs to run (the sandbox has no network); it must confirm the single-blob `git fetch --no-write-fetch-head origin <oid>` succeeds against GitHub's promisor endpoint. If the explicit single-object fetch is rejected there, the fallback is to trigger git's native lazy fetch through the same retry wrapper (e.g. `git cat-file -p <oid>`). Authored-with: Claude (AI assistant) Pull Request resolved: pytorch#191228 Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
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]
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. Pull Request resolved: #191364 Approved by: https://github.com/albanD
…y fetch (pytorch#191228) The STABLE_SHIM_VERSION linter intermittently fails in CI with `subprocess.TimeoutExpired` on `git diff <merge_base>..HEAD -- shim.h`, reported as an internal linter bug. Root cause: CI checks out a blobless partial clone (`--filter=blob:none`, added in pytorch#172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff timeout predates that (added with the linter in pytorch#166995) and was correct then -- the diff was purely local. `merge_base_with_main()` fetches the merge-base *commit* ahead of time, but the blobless filter deliberately omits file contents even for explicitly fetched commits, so the merge-base blob of the linted file is never local. When `git diff` needs it, git triggers an on-demand lazy fetch in the middle of the command -- an uncontrolled network round-trip that races the 5s timeout under the network contention of lintrunner running adapters concurrently. This is the same partial-clone symptom pytorch#189419 already fixed for the sibling `git cat-file` probe in `merge_base_with_main()`, which was simply never applied to the `git diff`/`git show` paths. pytorch#189419 established the design: keep a short timeout as a fast "is it local?" probe and, on absence, fall back to an explicit, controlled `git fetch`. pytorch#189444 tried to instead bump the probe timeout to wait the lazy fetch out; pytorch#189946 reverted that, on the grounds that a timeout is the signal that the object is not present, not something to wait out. So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to wait it out) would repeat the already-reverted mistake. Fix: apply pytorch#189419's design to the missing blob. `ensure_diff_blob_local()` resolves the blob OID offline (trees are present under blob:none) and, only if it is missing locally, fetches that single object through the existing retrying network helper; the diff/show then runs entirely from local objects with a short, honest timeout. `GIT_NO_LAZY_FETCH=1` guards the resolution and presence checks so they cannot themselves trigger a fetch -- a deterministic improvement over the cat-file probe's timeout race. In a full clone the blob is already present and this is a no-op with no network access. The generated-shims linter's prior 60s `git show` workaround is replaced by the same prefetch + 5s timeout. Test Plan: Verified locally in a full clone that the helper is a no-op and the git command stays local and fast: ``` python tools/linter/adapters/stable_shim_version_linter.py \ torch/csrc/inductor/aoti_torch/c/shim.h ``` End-to-end validation on a blobless partial clone still needs to run (the sandbox has no network); it must confirm the single-blob `git fetch --no-write-fetch-head origin <oid>` succeeds against GitHub's promisor endpoint. If the explicit single-object fetch is rejected there, the fallback is to trigger git's native lazy fetch through the same retry wrapper (e.g. `git cat-file -p <oid>`). Authored-with: Claude (AI assistant) Pull Request resolved: pytorch#191228 Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
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
Stack from ghstack (oldest at bottom):
The STABLE_SHIM_VERSION linter intermittently fails in CI with
subprocess.TimeoutExpiredongit diff <merge_base>..HEAD -- shim.h,reported as an internal linter bug.
Root cause: CI checks out a blobless partial clone (
--filter=blob:none, addedin #172544; see .github/actions/checkout-pytorch/action.yml). The 5s diff
timeout predates that (added with the linter in #166995) and was correct then --
the diff was purely local.
merge_base_with_main()fetches the merge-basecommit ahead of time, but the blobless filter deliberately omits file contents
even for explicitly fetched commits, so the merge-base blob of the linted file
is never local. When
git diffneeds it, git triggers an on-demand lazy fetchin the middle of the command -- an uncontrolled network round-trip that races
the 5s timeout under the network contention of lintrunner running adapters
concurrently.
This is the same partial-clone symptom #189419 already fixed for the sibling
git cat-fileprobe inmerge_base_with_main(), which was simply never appliedto the
git diff/git showpaths. #189419 established the design: keep a shorttimeout as a fast "is it local?" probe and, on absence, fall back to an
explicit, controlled
git fetch. #189444 tried to instead bump the probetimeout to wait the lazy fetch out; #189946 reverted that, on the grounds that a
timeout is the signal that the object is not present, not something to wait out.
So bumping the diff timeout (or wrapping the diff in the retrying fetch helper to
wait it out) would repeat the already-reverted mistake.
Fix: apply #189419's design to the missing blob.
ensure_diff_blob_local()resolves the blob OID offline (trees are present under blob:none) and, only if
it is missing locally, fetches that single object through the existing retrying
network helper; the diff/show then runs entirely from local objects with a
short, honest timeout.
GIT_NO_LAZY_FETCH=1guards the resolution and presencechecks so they cannot themselves trigger a fetch -- a deterministic improvement
over the cat-file probe's timeout race. In a full clone the blob is already
present and this is a no-op with no network access. The generated-shims linter's
prior 60s
git showworkaround is replaced by the same prefetch + 5s timeout.Test Plan:
Verified locally in a full clone that the helper is a no-op and the git command
stays local and fast:
End-to-end validation on a blobless partial clone still needs to run (the
sandbox has no network); it must confirm the single-blob
git fetch --no-write-fetch-head origin <oid>succeeds against GitHub'spromisor endpoint. If the explicit single-object fetch is rejected there, the
fallback is to trigger git's native lazy fetch through the same retry wrapper
(e.g.
git cat-file -p <oid>).Authored-with: Claude (AI assistant)