Skip to content

[core] Load restartable DEAD actors on GCS restart - #68721

Open
AshrafAhmed9 wants to merge 2 commits into
ray-project:masterfrom
AshrafAhmed9:fix-gcs-init-restartable-dead-actor
Open

AshrafAhmed9 wants to merge 2 commits into
ray-project:masterfrom
AshrafAhmed9:fix-gcs-init-restartable-dead-actor

Conversation

@AshrafAhmed9

@AshrafAhmed9 AshrafAhmed9 commented Dec 1, 2026 •

Copy link
Copy Markdown

Description

With GCS fault tolerance, a restartable actor that went out of scope (DEAD, OUT_OF_SCOPE, max_restarts=-1 or restarts left, job alive) makes the restarted GCS abort in GcsActorManager::Initialize. OnInitializeActorShouldLoad lets the actor through, but the task-spec GcsActor constructor checks state != DEAD, so every new GCS crashes on the same row.

This keeps the actor loaded, so it's still available for lineage reconstruction after a GCS restart, the same as without a restart:

  • The task-spec constructor allows DEAD only when IsActorRestartable is true.
  • Initialize rebuilds only what DestroyActor leaves in place for such an actor. It stays in registered_actors_ and named_actors_ and is registered under its owner's children_actor_ids_, because RemoveActorFromOwner checks for that entry when the reference is finally deleted (REF_DELETED). It gets no created_actors_ or worker entry, and the owner isn't polled again, because that poll already returned before the actor went out of scope.

Related issues

Closes #68705

No open PR or other issue covers this (searched open PRs for 68705 and for the GCS actor init path). #66073 fixed a different crash in the same init path, for actors without a task spec.

Additional information

Not changed here: DestroyActor only moves an out-of-scope actor's death cause to REF_DELETED, so an owner dying (OWNER_DIED) doesn't end a restartable out-of-scope actor. That's the same on master without a GCS restart, so I've kept it out of this PR.

One limitation: since the owner isn't polled again, an owner that dies while the GCS is down is only noticed if its worker or node failure is reported to the new GCS. Polling the owner again would catch that case, but the owner has already dropped its reference, so I left it out. Happy to change that if you prefer.

Testing: bazel test //src/ray/gcs/actor/tests:gcs_actor_manager_test passes (51 tests). The new TestInitializeLoadsRestartableDeadActor aborts on the state != DEAD check without the fix. TestDestroyReloadedRestartableDeadActor deletes the reference after the restart and checks the actor is removed; without the owner registration it aborts in RemoveActorFromOwner. TestInitializeDropsNonRestartableDeadActor checks that a max_restarts=0 actor is still dropped.

I used Claude Code (AI assistance) for this change. I reviewed every changed line and ran the tests above locally.

With GCS FT, a restartable actor that went out of scope (max_restarts=-1 or
restarts left, job alive) is DEAD in the actor table but still kept in
registered_actors_ for lineage reconstruction. On restart, Initialize built it
with the task-spec GcsActor constructor, which checked state != DEAD, so the
GCS aborted and crash-looped on every restart.

Allow DEAD in that constructor when the actor is restartable. Initialize then
rebuilds only what DestroyActor leaves in place for such an actor: it stays in
registered_actors_, named_actors_ and its owner's children, with no worker, no
created_actors_ entry and no owner polling.

Tested with gcs_actor_manager_test. The new restartable DEAD actor test aborts
on the CHECK without the fix and passes with it.

Closes ray-project#68705

Signed-off-by: Ashrafahmed9 <[email protected]>
@AshrafAhmed9
AshrafAhmed9 requested a review from a team as a code owner December 1, 2026 10:44

@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 updates the GCS actor initialization logic to support reloading restartable DEAD actors (e.g., those that went out of scope but still have restarts left) so they can be reconstructed via lineage reconstruction. It also adds corresponding unit tests. A review comment highlights a potential memory leak and lifecycle bug where a restartable DEAD actor is not properly cleaned up when its owner dies because the transition to the OWNER_DIED death cause is not handled in DestroyActor.

Comment on lines +1832 to +1838
if (actor->GetState() == ray::rpc::ActorTableData::DEAD) {
// A DEAD actor that got here is restartable (see OnInitializeActorShouldLoad),
// i.e. it went out of scope. Rebuild what DestroyActor leaves in place: it
// stays in registered_actors_, named_actors_ and its owner's children, but
// it has no worker and the owner is no longer polled for it. Registering
// the child lets the owner's death destroy it.
if (!actor->IsDetached()) {

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.

high

Memory Leak / Lifecycle Bug when Owner Dies

While registering the restartable DEAD actor under its owner's children_actor_ids_ is intended to let the owner's death destroy it, there is a lifecycle and memory leak issue in DestroyActor when handling already DEAD (out-of-scope) actors whose owners die.

The Issue:

  1. When the owner dies, OnWorkerDead is called, which invokes DestroyActor with OWNER_DIED as the death cause.
  2. In DestroyActor (around line 1113), the death cause of an already DEAD actor is only updated if the new cause is REF_DELETED:
    } else if (mutable_actor_table_data->death_cause().context_case() ==
                   ContextCase::kActorDiedErrorContext &&
               death_cause.context_case() == ContextCase::kActorDiedErrorContext &&
               mutable_actor_table_data->death_cause()
                       .actor_died_error_context()
                       .reason() == rpc::ActorDiedErrorContext::OUT_OF_SCOPE &&
               death_cause.actor_died_error_context().reason() ==
                   rpc::ActorDiedErrorContext::REF_DELETED) {
  3. Since OWNER_DIED does not match this condition, the actor's death cause remains OUT_OF_SCOPE.
  4. Consequently, is_restartable is evaluated as true (since OUT_OF_SCOPE with restarts left is restartable).
  5. Because is_restartable remains true, the actor is never erased from registered_actors_ or owners_ (via RemoveActorFromOwner).
  6. This results in a permanent memory leak of both the GcsActor and its owner entry in owners_.

Suggested Fix:

In DestroyActor (around line 1113), update the condition to also allow transition to OWNER_DIED (or any other terminal reason), which will correctly mark the actor as non-restartable and trigger the cleanup:

              (death_cause.actor_died_error_context().reason() == rpc::ActorDiedErrorContext::REF_DELETED ||
               death_cause.actor_died_error_context().reason() == rpc::ActorDiedErrorContext::OWNER_DIED))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch on the comment, it was wrong and is fixed in ee27c25. Owner death doesn't end an out-of-scope restartable actor because DestroyActor only moves the death cause to REF_DELETED, but that's the same on master without a GCS restart, so I've kept it out of this PR. The owner entry is still needed: RemoveActorFromOwner checks it when the reference is deleted, and the new TestDestroyReloadedRestartableDeadActor crashes there without it.

The owner entry restored in Initialize is needed by RemoveActorFromOwner when
DestroyActor runs with REF_DELETED, not for owner death. Fix the comment and add
a test that destroys a reloaded restartable DEAD actor.

Signed-off-by: Ashrafahmed9 <[email protected]>
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Dec 1, 2026

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] With GCS FT, GCS crash-loops on restart when a DEAD actor is still restartable

2 participants