Skip to content

[Core] Add worker fork server daemon and post-fork child setup - #67514

Merged
ryanaoleary merged 5 commits into
ray-project:masterfrom
chiayi:fork-server-too
Nov 24, 2026
Merged

ryanaoleary merged 5 commits into
ray-project:masterfrom
chiayi:fork-server-too

Conversation

@chiayi

@chiayi chiayi commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Description

Adds the standalone Python worker fork server process and unit tests to support forking workers from a warm fork server process instead of starting a new Python interpreter from scratch.

Key Changes

  • Manage fork server process lifecycle and its Unix domain socket
  • Pre-import Ray worker dependencies and configured preload_modules in a single-threaded process, freeze the GC heap for copy-on-write sharing, and fork workers on demand over a Unix socket
  • Reset post-fork child state before initializing the worker
  • Add unit tests for fork server process

Related issues

#67446 - Python worker fork server

Additional information

Wait for #67356

@chiayi
chiayi force-pushed the fork-server-too branch 7 times, most recently from 193da02 to 8954e1a Compare November 3, 2026 21:21
@chiayi
chiayi force-pushed the fork-server-too branch 11 times, most recently from ea48bf7 to e27f857 Compare November 8, 2026 02:37
@chiayi
chiayi force-pushed the fork-server-too branch 9 times, most recently from 9abefde to 63e423f Compare November 11, 2026 19:42

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

@chiayi
chiayi force-pushed the fork-server-too branch 2 times, most recently from fa12b0b to 944c2ab Compare November 12, 2026 22:44

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

@chiayi

chiayi commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@ryanaoleary Thanks for reviewing the PR and just to summarize the comments that were addressed. These are the 2 PRs that are in mentioned as followups:

  1. WorkerPool & Process C++ integrations: connects workerpool to fork server socket. This will also include the SCM_RIGHTS changes and reading the request in the child so both side of the socket protocol can be together.
  2. RuntimeEnvAgent Integrations: This will wire the RuntimEnvAgent to manage the default and individual runtime_env fork servers.

Let me know if this sounds good! Thank you!

@chiayi
chiayi force-pushed the fork-server-too branch 3 times, most recently from 4593cc7 to 5728468 Compare November 13, 2026 07:18

@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/_private/utils.py Resolved
@ryanaoleary

Copy link
Copy Markdown
Contributor

@ryanaoleary Thanks for reviewing the PR and just to summarize the comments that were addressed. These are the 2 PRs that are in mentioned as followups:

  1. WorkerPool & Process C++ integrations: connects workerpool to fork server socket. This will also include the SCM_RIGHTS changes and reading the request in the child so both side of the socket protocol can be together.
  2. RuntimeEnvAgent Integrations: This will wire the RuntimEnvAgent to manage the default and individual runtime_env fork servers.

Let me know if this sounds good! Thank you!

Sounds good, that split works for me, including keeping the log and stdio fd args in the runtime env agent PR. Left two follow-ups inline.

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

Thanks for the changes! Mainly left some comments regarding making the suppressed failures more visible.

time.sleep(0.01)
st = os.lstat(self.socket_path)
self._socket_id = (st.st_dev, st.st_ino)
except BaseException:

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.

If something were to prevent the fork server from being brought up, maybe we should surface the error up as well.

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.

Ah good call, added a warning log with details before stopping.

with suppress(OSError):
self.process.stdin.close()
if self._socket_id is not None:
with suppress(OSError):

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.

Instead of suppressing errors silently here, should we be logging anything?

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.

Updated to log unexpected cleanup errors as warnings and, will still ignore alreadygone processes.

import ray._common.usage.usage_lib as _usage_lib # noqa: F401
import ray._private.workers.default_worker as default_worker

with suppress(Exception):

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.

nit: Should we be logging something 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.

Updated to log a warning with traceback here


assert server.process.poll() is not None
assert not os.path.exists(sock_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.

Could we add a case to make sure forked children are reaped?

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.

Added in e2e test. PTAL!

…ol caching, and logging

Signed-off-by: Aaron Liang <[email protected]>

@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 58fe4d2. Configure here.

Comment thread python/ray/_raylet.pyx Resolved
Comment thread python/ray/_private/utils.py Resolved
Comment thread python/ray/_private/utils.py Resolved
Comment thread python/ray/_private/utils.py Resolved
…up guards, and env resets

Signed-off-by: Aaron Liang <[email protected]>

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

Thanks for the PR! And the reviews from @ryanaoleary! Changes looks good on my end. One quick thing, could we make sure we run the whole windows and mac test suite in premerge just as a sanity check?

@ryanaoleary ryanaoleary added the go add ONLY when ready to merge, run all tests label Nov 20, 2026

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

LGTM as well

@ryanaoleary

Copy link
Copy Markdown
Contributor

cc: @Kunchd to merge, I added the go label but I'm not sure if the full mac/windows tests ran

@ryanaoleary
ryanaoleary enabled auto-merge (squash) November 24, 2026 00:05

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

🚢

@Sparks0219 Sparks0219 added go add ONLY when ready to merge, run all tests and removed go add ONLY when ready to merge, run all tests labels Nov 24, 2026
@ryanaoleary
ryanaoleary merged commit 32f51e2 into ray-project:master Nov 24, 2026
8 checks passed
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 core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants