Skip to content

Register named remote actors and avoid late PgLeave respawns#421

Open
adamrobbie wants to merge 4 commits into
slawlor:mainfrom
adamrobbie:issue-93-named-remote-registry
Open

Register named remote actors and avoid late PgLeave respawns#421
adamrobbie wants to merge 4 commits into
slawlor:mainfrom
adamrobbie:issue-93-named-remote-registry

Conversation

@adamrobbie

@adamrobbie adamrobbie commented Apr 23, 2026

Copy link
Copy Markdown

Summary

This PR makes named remote actors visible in the local named registry, matching the behavior of local actors. It also closes several lifecycle safety gaps that would have caused registry collisions and stale-message races.

Motivation

Addresses #93: "Remote actors don't appear in the local registry".

Remote actors already behave like local actors in most ways, but their names were not exposed through ractor::registry::where_is(...). That made name-based lookup inconsistent and reduced the usefulness of remote actors in cluster setups.

What changed

ractor/src/actor/actor_cell.rs

  • Re-enabled name registration for remote actors in ActorCell::new_remote
  • Name collisions (remote name already taken by a local actor) now log a warn! and skip registration instead of returning a hard SpawnErr. The shim is still spawned and reachable by pid.

ractor/src/actor/actor_ref.rs

  • Documented that ActorRef::<T>::where_is returns None for remote actors because remote shims are typed as RemoteActorMessage internally. Callers should use registry::where_is directly for untyped remote lookups.

ractor_cluster/src/node/node_session.rs

  • ActorFailed for a remote shim: kill and remove without immediately respawning. Respawning with the same pid reintroduces stale-message races and registry collisions; the remote node controls re-announcement via a new Spawn control message.
  • PgLeave for an unknown pid: log a debug message and skip instead of recreating the shim. If the actor already terminated locally, group membership was already cleaned up by the shutdown path.

PID registry behavior unchanged:

  • Local actors still register in the PID registry
  • Remote actors do not register in the PID registry

Regression tests added

  • Named remote actor appears in registry::where_is(...) and is removed on shutdown
  • Remote spawn with a colliding local name succeeds without evicting the local actor
  • ActorFailed on a remote shim does not respawn it
  • Late PgLeave after remote actor termination does not respawn the shim

Testing

  • cargo fmt --all
  • cargo clippy --all -- -D clippy::all -D warnings
  • cargo test -p ractor --features cluster remote_actor_with_name_is_registered -- --nocapture
  • cargo test -p ractor --features cluster remote_actor_name_collision_with_local_does_not_fail_spawn -- --nocapture
  • cargo test -p ractor_cluster node_session_handle_control -- --nocapture
  • cargo test -p ractor_cluster actor_failed_does_not_respawn_remote_actor -- --nocapture
  • cargo test -p ractor_cluster pg_leave_after_terminate_does_not_respawn_remote_actor -- --nocapture

@adamrobbie adamrobbie changed the title Register named remote actors in the local registry Register named remote actors and avoid late PgLeave respawns Apr 23, 2026
@adamrobbie

Copy link
Copy Markdown
Author

And thank you for a library like this.

Adam Robbie added 2 commits April 23, 2026 15:37
- ActorCell::new_remote now logs a warning and skips registration
  when the name is already taken, rather than returning a SpawnErr.
  The shim is still spawned and reachable by pid.
- Document that ActorRef::<T>::where_is returns None for remote actors
  because they are typed as RemoteActorMessage internally; callers
  should use registry::where_is directly for remote lookups.
- Add regression test: remote spawn with a colliding local name must
  not fail and must not evict the local actor from the registry.
Stop respawning the RemoteActor shim immediately when it panics.
Respawning with the same pid reintroduces stale-message races and
registry name collisions. The remote node controls re-announcement
via a new Spawn control message.

Also adds actor_failed_does_not_respawn_remote_actor regression test.
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.22%. Comparing base (4518baa) to head (6039f09).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
+ Coverage   86.00%   86.22%   +0.21%     
==========================================
  Files          73       73              
  Lines       13564    13791     +227     
==========================================
+ Hits        11666    11891     +225     
- Misses       1898     1900       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@slawlor

slawlor commented Jun 10, 2026

Copy link
Copy Markdown
Owner

can you fix the failing tests? Then I'm happy to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants