Repository navigation
fix(artifacts): ensure monotonic versioning and isolate extensions in LocalArtifactStore - #9600
Conversation
… LocalArtifactStore - Parse numeric versions monotonically to avoid collisions when earlier versions are pruned - Check for existing version numbers across all file extensions before writing - Add unit test verifying version isolation when prior versions are removed
Strix Security Review✅ No open security findings. PR summary: `LocalArtifactStore.save` now picks the next artifact version from the highest surviving integer version plus one and skips any number already taken by another file extension, instead of counting files in the directory; a regression test covers pruned versions combined with an extension change. Review summaryThe PR replaces the file-count-based version number in Ruled out (4)
Review 1 on this PR · Reviewed by Strix |
Related issue
Fixes #9599
Summary
LocalArtifactStore.savepreviously computed the next version number aslen(list(directory.glob("v*.*"))) + 1.When earlier artifact versions were pruned or removed (e.g.,
v1.htmlwas deleted to retain onlyv2.svg), and a subsequent artifact was saved with a different file extension (e.g..png),path.open("xb")did not raiseFileExistsErrorbecause the existing file had a different extension. As a result, two different files were written with the identical version number (e.g.,v2.svgandv2.png), causingload()to overwrite and lose access to one of the versions.This fix:
max(existing_versions, default=0) + 1from parsed integer versions (path.stem[1:].isdigit()).versiondoes not collide with ANY existing extension (any(directory.glob(f"v{version}.*"))) before attempting to write.test_local_store_version_isolation_with_pruned_versions_and_extension_changes.Verification
Tests added or updated for the changed behavior
Relevant tests and quality checks pass locally
Added
test_local_store_version_isolation_with_pruned_versions_and_extension_changesinlib/crewai/tests/test_artifacts.py.All 76 tests in
test_artifacts.pypass (100% pass rate).ruff formatandruff checkverified.Additional context
None