Skip to content

Honor LFS endpoints during Git cache recovery - #2542

Draft
zaniebot wants to merge 6 commits into
zb/preview-git-partial-fetchesfrom
zb/fix-git-lfs-cache-recovery
Draft

zaniebot wants to merge 6 commits into
zb/preview-git-partial-fetchesfrom
zb/fix-git-lfs-cache-recovery

Conversation

@zaniebot

@zaniebot zaniebot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Git LFS fetches in the shared database can ignore the selected revision's .lfsconfig, and checkout recovery can follow a configured remote endpoint instead of copying local objects. Load the revision's configuration before fetching and force local copies to use the database endpoint. An unsupported git lfs fsck --objects now triggers a fetch instead of treating missing objects as cached.

@zaniebot
zaniebot deployed to automations October 9, 2026 00:54 — with GitHub Actions Active
@astral-automations-bot astral-automations-bot Bot added bug Something isn't working preview Experimental behavior labels Oct 9, 2026
@zaniebot
zaniebot deployed to automations October 9, 2026 00:59 — with GitHub Actions Active
Comment thread crates/uv-git/src/git.rs
Comment on lines +1308 to 1309
repo.prepare_lfs_config(revision)?;
configure_git_network(&mut cmd, url, disable_ssl, offline);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Enforce offline mode for the selected LFS endpoint

Loading .lfsconfig can now select an HTTP endpoint even when the Git source uses file://. configure_git_network only sets GIT_ALLOW_PROTOCOL=file, which Git LFS's HTTP client does not honor. In an isolated reproduction, the base commands made no HTTP requests, while the new commands posted to /objects/batch with that restriction set. Consequently, uv lock --offline can access the network for this input. Enforce offline policy against the resolved LFS endpoint before fetching, while allowing local database copies.

Comment thread crates/uv-git/src/git.rs
Comment on lines 651 to +652
pub(crate) fn contains_lfs_artifacts(&self, oid: GitOid) -> bool {
self.repo.lfs_fsck_objects(&format!("{oid}^0"))
self.repo.lfs_fsck_objects(&format!("{oid}^0")) == LfsValidation::Passed

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Load the selected revision's configuration before cache validation

prepare_lfs_config now leaves revision-specific configuration in the shared database, but this cache-hit check runs before updating it. After fetching a revision with lfs.fetchexclude = module.py, requesting another cached commit without that exclusion still validates using the previous exclusion. I reproduced fsck succeeding with the required object absent, then failing after removing the stale configuration. GitSource::fetch consequently skips the remote fetch, and checkout recovery fails against the incomplete database. Prepare the requested revision's configuration before this validation, treating preparation failures as cache misses.

@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 13.75%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
✅ 65 untouched benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ ⚠️ Simulation discover_workspace_from_all_members_with_excludes 162.6 ms 140.5 ms +15.74%
⚡ WallTime git_fetch_warm_reference[django] 12.1 ms 10.6 ms +14.29%
⚡ WallTime git_fetch_warm_reference[flask] 12 ms 10.6 ms +13.18%
⚡ WallTime git_fetch_warm_reference[sampleproject] 7.5 ms 6.7 ms +11.85%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/fix-git-lfs-cache-recovery (38357d1) with zb/preview-git-partial-fetches (2bda788)2

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on zb/preview-git-partial-fetches (25072c4) during the generation of this report, so 66d95ad was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@zaniebot
zaniebot deployed to automations October 9, 2026 03:27 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 03:33 — with GitHub Actions Active
Comment thread crates/uv-git/src/git.rs
Comment on lines +1349 to +1350
if !local_endpoint {
return Err(GitError::TransportNotAllowed.into());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Check cached LFS objects before rejecting the offline endpoint

For a file:// source selected by branch or tag, GitSource::fetch bypasses the precise-commit cache shortcut, and GitRemote::checkout calls this even when all required LFS objects are cached. An HTTP endpoint in .lfsconfig now makes --offline fail despite needing no downloads. In an isolated Git LFS probe, both fsck --objects and fetch origin <revision> succeeded in this state with zero HTTP requests. After preparing the revision’s configuration, allow LfsValidation::Passed to return success before rejecting a nonlocal endpoint; keep Skipped on the fetch-required path.

@zaniebot
zaniebot deployed to automations October 9, 2026 03:53 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 03:57 — with GitHub Actions Active
Comment thread crates/uv/tests/project/edit.rs Outdated
Comment on lines +1656 to +1659
Command::new("git")
.args(["lfs", "fsck", "--objects", &revision])
.current_dir(db_root.path())
.output()?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Verify checkout objects in the old-LFS recovery test

This case removes LFS objects from both the database and checkout, but only verifies the database afterward. Consequently, incorrectly treating Skipped as cache-ready in GitDatabase::copy_to remains undetected: module.py is already materialized, and an isolated probe confirmed that git lfs checkout succeeds with its cached object missing. Also run the unshimmed git lfs fsck --objects in checkout_root after recovery so the test protects the new forced-copy behavior.

@zaniebot
zaniebot deployed to automations October 9, 2026 04:49 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 04:53 — with GitHub Actions Active
Comment thread crates/uv/tests/project/edit.rs Outdated

/// Revision-local LFS endpoints apply to downloads, while cached-object copies stay local.
#[test]
#[cfg(all(feature = "test-git-lfs", feature = "test-pypi"))]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Remove the unnecessary PyPI gate from the local LFS test

This test uses local repositories and runs every lock command with --offline; unlike the neighboring compatibility tests, it never downloads an older uv from PyPI. Requiring test-pypi unnecessarily excludes the endpoint, cache-recovery, and old-LFS regression coverage when running with only test-git-lfs enabled. Gate it solely on test-git-lfs, as the preceding offline-endpoint test does.

@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch 2 times, most recently from babb44f to 7868bb5 Compare October 14, 2026 16:28
@zaniebot
zaniebot deployed to automations October 14, 2026 16:29 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 14, 2026 16:35 — with GitHub Actions Active
Comment thread crates/uv/tests/project/edit.rs Outdated
Comment on lines +1627 to +1633
#[cfg(unix)]
{
// Older Git LFS cannot validate cached objects, so it must attempt a fetch.
fs_err::rename(unavailable_endpoint.path(), endpoint.path())?;
clear_source_metadata()?;
fs_err::remove_dir_all(db_root.child(".git/lfs/objects"))?;
fs_err::remove_dir_all(checkout_root.child(".git/lfs/objects"))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Give old-LFS recovery its own named test

The unsupported-fsck --objects scenario is independent of the endpoint switching and stale-exclusion scenarios above, but it only runs after they all succeed and must undo their endpoint rename before starting. This couples unrelated regression fixtures and prevents selecting the old-LFS case independently with nextest. Move this block into a separately named, Unix-gated integration test with explicit cache setup and a command snapshot.

@zaniebot
zaniebot added this pull request to stack #2718 October 14, 2026 16:49
@zaniebot zaniebot closed this Oct 14, 2026
@zaniebot zaniebot reopened this Oct 14, 2026
@zaniebot
zaniebot deployed to automations October 14, 2026 16:53 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 14, 2026 16:57 — with GitHub Actions Active
Comment thread crates/uv/tests/project/edit.rs Outdated
Comment on lines +1551 to +1555
let lock = || {
let mut command = context.lock();
command.args(["--offline", "--preview-features", "git-partial-fetches"]);
command
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Keep endpoint-recovery commands explicit and snapshotted

The endpoint and stale-configuration recovery steps below use lock().assert().success(), hiding their defining offline/partial-fetch arguments and leaving command output unchecked. The preceding add_git_lfs_offline_http_endpoint test demonstrates the repository’s preferred explicit uv_snapshot! pattern. Inline these context.lock() invocations with their arguments and separate snapshots, retaining the object-content assertions, so each recovery step shows its inputs and checks its diagnostics.

@zaniebot
zaniebot removed this pull request from stack #2718 October 14, 2026 17:58
@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch from 7868bb5 to ff46f09 Compare October 14, 2026 17:59
@zaniebot
zaniebot added this pull request to stack #2728 October 14, 2026 17:59
@zaniebot
zaniebot deployed to automations October 14, 2026 18:01 — with GitHub Actions Active
@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch from ff46f09 to fb81ee0 Compare October 14, 2026 19:39
@zaniebot
zaniebot deployed to automations October 14, 2026 19:40 — with GitHub Actions Active
@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch from fb81ee0 to f24ca22 Compare October 14, 2026 19:52
@zaniebot
zaniebot deployed to automations October 14, 2026 19:56 — with GitHub Actions Active
@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch from f24ca22 to 66cede2 Compare October 14, 2026 20:07
@zaniebot
zaniebot deployed to automations October 14, 2026 20:08 — with GitHub Actions Active
@zaniebot
zaniebot force-pushed the zb/fix-git-lfs-cache-recovery branch from 66cede2 to 38357d1 Compare October 14, 2026 20:19
@zaniebot
zaniebot deployed to automations October 14, 2026 20:21 — with GitHub Actions Active

This branch was successfully deployed

1 active (outdated) deployment
automations — 38357d19 Deployed Oct 14, 2026 by zaniebot via review-code-quality / code quality review #10190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant