Skip to content

fix: sort directory names before hashing an image source directory - #1869

Closed
mitsa-ng wants to merge 1 commit into
flyteorg:mainfrom
mitsa-ng:fix/image-hash-directory-order
Closed

mitsa-ng wants to merge 1 commit into
flyteorg:mainfrom
mitsa-ng:fix/image-hash-directory-order

Conversation

@mitsa-ng

Copy link
Copy Markdown

Problem

update_hasher_for_source sorted each directory's files but never sorted dirnames, so os.walk visited subdirectories in filesystem readdir order. Identical source trees therefore produced different image tags on machines whose filesystems list directories in different orders, so images that already existed in the registry were rebuilt and pushed again.

Reported in flyteorg/flyte#8455.

Fix

Sort dirnames in place inside the os.walk loop (next to the existing files.sort()). Sorting in place is what makes os.walk recurse in deterministic order.

Testing

  • New regression test tests/flyte/_utils/test_file_handling.py: hashes the same tree through two deterministic os.walk stand-ins that visit entries in ascending and descending name order, and asserts the digests match. It fails on the current main and passes with this change, independent of the host filesystem's readdir order.
  • uv run python -m pytest -k "not integration and not sandbox and not gpu and not external" tests/flyte/_utils tests/flyte/test_image.py tests/flyte/imagebuild: 241 passed, 1 skipped
  • uv run python -m pytest -k "not integration and not sandbox" tests/flyte/code_bundle: 105 passed
  • ruff check and ruff format --check: clean

Fixes flyteorg/flyte#8455

update_hasher_for_source sorted each directory's files but not its
subdirectories, so os.walk visited them in filesystem readdir order.
Identical source trees therefore produced different image tags on
machines whose filesystems list directories in different orders,
forcing rebuilds and re-pushes of images that already exist.

Sort dirnames in place so the walk order is deterministic everywhere.

Fixes flyteorg/flyte#8455
@mitsa-ng

Copy link
Copy Markdown
Author

Closing as a duplicate of #1868, which was opened earlier and fixes the same issue (flyteorg/flyte#8455).

@mitsa-ng mitsa-ng closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [V2] Image hash depends on filesystem directory listing order, so identical source gets a different image tag per machine

1 participant