From 461f4d9007160f7061a4fc0c4a5a84c613fdbff7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 1 Mar 2025 20:36:38 -0500 Subject: [PATCH] Make interpreter caching robust to OS upgrades (#11875) ## Summary In. https://github.com/astral-sh/uv/issues/11857, we had a case of a user that was seeing incorrect resolution results after upgrading to a newer version of macOS, since we retained cache information about the interpreter. This PR adds the OS name and version to the cache key for the interpreter. This seems to be extremely cheap, and it's nice to make this robust so that users don't run into the same confusion in the future. Closes https://github.com/astral-sh/uv/issues/11857. --- Cargo.lock | 1 + crates/uv-python/Cargo.toml | 1 + crates/uv-python/src/interpreter.rs | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd650bede..63dedc89e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5456,6 +5456,7 @@ dependencies = [ "schemars", "serde", "serde_json", + "sys-info", "target-lexicon", "temp-env", "tempfile", diff --git a/crates/uv-python/Cargo.toml b/crates/uv-python/Cargo.toml index 7b9b98d6b..0a26279f9 100644 --- a/crates/uv-python/Cargo.toml +++ b/crates/uv-python/Cargo.toml @@ -51,6 +51,7 @@ same-file = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } +sys-info = { workspace = true } target-lexicon = { workspace = true } tempfile = { workspace = true } thiserror = { workspace = true } diff --git a/crates/uv-python/src/interpreter.rs b/crates/uv-python/src/interpreter.rs index 417d094ee..228bad505 100644 --- a/crates/uv-python/src/interpreter.rs +++ b/crates/uv-python/src/interpreter.rs @@ -848,9 +848,13 @@ impl InterpreterInfo { let cache_entry = cache.entry( CacheBucket::Interpreter, - // Shard interpreter metadata by host architecture, to avoid cache collisions when - // running universal binaries under Rosetta. - ARCH, + // Shard interpreter metadata by host architecture, operating system, and version, to + // invalidate the cache (e.g.) on OS upgrades. + cache_digest(&( + ARCH, + sys_info::os_type().unwrap_or_default(), + sys_info::os_release().unwrap_or_default(), + )), // We use the absolute path for the cache entry to avoid cache collisions for relative // paths. But we don't to query the executable with symbolic links resolved. format!("{}.msgpack", cache_digest(&absolute)),