Skip to content

[core] Add local:// runtime_env URIs for code already in node - #65245

Merged
abrarsheikh merged 18 commits into
ray-project:masterfrom
YashwanthRanjanSingaravel:feat/image-workdir-support
Sep 15, 2026
Merged

abrarsheikh merged 18 commits into
ray-project:masterfrom
YashwanthRanjanSingaravel:feat/image-workdir-support

Conversation

@YashwanthRanjanSingaravel

Copy link
Copy Markdown
Contributor

Description

  • Adds a local:// runtime_env URI: working_dir: local:///app
  • Used in place with no uploading or unpacking

Changes

  • Protocol.LOCAL: parse_uri returns the path itself, rejects non absolute paths.
  • working_dir/py_modules: no upload or download, 0 bytes cached, never deleted.
  • new section in the docs.

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
@YashwanthRanjanSingaravel YashwanthRanjanSingaravel removed their assignment Aug 6, 2026
@YashwanthRanjanSingaravel YashwanthRanjanSingaravel added the go add ONLY when ready to merge, run all tests label Aug 6, 2026
@YashwanthRanjanSingaravel
YashwanthRanjanSingaravel marked this pull request as draft August 6, 2026 00:51

@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 introduces support for "local://" URIs in "working_dir" and "py_modules" within Ray's runtime environments, allowing the use of directories already present on all cluster nodes without packaging or uploading them. The review feedback highlights several Windows-specific issues, including a command execution failure when paths contain spaces, and multiple test failures due to Unix-style absolute paths not being recognized as absolute on Windows. Suggestions are provided to make both the runtime execution and the test suite fully cross-platform.

@YashwanthRanjanSingaravel
YashwanthRanjanSingaravel marked this pull request as ready for review August 6, 2026 18:31

@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 introduces support for local:// URIs in runtime_env (working_dir and py_modules), allowing users to reference directories already present on all cluster nodes (such as those baked into container images) without uploading or downloading them. Feedback highlights a potential issue on Windows where using subprocess.list2cmdline to quote paths for cmd.exe shell execution (such as cd) can fail if the path contains shell metacharacters like & but no spaces, suggesting wrapping the path in double quotes directly instead.

@YashwanthRanjanSingaravel

Copy link
Copy Markdown
Contributor Author

bugbot run

@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.

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core 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 27, 2026
@YashwanthRanjanSingaravel YashwanthRanjanSingaravel removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 27, 2026
Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
Comment thread python/ray/_common/runtime_env_uri.py Resolved
@MortalHappiness MortalHappiness self-assigned this Sep 11, 2026
Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
@MortalHappiness

Copy link
Copy Markdown
Member

Please fix premerge errors. We also need to trigger Windows CI runs before merging this PR.

@ronny-anyscale ronny-anyscale 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.

Docs style review from the Anyscale docs team, scoped to prose style, grammar, and Ray's documentation conventions. I don't own this code, so anything technical below is a question for the maintainers rather than a request.

Ronny Roland (Anyscale docs team) ran this review with Claude Code assisting. I read every comment and stand behind each one.

This is non-blocking. @abrarsheikh and @MortalHappiness have both approved, and the approval is on the head I reviewed (73fd81b). Nothing here should hold the merge. If it lands first, I'll open a follow-up PR with these instead.

The standard is Ray's own style guide, doc/source/ray-contribute/writing-style.md. Worth noting that Vale doesn't gate this page at all (.vale.ini scopes it to Ray Data and the example gallery), so none of this would have been caught automatically.

The new local:// section is genuinely good. The warning about content drift across nodes is the right call and states the failure mode precisely, and the py_modules versus local-path contrast is the clearest part of the page. The comments are small: semicolons and parentheticals (§Sentence structure), "note that" (§Cut qualifiers and filler), a few passive constructions with Ray as the actor, one parallel-structure slip, and a list lead-in.

A note on two things I checked and deliberately left alone:

  • local://C:/app on L829 is correct with two slashes. parse_uri accepts it alongside local:///C:/app, and the error message recommends that exact spelling. My comment there is wording only.
  • The archive list on L863 matches PACKAGE_UPLOAD_EXTENSIONS exactly.

I also read this thread before writing anything. The py_modules PYTHONPATH difference was settled there as "keep the behavior, document it carefully," and this section is that documentation, so my L845 comment styles your applied fix rather than reopening the discussion.

One question, no suggestion attached: the heading "Directories already present on every node" doesn't contain local://, which is the string a reader scanning this page for the feature will look for. Something in the shape of "Local URIs" would also sit parallel to the "Remote URIs" section immediately below it. Entirely your call, and safe either way since the :ref: label is explicit.

On wrapping: the new section hard-wraps mid-sentence at roughly 88 columns. The rest of this file and the guide's §Soft-wrap prose both want one source line per paragraph, so my suggestions soft-wrap as they go.

@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.

Stale Bugbot comment from a previous run.

Comment thread python/ray/_common/runtime_env_uri.py Resolved

@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 48097bd. Configure here.

Comment thread python/ray/_common/runtime_env_uri.py Resolved
Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
@abrarsheikh
abrarsheikh merged commit 3aa6939 into ray-project:master Sep 15, 2026
6 checks passed
abrarsheikh pushed a commit that referenced this pull request Sep 21, 2026
#66292)

## Description

- `TestLocalWorkingDir::test_used_in_place_without_upload[working_dir]`
passes, then errors at teardown.
- On Windows the error is `RecursionError: maximum recursion depth
exceeded`.
- A `local://` working_dir is used in place, so `modify_context` makes
it the worker's cwd.
- Windows refuses to remove a directory a live process sits in, giving
`WinError 32`.
- `TemporaryDirectory`'s `onerror` handler then recurses until the stack
runs out.
- The test requested `start_cluster` before `tmp_working_dir`.
- pytest tears fixtures down in reverse, so the directory went away
while workers were alive.
- Introduced by #65245. It only shows in the soft failing flaky Windows
postmerge job.

## Changes

- `test_runtime_env_working_dir.py`: request `tmp_working_dir` before
`start_cluster`.
  - The cluster now tears down first.
- `Cluster.shutdown` kills worker processes with `wait=True`, so the
directory is free.
- The docstring records why the fixture order matters.

## Tests

- No new test. The existing `[working_dir]` parameter is the regression
test, and it is the failing one.
- `[py_modules]` already passed, because that path only extends
`PYTHONPATH` and never sets cwd.
- The production behaviour is unchanged;
`test_directory_is_never_deleted` still covers it.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
ray-project#66292)

## Description

- `TestLocalWorkingDir::test_used_in_place_without_upload[working_dir]`
passes, then errors at teardown.
- On Windows the error is `RecursionError: maximum recursion depth
exceeded`.
- A `local://` working_dir is used in place, so `modify_context` makes
it the worker's cwd.
- Windows refuses to remove a directory a live process sits in, giving
`WinError 32`.
- `TemporaryDirectory`'s `onerror` handler then recurses until the stack
runs out.
- The test requested `start_cluster` before `tmp_working_dir`.
- pytest tears fixtures down in reverse, so the directory went away
while workers were alive.
- Introduced by ray-project#65245. It only shows in the soft failing flaky Windows
postmerge job.

## Changes

- `test_runtime_env_working_dir.py`: request `tmp_working_dir` before
`start_cluster`.
  - The cluster now tears down first.
- `Cluster.shutdown` kills worker processes with `wait=True`, so the
directory is free.
- The docstring records why the fixture order matters.

## Tests

- No new test. The existing `[working_dir]` parameter is the regression
test, and it is the failing one.
- `[py_modules]` already passed, because that path only extends
`PYTHONPATH` and never sets cwd.
- The production behaviour is unchanged;
`test_directory_is_never_deleted` still covers it.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
rueian pushed a commit that referenced this pull request Sep 28, 2026
…cted (#66302)

## Description

- `TestLocalWorkingDir::test_relative_path_rejected_on_the_client`
passes, then errors at teardown.
- Only in `//python/ray/tests:test_runtime_env_working_dir_client_mode`,
on every Windows postmerge run.
- The teardown error is:
- `ValueError: Removing a node that is connected to this Ray client is
not allowed`
  - raised by `Cluster.remove_node` at `cluster_utils.py:305`.
- `connect` sets `worker.node` before it validates the runtime_env.
- `worker.py:2649` reads `worker.node.get_runtime_env_dir_path()`, then
calls `upload_working_dir_if_needed`.
- `parse_uri` rejects the relative `local://` path there, so `ray.init`
raises after connecting.
  - The driver is left attached to the head node.
- Under `RAY_CLIENT_MODE=1` the fixture's own `ray.shutdown` is
redirected to the Ray Client.
- It never reaches `disconnect`, which is what clears `worker.node` at
`worker.py:2827`.
- That is why the plain target passes and only the client mode target
fails.
- Introduced by #65245.

## Changes

- `test_runtime_env_working_dir.py`: detach the driver after the
expected `ValueError`.
- The `ray.shutdown` runs inside `disable_client_hook` so it reaches the
real one in both modes.
- `disable_client_hook` restores the previous hook state on exit;
`test_client.py` already uses it.

## Tests

- No new test. The existing test is the regression test, and it is the
one erroring today.
- Verified the bypass with `RAY_CLIENT_MODE=1`:
`client_mode_should_convert()` is `True` normally,
  `False` inside `disable_client_hook()`, and `True` again afterwards.
- The client side rejection itself stays covered by
`unit/test_runtime_env_working_dir.py`.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…oject#65245)

## Description

- Adds a `local://` runtime_env URI: `working_dir: local:///app`
- Used in place with no uploading or unpacking

## Changes

- `Protocol.LOCAL`: `parse_uri` returns the path itself, rejects non
absolute paths.
- `working_dir`/`py_modules`: no upload or download, 0 bytes cached,
never deleted.
- new section in the docs.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
ray-project#66292)

## Description

- `TestLocalWorkingDir::test_used_in_place_without_upload[working_dir]`
passes, then errors at teardown.
- On Windows the error is `RecursionError: maximum recursion depth
exceeded`.
- A `local://` working_dir is used in place, so `modify_context` makes
it the worker's cwd.
- Windows refuses to remove a directory a live process sits in, giving
`WinError 32`.
- `TemporaryDirectory`'s `onerror` handler then recurses until the stack
runs out.
- The test requested `start_cluster` before `tmp_working_dir`.
- pytest tears fixtures down in reverse, so the directory went away
while workers were alive.
- Introduced by ray-project#65245. It only shows in the soft failing flaky Windows
postmerge job.

## Changes

- `test_runtime_env_working_dir.py`: request `tmp_working_dir` before
`start_cluster`.
  - The cluster now tears down first.
- `Cluster.shutdown` kills worker processes with `wait=True`, so the
directory is free.
- The docstring records why the fixture order matters.

## Tests

- No new test. The existing `[working_dir]` parameter is the regression
test, and it is the failing one.
- `[py_modules]` already passed, because that path only extends
`PYTHONPATH` and never sets cwd.
- The production behaviour is unchanged;
`test_directory_is_never_deleted` still covers it.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…cted (ray-project#66302)

## Description

- `TestLocalWorkingDir::test_relative_path_rejected_on_the_client`
passes, then errors at teardown.
- Only in `//python/ray/tests:test_runtime_env_working_dir_client_mode`,
on every Windows postmerge run.
- The teardown error is:
- `ValueError: Removing a node that is connected to this Ray client is
not allowed`
  - raised by `Cluster.remove_node` at `cluster_utils.py:305`.
- `connect` sets `worker.node` before it validates the runtime_env.
- `worker.py:2649` reads `worker.node.get_runtime_env_dir_path()`, then
calls `upload_working_dir_if_needed`.
- `parse_uri` rejects the relative `local://` path there, so `ray.init`
raises after connecting.
  - The driver is left attached to the head node.
- Under `RAY_CLIENT_MODE=1` the fixture's own `ray.shutdown` is
redirected to the Ray Client.
- It never reaches `disconnect`, which is what clears `worker.node` at
`worker.py:2827`.
- That is why the plain target passes and only the client mode target
fails.
- Introduced by ray-project#65245.

## Changes

- `test_runtime_env_working_dir.py`: detach the driver after the
expected `ValueError`.
- The `ray.shutdown` runs inside `disable_client_hook` so it reaches the
real one in both modes.
- `disable_client_hook` restores the previous hook state on exit;
`test_client.py` already uses it.

## Tests

- No new test. The existing test is the regression test, and it is the
one erroring today.
- Verified the bypass with `RAY_CLIENT_MODE=1`:
`client_mode_should_convert()` is `True` normally,
  `False` inside `disable_client_hook()`, and `True` again afterwards.
- The client side rejection itself stays covered by
`unit/test_runtime_env_working_dir.py`.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 23, 2026
)

## Description

Adds a caution to the `uv run` section of the runtime environments page:
don't set `py_executable` to a bare `uv run` to enable the uv
integration. When the driver is launched with `uv run`, Ray sets
`py_executable` itself. A bare `uv run` starts workers in whatever
environment uv resolves from the worker's starting directory, and if
that environment lacks Ray, workers crash on startup and jobs hang
without a clear error.

@martinlhw, this is a docs-only alternative to #66191, which you're
assigned to. Your question on that PR, whether bare `uv run` always
fails, turned out to be the deciding one: it doesn't. Results on Ray
2.59.0 with uv 0.11.14, macOS, local cluster:

| Setup | Result |
|---|---|
| Plain `python` driver outside any uv project, `py_executable="uv run"`
| Workers crash with `ModuleNotFoundError: No module named 'ray'`;
`ray.get` times out |
| Plain `python` driver inside a uv project that depends on Ray | Works
|
| Driver launched with `uv run` | Works, because the uv hook overwrites
`py_executable` |
| `JobSubmissionClient.submit_job` with `py_executable="uv run"`,
cluster started inside a uv project | `SUCCEEDED`, with and without
`working_dir` |
| Same submission, cluster started outside a uv project | Stuck in
`PENDING` (reproduces #54275) |

Because the bare value works in some setups, rejecting it with a
`ValueError` as #66191 does would break working configurations,
including per-task `runtime_env` usage that the uv hook never rewrites.
The failure is also the same one any `py_executable` pointing at a
Python without Ray produces, so a string match on `uv run` covers only
one case of it. A docs caution addresses what the issue reporter asked
for at minimum, "noting in the docs specifically that `py_executable`
shouldn't be provided." If Core wants a runtime guard too, a warning
rather than an error seems like the safer shape, and it can land
separately.

## Related issues

Addresses #54275. Supersedes #66191, which conflicts with master: its
`local://` changes landed separately in #65245, and the page it edits
moved to MyST in #66461.

## Additional information

- Duplicate check: #66191 is the only open PR referencing #54275, and
none of the open `py_executable` or uv PRs touch this guidance.
- Tests: prose-only change. Vale reports no findings on the added lines,
and pre-commit passes. The behavior described is from the local runs in
the table above.
- AI assistance: Claude Code drafted this change and ran the tests
above. I reviewed every line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[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 docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants