Skip to content

Heal interpreter metadata cache entries when creating a virtual environment indicates corruption - #617

Closed
zaniebot wants to merge 3 commits into
mainfrom
zb/fix-bug/21066-stale-interpreter-cache
Closed

zaniebot wants to merge 3 commits into
mainfrom
zb/fix-bug/21066-stale-interpreter-cache

Conversation

@zaniebot

Copy link
Copy Markdown
Collaborator

When a system Python changes its loaded libpython without changing the launcher, its cached version can disagree with the interpreter already running inside a project environment. uv then repeatedly recreates the environment with stale pyvenv.cfg metadata and can evaluate requires-python against the wrong version. Refresh the base interpreter's persistent metadata only when an existing environment has a pyvenv.cfg version conflict and the same underlying interpreter reports a different cached version, so subsequent discovery and environment creation use the actual interpreter while genuine incompatibilities retain their existing behavior.

Fixes astral-sh#21066.

@astral-automations-bot astral-automations-bot Bot added the bug Something isn't working label Aug 12, 2026
Comment thread crates/uv-python/src/interpreter.rs Outdated
}

/// Query the interpreter directly and update its cached metadata.
pub fn query_fresh(executable: impl AsRef<Path>, cache: &Cache) -> Result<Self, Error> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we'd call this query_with_refresh?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Though I wonder why we don't just make query_with_cache pub?

Comment thread crates/uv/tests/sync/sync.rs Outdated
Comment on lines +12637 to +12639
// Replace only exact MessagePack strings, preserving path fields and the executable ctime.
let mut encoded_version = vec![0xa0 | u8::try_from(actual_version.len())?];
encoded_version.extend_from_slice(actual_version.as_bytes());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test case approach seems pretty questionable?

Comment thread crates/uv/src/commands/project/mod.rs Outdated
) {
);

// A launcher's shared library can change without updating the executable timestamp used to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we're over-specifying here? Can we just say that the cache can be corrupted?

@zanieb zanieb changed the title Refresh stale base interpreter metadata after virtualenv conflicts Heal interpreter metadata cache entries when creating a virtual environment indicates corruption Aug 12, 2026
@zanieb
zanieb marked this pull request as ready for review August 12, 2026 15:38
@astral-automations-bot

Copy link
Copy Markdown

Promoted to #21073.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UV recreates the venv on every run.

3 participants