Skip to content

Conversation

@TrevorBurnham
Copy link

@TrevorBurnham TrevorBurnham commented Dec 21, 2025

Fixes #5731

Summary

This PR implements automatic cache cleanup that runs in the background during normal
uv operations. This addresses issue #5731 by preventing unbounded cache growth
without requiring user intervention.

The autoprune task:

  • Spawns as a fire-and-forget background task when the cache is initialized
  • Removes unreferenced archives older than 1 hour (grace period for in-flight ops)
  • Requires no exclusive lock since archives are immutable and uniquely identified;
    if there's no symlink referencing an archive, no process can be using it

Test Plan

I've added unit tests for this feature. Having said that, I'm new to this project, so I'd appreciate any suggestions for testing more thoroughly.

@konstin
Copy link
Member

konstin commented Jan 6, 2026

Do I understand it correctly that this doesn't remove old unpacked wheels generally, just archives having no symlinks pointing to them?

I do think that needs to lock, there can be multiple uv versions running on a system and it's generally safer to lock than to use time based approaches.

@konstin konstin added the enhancement New feature or improvement to existing functionality label Jan 6, 2026
@TrevorBurnham TrevorBurnham force-pushed the feature/cache-autoprune branch from 817c830 to e20251d Compare January 6, 2026 22:55
@TrevorBurnham
Copy link
Author

@konstin That's a very good catch! I've updated this PR to take the safer approach of only removing archives that are unreferenced.

Implements automatic cache cleanup that runs in the background during normal
uv operations. This addresses issue astral-sh#5731 by preventing unbounded cache growth
without requiring user intervention.

The autoprune task:
- Spawns as a fire-and-forget background task when the cache is initialized
- Removes unreferenced archives older than 1 hour (grace period for in-flight ops)
- Requires no exclusive lock since archives are immutable and uniquely identified;
  if there's no symlink referencing an archive, no process can be using it

This intentionally does NOT remove outdated bucket versions (e.g., wheels-v4),
as different uv versions may be running concurrently on the same system.

This is particularly useful for long-running processes like MCP servers where
the cache cannot be manually pruned while uv is in use.
@TrevorBurnham TrevorBurnham force-pushed the feature/cache-autoprune branch from e20251d to 3ff71d5 Compare January 6, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv cache size limit

2 participants