[BUG] cleanup_uploaded_files(providers=...) clears every provider's cache, not just the requested ones
Description
cleanup_uploaded_files(..., providers=[...]) scopes remote deletion to the requested providers, but then unconditionally wipes the whole cache. Entries belonging to providers that were not requested are dropped without ever being deleted from the provider, so those uploads become orphaned (no record left to delete them later) and the same files get re-uploaded on the next run. acleanup_uploaded_files() has the same defect.
# lib/crewai-files/src/crewai_files/cache/cleanup.py
for provider in _get_providers_from_cache(cache):
if providers is not None and provider not in providers:
continue # <- only filters what gets deleted remotely
provider_uploads[provider] = cache.get_all_for_provider(provider)
...
cache.clear() # <- clears every provider (line 97); line 277 in the async twin
The providers= docstring says "Optional list of providers to clean up. If None, cleans all", and delete_from_provider=False is a supported mode, so the cache clear should follow the same scope.
Steps to Reproduce
On main @ 43e2963 (crewai / crewai-files 1.15.32), no API keys or network needed:
import asyncio
from crewai_files.cache.cleanup import cleanup_uploaded_files
from crewai_files.cache.upload_cache import UploadCache
cache = UploadCache()
async def seed():
await cache.aset_by_hash("hash-openai", "text/plain", "openai", "file-a")
await cache.aset_by_hash("hash-anthropic", "text/plain", "anthropic", "file-b")
asyncio.run(seed())
print("before:", sorted(cache.get_providers()), "entries:", len(cache))
removed = cleanup_uploaded_files(cache, delete_from_provider=False, providers=["openai"])
print("cleanup removed:", removed)
print("after:", sorted(cache.get_providers()), "entries:", len(cache))
print("anthropic entry survives:", cache.get_by_hash("hash-anthropic", "anthropic") is not None)
Expected behavior
Only the entries of the requested providers are removed, so the anthropic entry survives:
before: ['anthropic', 'openai'] entries: 2
cleanup removed: 0
after: ['anthropic'] entries: 1
anthropic entry survives: True
Screenshots/Code snippets
Actual output:
before: ['anthropic', 'openai'] entries: 2
cleanup removed: 0
after: [] entries: 0
anthropic entry survives: False
Note cleanup removed: 0: nothing was deleted from any provider, yet the cache is empty — the anthropic upload is now unreachable from the cache and can no longer be cleaned up through it. The same happens when an uploader is unavailable (uploader is None → continue) or the provider is filtered out.
Operating System
macOS Sonoma (26.6.2)
Python Version
3.13.17
crewAI Version
1.15.32 (main @ 43e2963, 2026-10-27)
crewAI Tools Version
Not involved — the defect is in the crewai-files package (lib/crewai-files).
Virtual Environment
Venv (uv)
Evidence
Full run of the snippet above, plus the async twin (acleanup_uploaded_files) which calls await cache.aclear() at cleanup.py:277 with the same scoping gap.
Relevant code: lib/crewai-files/src/crewai_files/cache/cleanup.py:79-97 (sync) and :246-277 (async). UploadCache has no per-provider clear today, only clear() / aclear() (upload_cache.py:369-381).
Possible Solution
Add a provider-scoped clear to UploadCache and use it here instead of the global clear:
# upload_cache.py
async def aclear_provider(self, provider: ProviderType) -> int:
keys = list(self._provider_keys.get(provider, ()))
for key in keys:
await self._cache.delete(key)
self._untrack_key(provider, key)
return len(keys)
# cleanup.py (sync)
for provider in provider_uploads:
cache.clear_provider(provider) # await cache.aclear_provider(provider) in the async twin
This keeps the documented providers= scope and leaves other providers' entries untouched. I am happy to send the PR with regression tests for both the sync and async paths.
Additional context
- Not a duplicate: searches for
cleanup_uploaded_files,acleanup_uploaded_files,cleanup providers uploads,cache clear cleanupreturn 0 issues and 0 PRs on this repo. The open cache issues (#8312 capacity eviction on replace, #8550 exceedingmax_entriesafterclear(), #8516 sync-wrapper deadlock) are different defects in the same file. git logshows theproviders=filtering and the unconditionalcache.clear()both come from the 2026-10-23 code-move commit07361f6;c5f996a(2026-10-27) only movedlist_files()off the event loop.
Authored with an AI coding assistant. .github/CONTRIBUTING.md requires the llm-generated label for agent-authored issues, but external contributors cannot apply labels: gh issue create --label and gh issue edit --add-label both fail with does not have the correct permissions. Maintainers, please add llm-generated to this issue. Self-assignment is blocked for the same reason, so I claimed the work in a comment instead.
I'd like to work on this one. As an external contributor I can't self-assign (GitHub requires triage permission), so this comment is my claim on #8711 — please assign me (@2SinceJuly) if that's your convention.
Plan: add a provider-scoped clear to UploadCache (clear_provider / aclear_provider) and use it from both cleanup_uploaded_files() and acleanup_uploaded_files(), with regression tests covering the sync and async paths (other providers' entries survive; requested provider's entries are removed whether or not delete_from_provider is set). PR to follow.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.