crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

UploadCache capacity eviction removes a valid entry when replacing an existing one (still on main)

Open Wilson0511 opened this issue 1 month ago • 2 comments

Description

UploadCache.aset_by_hash() / set_by_hash() run _evict_if_needed() before determining whether the key already exists. At capacity, replacing an existing entry therefore evicts a different valid entry, even though a replacement needs no additional capacity. With max_entries=2, set(a), set(b), set(b) leaves only b, so a later upload of a is needlessly repeated.

Originally reported in #8199 with a fix in #8200, both closed by the author without explanation. The bug is still present on current main (lib/crewai-files/src/crewai_files/cache/upload_cache.py, _evict_if_needed() called unconditionally before the key lookup). I reproduced it locally against main: the regression test fails with len(cache) == 1 instead of 2.

Fix

Only evict when the key is new:

key = _make_key(file_hash, provider)
if key not in self._provider_keys.get(provider, set()):
    await self._evict_if_needed()

PR incoming with this fix plus the regression tests from #8200 (replacement preserves other entries, new provider counts as a new entry, replacement refreshes eviction order). Happy to be assigned.

AI disclosure

Per CONTRIBUTING.md: prepared with AI assistance; I cannot apply labels here — please add the llm-generated label.

Wilson0511 avatar Oct 20 '26 13:10 Wilson0511

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.

github-actions[bot] avatar Nov 20 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 26 '26 12:11 github-actions[bot]