acoustic-carpenter-78188
07/30/2026, 4:14 PMflyte deploy crashes with a raw ValueError out of `pathlib`:
ValueError: 'C:\...\Temp\58627233-...\pxPyFactory\pxpyfactory' is not in the subpath of
'C:\...\Temp\58627233-...\build.uc-image-builder'
flyte/_internal/imagebuild/remote_builder.py in _get_layers_proto
The event's frame locals tell the whole story:
context_path = .../Temp/58627233-.../build.uc-image-builder
dst_path = .../Temp/58627233-.../pxPyFactory/pxpyfactory # <- outside the context!
layer = CopyConfig(1, WindowsPath('../../../pxPyFactory/pxpyfactory'), './pxpyfactory')
copy_files_to_context re-roots paths that would escape the docker build context under `_flyte_abs_context`:
if src.is_absolute() or ".." in str(src):
rel_path = PurePath(*src.parts[1:])
dst_path = context_path / "_flyte_abs_context" / rel_path
parts[1:] is right for an absolute path — it strips the anchor (/, or C:\ on Windows). It is wrong for a relative path with .., because it strips only the first component. For ../../../pxPyFactory/pxpyfactory that leaves two .. behind:
<context>/_flyte_abs_context/../../pxPyFactory/pxpyfactory
and the os.path.normpath(...) at the end of the function collapses that straight back out of the context — exactly the dst_path in the Sentry event. Two things go wrong:
1. The layer's files are copied next to the build context rather than into it, so the built image silently misses them (or picks up a stale copy).
2. _get_layers_proto then calls dst_path.relative_to(context_path), which raises ValueError and is crash-reported as an SDK bug.
This is not Windows-specific — the same ../../.. source folder reproduces it on posix. (It was previously triaged as a user error on the basis of the Windows path in the title; it isn't.)
What
• Split the absolute and relative branches. The relative branch drops every `../.` component, so the destination always lands under _flyte_abs_context.
• Check ".." in src.parts instead of ".." in str(src) — the old substring test also re-rooted a directory legitimately named my..pkg.
• Normalize dst_path before copying and raise ImageBuildError (a RuntimeUserError, so it is a clean user-facing message rather than a crash report) if it still resolves outside the context. Defense in depth for anything this function is handed in the future.
Behavior for the paths that already worked is unchanged: /abs/requirements.txt → _flyte_abs_context/abs/requirements.txt, ../requirements.txt → _flyte_abs_context/requirements.txt, pkg/ → pkg/.
Tests
4 new tests in `tests/flyte/imagebuild/test_utils.py`: the multi-level traversal reproducing the Sentry case (asserting the destination stays in the context and that relative_to(context_path) — the call that crashed — now succeeds), a regression guard on the single-.. case, the my..pkg false positive, and the ImageBuildError escape hatch. 3 of the 4 verified to fail on main without the source change (the 4th is the unchanged-behavior guard). 18/18 in the file pass.
fixes FLYTE-SDK-6B
flyteorg/flyte-sdk