Skip to content

[Core] Fix test_runtime_env_working_dir failures on Windows - #66365

Merged
robertnishihara merged 2 commits into
ray-project:masterfrom
martinlhw:windows-flaky
Sep 25, 2026
Merged

robertnishihara merged 2 commits into
ray-project:masterfrom
martinlhw:windows-flaky

Conversation

@martinlhw

Copy link
Copy Markdown
Contributor

Description

download_remote_uri strips the file:// scheme by slicing and passes the rest to open(). Path.as_uri() percent-encodes the path and on Windows emits file:///C:/..., so the slice becomes /C:/..., which causes open() to fail with OSError: [Errno 22] Invalid argument. This has been failing test_lazy_reads[py_modules_tar_xz] on every Windows postmerge run since #65742 added that case.

Related issues

Closes anyscale#1966, anyscale#1967

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

Tests

Added TestFileProtocol::test_download_percent_encoded_file_uri, which fails on Linux without the fix.

Signed-off-by: hyungwoo.lee <[email protected]>
@martinlhw
martinlhw requested a review from a team as a code owner September 22, 2026 06:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the handling of 'file' protocol URIs by correctly decoding percent-encoded paths (such as those with spaces) using urlparse and url2pathname, and adds a test case to verify this behavior. However, the current implementation fails on Windows when the URI contains a drive letter (e.g., 'file://C:/path'), as urlparse interprets the drive letter as the netloc, which then gets discarded. A code suggestion has been provided to reconstruct the path correctly on Windows before passing it to url2pathname.


if protocol == "file":
source_uri = source_uri[len("file://") :]
source_uri = url2pathname(urlparse(source_uri).path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When source_uri is formatted as file://C:/path (which is common on Windows and explicitly constructed in some of Ray's tests like test_download_and_unpack_package_with_file_uri), urlparse parses C: as the netloc (host) and /path as the path.

Using urlparse(source_uri).path directly will discard the drive letter C:, resulting in /path (which url2pathname converts to \path). This makes the path drive-relative and will fail if the file is on a different drive or if the current working directory's drive changes.

To handle this robustly on Windows (including drive letters parsed as hostnames and UNC paths), we can reconstruct the path when netloc is present before passing it to url2pathname.

Suggested change
source_uri = url2pathname(urlparse(source_uri).path)
parsed = urlparse(source_uri)
host = parsed.netloc
path = parsed.path
if host:
if os.name == "nt" and len(host) == 2 and host[1] == ":":
path = host + path
else:
path = f"//{host}{path}"
source_uri = url2pathname(path)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 7575ce6. Configure here.


if protocol == "file":
source_uri = source_uri[len("file://") :]
source_uri = url2pathname(urlparse(source_uri).path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File URI drops Windows drive letter

Medium Severity

urlparse places a Windows drive letter in netloc for two-slash URIs such as file://D:/pkg.zip. Passing only .path to url2pathname drops that drive and yields a current-drive path, so download_remote_uri opens the wrong file. The previous slice kept the drive and succeeded; this is the form Windows users typically write when pointing working_dir or py_modules at a mapped share.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7575ce6. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: hyungwoo.lee <[email protected]>
@martinlhw martinlhw added the go add ONLY when ready to merge, run all tests label Sep 23, 2026
@robertnishihara
robertnishihara merged commit aa63d2d into ray-project:master Sep 25, 2026
7 checks passed
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ect#66365)

## Description

`download_remote_uri` strips the `file://` scheme by slicing and passes
the rest to `open()`. `Path.as_uri()` percent-encodes the path and on
Windows emits `file:///C:/...`, so the slice becomes `/C:/...`, which
causes `open()` to fail with `OSError: [Errno 22] Invalid argument`.
This has been failing `test_lazy_reads[py_modules_tar_xz]` on every
Windows postmerge run since ray-project#65742 added that case.
## Related issues

Closes anyscale#1966,
anyscale#1967

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

## Tests
Added `TestFileProtocol::test_download_percent_encoded_file_uri`, which
fails on Linux without the fix.

---------

Signed-off-by: hyungwoo.lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests windows

Development

Successfully merging this pull request may close these issues.

CI test windows://python/ray/tests:test_runtime_env_working_dir is consistently_failing

3 participants