Skip to content

Invalidate interpreter cache when pyvenv.cfg changes - #18537

Draft
zanieb wants to merge 7 commits into
astral-sh:mainfrom
zaniebot:claude/investigate-uv-18510-FWEM6
Draft

zanieb wants to merge 7 commits into
astral-sh:mainfrom
zaniebot:claude/investigate-uv-18510-FWEM6

Conversation

@zanieb

@zanieb zanieb commented Mar 17, 2026

Copy link
Copy Markdown
Member

Closes #18510.

Adds the pyvenv.cfg mtime to the interpreter cache key since toggling --system-site-packages changes the interpreter's reported site packages at query time.

claude added 2 commits March 17, 2026 16:55
Include `pyvenv.cfg` timestamp in interpreter cache validation so that
recreating a virtual environment with different settings (e.g., toggling
`--system-site-packages`) properly invalidates the cached interpreter
info, even when the underlying Python executable hasn't changed.

Closes astral-sh#18510

https://claude.ai/code/session_01XnGrXu7zANvMbh53D2GMU2
Instead of taking the max of executable and pyvenv.cfg timestamps
(which fails when the executable timestamp is newer than pyvenv.cfg),
include the pyvenv.cfg content directly in the cache key digest. This
guarantees a cache miss whenever pyvenv.cfg changes, regardless of
timestamp ordering.

https://claude.ai/code/session_01XnGrXu7zANvMbh53D2GMU2
@zanieb zanieb added the bug Something isn't working label Mar 17, 2026
Comment thread crates/uv-python/src/interpreter.rs Resolved
Use the pyvenv.cfg modification time as a separate component in the
cache filename digest rather than hashing the full file content. This
is cheaper (stat vs read) while still correctly invalidating the cache
when the virtual environment is recreated.

https://claude.ai/code/session_01XnGrXu7zANvMbh53D2GMU2
@zanieb
zanieb force-pushed the claude/investigate-uv-18510-FWEM6 branch from 4ea068e to 852ff09 Compare March 17, 2026 23:23
@Gankra
Gankra force-pushed the claude/investigate-uv-18510-FWEM6 branch from d15d71c to 840cb85 Compare April 10, 2026 16:16
@Gankra

Gankra commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

The current implementation is me throwing codex at the problem:

  • It didn't like the relying on the windows equivalent of mtime because it's possible to go fast enough to confuse it, but that didn't actually change anything (I still agree relying on mtime is sus)
  • It figures the issue is we don't properly check if pyvenv.cfg exists before invoking Scripts/python.exe, which "more correct cache validity checks" actually uncovered. i.e. the first two commits of the PR are totally correct they just expose a test that was kinda spuriously working based on sketchy caching.
  • In fixing that by actually checking for pyvenv.cfg, it thinks it ran into issues where reading the venv a bunch before trying to delete and recreate it causes windows to complain about things being open, so it added a bunch of gross retries.

I'm looking into this one remaining snapshot change.

This branch has not been deployed

No deployments
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.

Interpreter cache pollution by system-site-packages venvs

4 participants