Skip to content

[Jobs] Fix submit_job crashing on module objects in py_modules - #66608

Merged
Sparks0219 merged 2 commits into
masterfrom
marwan/jobs-fix-py-modules-module-objects
Oct 20, 2026
Merged

Sparks0219 merged 2 commits into
masterfrom
marwan/jobs-fix-py-modules-module-objects

Conversation

@marwan116

Copy link
Copy Markdown
Contributor

What broke

Since 2.57, JobSubmissionClient.submit_job() raises before it uploads anything when py_modules contains an imported module, which the runtime_env API reference lists as a supported entry:

import my_module
from ray.job_submission import JobSubmissionClient

client = JobSubmissionClient("http://127.0.0.1:8265")
client.submit_job(entrypoint="python main.py", runtime_env={"py_modules": [my_module]})
  File ".../ray/dashboard/modules/job/sdk.py", line 221, in submit_job
    runtime_env = copy.deepcopy(runtime_env or {})
TypeError: cannot pickle 'module' object

Expected: the module's directory is uploaded and the job runs, as on 2.56.1. A user upgrading from 2.56.1 hit this and is pinned there.

py_modules entry 2.56.1 2.57.0, 2.58.0, master
module object, Python SDK works TypeError at submit
path string, Python SDK works works
path string, ray job submit --runtime-env-json works works

Why

#63990 (the fix for #46625) made submit_job deep-copy runtime_env, so that uploading stops rewriting the caller's dict with gcs:// URIs. Module objects can't be deep-copied, so the copy itself raises. Nothing in CI passes a module object through submit_job, so it went unnoticed.

The fix

Copy shallowly: dict(runtime_env or {}).

  • That is enough for [Ray Core] GCS expires due to unmodified files in the working-dir #46625. upload_working_dir_if_needed and upload_py_modules_if_needed only rebind top-level keys (runtime_env["py_modules"] = py_modules_uris, a new list) and never mutate a value in place, so the caller's dict and list are left alone.
  • A RuntimeEnv argument becomes a plain dict before upload and is rebuilt by the existing RuntimeEnv(**runtime_env) right after. RuntimeEnv validation rejects module objects, so only a plain dict can carry one.

Not a duplicate

No open issue or PR covers this. The open PRs in the area don't touch the submission path: #64621 changes CLI stack traces (cli.py, cli_utils.py), #66570 changes how nodes install py_modules wheels, and #65933 and #66279 change how nodes download packages. Nothing on #63990 mentions module objects.

Testing

test_submit_job_with_module_object_in_py_modules runs the real upload path behind a fake HTTP layer and checks that the module's directory is zipped with its parent (my_module/__init__.py), that the job request carries a gcs:// URI, and that the caller's dict still holds the module. Against the unmodified sdk.py it fails with TypeError: cannot pickle 'module' object.

$ python -m pytest -v python/ray/dashboard/modules/job/tests/test_sdk.py
110 passed in 141.93s

$ python -m pytest -v python/ray/dashboard/modules/job/tests/test_http_job_server.py
1 failed, 63 passed in 348.11s

The one failure, test_submit_job[conda_yaml], times out because conda isn't installed on the test machine; it times out the same way with the unmodified sdk.py.

End to end on a local cluster, submit_job(runtime_env={"py_modules": [my_module]}) now succeeds and the driver imports the module; the same script raises the TypeError with the 2.58.0 wheel. Pre-commit passes on both changed files.

AI assistance was used for this change.

🤖 Generated with Claude Code

@marwan116 marwan116 added dashboard Issues specific to the Ray Dashboard core Issues that should be addressed in Ray Core labels Sep 30, 2026
@marwan116
marwan116 marked this pull request as ready for review September 30, 2026 16:13
@marwan116
marwan116 requested a review from a team as a code owner September 30, 2026 16:13
@marwan116 marwan116 added the go add ONLY when ready to merge, run all tests label Sep 30, 2026

@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 replaces the deep copy of runtime_env with a shallow copy using dict() in submit_job to prevent failures when py_modules contains module objects that cannot be deep-copied. It also adds a unit test to verify this behavior. I have no feedback to provide.

@marwan116 marwan116 self-assigned this Sep 30, 2026
@praneethkaturi

Copy link
Copy Markdown
Contributor

Lgtm - since it's a shallow copy now, perhaps we extend the comment to say downstream code must not mutate nested values in place?

@marwan116

Copy link
Copy Markdown
Contributor Author

Done in c7ae244.

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

:ship

@Sparks0219
Sparks0219 enabled auto-merge (squash) October 5, 2026 18:57
@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 Oct 20, 2026
marwan116 and others added 2 commits October 20, 2026 06:47
Since 2.57, JobSubmissionClient.submit_job() raises before uploading
anything when py_modules contains an imported module, one of the entry
types the runtime_env docs list:

    import my_module
    client.submit_job(entrypoint="...", runtime_env={"py_modules": [my_module]})
    TypeError: cannot pickle 'module' object

#63990 made submit_job copy runtime_env with copy.deepcopy, so that
uploading no longer rewrites the caller's dict with gcs:// URIs (#46625).
Module objects can't be deep-copied, so the copy itself raises.

A shallow copy is enough for #46625: the working_dir and py_modules
upload helpers only rebind top-level keys and never mutate a value in
place. Path strings, URIs and `ray job submit` were never affected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marwan Sarieddine <[email protected]>
Review follow-up. The shallow copy still shares nested values with the
caller's dict, so the steps after it must replace keys rather than
mutate values in place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marwan Sarieddine <[email protected]>
@marwan116
marwan116 force-pushed the marwan/jobs-fix-py-modules-module-objects branch from c7ae244 to 6d28c2c Compare October 20, 2026 13:47
@github-actions
github-actions Bot disabled auto-merge October 20, 2026 13:47
@Sparks0219
Sparks0219 merged commit 6aebb83 into master Oct 20, 2026
6 checks passed
@Sparks0219
Sparks0219 deleted the marwan/jobs-fix-py-modules-module-objects branch October 20, 2026 17:16
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 dashboard Issues specific to the Ray Dashboard go add ONLY when ready to merge, run all tests stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants