Skip to content

[core][move semantics][5/n] Raylet pins a pulled consume_once object as the primary copy and reports it to the owner - #67093

Merged
Sparks0219 merged 8 commits into
masterfrom
karticam/consumer-pins-moved-object
Nov 24, 2026
Merged

Sparks0219 merged 8 commits into
masterfrom
karticam/consumer-pins-moved-object

Conversation

@karticam

@karticam karticam commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This is PR 5 of a series of PRs to implement move semantics for plasma objects in core.

The complete design doc is here: https://docs.google.com/document/d/1ZJhgRmwVyKfNCR21CWf6xMcc0B6HJwSPQsfebTRvnnE/edit?tab=t.0#heading=h.7wcod1f9afpg

After #67041, the raylet of the node where a consuming actor runs knows which of the objects it pulls are moves. This PR acts on that record when such an object arrives: the received copy is pinned as the object's new primary copy and the owner is told where the primary copy now lives. The producer's copy is not freed yet; that is in a future PR.

Changes

  1. Receiving a move keeps the object alive until it is pinned. ObjectBufferPool::WriteChunk now returns whether the chunk it wrote sealed the object, and takes defer_release. With it set, the sealing chunk seals the object but keeps the plasma store reference that was taken when the object was created. The reason: the seal happens on the RPC thread, the pin happens later on the main thread, and in between a sealed copy that nobody references is just another evictable object. Holding the reference across that window is what stops the store from evicting the fresh copy before it is pinned. ReleaseObject drops the reference once the pin is done.
  2. AbortCreate skips an object sealed this way (i.e. by move semantic method). This is because the store rejects aborting a sealed object, and the pull that owns the object is cancelled by the store's own "object added" notification, which in-turn triggerse AbortCreate which lands before the pin.
  3. The raylet pins the move when the store reports the object as local. The pin happens in NodeManager::HandleObjectLocal. If the object has a move record, it calls PinAndReportMovedObject first. Only then does it call LeaseDependencyManager::HandleObjectLocal, which cancels the wait pull and drops the record. This order is safe for one reason. PlasmaStore::SealObjects invokes add_object_callback before Seal returns to WriteChunk, and that callback posts HandleObjectLocal to the main service. ReceiveObjectChunk posts its ReleaseObject only after WriteChunk returns. So the pin always runs before the release. The chunk ack in HandlePush is unchanged. An object without a record is handled as before.
  4. NodeManager::PinAndReportMovedObject. Same steps as HandlePinObjectIDs for one object: skip if the owner is known dead. Also skip if fetch from plasma fails, if the object is gone or pending deletion. If everything is fine, it calls PinObjectsAndWaitForFree and then reports to the owner.
  5. The owner learns the new primary. ObjectLocationUpdate gains a primary_moved_to_node_id field. OwnershipBasedObjectDirectory::ReportObjectPrimaryMoved sends it through the existing UpdateObjectLocationBatch. That batch already carries the ADDED update that ObjectManager::HandleObjectAdded sent for the same object, so the move report is always ordered after it. If that ADDED update is still waiting in the buffer, because a batch to the owner is in flight, the two go out as one message. On the owner, HandleUpdateObjectLocationBatch calls the existing UpdateObjectPinnedAtRaylet. From then on the consumer's node holds the primary copy. If that node dies, the object is reconstructed or reported lost, like any other primary copy. Losing the producer's node no longer loses the object.
  6. ObjectManager::DebugString reports the number of move records, and NodeManager::DebugString the number of received moves pinned or not pinned. All zero on a node that never receives a move.

@karticam
karticam requested a review from a team as a code owner October 15, 2026 21:57
@karticam
karticam added this pull request to stack #66768 October 15, 2026 21:57
@karticam karticam added core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests labels Oct 15, 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 implements the pinning and reporting of primary copies for moved consume_once objects across nodes. It introduces deferred release mechanics in ObjectBufferPool to prevent early eviction of objects before they are pinned, updates the ObjectManager and NodeManager to handle pinning and reporting, and adds comprehensive tests. The review feedback suggests replacing a static time.sleep(1) in the new integration tests with a dynamic wait_for_condition check to avoid potential flakiness and improve test execution speed.

@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 src/ray/core_worker/core_worker.cc Resolved
Comment thread src/ray/protobuf/core_worker.proto Resolved
@karticam karticam added the unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. label Oct 16, 2026

@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 src/ray/raylet/node_manager.cc 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.

Stale Bugbot comment from a previous 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 71624cb. Configure here.

@karticam
karticam force-pushed the karticam/consumer-pins-moved-object branch from 71624cb to daaf0b9 Compare November 3, 2026 03:07
@karticam
karticam force-pushed the karticam/consumer-pins-moved-object branch from daaf0b9 to 1c9aef1 Compare November 14, 2026 02:36
@Sparks0219
Sparks0219 force-pushed the karticam/consumer-pins-moved-object branch from 1c9aef1 to 6c82b15 Compare November 16, 2026 00:18
@karticam
karticam force-pushed the karticam/consumer-pins-moved-object branch from 6c82b15 to cf9317e Compare November 18, 2026 04:07
@Sparks0219
Sparks0219 force-pushed the karticam/consumer-pins-moved-object branch from cf9317e to 4d9737a Compare November 18, 2026 07:11
Comment thread src/ray/raylet/node_manager.cc Resolved
Comment thread src/ray/raylet/node_manager.cc Resolved
@Sparks0219

Copy link
Copy Markdown
Contributor

Ai comments from Claudius

  1. A failed move pull pins an error object forever (node_manager.cc:2493, object_manager.cc:278).
    • If the owner dies or the fetch times out during a move pull, MarkObjectFailed writes an error object with an empty owner address and seals it.
    • The move record is still live at that point, so HandleObjectLocal passes it to PinAndReportMovedObject. That function doesn't check for a missing owner, so the error object gets pinned.
    • The raylet only releases pinned objects when the owner sends a free or dies. Neither happens for an empty owner, so the pin is never released.
    • The report to the owner silently does nothing, and the new metric counts it as "pinned".
    • Fix: skip the pin when object_info.owner_worker_id.IsNil().
  2. Raylet crash in EnsureBufferExists (object_buffer_pool.cc:293, :315).
    • If a create with a different size arrives between the seal and ReleaseObject, AbortCreateInternal now returns early for sealed entries. The RAY_CHECK(!create_buffer_state_.contains(...)) that follows then fails.
    • The window is narrow, but it kills the raylet. Fix: return an error early when the existing entry is sealed.

Should fix

  • Destructor crash: ~ObjectBufferPool (object_buffer_pool.cc:57) still calls Abort on sealed deferred entries, and PlasmaClient::Abort has RAY_CHECK(!is_sealed). It only triggers if teardown lands in the seal→release window. Fix: release only, no abort.
  • The producer-death test passes without this PR. In test_consume_once_cross_node.py:115, ordinary recovery re-pins the consumer's existing copy anyway. To make it meaningful, add memory pressure on node B so an unpinned copy would be evicted, or add a C++ test on the owner-side HandleUpdateObjectLocationBatch.
  • Gemini's suggested fix for the sleep isn't enough. Waiting until node_b appears in the object's locations doesn't guarantee the move report has arrived, because ADDED can go out in an earlier batch.
  • Nit: the doc comment on num_moved_objects_pin_failed_ says only "left the store", but the counter also counts a dead owner and pending deletion.

@Sparks0219

Copy link
Copy Markdown
Contributor

maybe should try moving the order of create_bs.erase(...) to before the Release so Abort doesn't need to be modified?

@karticam

Copy link
Copy Markdown
Contributor Author

Thanks! Replies to #67093 (comment) and #67093 (comment):

  1. A failed move pull pins an error object forever. Fixed in c4353d1: PinAndReportMovedObject now returns early when the owner's worker ID is Nil (the error object MarkObjectFailed writes has no owner), so nothing is pinned or reported and it's counted as not pinned. Added TestHandleObjectLocalSkipsMovedObjectWithoutOwner.
  2. Raylet crash in EnsureBufferExists, and the destructor calling Abort on a sealed entry. Both fixed by your suggestion in 1dcfff1: WriteChunk now erases the CreateBufferState entry at every seal and, for a move, only keeps the store reference until ReleaseObject, which is now just the Release. No sealed entry lingers, so EnsureBufferExists, AbortCreate and the destructor never see one, and AbortCreateInternal is back to master's code. A second create for the sealed object is rejected by the plasma store (ObjectExists), the same as for any sealed object.
  3. The producer-death test passes without this PR. Agreed. Added a C++ test on the owner side in ffcae56 (CoreWorkerTest.PrimaryMovedReportMovesThePrimaryCopy): after a location batch with primary_moved_to_node_id, the owner records the consumer's node as primary, and removing the producer's node neither unpins the object nor queues its recovery. It fails if the owner ignores the report. The Python test stays as an end-to-end check.
  4. Gemini's suggested fix for the sleep. Agreed it isn't enough, since the location can arrive in an earlier batch than the move report, so I kept the sleep; the new C++ test covers the owner-side handling deterministically.
  5. Nit on num_moved_objects_pin_failed_. Fixed in ffcae56: the comment now lists every reason (owner missing or dead, copy left the store, pending deletion).

Base automatically changed from karticam/consumer-learns-is-move to master November 24, 2026 17:45
…y reason a moved pin is skipped

Signed-off-by: kartica.modi <[email protected]>
Each test starts a multi-node cluster, and the file takes 60 to 75 seconds on CI, past the 60 second limit of the small test group.

Signed-off-by: kartica.modi <[email protected]>
@Sparks0219
Sparks0219 force-pushed the karticam/consumer-pins-moved-object branch from e3cb95b to 0c0e534 Compare November 24, 2026 17:45

@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 merged commit b25c0e4 into master Nov 24, 2026
5 checks passed
@Sparks0219
Sparks0219 deleted the karticam/consumer-pins-moved-object branch November 24, 2026 21:36
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 unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants