Skip to content

[core] (FreeObjects 1/n) Adding FreeLocalObjects RPC for owner-driven free mechanism - #63218

Merged
edoakes merged 37 commits into
ray-project:masterfrom
aaronscalene:aaron/passive-owner-callback
Jun 9, 2026
Merged

edoakes merged 37 commits into
ray-project:masterfrom
aaronscalene:aaron/passive-owner-callback

Conversation

@aaronscalene

@aaronscalene aaronscalene commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Within this multi-step PR process, our goal is to change our current FreeObjects implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting. This is a continuation from #63117. Due to the race condition detailed in the testing section of the PR, we decided to merge both changes for a complete PR.

Our current design for FreeObjects involves the following steps:

  1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference.
  2. The owner finds out, and sends a pubsub message (initialized when pinning the primary copy) to the primary copy raylet.
  3. The primary copy raylet frees its primary copy, and then broadcasts free secondary copies to all nodes within the cluster. (This is batched and sent periodically). The reason the primary copy raylet needs to broadcast secondary copies is because it doesn't store object locations for its primary copy, this is only stored on the owner. Thus, in order to ensure all secondary copies are freed, there is a need to broadcast to all nodes.

Design

As noted above, the owner stores the locations of all copies of the objects, where pinned_at_node_id_ represents the primary copy location and the locations vector demonstrates all secondary object locations.

We now move towards a new design FreeObjects. We will get rid of the pubsub between owner -> primary copy raylet. Instead:

  1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference.
  2. The owner sends RPCs to primary and secondary copy holders to free their objects. (Since it has all of its locations)

However, this doesn't easily solve our issue since the pubsub also has an owner_dead_callback, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly.

Originally, the design was that:

  • the pubsub connection fails / ends for some unexpected reason
  • the owner is thought to be dead, so the primary copy raylet then frees its primary copy and queues up FreeObjects to broadcast to all secondary copies

The new design:

  • The GCS already publishes WorkerFailure and NodeRemoved announcements to all raylets. This is so that raylets know to release worker leases of dead nodes / workers
  • With this new design, the raylets will listen and additionally clear any objects that had their owner on the failed worker / node
  • Something to consider is how exactly GCS gets these notifications, and if there would be any slowness in these notifications.

1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it.

2.) On node death, similar story.

However, in old implementation, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification. Hence all in all, there really shouldn't be a significant change in behavior.

Description

This PR covers the first and second part of the FreeObjects change. The first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new FreeLocalObjects RPC to all primary and secondary copy locations when OnObjectsOutOfScopeOrFreed. The second part amends the functionality of the current owner dead pubsub callback to be moved from an eager pubsub death callback to a more passive listener callback.

Considerations

NodeManager RPC vs. ObjectManager RPC

For this PR, I considered either 1) Adding a new RPC to NodeManager or 2) Adding new route that calls into existing ObjectManager FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' NodeManager, so part of this is to keep with existing implementation. Another reason is that our new HandleFreeLocalObjects would be responsible for 2 things: 1) if primary copy, delete metadata from LocalObjectManager (manages spilled and primary copies) and 2) if any copy, queue up within FreeObjects. Thus, NodeManager currently has functionality that calls into LocalObjectManager. Furthermore, I find that directly interfacing with ObjectManager is not as intuitive, and creating a new path just for ObjectManager does not seem ideal.

Moving Around ReferenceCounter Variables

For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified.

Only Owner Frees

An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet.

Dead Code Deleted in Future

For this PR, I kept FreeObjects's local_only=false case still alive, even though this case is essentially never called again. In the future, I will delete this dead code.

Testing Changes and ReferenceCounter Changes

For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation.

Pass Over All Objects

This new design introduces a pass over all objects within the current node every announcement. However, failed nodes and worker announcements should not be too common and if the object is not owned by the failed worker / node it would be a no-op; thus this should not lead to any latency issues.

Owner is Less Eager

This new design will be a less eager free, especially for the primary copy of the node. This is definitely an important part to consider, however since it is similar a pubsub for node information, the latency should not be that big of a deal. Furthermore, the pubsub interface already keeps track of network failures etc. to some extent, and if there are further failures / GCS failures there are probably worse problems to deal with.

LocalObjectManager local_objects_ vs. ObjectManager local_objects_

An important distinction is needed between both classes' local objects, where we need to aggregate and free any objects within both classes. LocalObjectManager in this case keeps track of primary copies as well as spilled copies. ObjectManager keeps track of anything in plasma such as primary copies / secondary copies. Thus, we need to get the union of both objects to get the objects that we want to free.

Testing

Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in #63181

We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly.

@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 a new RPC mechanism, FreeLocalObjects, to allow the CoreWorker to explicitly instruct NodeManager instances to free local objects. This replaces the previous eviction-pubsub callback approach. My review identified several areas for improvement: the CoreWorker lambda capture should use shared_from_this for lifetime safety, the RPC implementation should be batched to avoid performance degradation in large clusters, and the now-unused objects_pending_deletion_ logic in LocalObjectManager should be cleaned up.

Comment thread src/ray/core_worker/core_worker.cc Resolved
Comment thread src/ray/core_worker/core_worker.cc Resolved
Comment thread src/ray/raylet/local_object_manager.cc Resolved
@aaronscalene
aaronscalene force-pushed the aaron/passive-owner-callback branch from 483b867 to 9482fe8 Compare May 8, 2026 23:21
@aaronscalene aaronscalene changed the title [core] [DO NOT MERGE] (FreeObjects 2/n) [core] (FreeObjects 2/n) Added GCS passive owner death removal May 15, 2026
@aaronscalene aaronscalene changed the title [core] (FreeObjects 2/n) Added GCS passive owner death removal [core] (FreeObjects 2/n) Added GCS passive owner death object freeing May 15, 2026
@aaronscalene
aaronscalene force-pushed the aaron/passive-owner-callback branch from 3c5129a to 01dd4d9 Compare May 15, 2026 21:20
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
@aaronscalene
aaronscalene force-pushed the aaron/passive-owner-callback branch from 01dd4d9 to a8c096f Compare May 20, 2026 22:22
@aaronscalene
aaronscalene marked this pull request as ready for review May 21, 2026 03:14
@aaronscalene
aaronscalene requested a review from a team as a code owner May 21, 2026 03:14
Comment thread src/ray/protobuf/node_manager.proto Resolved
Comment thread src/ray/raylet/local_object_manager.cc Resolved
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label May 21, 2026
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
v
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
i
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
@aaronscalene
aaronscalene force-pushed the aaron/passive-owner-callback branch from a8c096f to cc91473 Compare May 22, 2026 21:24
Comment thread src/ray/raylet/local_object_manager.cc Outdated
// Only free the object if it is not already freed.
void LocalObjectManager::ReleaseFreedLocalObject(const ObjectID &object_id) {
// Primary-copy bookkeeping only runs when we actually hold the primary copy
// and it hasn't been freed yet. Secondary copies fall through to the enqueue

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.

Can you explain what you mean by secondary copies fall through to the enqueue below? I'm still a bit confused on why you needed to remove the early return here. How were secondary copies cleaned up prior to this change, I'm assuming since the local object manager tracks primary copies only the early return caught them, so there was something else that cleaned them up?

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.

Originally, this path was only called by primary copies, which then triggers the FreeObjects broadcast. Now, since each local object goes through this path, for primary copies we will remove any bookkeeping and for secondary copies we just want to enqueue it to be freed.

Signed-off-by: aaron.li <[email protected]>

@aaronscalene aaronscalene left a comment •

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.

reviewed

const auto obj_id = ObjectID::FromBinary(object_id_binary);
ReleaseFreedObject(obj_id);
};
auto owner_dead_callback = [owner_address](const std::string &object_id_binary,

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!

return GetCoreWorker()->gcs_client_->Nodes().IsNodeDead(node_id);
},
/*spread_free_local_objects=*/
[this](const ObjectID &object_id, const std::vector<NodeID> &locations) {

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: seems like the only place that that this is called has the locations in an unordered set. Do we need to do the conversion to a vector 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.

Good idea, done!

send_reply_callback(Status::OK(), nullptr, nullptr);
}

// TODO(aaronscalene) will delete local_only=false and related dead code in #63213

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: format should be TODO(#63213)

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.

}
}

std::vector<ObjectID> LocalObjectManager::GetLocalObjectsOwnedBy(

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.

super nit: this is duplicated in both object_manager and local_object_manager. What you could do is add these functions into a shared util file and pass the local_objects_ as a parameter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

^^^

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.

Hmm, this might be hard because the LocalObjectInfo in object_manager is different from the LocalObjectInfo in local_object_manager, so there still needs to be four separate definitions, unless I add methods to LocalObjectInfos to compromise them together, which I don't really like. I decided to move LocalObjectsMatchedBy into a util function shared file, which I think is beneficial.

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

LGTM, nice job! @edoakes could you PTAL and merge?

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

I think it would be helpful to point out the failure model a bit more explicitly in the PR description.

1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it. Meanwhile, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification.

2.) On node death, similar story.

Hence all in all, there really shouldn't be a significant change in behavior.

Comment thread src/ray/raylet/local_object_manager.cc Outdated
void LocalObjectManager::ReleaseFreedLocalObject(const ObjectID &object_id) {
// This is called for both primary and secondary copies. For secondary copies, they
// should just be queued up to be freed below. For primary copies, additional
// bookkeeping is needed to ensure there is no regression.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what does "no regression" mean?

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.

Good catch, bad comment. Changed it to a more suitable comment.

}
}

std::vector<ObjectID> LocalObjectManager::GetLocalObjectsOwnedBy(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

^^^

Comment thread src/ray/raylet/main.cc
[&](const std::vector<ray::ObjectID> &object_ids) {
object_manager->FreeObjects(object_ids,
/*local_only=*/false);
/*local_only=*/true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

local_only flag will be removed in a future PR?

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.

Yes #63213

Comment thread src/ray/raylet/node_manager.cc Outdated
for (const auto &id : object_manager_.GetLocalObjectsOwnedByOwnersOn(node_id)) {
ids.insert(id);
}
RAY_UNUSED(FreeLocalObjects(std::vector<ObjectID>(ids.begin(), ids.end())));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why RAY_UNUSED? either handle the error if it's recoverable (at minimum a warning) or make it a RAY_CHECK

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.

Artifact of past implementation, no need for status anymore so changed to void, good catch.

publisher_.get(),
subscriber_.get(),
/*is_node_dead=*/[](const NodeID &) { return false; },
/*spread_free_local_objects=*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: "spread" is a bit misleading here as it indicates that we are sending the RPC across the cluster

I would call this something like free_objects_on_nodes_async

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

Comment thread src/ray/core_worker/core_worker.cc Outdated
Comment on lines +4568 to +4569
void CoreWorker::SpreadFreeLocalObjects(const ObjectID &object_id,
const std::vector<NodeID> &locations) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same comment on naming as above, something like FreeObjectOnNodesAsync

The "local" naming here is also a bit confusing -- it makes sense in the RPC to a specific raylet, but here we are actually freeing the object across non-local nodes.

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.

Makes sense, done

Comment thread src/ray/core_worker/core_worker.cc Outdated
Comment on lines +4582 to +4587
if (!status.ok()) {
RAY_LOG(WARNING).WithField(object_id)
<< "FreeLocalObjects RPC to node " << node_id
<< " failed: " << status.ToString();
}
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does the RPC retry automatically? In what case would we ever get !status.ok() and how should we handle it?

@aaronscalene aaronscalene Jun 4, 2026 •

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.

RPC does retry automatically as it is through RetryableGrpcClient. Thus, for any network related errors, this should automatically retry. I believe this status case will only happen when the Raylet dies. I looked at other implementations and they seem to just log a warning within the raylet client, which is what I ended up doing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm it would be good to have a specific status for that (node died error) and possibly use the statusset for this @Sparks0219. That way clients are forced to explicitly handle a subset of possible errors as applicable.

Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Comment thread src/ray/raylet/node_manager.cc Resolved
@aaronscalene
aaronscalene force-pushed the aaron/passive-owner-callback branch from 8f4c9cd to fdf18e3 Compare June 8, 2026 19:13

@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 9c25256. Configure here.

@edoakes
edoakes enabled auto-merge (squash) June 8, 2026 21:39
@github-actions
github-actions Bot disabled auto-merge June 8, 2026 22:45
@edoakes
edoakes merged commit ce4ccec into ray-project:master Jun 9, 2026
3 checks passed
sampan-s-nayak pushed a commit to sampan-s-nayak/ray that referenced this pull request Jun 10, 2026
… free mechanism (ray-project#63218)

## Motivation
Within this multi-step PR process, our goal is to change our current
**FreeObjects** implementation to an owner driven process. Current
design of FreeObjects involves spraying the entire cluster with
FreeObjects RPCs. This introduces many caveats: bloating observability
with FreeObjects RPC counts, sending excessive RPCs, and worse mental
model from owner-driven reference counting. This is a continuation from
ray-project#63117. Due to the race condition detailed in the testing section of the
PR, we decided to merge both changes for a complete PR.

Our current design for **FreeObjects** involves the following steps:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner finds out, and sends a pubsub message (initialized when
pinning the primary copy) to the primary copy raylet.
3. The primary copy raylet frees its primary copy, and then broadcasts
free secondary copies to all nodes within the cluster. (This is batched
and sent periodically). The reason the primary copy raylet needs to
broadcast secondary copies is because it doesn't store object locations
for its primary copy, this is only stored on the owner. Thus, in order
to ensure all secondary copies are freed, there is a need to broadcast
to all nodes.

## Design
As noted above, the owner stores the locations of all copies of the
objects, where `pinned_at_node_id_` represents the primary copy location
and the `locations` vector demonstrates all secondary object locations.

We now move towards a new design **FreeObjects**. We will get rid of the
pubsub between owner -> primary copy raylet. Instead:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner sends RPCs to primary and secondary copy holders to free
their objects. (Since it has all of its locations)

However, this doesn't easily solve our issue since the pubsub also has
an `owner_dead_callback`, which fires when the owner has died. This will
help clean up the primary object and ensure there are no memory leaks in
this case. To continue supporting this functionality, if the owner dies,
this information is propagated by the GCS, and thus each raylet just
listens to the GCS events and updates their states accordingly.

Originally, the design was that:
- the pubsub connection fails / ends for some unexpected reason
- the owner is thought to be dead, so the primary copy raylet then frees
its primary copy and queues up **FreeObjects** to broadcast to all
secondary copies

The new design:
- The GCS already publishes WorkerFailure and NodeRemoved announcements
to all raylets. This is so that raylets know to release worker leases of
dead nodes / workers
- With this new design, the raylets will listen and additionally clear
any objects that had their owner on the failed worker / node
- Something to consider is how exactly GCS gets these notifications, and
if there would be any slowness in these notifications.

1.) When the worker process dies (but the node remains alive), the
raylet picks up the worker death relatively quickly via the broken IPC
connection and sends the worker death up to the GCS, and GCS broadcasts
it.

2.) On node death, similar story.

However, in old implementation, the long poll connection would be
sitting the retryable grpc client queue waiting for either the
connection to come back up or the GCS to get a worker death
notification. Hence all in all, there really shouldn't be a significant
change in behavior.

## Description
This PR covers the first and second part of the **FreeObjects** change.
The first part is strictly adding functionality for the owner to be in
charge of freeing objects. We make the first step away from this design
such that the owner calls a new **FreeLocalObjects** RPC to all primary
and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The
second part amends the functionality of the current owner dead pubsub
callback to be moved from an eager pubsub death callback to a more
passive listener callback.

## Considerations
### NodeManager RPC vs. ObjectManager RPC
For this PR, I considered either 1) Adding a new RPC to **NodeManager**
or 2) Adding new route that calls into existing **ObjectManager**
FreeObjects. Ultimately, I decided to go with 1). A design consideration
here is that workers currently only call into raylets' **NodeManager**,
so part of this is to keep with existing implementation. Another reason
is that our new **HandleFreeLocalObjects** would be responsible for 2
things: 1) if primary copy, delete metadata from **LocalObjectManager**
(manages spilled and primary copies) and 2) if any copy, queue up within
**FreeObjects**. Thus, **NodeManager** currently has functionality that
calls into **LocalObjectManager**. Furthermore, I find that directly
interfacing with **ObjectManager** is not as intuitive, and creating a
new path just for **ObjectManager** does not seem ideal.

### Moving Around ReferenceCounter Variables
For this PR, I decided to follow similar formats in the codebase, and
have all the lambdas within the constructor shifted to the end. In this
case, they can be considered optional arguments and can be defaulted to
null if not specified. This leads to easier testing implementations. A
tricky part is to ensure these functions generate no-op if they are not
specified.

### Only Owner Frees
An important consideration is that now that we are sending from the
worker side, only if the object is freed is owned by the current worker
should the worker send RPC requests to the object locations. Otherwise,
the worker should just keep quiet.

### Dead Code Deleted in Future
For this PR, I kept **FreeObjects**'s `local_only=false` case still
alive, even though this case is essentially never called again. In the
future, I will delete this dead code.

### Testing Changes and ReferenceCounter Changes
For this PR, there were many testing changes that are needed because of
this new path that is different from the first one. For now, many of
these tests are just hardcoded to match correct behavior, but in the
future some unnecessary tests might be deleted or shuffled around to
match the new implementation.

### Pass Over All Objects
This new design introduces a pass over all objects within the current
node every announcement. However, failed nodes and worker announcements
should not be too common and if the object is not owned by the failed
worker / node it would be a no-op; thus this should not lead to any
latency issues.

### Owner is Less Eager
This new design will be a less eager free, especially for the primary
copy of the node. This is definitely an important part to consider,
however since it is similar a pubsub for node information, the latency
should not be that big of a deal. Furthermore, the pubsub interface
already keeps track of network failures etc. to some extent, and if
there are further failures / GCS failures there are probably worse
problems to deal with.

### LocalObjectManager local_objects_ vs. ObjectManager local_objects_
An important distinction is needed between both classes' local objects,
where we need to aggregate and free any objects within both classes.
LocalObjectManager in this case keeps track of primary copies as well as
spilled copies. ObjectManager keeps track of anything in plasma such as
primary copies / secondary copies. Thus, we need to get the union of
both objects to get the objects that we want to free.

## Testing
Ran python tests and C++ tests adjacent to these changes to ensure no
regressions. Future e2e testing in ray-project#63181

We will fix this race condition in the immediate next PR, which uses the
GCS to broadcast deaths and have the raylets free accordingly.

---------

Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaronscalene <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
… free mechanism (ray-project#63218)

## Motivation
Within this multi-step PR process, our goal is to change our current
**FreeObjects** implementation to an owner driven process. Current
design of FreeObjects involves spraying the entire cluster with
FreeObjects RPCs. This introduces many caveats: bloating observability
with FreeObjects RPC counts, sending excessive RPCs, and worse mental
model from owner-driven reference counting. This is a continuation from
ray-project#63117. Due to the race condition detailed in the testing section of the
PR, we decided to merge both changes for a complete PR.

Our current design for **FreeObjects** involves the following steps:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner finds out, and sends a pubsub message (initialized when
pinning the primary copy) to the primary copy raylet.
3. The primary copy raylet frees its primary copy, and then broadcasts
free secondary copies to all nodes within the cluster. (This is batched
and sent periodically). The reason the primary copy raylet needs to
broadcast secondary copies is because it doesn't store object locations
for its primary copy, this is only stored on the owner. Thus, in order
to ensure all secondary copies are freed, there is a need to broadcast
to all nodes.

## Design
As noted above, the owner stores the locations of all copies of the
objects, where `pinned_at_node_id_` represents the primary copy location
and the `locations` vector demonstrates all secondary object locations.

We now move towards a new design **FreeObjects**. We will get rid of the
pubsub between owner -> primary copy raylet. Instead:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner sends RPCs to primary and secondary copy holders to free
their objects. (Since it has all of its locations)

However, this doesn't easily solve our issue since the pubsub also has
an `owner_dead_callback`, which fires when the owner has died. This will
help clean up the primary object and ensure there are no memory leaks in
this case. To continue supporting this functionality, if the owner dies,
this information is propagated by the GCS, and thus each raylet just
listens to the GCS events and updates their states accordingly.

Originally, the design was that:
- the pubsub connection fails / ends for some unexpected reason
- the owner is thought to be dead, so the primary copy raylet then frees
its primary copy and queues up **FreeObjects** to broadcast to all
secondary copies

The new design:
- The GCS already publishes WorkerFailure and NodeRemoved announcements
to all raylets. This is so that raylets know to release worker leases of
dead nodes / workers
- With this new design, the raylets will listen and additionally clear
any objects that had their owner on the failed worker / node
- Something to consider is how exactly GCS gets these notifications, and
if there would be any slowness in these notifications.

1.) When the worker process dies (but the node remains alive), the
raylet picks up the worker death relatively quickly via the broken IPC
connection and sends the worker death up to the GCS, and GCS broadcasts
it.

2.) On node death, similar story.

However, in old implementation, the long poll connection would be
sitting the retryable grpc client queue waiting for either the
connection to come back up or the GCS to get a worker death
notification. Hence all in all, there really shouldn't be a significant
change in behavior.

## Description
This PR covers the first and second part of the **FreeObjects** change.
The first part is strictly adding functionality for the owner to be in
charge of freeing objects. We make the first step away from this design
such that the owner calls a new **FreeLocalObjects** RPC to all primary
and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The
second part amends the functionality of the current owner dead pubsub
callback to be moved from an eager pubsub death callback to a more
passive listener callback.

## Considerations
### NodeManager RPC vs. ObjectManager RPC
For this PR, I considered either 1) Adding a new RPC to **NodeManager**
or 2) Adding new route that calls into existing **ObjectManager**
FreeObjects. Ultimately, I decided to go with 1). A design consideration
here is that workers currently only call into raylets' **NodeManager**,
so part of this is to keep with existing implementation. Another reason
is that our new **HandleFreeLocalObjects** would be responsible for 2
things: 1) if primary copy, delete metadata from **LocalObjectManager**
(manages spilled and primary copies) and 2) if any copy, queue up within
**FreeObjects**. Thus, **NodeManager** currently has functionality that
calls into **LocalObjectManager**. Furthermore, I find that directly
interfacing with **ObjectManager** is not as intuitive, and creating a
new path just for **ObjectManager** does not seem ideal.

### Moving Around ReferenceCounter Variables
For this PR, I decided to follow similar formats in the codebase, and
have all the lambdas within the constructor shifted to the end. In this
case, they can be considered optional arguments and can be defaulted to
null if not specified. This leads to easier testing implementations. A
tricky part is to ensure these functions generate no-op if they are not
specified.

### Only Owner Frees
An important consideration is that now that we are sending from the
worker side, only if the object is freed is owned by the current worker
should the worker send RPC requests to the object locations. Otherwise,
the worker should just keep quiet.

### Dead Code Deleted in Future
For this PR, I kept **FreeObjects**'s `local_only=false` case still
alive, even though this case is essentially never called again. In the
future, I will delete this dead code.

### Testing Changes and ReferenceCounter Changes
For this PR, there were many testing changes that are needed because of
this new path that is different from the first one. For now, many of
these tests are just hardcoded to match correct behavior, but in the
future some unnecessary tests might be deleted or shuffled around to
match the new implementation.

### Pass Over All Objects
This new design introduces a pass over all objects within the current
node every announcement. However, failed nodes and worker announcements
should not be too common and if the object is not owned by the failed
worker / node it would be a no-op; thus this should not lead to any
latency issues.

### Owner is Less Eager
This new design will be a less eager free, especially for the primary
copy of the node. This is definitely an important part to consider,
however since it is similar a pubsub for node information, the latency
should not be that big of a deal. Furthermore, the pubsub interface
already keeps track of network failures etc. to some extent, and if
there are further failures / GCS failures there are probably worse
problems to deal with.

### LocalObjectManager local_objects_ vs. ObjectManager local_objects_
An important distinction is needed between both classes' local objects,
where we need to aggregate and free any objects within both classes.
LocalObjectManager in this case keeps track of primary copies as well as
spilled copies. ObjectManager keeps track of anything in plasma such as
primary copies / secondary copies. Thus, we need to get the union of
both objects to get the objects that we want to free.

## Testing
Ran python tests and C++ tests adjacent to these changes to ensure no
regressions. Future e2e testing in ray-project#63181

We will fix this race condition in the immediate next PR, which uses the
GCS to broadcast deaths and have the raylets free accordingly.

---------

Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaronscalene <[email protected]>
Sparks0219 pushed a commit that referenced this pull request Aug 11, 2026
## Description
There is currently a method `_internal.free` that explicitly frees a
ref's objects' copies across the cluster (primary and secondary). This
calls into the FreeObjects path that then frees the primary copy and
broadcasts frees to other nodes (if `local_only`=false). For more
information on this, please read #63218. In the new implementation of
FreeObjects, we remove this broadcast, which means all copies will only
be locally deleted now. This introduces slight regression (although
secondary copies will eventually be evicted). Since `_internal.free` has
been deprecated for ~11 months now, the decision is made to just remove
it.

## Current Use Case Considerations
### Ray Data Split
Ray Data in one use case touches upon internal free. However, the
default case for the internal free codepath is usually `false`.
Furthermore, it seems that they do not necessarily need this
functionality and can just wait for object free. There ends up being a
lot of cleanups for Ray Data because of flags that are no longer
necessary due to the removal of this codepath. All these flags are
defaulted to false.

### Java Internal Free
Java runtime also has an internal free implementation that plumbs into
the same codepath as cython. We decide to not support multi-language
runtimes, and thus do not want to continue supporting this.

### Out of Band Serialization / Deserialization
There is current support for out of band serialization / deserialization
through cloudpickle, which would then rely on internal free for freeing
the underlying object. We do not want to continue supporting this, and
thus remove this.

### Testing Usecases
Some testing use cases who only test adjacent conditions have maintained
functionality. However, some test cases that purely test
`_internal.free` or are largely coupled with `_internal.free` are
removed.

---------

Signed-off-by: aaron.li <[email protected]>
Co-authored-by: aaron.li <[email protected]>
Co-authored-by: Aaron <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
… free mechanism (ray-project#63218)

## Motivation
Within this multi-step PR process, our goal is to change our current
**FreeObjects** implementation to an owner driven process. Current
design of FreeObjects involves spraying the entire cluster with
FreeObjects RPCs. This introduces many caveats: bloating observability
with FreeObjects RPC counts, sending excessive RPCs, and worse mental
model from owner-driven reference counting. This is a continuation from
ray-project#63117. Due to the race condition detailed in the testing section of the
PR, we decided to merge both changes for a complete PR.

Our current design for **FreeObjects** involves the following steps:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner finds out, and sends a pubsub message (initialized when
pinning the primary copy) to the primary copy raylet.
3. The primary copy raylet frees its primary copy, and then broadcasts
free secondary copies to all nodes within the cluster. (This is batched
and sent periodically). The reason the primary copy raylet needs to
broadcast secondary copies is because it doesn't store object locations
for its primary copy, this is only stored on the owner. Thus, in order
to ensure all secondary copies are freed, there is a need to broadcast
to all nodes.

## Design
As noted above, the owner stores the locations of all copies of the
objects, where `pinned_at_node_id_` represents the primary copy location
and the `locations` vector demonstrates all secondary object locations.

We now move towards a new design **FreeObjects**. We will get rid of the
pubsub between owner -> primary copy raylet. Instead:
1. The reference goes out of scope. The reference here represents both
the owner's python references, as well as other borrower references
throughout the cluster, which is tracked through the owner reference.
2. The owner sends RPCs to primary and secondary copy holders to free
their objects. (Since it has all of its locations)

However, this doesn't easily solve our issue since the pubsub also has
an `owner_dead_callback`, which fires when the owner has died. This will
help clean up the primary object and ensure there are no memory leaks in
this case. To continue supporting this functionality, if the owner dies,
this information is propagated by the GCS, and thus each raylet just
listens to the GCS events and updates their states accordingly.

Originally, the design was that:
- the pubsub connection fails / ends for some unexpected reason
- the owner is thought to be dead, so the primary copy raylet then frees
its primary copy and queues up **FreeObjects** to broadcast to all
secondary copies

The new design:
- The GCS already publishes WorkerFailure and NodeRemoved announcements
to all raylets. This is so that raylets know to release worker leases of
dead nodes / workers
- With this new design, the raylets will listen and additionally clear
any objects that had their owner on the failed worker / node
- Something to consider is how exactly GCS gets these notifications, and
if there would be any slowness in these notifications.

1.) When the worker process dies (but the node remains alive), the
raylet picks up the worker death relatively quickly via the broken IPC
connection and sends the worker death up to the GCS, and GCS broadcasts
it.

2.) On node death, similar story.

However, in old implementation, the long poll connection would be
sitting the retryable grpc client queue waiting for either the
connection to come back up or the GCS to get a worker death
notification. Hence all in all, there really shouldn't be a significant
change in behavior.

## Description
This PR covers the first and second part of the **FreeObjects** change.
The first part is strictly adding functionality for the owner to be in
charge of freeing objects. We make the first step away from this design
such that the owner calls a new **FreeLocalObjects** RPC to all primary
and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The
second part amends the functionality of the current owner dead pubsub
callback to be moved from an eager pubsub death callback to a more
passive listener callback.

## Considerations
### NodeManager RPC vs. ObjectManager RPC
For this PR, I considered either 1) Adding a new RPC to **NodeManager**
or 2) Adding new route that calls into existing **ObjectManager**
FreeObjects. Ultimately, I decided to go with 1). A design consideration
here is that workers currently only call into raylets' **NodeManager**,
so part of this is to keep with existing implementation. Another reason
is that our new **HandleFreeLocalObjects** would be responsible for 2
things: 1) if primary copy, delete metadata from **LocalObjectManager**
(manages spilled and primary copies) and 2) if any copy, queue up within
**FreeObjects**. Thus, **NodeManager** currently has functionality that
calls into **LocalObjectManager**. Furthermore, I find that directly
interfacing with **ObjectManager** is not as intuitive, and creating a
new path just for **ObjectManager** does not seem ideal.

### Moving Around ReferenceCounter Variables
For this PR, I decided to follow similar formats in the codebase, and
have all the lambdas within the constructor shifted to the end. In this
case, they can be considered optional arguments and can be defaulted to
null if not specified. This leads to easier testing implementations. A
tricky part is to ensure these functions generate no-op if they are not
specified.

### Only Owner Frees
An important consideration is that now that we are sending from the
worker side, only if the object is freed is owned by the current worker
should the worker send RPC requests to the object locations. Otherwise,
the worker should just keep quiet.

### Dead Code Deleted in Future
For this PR, I kept **FreeObjects**'s `local_only=false` case still
alive, even though this case is essentially never called again. In the
future, I will delete this dead code.

### Testing Changes and ReferenceCounter Changes
For this PR, there were many testing changes that are needed because of
this new path that is different from the first one. For now, many of
these tests are just hardcoded to match correct behavior, but in the
future some unnecessary tests might be deleted or shuffled around to
match the new implementation.

### Pass Over All Objects
This new design introduces a pass over all objects within the current
node every announcement. However, failed nodes and worker announcements
should not be too common and if the object is not owned by the failed
worker / node it would be a no-op; thus this should not lead to any
latency issues.

### Owner is Less Eager
This new design will be a less eager free, especially for the primary
copy of the node. This is definitely an important part to consider,
however since it is similar a pubsub for node information, the latency
should not be that big of a deal. Furthermore, the pubsub interface
already keeps track of network failures etc. to some extent, and if
there are further failures / GCS failures there are probably worse
problems to deal with.

### LocalObjectManager local_objects_ vs. ObjectManager local_objects_
An important distinction is needed between both classes' local objects,
where we need to aggregate and free any objects within both classes.
LocalObjectManager in this case keeps track of primary copies as well as
spilled copies. ObjectManager keeps track of anything in plasma such as
primary copies / secondary copies. Thus, we need to get the union of
both objects to get the objects that we want to free.

## Testing
Ran python tests and C++ tests adjacent to these changes to ensure no
regressions. Future e2e testing in ray-project#63181

We will fix this race condition in the immediate next PR, which uses the
GCS to broadcast deaths and have the raylets free accordingly.

---------

Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaronscalene <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
## Description
There is currently a method `_internal.free` that explicitly frees a
ref's objects' copies across the cluster (primary and secondary). This
calls into the FreeObjects path that then frees the primary copy and
broadcasts frees to other nodes (if `local_only`=false). For more
information on this, please read ray-project#63218. In the new implementation of
FreeObjects, we remove this broadcast, which means all copies will only
be locally deleted now. This introduces slight regression (although
secondary copies will eventually be evicted). Since `_internal.free` has
been deprecated for ~11 months now, the decision is made to just remove
it.

## Current Use Case Considerations
### Ray Data Split
Ray Data in one use case touches upon internal free. However, the
default case for the internal free codepath is usually `false`.
Furthermore, it seems that they do not necessarily need this
functionality and can just wait for object free. There ends up being a
lot of cleanups for Ray Data because of flags that are no longer
necessary due to the removal of this codepath. All these flags are
defaulted to false.

### Java Internal Free
Java runtime also has an internal free implementation that plumbs into
the same codepath as cython. We decide to not support multi-language
runtimes, and thus do not want to continue supporting this.

### Out of Band Serialization / Deserialization
There is current support for out of band serialization / deserialization
through cloudpickle, which would then rely on internal free for freeing
the underlying object. We do not want to continue supporting this, and
thus remove this.

### Testing Usecases
Some testing use cases who only test adjacent conditions have maintained
functionality. However, some test cases that purely test
`_internal.free` or are largely coupled with `_internal.free` are
removed.

---------

Signed-off-by: aaron.li <[email protected]>
Co-authored-by: aaron.li <[email protected]>
Co-authored-by: Aaron <[email protected]>
Signed-off-by: 400Ping <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Description
There is currently a method `_internal.free` that explicitly frees a
ref's objects' copies across the cluster (primary and secondary). This
calls into the FreeObjects path that then frees the primary copy and
broadcasts frees to other nodes (if `local_only`=false). For more
information on this, please read ray-project#63218. In the new implementation of
FreeObjects, we remove this broadcast, which means all copies will only
be locally deleted now. This introduces slight regression (although
secondary copies will eventually be evicted). Since `_internal.free` has
been deprecated for ~11 months now, the decision is made to just remove
it.

## Current Use Case Considerations
### Ray Data Split
Ray Data in one use case touches upon internal free. However, the
default case for the internal free codepath is usually `false`.
Furthermore, it seems that they do not necessarily need this
functionality and can just wait for object free. There ends up being a
lot of cleanups for Ray Data because of flags that are no longer
necessary due to the removal of this codepath. All these flags are
defaulted to false.

### Java Internal Free
Java runtime also has an internal free implementation that plumbs into
the same codepath as cython. We decide to not support multi-language
runtimes, and thus do not want to continue supporting this.

### Out of Band Serialization / Deserialization
There is current support for out of band serialization / deserialization
through cloudpickle, which would then rely on internal free for freeing
the underlying object. We do not want to continue supporting this, and
thus remove this.

### Testing Usecases
Some testing use cases who only test adjacent conditions have maintained
functionality. However, some test cases that purely test
`_internal.free` or are largely coupled with `_internal.free` are
removed.

---------

Signed-off-by: aaron.li <[email protected]>
Co-authored-by: aaron.li <[email protected]>
Co-authored-by: Aaron <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 7, 2026
…66790)

## Why are these changes needed?

The Ray Core style-pass stack, #66642 through #66677, flagged
pre-existing problems in the pages it edited and left them as written,
because a style pass shouldn't change claims. This PR fixes the ones
that don't change a technical claim. It's stacked on #66677, the top of
that stack, because it edits lines on pages across every layer.

Each fix is settled by the page itself, its own code sample, or a
renamed symbol:

- `configure.md`: the default worker port range 10002 to 19999 holds
9,998 ports, so the per-node worker maximum is 9,998, not 10,000.
- `user-spawn-processes.md`: the deprecation note told readers to enable
`process_group_cleanup_enabled`, which L19 of the same page says is on
by default.
- `type-hint.md`: the Pattern 2 sample uses `ray` and `ObjectRef`
without importing them.
- `actors/terminating-actors.md`: the front-matter description said
cleanup runs when `ray.shutdown` is called, which the page never says.
It now names the `__ray_shutdown__` method the page covers. The
`sys.exit` sentence sits below the Python, Java, and C++ tabs, so it now
scopes `sys.exit` to Python.
- `objects/object-spilling.md`: the CLI tab wrapped a `ray start` shell
command in a `{doctest}` fence. It's now `bash`.
- `patterns/nested-ray-get.md` and
`patterns/out-of-band-object-ref-serialization.md`: the front-matter
descriptions contradicted their page bodies ("serializes execution",
"can let its value be reclaimed early"). They now summarize what the
bodies say.
- `scheduling/memory-management.md`: the prose named a "Reference
Creation Site" column, but every `ray memory` sample on the page labels
it "Call Site". "In Ray 1.3 and later" is gone, since every supported
release is 2.x.
- `scheduling/ray-oom-prevention.md`: "how to address memory issues"
linked to a label left on the "Questions or issues?" section after
#63652 deleted the section it named. It now links to the out-of-memory
troubleshooting guide that #63652 expanded, and the orphaned label is
gone. Nothing else in `doc/source` targets it.
- `scheduling/resources.md`: the lead-in said the rules configure
"logical resources", but one rule in the list says object store memory
isn't a logical resource.
- `compiled-graph/overlap.md`: overlap "reduces" latency by about 14%,
rather than "improves" it. The page's output shows 1.0670 s to 0.9211 s.
- `compiled-graph/profiling.md`: NVIDIA's product is Nsight Systems. A
`(nsight-system-profiler)=` label keeps the old heading fragment
working.
- `internals/token-authentication.md`: two notes said that new HTTP
services must add the middleware and header injection themselves. The
first one goes, and the one in the "Adding token authentication to new
services" section stays.
- `examples/monte-carlo-pi.md`: the task takes exactly `num_samples`
samples, not "up to".
- `examples/index.md`: five link texts didn't match the titles of the
notebooks they link to. They now render the live titles.
- `internals/object-spilling.md`: "GCS" in the cloud storage passages
meant Google Cloud Storage, which reads as Ray's GCS on a Ray Core page.
`ReleaseFreedObject` is now `ReleaseFreedLocalObject`, renamed in
#63218. The two `PopDeleteWorker` links pointed at different lines of
`worker_pool.cc`, and the `blob/master` anchors had drifted. Those three
links are now pinned to a commit. The page's other `blob/master` links
have drifted too and need symbol-by-symbol remapping, which is left for
a follow-up.
- `internals/ray-event-exporter.md`: the Step 5 link text named
`AddEvent()`, but the function at the pinned commit and on master is
`AddEvents()`. The Step 6 `AggregatorAgent` link pointed at the default
event list, at the same anchor as Step 4, rather than the class.
- `internals/metric-exporter.md`: the `SetMetricValue()` link pointed at
a call site in `metric.cc`. It now points at the definition, which other
links on the page already use.

Not included: two typos in the `scheduling/labels.md` operator table,
curly quotes in code spans and "anything by one value", which sit on
lines that #66550 edits.

## Related issue number

None. Not a duplicate: I searched open PRs touching `doc/source/core/`
and `doc/source/ray-core/`. Open PRs editing these pages are this stack,
#66464 (Compiled Graph deprecation banners, on lines this PR doesn't
touch), and #66550 (left alone as described above).

## Checks

- Docs-only: every change is in a `.md` file under `doc/source/core/`,
so no library tests run.
- `vale` on the 18 changed files from the repo root: the same alerts as
the base branch, with none added.
- `codespell` on the changed files: clean.
- `doc/.claude/skills/ray-soft-wrap/scripts/softwrap.py --check` on the
changed files: clean.
- Every link changed here was checked against the file at its pinned
commit, at the line it names.
- `pre-commit`: passed.
- Full `-W` doc build: relying on the Read the Docs preview.

AI assistance (Claude Code) was used to draft these edits. Draft until
the submitter has reviewed every changed 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 go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants