Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 0.4.23: data did not match any variant of untagged enum CacheInfoWire #8367

Closed
KapJI opened this issue Oct 19, 2024 · 15 comments · Fixed by #8386
Closed

Regression in 0.4.23: data did not match any variant of untagged enum CacheInfoWire #8367

KapJI opened this issue Oct 19, 2024 · 15 comments · Fixed by #8386
Assignees
Labels
cache Caching of packages and metadata

Comments

@KapJI
Copy link

KapJI commented Oct 19, 2024

My Github Actions CI started failing with this error:

error: Failed to build: `homeassistant-stubs @ file:///home/runner/work/homeassistant-stubs/homeassistant-stubs`
  Caused by: Failed to deserialize cache entry
  Caused by: data did not match any variant of untagged enum CacheInfoWire

I bisected it to 0.4.23 here: KapJI/homeassistant-stubs#496

This is an example workflow, enable-cache: false, other settings for astral-sh/setup-uv are default, it's using ubuntu-latest runner:
https://github.com/KapJI/homeassistant-stubs/actions/runs/11418948703/job/31772992617

All these tools in pre-commit hook are running via uv run. In this workflow no caches were materialized but UV_CACHE_DIR was set by setup-uv.

  • I tried to remove all stored caches from the repo jsut in case with no result.
  • Also I tried using different cache-local-path, also with no result.
@KapJI
Copy link
Author

KapJI commented Oct 19, 2024

@zanieb zanieb added bug Something isn't working cache Caching of packages and metadata labels Oct 19, 2024
@zanieb
Copy link
Member

zanieb commented Oct 19, 2024

Thanks for the bisect!

@charliermarsh
Copy link
Member

Are you somehow sharing a cache across multiple uv versions?

@charliermarsh
Copy link
Member

Like somehow writing to the cache from 0.4.23 and then reading from it on 0.4.22?

@charliermarsh
Copy link
Member

I think that's very likely what's happening. Your uv.lock has:

[[package]]
name = "uv"
version = "0.4.15"

So the outer uv run for pre-commit is using 0.4.23 or whatever you've pinned, but the uv run within your pre-commit jobs is using the uv version locked in the project (0.4.15). It's not safe to write cache data with a later version and then read it with an earlier version unfortunately.

@charliermarsh charliermarsh removed the bug Something isn't working label Oct 19, 2024
@charliermarsh
Copy link
Member

I think you need to either use 0.4.15 in your project (to match home-assistant), or use different cache directories between your top-level uv run (or even --no-cache?) and the jobs in your pre-commit.

@charliermarsh
Copy link
Member

Alternatively we could decide to change our policy (written up here) so that versions like 0.4.15 are expected to be able to read cache data from 0.4.23.

@charliermarsh
Copy link
Member

(I'm not opposed to changing the policy, it just means more frequent cache version bumps.)

@KapJI
Copy link
Author

KapJI commented Oct 19, 2024

Wow, that's a good catch! I don't know how it got into uv.lock though. Is there any reasonable case when this should be allowed?

Edit: I found it's a dependency of homeassistant itself.

@KapJI
Copy link
Author

KapJI commented Oct 19, 2024

Basically the issue here is that some downstream dependency may add different version of uv to its dependencies, like homeassistant in this case. This means it's not safe to use uv within uv run as outer and inner versions may mismatch.

I wonder if uv can detect such case and show some warning as this scenario may probably lead to many other issues.

@AlexWaygood
Copy link
Member

I actually just ran into this while working on typeshed.

Typeshed has uv listed as a test dependency in its requirements-tests.txt file (because we use it in our test scripts, but we don't want to mandate that users have to use uv for local development if they don't want to). But I also have uv installed globally for my local development, and the uv version I have installed globally is a much newer one than the uv pin in typeshed's requirements-tests.txt file that was installed into my typeshed-development virtual environment locally. Which led to uv crashing with this error message when one version of uv tried to read a cache entry written by another version of uv.

@charliermarsh
Copy link
Member

We should probably just change our cache versioning policy to make this less likely.

MtkN1 pushed a commit to MtkN1/uv that referenced this issue Oct 21, 2024
…#8386)

## Summary

Going forward, we're going to provide better versioning guarantees
around using the same cache across multiple uv versions, so this PR
updates the docs to reflect that. It also bumps the `sdists-` version to
fix the inconvenience demonstrated in
astral-sh#8367.

Closes astral-sh#8367.
@mishamsk
Copy link

@charliermarsh I may be reading the policy wrong, but it kinda implies that if two version have incompatible cache formats, then they will use different subfolders within the root cache folder to avoid errors. Which is what I'd expect. I am not concerned about extra gigabytes of duplicate data sitting around as long as it helps uv "just work".

But now it seems that either I am reading the text wrong, or. the reality is different. I have pretty much the same case as @AlexWaygood - the most recent version of uv installed and used globally (e.g. for quick scripts), but locked older versions in many a project. The latter randomly fail to uv sync.

I imagine adding forward compatibility may be really hard. Wonder if you could just treat the UV_CACHE as root folder, but really place cache under versioned subfolders, maybe versioned to a specific uv version to keep it really simple and stupid.

Whatever is the case, the amount of reduced testing/ci/frustration time that uv already brought definitely worth these minor inconveniences. So no complains really! Absolutely lovely stuff you are all making!

@charliermarsh
Copy link
Member

Thank you @mishamsk ❤️

The cache policy going forward is what you described in your first paragraph: if two versions have incompatible cache formats, they use different subfolders within the cache. So they shouldn't error, but they may duplicate data.

But I just changed the policy (see the linked PR here), so it's possible that you're seeing breakages when sharing the cache between older uv versions.

@mishamsk
Copy link

Thank you @mishamsk ❤️

The cache policy going forward is what you described in your first paragraph: if two versions have incompatible cache formats, they use different subfolders within the cache. So they shouldn't error, but they may duplicate data.

But I just changed the policy (see the linked PR here), so it's possible that you're seeing breakages when sharing the cache between older uv versions.

ah, ok, that makes sense. you are just moving so fast, this PR is 4 days old, I haven't realized that it did include the change you mentioned in a comment ;-)

I'll go ahead and update uv version on one of my projects then, was just debating if there is value to do that. Now I know there is. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cache Caching of packages and metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants