Skip to content

[Tune] Sanitize Windows-reserved characters in trial directory names - #65286

Merged
matthewdeng merged 3 commits into
ray-project:masterfrom
stantheman0128:fix/49477-windows-trial-dir-sanitize
Aug 31, 2026
Merged

matthewdeng merged 3 commits into
ray-project:masterfrom
stantheman0128:fix/49477-windows-trial-dir-sanitize

Conversation

@stantheman0128

Copy link
Copy Markdown
Contributor

Description

Trial._generate_dirname() only stripped /, (, and ) before using the result as a directory name. On Windows, a colon or any of <>:"|?* in the generated name raises NotADirectoryError (WinError 267) when the trial tries to create its own directory. An env id such as ale_py:ALE/Pong-v5 produces a dirname that still contains a colon after the existing sanitization, and Windows refuses to create it.

This extends the regex to strip the full set of Windows-reserved filename characters. The stripping stays unconditional across platforms, matching how /, (, ) are already stripped regardless of OS for rsync compatibility. That way a directory created on Linux stays usable if the results are later copied to a Windows machine.

Reproduced on Windows 11 with the unmodified class: a trial whose generated name contains a colon fails with NotADirectoryError: [WinError 267] The directory name is invalid when Trial.init_local_path() calls os.makedirs. After the fix the same trial produces a sanitized name and the directory is created without error.

Related issues

Fixes #49477

Additional information

Added test_generate_dirname_strips_reserved_characters and a parametrized test_generate_dirname_custom_dirname_is_sanitized to python/ray/tune/tests/test_trial.py, covering the reserved characters directly. Verified against the pre-fix code that both tests fail with the reported error, and pass after the fix. Formatted with black (repo-pinned version) and checked with ruff.

Trial._generate_dirname() only stripped '/', '(' and ')' before using
the result as a directory name. On Windows, a colon (or any of
<>:"|?*) in the name raises NotADirectoryError (WinError 267) when
the trial tries to create its own directory, e.g. an env id like
"ale_py:ALE/Pong-v5" produces "PPO_ale_py:ALE-Pong-v5_...".

Extend the existing regex to also strip the full set of Windows
reserved filename characters. This is applied on every platform (not
gated on os.name), matching the existing '/', '(', ')' stripping that
is already unconditional for rsync compatibility, so a trial directory
created on Linux stays usable if later copied to Windows.

Fixes ray-project#49477

Signed-off-by: stantheman0128 <[email protected]>
@stantheman0128
stantheman0128 requested a review from a team as a code owner August 7, 2026 13:55

@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 updates Trial._generate_dirname in Ray Tune to strip Windows-reserved filename characters (such as angle brackets, colons, double quotes, backslashes, pipes, question marks, and asterisks) on all platforms, ensuring that trial directory names remain valid across different operating systems and environments. Additionally, new unit tests have been added to verify that both generated and custom directory names are properly sanitized. There are no review comments, so no further feedback is provided.

@ray-gardener ray-gardener Bot added tune Tune-related issues community-contribution Contributed by the community labels Aug 7, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 22, 2026
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Aug 25, 2026
@pseudo-rnd-thoughts pseudo-rnd-thoughts added the go add ONLY when ready to merge, run all tests label Aug 28, 2026

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR, LGTM

@matthewdeng
matthewdeng merged commit 960e281 into ray-project:master Aug 31, 2026
6 checks passed
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ay-project#65286)

## Description
`Trial._generate_dirname()` only stripped `/`, `(`, and `)` before using
the result as a directory name. On Windows, a colon or any of `<>:"|?*`
in the generated name raises `NotADirectoryError` (WinError 267) when
the trial tries to create its own directory. An env id such as
`ale_py:ALE/Pong-v5` produces a dirname that still contains a colon
after the existing sanitization, and Windows refuses to create it.

This extends the regex to strip the full set of Windows-reserved
filename characters. The stripping stays unconditional across platforms,
matching how `/`, `(`, `)` are already stripped regardless of OS for
rsync compatibility. That way a directory created on Linux stays usable
if the results are later copied to a Windows machine.

Reproduced on Windows 11 with the unmodified class: a trial whose
generated name contains a colon fails with `NotADirectoryError:
[WinError 267] The directory name is invalid` when
`Trial.init_local_path()` calls `os.makedirs`. After the fix the same
trial produces a sanitized name and the directory is created without
error.

## Related issues
Fixes ray-project#49477

## Additional information
Added `test_generate_dirname_strips_reserved_characters` and a
parametrized `test_generate_dirname_custom_dirname_is_sanitized` to
`python/ray/tune/tests/test_trial.py`, covering the reserved characters
directly. Verified against the pre-fix code that both tests fail with
the reported error, and pass after the fix. Formatted with `black`
(repo-pinned version) and checked with `ruff`.

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

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests tune Tune-related issues unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RLlib][Windows] Windows Invalid Directory Name Error in Ray RLlib

3 participants